@@ -93,7 +93,8 @@ |
||
| 93 | 93 | ?EventDispatcherInterface $dispatcher = null |
| 94 | 94 | ): FilterProvider { |
| 95 | 95 | $core = new InterceptableCore(new Core(), $dispatcher); |
| 96 | - foreach ($config->getInterceptors() as $interceptor) { |
|
| 96 | + foreach ($config->getInterceptors() as $interceptor) |
|
| 97 | + { |
|
| 97 | 98 | $core->addInterceptor($container->get($interceptor)); |
| 98 | 99 | } |
| 99 | 100 | |
@@ -34,7 +34,8 @@ discard block |
||
| 34 | 34 | $filter = $this->createFilterInstance($name); |
| 35 | 35 | [$mappingSchema, $errors, $setters, $optionalFilters] = $attributeMapper->map($filter, $input); |
| 36 | 36 | |
| 37 | - if ($filter instanceof HasFilterDefinition) { |
|
| 37 | + if ($filter instanceof HasFilterDefinition) |
|
| 38 | + { |
|
| 38 | 39 | $mappingSchema = \array_merge( |
| 39 | 40 | $mappingSchema, |
| 40 | 41 | $filter->filterDefinition()->mappingSchema() |
@@ -48,7 +49,8 @@ discard block |
||
| 48 | 49 | \assert($schemaBuilder instanceof Builder); |
| 49 | 50 | |
| 50 | 51 | $schema = $schemaBuilder->makeSchema($name, $mappingSchema); |
| 51 | - foreach ($optionalFilters as $optionalFilter) { |
|
| 52 | + foreach ($optionalFilters as $optionalFilter) |
|
| 53 | + { |
|
| 52 | 54 | $schema[$optionalFilter][Builder::SCHEMA_OPTIONAL] = true; |
| 53 | 55 | } |
| 54 | 56 | |
@@ -66,7 +68,8 @@ discard block |
||
| 66 | 68 | $class = new \ReflectionClass($name); |
| 67 | 69 | |
| 68 | 70 | $args = []; |
| 69 | - if ($constructor = $class->getConstructor()) { |
|
| 71 | + if ($constructor = $class->getConstructor()) |
|
| 72 | + { |
|
| 70 | 73 | $args = $this->resolver->resolveArguments($constructor); |
| 71 | 74 | } |
| 72 | 75 | |
@@ -35,45 +35,63 @@ discard block |
||
| 35 | 35 | $optionalFilters = []; |
| 36 | 36 | $class = new \ReflectionClass($filter); |
| 37 | 37 | |
| 38 | - foreach ($class->getProperties() as $property) { |
|
| 38 | + foreach ($class->getProperties() as $property) |
|
| 39 | + { |
|
| 39 | 40 | /** @var object $attribute */ |
| 40 | - foreach ($this->reader->getPropertyMetadata($property) as $attribute) { |
|
| 41 | - if ($attribute instanceof AbstractInput) { |
|
| 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) { |
|
| 54 | - if ($this->allowsNull($property)) { |
|
| 59 | + } |
|
| 60 | + catch (ValidationException $e) |
|
| 61 | + { |
|
| 62 | + if ($this->allowsNull($property)) |
|
| 63 | + { |
|
| 55 | 64 | $this->setValue($filter, $property, null); |
| 56 | 65 | $optionalFilters[] = $property->getName(); |
| 57 | - } else { |
|
| 66 | + } |
|
| 67 | + else |
|
| 68 | + { |
|
| 58 | 69 | $errors[$prefix] = $e->errors; |
| 59 | 70 | } |
| 60 | 71 | } |
| 61 | 72 | |
| 62 | 73 | $schema[$property->getName()] = $attribute->getSchema($property); |
| 63 | - } elseif ($attribute instanceof NestedArray) { |
|
| 74 | + } |
|
| 75 | + elseif ($attribute instanceof NestedArray) |
|
| 76 | + { |
|
| 64 | 77 | $values = $attribute->getValue($input, $property); |
| 65 | 78 | $propertyValues = []; |
| 66 | 79 | |
| 67 | 80 | $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName(); |
| 68 | 81 | |
| 69 | - if (\is_array($values)) { |
|
| 70 | - foreach (\array_keys($values) as $key) { |
|
| 71 | - try { |
|
| 82 | + if (\is_array($values)) |
|
| 83 | + { |
|
| 84 | + foreach (\array_keys($values) as $key) |
|
| 85 | + { |
|
| 86 | + try |
|
| 87 | + { |
|
| 72 | 88 | $propertyValues[$key] = $this->provider->createFilter( |
| 73 | 89 | $attribute->class, |
| 74 | 90 | $input->withPrefix($prefix . '.' . $key) |
| 75 | 91 | ); |
| 76 | - } catch (ValidationException $e) { |
|
| 92 | + } |
|
| 93 | + catch (ValidationException $e) |
|
| 94 | + { |
|
| 77 | 95 | $errors[$property->getName()][$key] = $e->errors; |
| 78 | 96 | } |
| 79 | 97 | } |
@@ -81,7 +99,9 @@ discard block |
||
| 81 | 99 | |
| 82 | 100 | $this->setValue($filter, $property, $propertyValues); |
| 83 | 101 | $schema[$property->getName()] = [$attribute->class, $prefix . '.*']; |
| 84 | - } elseif ($attribute instanceof Setter) { |
|
| 102 | + } |
|
| 103 | + elseif ($attribute instanceof Setter) |
|
| 104 | + { |
|
| 85 | 105 | $setters[$property->getName()][] = $attribute; |
| 86 | 106 | } |
| 87 | 107 | } |
@@ -92,13 +112,15 @@ discard block |
||
| 92 | 112 | |
| 93 | 113 | private function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
| 94 | 114 | { |
| 95 | - if ($value === null) { |
|
| 115 | + if ($value === null) |
|
| 116 | + { |
|
| 96 | 117 | return; |
| 97 | 118 | } |
| 98 | 119 | |
| 99 | 120 | $setters = $this->reader->getPropertyMetadata($property, Setter::class); |
| 100 | 121 | |
| 101 | - foreach ($setters as $setter) { |
|
| 122 | + foreach ($setters as $setter) |
|
| 123 | + { |
|
| 102 | 124 | $value = $setter->updateValue($value); |
| 103 | 125 | } |
| 104 | 126 | |
@@ -21,13 +21,17 @@ discard block |
||
| 21 | 21 | $errors = []; |
| 22 | 22 | $result = []; |
| 23 | 23 | |
| 24 | - foreach ($mappingSchema as $field => $map) { |
|
| 25 | - if (empty($map[Builder::SCHEMA_FILTER])) { |
|
| 24 | + foreach ($mappingSchema as $field => $map) |
|
| 25 | + { |
|
| 26 | + if (empty($map[Builder::SCHEMA_FILTER])) |
|
| 27 | + { |
|
| 26 | 28 | $value = $input->getValue($map[Builder::SCHEMA_SOURCE], $map[Builder::SCHEMA_ORIGIN]); |
| 27 | 29 | |
| 28 | - if ($value !== null) { |
|
| 30 | + if ($value !== null) |
|
| 31 | + { |
|
| 29 | 32 | /** @var Setter $setter */ |
| 30 | - foreach ($setters[$field] ?? [] as $setter) { |
|
| 33 | + foreach ($setters[$field] ?? [] as $setter) |
|
| 34 | + { |
|
| 31 | 35 | $value = $setter->updateValue($value); |
| 32 | 36 | } |
| 33 | 37 | |
@@ -37,12 +41,17 @@ discard block |
||
| 37 | 41 | } |
| 38 | 42 | |
| 39 | 43 | $nested = $map[Builder::SCHEMA_FILTER]; |
| 40 | - if (empty($map[Builder::SCHEMA_ARRAY])) { |
|
| 44 | + if (empty($map[Builder::SCHEMA_ARRAY])) |
|
| 45 | + { |
|
| 41 | 46 | // slicing down |
| 42 | - try { |
|
| 47 | + try |
|
| 48 | + { |
|
| 43 | 49 | $result[$field] = $this->provider->createFilter($nested, $input->withPrefix($map[Builder::SCHEMA_ORIGIN])); |
| 44 | - } catch (ValidationException $e) { |
|
| 45 | - if ($map[Builder::SCHEMA_OPTIONAL]) { |
|
| 50 | + } |
|
| 51 | + catch (ValidationException $e) |
|
| 52 | + { |
|
| 53 | + if ($map[Builder::SCHEMA_OPTIONAL]) |
|
| 54 | + { |
|
| 46 | 55 | $result[$field] = null; |
| 47 | 56 | continue; |
| 48 | 57 | } |
@@ -54,10 +63,14 @@ discard block |
||
| 54 | 63 | $values = []; |
| 55 | 64 | |
| 56 | 65 | // List of "key" => "location in request" |
| 57 | - foreach ($this->iterate($map, $input) as $index => $origin) { |
|
| 58 | - try { |
|
| 66 | + foreach ($this->iterate($map, $input) as $index => $origin) |
|
| 67 | + { |
|
| 68 | + try |
|
| 69 | + { |
|
| 59 | 70 | $values[$index] = $this->provider->createFilter($nested, $input->withPrefix($origin)); |
| 60 | - } catch (ValidationException $e) { |
|
| 71 | + } |
|
| 72 | + catch (ValidationException $e) |
|
| 73 | + { |
|
| 61 | 74 | $errors[$field][$index] = $e->errors; |
| 62 | 75 | } |
| 63 | 76 | } |
@@ -78,11 +91,13 @@ discard block |
||
| 78 | 91 | $schema[Builder::SCHEMA_ITERATE_ORIGIN] |
| 79 | 92 | ); |
| 80 | 93 | |
| 81 | - if (empty($values) || !\is_array($values)) { |
|
| 94 | + if (empty($values) || !\is_array($values)) |
|
| 95 | + { |
|
| 82 | 96 | return []; |
| 83 | 97 | } |
| 84 | 98 | |
| 85 | - foreach (\array_keys($values) as $key) { |
|
| 99 | + foreach (\array_keys($values) as $key) |
|
| 100 | + { |
|
| 86 | 101 | yield $key => $schema[Builder::SCHEMA_ORIGIN] . '.' . $key; |
| 87 | 102 | } |
| 88 | 103 | } |
@@ -11,7 +11,8 @@ |
||
| 11 | 11 | |
| 12 | 12 | public function __construct(array $casters = []) |
| 13 | 13 | { |
| 14 | - foreach ($casters as $caster) { |
|
| 14 | + foreach ($casters as $caster) |
|
| 15 | + { |
|
| 15 | 16 | $this->register($caster); |
| 16 | 17 | } |
| 17 | 18 | } |
@@ -22,9 +22,12 @@ |
||
| 22 | 22 | public function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
| 23 | 23 | { |
| 24 | 24 | $type = $property->getType(); |
| 25 | - if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) { |
|
| 26 | - foreach ($this->registry->getCasters() as $setter) { |
|
| 27 | - if ($setter->supports($type)) { |
|
| 25 | + if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) |
|
| 26 | + { |
|
| 27 | + foreach ($this->registry->getCasters() as $setter) |
|
| 28 | + { |
|
| 29 | + if ($setter->supports($type)) |
|
| 30 | + { |
|
| 28 | 31 | $setter->setValue($filter, $property, $value); |
| 29 | 32 | return; |
| 30 | 33 | } |