| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Data\Didit;
- abstract readonly class DiditData
- {
- abstract public function toArray(): array;
- protected static function digits(?string $value): string
- {
- return preg_replace('/\D+/', '', (string) $value) ?? '';
- }
- protected function filterFilledRecursive(array $data): array
- {
- $filtered = [];
- foreach ($data as $key => $value) {
- if ($value instanceof self) {
- $value = $value->toArray();
- }
- if (is_array($value)) {
- $value = $this->filterFilledRecursive($value);
- }
- if ($value !== null && $value !== '' && $value !== []) {
- $filtered[$key] = $value;
- }
- }
- return $filtered;
- }
- protected static function requireFilled(mixed $value, string $field): void
- {
- if ($value === null || $value === '' || $value === []) {
- throw new \InvalidArgumentException("{$field} e obrigatorio.");
- }
- }
- }
|