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