@@ -36,39 +36,54 @@ discard block |
||
| 36 | 36 | $schema = []; |
| 37 | 37 | $class = new \ReflectionClass($filter); |
| 38 | 38 | |
| 39 | - foreach ($class->getProperties() as $property) { |
|
| 40 | - foreach ($this->reader->getPropertyMetadata($property) as $attribute) { |
|
| 41 | - if ($attribute instanceof AbstractInput) { |
|
| 39 | + foreach ($class->getProperties() as $property) |
|
| 40 | + { |
|
| 41 | + foreach ($this->reader->getPropertyMetadata($property) as $attribute) |
|
| 42 | + { |
|
| 43 | + if ($attribute instanceof AbstractInput) |
|
| 44 | + { |
|
| 42 | 45 | $this->setValue($filter, $property, $attribute->getValue($input, $property)); |
| 43 | 46 | $schema[$property->getName()] = $attribute->getSchema($property); |
| 44 | - } elseif ($attribute instanceof NestedFilter) { |
|
| 47 | + } |
|
| 48 | + elseif ($attribute instanceof NestedFilter) |
|
| 49 | + { |
|
| 45 | 50 | $prefix = $attribute->prefix ?? $property->name; |
| 46 | - try { |
|
| 51 | + try |
|
| 52 | + { |
|
| 47 | 53 | $value = $this->provider->createFilter( |
| 48 | 54 | $attribute->class, |
| 49 | 55 | $input->withPrefix($prefix) |
| 50 | 56 | ); |
| 51 | 57 | |
| 52 | 58 | $this->setValue($filter, $property, $value); |
| 53 | - } catch (ValidationException $e) { |
|
| 59 | + } |
|
| 60 | + catch (ValidationException $e) |
|
| 61 | + { |
|
| 54 | 62 | $errors[$prefix] = $e->errors; |
| 55 | 63 | } |
| 56 | 64 | |
| 57 | 65 | $schema[$property->getName()] = $attribute->getSchema($property); |
| 58 | - } elseif ($attribute instanceof NestedArray) { |
|
| 66 | + } |
|
| 67 | + elseif ($attribute instanceof NestedArray) |
|
| 68 | + { |
|
| 59 | 69 | $values = $attribute->getValue($input, $property); |
| 60 | 70 | $propertyValues = []; |
| 61 | 71 | |
| 62 | 72 | $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName(); |
| 63 | 73 | |
| 64 | - if (\is_array($values)) { |
|
| 65 | - foreach (\array_keys($values) as $key) { |
|
| 66 | - try { |
|
| 74 | + if (\is_array($values)) |
|
| 75 | + { |
|
| 76 | + foreach (\array_keys($values) as $key) |
|
| 77 | + { |
|
| 78 | + try |
|
| 79 | + { |
|
| 67 | 80 | $propertyValues[$key] = $this->provider->createFilter( |
| 68 | 81 | $attribute->class, |
| 69 | 82 | $input->withPrefix($prefix . '.' . $key) |
| 70 | 83 | ); |
| 71 | - } catch (ValidationException $e) { |
|
| 84 | + } |
|
| 85 | + catch (ValidationException $e) |
|
| 86 | + { |
|
| 72 | 87 | $errors[$property->getName()][$key] = $e->errors; |
| 73 | 88 | } |
| 74 | 89 | } |
@@ -85,13 +100,15 @@ discard block |
||
| 85 | 100 | |
| 86 | 101 | private function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
| 87 | 102 | { |
| 88 | - if ($value === null) { |
|
| 103 | + if ($value === null) |
|
| 104 | + { |
|
| 89 | 105 | return; |
| 90 | 106 | } |
| 91 | 107 | |
| 92 | 108 | $setters = $this->reader->getPropertyMetadata($property, Setter::class); |
| 93 | 109 | |
| 94 | - foreach ($setters as $setter) { |
|
| 110 | + foreach ($setters as $setter) |
|
| 111 | + { |
|
| 95 | 112 | $value = $setter->updateValue($value); |
| 96 | 113 | } |
| 97 | 114 | |