@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function makeSchema(string $name, array $schema): array |
44 | 44 | { |
45 | - if (empty($schema)) { |
|
45 | + if (empty($schema)){ |
|
46 | 46 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
47 | 47 | } |
48 | 48 | |
49 | 49 | $result = []; |
50 | - foreach ($schema as $field => $definition) { |
|
50 | + foreach ($schema as $field => $definition){ |
|
51 | 51 | $optional = false; |
52 | 52 | |
53 | 53 | // short definition |
54 | - if (\is_string($definition)) { |
|
54 | + if (\is_string($definition)){ |
|
55 | 55 | // simple scalar field definition |
56 | - if (!\class_exists($definition)) { |
|
56 | + if (!\class_exists($definition)){ |
|
57 | 57 | [$source, $origin] = $this->parseDefinition($field, $definition); |
58 | 58 | $result[$field] = [ |
59 | 59 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +74,25 @@ discard block |
||
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - if (!\is_array($definition) || $definition === []) { |
|
77 | + if (!\is_array($definition) || $definition === []){ |
|
78 | 78 | throw new SchemaException( |
79 | 79 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
83 | 83 | // complex definition |
84 | - if (!empty($definition[self::ORIGIN])) { |
|
84 | + if (!empty($definition[self::ORIGIN])){ |
|
85 | 85 | $origin = $definition[self::ORIGIN]; |
86 | 86 | |
87 | 87 | // [class, 'data:something.*'] vs [class, 'data:something'] |
88 | 88 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
89 | 89 | $origin = \rtrim($origin, '.*'); |
90 | - } else { |
|
90 | + }else{ |
|
91 | 91 | $origin = $field; |
92 | 92 | $iterate = true; |
93 | 93 | } |
94 | 94 | |
95 | - if (!empty($definition[self::OPTIONAL])) { |
|
95 | + if (!empty($definition[self::OPTIONAL])){ |
|
96 | 96 | $optional = true; |
97 | 97 | } |
98 | 98 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | self::SCHEMA_OPTIONAL => $optional, |
106 | 106 | ]; |
107 | 107 | |
108 | - if ($iterate) { |
|
108 | + if ($iterate){ |
|
109 | 109 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
110 | 110 | |
111 | 111 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | 'path', |
138 | 138 | 'remoteAddress', |
139 | 139 | 'uri', |
140 | - ], true)) { |
|
140 | + ], true)){ |
|
141 | 141 | return [$definition, $field]; |
142 | 142 | } |
143 | 143 | |
144 | - if (!\str_contains($definition, ':')) { |
|
144 | + if (!\str_contains($definition, ':')){ |
|
145 | 145 | return ['data', empty($definition) ? $field : $definition]; |
146 | 146 | } |
147 | 147 |
@@ -42,18 +42,22 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function makeSchema(string $name, array $schema): array |
44 | 44 | { |
45 | - if (empty($schema)) { |
|
45 | + if (empty($schema)) |
|
46 | + { |
|
46 | 47 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
47 | 48 | } |
48 | 49 | |
49 | 50 | $result = []; |
50 | - foreach ($schema as $field => $definition) { |
|
51 | + foreach ($schema as $field => $definition) |
|
52 | + { |
|
51 | 53 | $optional = false; |
52 | 54 | |
53 | 55 | // short definition |
54 | - if (\is_string($definition)) { |
|
56 | + if (\is_string($definition)) |
|
57 | + { |
|
55 | 58 | // simple scalar field definition |
56 | - if (!\class_exists($definition)) { |
|
59 | + if (!\class_exists($definition)) |
|
60 | + { |
|
57 | 61 | [$source, $origin] = $this->parseDefinition($field, $definition); |
58 | 62 | $result[$field] = [ |
59 | 63 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +78,30 @@ discard block |
||
74 | 78 | continue; |
75 | 79 | } |
76 | 80 | |
77 | - if (!\is_array($definition) || $definition === []) { |
|
81 | + if (!\is_array($definition) || $definition === []) |
|
82 | + { |
|
78 | 83 | throw new SchemaException( |
79 | 84 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
80 | 85 | ); |
81 | 86 | } |
82 | 87 | |
83 | 88 | // complex definition |
84 | - if (!empty($definition[self::ORIGIN])) { |
|
89 | + if (!empty($definition[self::ORIGIN])) |
|
90 | + { |
|
85 | 91 | $origin = $definition[self::ORIGIN]; |
86 | 92 | |
87 | 93 | // [class, 'data:something.*'] vs [class, 'data:something'] |
88 | 94 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
89 | 95 | $origin = \rtrim($origin, '.*'); |
90 | - } else { |
|
96 | + } |
|
97 | + else |
|
98 | + { |
|
91 | 99 | $origin = $field; |
92 | 100 | $iterate = true; |
93 | 101 | } |
94 | 102 | |
95 | - if (!empty($definition[self::OPTIONAL])) { |
|
103 | + if (!empty($definition[self::OPTIONAL])) |
|
104 | + { |
|
96 | 105 | $optional = true; |
97 | 106 | } |
98 | 107 | |
@@ -105,7 +114,8 @@ discard block |
||
105 | 114 | self::SCHEMA_OPTIONAL => $optional, |
106 | 115 | ]; |
107 | 116 | |
108 | - if ($iterate) { |
|
117 | + if ($iterate) |
|
118 | + { |
|
109 | 119 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
110 | 120 | |
111 | 121 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -137,11 +147,13 @@ discard block |
||
137 | 147 | 'path', |
138 | 148 | 'remoteAddress', |
139 | 149 | 'uri', |
140 | - ], true)) { |
|
150 | + ], true)) |
|
151 | + { |
|
141 | 152 | return [$definition, $field]; |
142 | 153 | } |
143 | 154 | |
144 | - if (!\str_contains($definition, ':')) { |
|
155 | + if (!\str_contains($definition, ':')) |
|
156 | + { |
|
145 | 157 | return ['data', empty($definition) ? $field : $definition]; |
146 | 158 | } |
147 | 159 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | public function __construct( |
17 | 17 | private readonly SchemaProviderInterface $schemaProvider, |
18 | 18 | private readonly SetterRegistryInterface $registry |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -26,29 +26,29 @@ discard block |
||
26 | 26 | { |
27 | 27 | $class = new \ReflectionClass($filter); |
28 | 28 | |
29 | - foreach ($this->schemaProvider->getSchema($filter) as $field => $map) { |
|
30 | - if (!empty($map[Builder::SCHEMA_FILTER]) && $data[$field] === []) { |
|
29 | + foreach ($this->schemaProvider->getSchema($filter) as $field => $map){ |
|
30 | + if (!empty($map[Builder::SCHEMA_FILTER]) && $data[$field] === []){ |
|
31 | 31 | continue; |
32 | 32 | } |
33 | 33 | |
34 | 34 | $property = $class->getProperty($field); |
35 | - if (!empty($map[Builder::SCHEMA_FILTER])) { |
|
35 | + if (!empty($map[Builder::SCHEMA_FILTER])){ |
|
36 | 36 | $this->registry->getDefault()->setValue($filter, $property, $data[$field]); |
37 | 37 | continue; |
38 | 38 | } |
39 | 39 | $type = $property->getType(); |
40 | - if (!isset($data[$field]) && $type->allowsNull()) { |
|
40 | + if (!isset($data[$field]) && $type->allowsNull()){ |
|
41 | 41 | $this->registry->getDefault()->setValue($filter, $property, null); |
42 | 42 | continue; |
43 | 43 | } |
44 | 44 | |
45 | - if (!$type instanceof \ReflectionNamedType || $type->isBuiltin()) { |
|
45 | + if (!$type instanceof \ReflectionNamedType || $type->isBuiltin()){ |
|
46 | 46 | $this->registry->getDefault()->setValue($filter, $property, $data[$field]); |
47 | 47 | continue; |
48 | 48 | } |
49 | 49 | |
50 | - foreach ($this->registry->getSetters() as $setter) { |
|
51 | - if ($setter->supports($type)) { |
|
50 | + foreach ($this->registry->getSetters() as $setter){ |
|
51 | + if ($setter->supports($type)){ |
|
52 | 52 | $setter->setValue($filter, $property, $data[$field]); |
53 | 53 | } |
54 | 54 | } |
@@ -26,29 +26,36 @@ |
||
26 | 26 | { |
27 | 27 | $class = new \ReflectionClass($filter); |
28 | 28 | |
29 | - foreach ($this->schemaProvider->getSchema($filter) as $field => $map) { |
|
30 | - if (!empty($map[Builder::SCHEMA_FILTER]) && $data[$field] === []) { |
|
29 | + foreach ($this->schemaProvider->getSchema($filter) as $field => $map) |
|
30 | + { |
|
31 | + if (!empty($map[Builder::SCHEMA_FILTER]) && $data[$field] === []) |
|
32 | + { |
|
31 | 33 | continue; |
32 | 34 | } |
33 | 35 | |
34 | 36 | $property = $class->getProperty($field); |
35 | - if (!empty($map[Builder::SCHEMA_FILTER])) { |
|
37 | + if (!empty($map[Builder::SCHEMA_FILTER])) |
|
38 | + { |
|
36 | 39 | $this->registry->getDefault()->setValue($filter, $property, $data[$field]); |
37 | 40 | continue; |
38 | 41 | } |
39 | 42 | $type = $property->getType(); |
40 | - if (!isset($data[$field]) && $type->allowsNull()) { |
|
43 | + if (!isset($data[$field]) && $type->allowsNull()) |
|
44 | + { |
|
41 | 45 | $this->registry->getDefault()->setValue($filter, $property, null); |
42 | 46 | continue; |
43 | 47 | } |
44 | 48 | |
45 | - if (!$type instanceof \ReflectionNamedType || $type->isBuiltin()) { |
|
49 | + if (!$type instanceof \ReflectionNamedType || $type->isBuiltin()) |
|
50 | + { |
|
46 | 51 | $this->registry->getDefault()->setValue($filter, $property, $data[$field]); |
47 | 52 | continue; |
48 | 53 | } |
49 | 54 | |
50 | - foreach ($this->registry->getSetters() as $setter) { |
|
51 | - if ($setter->supports($type)) { |
|
55 | + foreach ($this->registry->getSetters() as $setter) |
|
56 | + { |
|
57 | + if ($setter->supports($type)) |
|
58 | + { |
|
52 | 59 | $setter->setValue($filter, $property, $data[$field]); |
53 | 60 | } |
54 | 61 | } |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | public function __construct( |
34 | 34 | private readonly array $readers, |
35 | 35 | private readonly Builder $schemaBuilder |
36 | - ) { |
|
36 | + ){ |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function getSchema(FilterInterface $filter): array |
40 | 40 | { |
41 | - if (!isset($this->schema[$filter::class])) { |
|
41 | + if (!isset($this->schema[$filter::class])){ |
|
42 | 42 | $this->read($filter); |
43 | 43 | } |
44 | 44 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | public function getSetters(FilterInterface $filter): array |
52 | 52 | { |
53 | - if (!isset($this->setters[$filter::class])) { |
|
53 | + if (!isset($this->setters[$filter::class])){ |
|
54 | 54 | $this->read($filter); |
55 | 55 | } |
56 | 56 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | { |
62 | 62 | $this->schema[$filter::class] = []; |
63 | 63 | $this->setters[$filter::class] = []; |
64 | - foreach ($this->readers as $reader) { |
|
64 | + foreach ($this->readers as $reader){ |
|
65 | 65 | [$readSchema, $readSetters] = $reader->read($filter); |
66 | 66 | $this->schema[$filter::class] = \array_merge($this->schema[$filter::class], $readSchema); |
67 | 67 | $this->setters[$filter::class] = \array_merge($this->setters[$filter::class], $readSetters); |
@@ -70,20 +70,20 @@ discard block |
||
70 | 70 | |
71 | 71 | private function markOptionalFilters(FilterInterface $filter, array $schema): array |
72 | 72 | { |
73 | - if (!isset($this->optionalFilters[$filter::class])) { |
|
73 | + if (!isset($this->optionalFilters[$filter::class])){ |
|
74 | 74 | $this->optionalFilters[$filter::class] = []; |
75 | - foreach ($schema as $field => $map) { |
|
76 | - if (!empty($map[Builder::SCHEMA_FILTER])) { |
|
75 | + foreach ($schema as $field => $map){ |
|
76 | + if (!empty($map[Builder::SCHEMA_FILTER])){ |
|
77 | 77 | $property = new \ReflectionProperty($filter, $field); |
78 | 78 | $type = $property->getType(); |
79 | - if ($type instanceof \ReflectionNamedType && $type->allowsNull()) { |
|
79 | + if ($type instanceof \ReflectionNamedType && $type->allowsNull()){ |
|
80 | 80 | $this->optionalFilters[$filter::class][] = $field; |
81 | 81 | } |
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - foreach ($this->optionalFilters[$filter::class] as $field) { |
|
86 | + foreach ($this->optionalFilters[$filter::class] as $field){ |
|
87 | 87 | $schema[$field][Builder::SCHEMA_OPTIONAL] = true; |
88 | 88 | } |
89 | 89 |
@@ -38,7 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | public function getSchema(FilterInterface $filter): array |
40 | 40 | { |
41 | - if (!isset($this->schema[$filter::class])) { |
|
41 | + if (!isset($this->schema[$filter::class])) |
|
42 | + { |
|
42 | 43 | $this->read($filter); |
43 | 44 | } |
44 | 45 | |
@@ -50,7 +51,8 @@ discard block |
||
50 | 51 | |
51 | 52 | public function getSetters(FilterInterface $filter): array |
52 | 53 | { |
53 | - if (!isset($this->setters[$filter::class])) { |
|
54 | + if (!isset($this->setters[$filter::class])) |
|
55 | + { |
|
54 | 56 | $this->read($filter); |
55 | 57 | } |
56 | 58 | |
@@ -61,7 +63,8 @@ discard block |
||
61 | 63 | { |
62 | 64 | $this->schema[$filter::class] = []; |
63 | 65 | $this->setters[$filter::class] = []; |
64 | - foreach ($this->readers as $reader) { |
|
66 | + foreach ($this->readers as $reader) |
|
67 | + { |
|
65 | 68 | [$readSchema, $readSetters] = $reader->read($filter); |
66 | 69 | $this->schema[$filter::class] = \array_merge($this->schema[$filter::class], $readSchema); |
67 | 70 | $this->setters[$filter::class] = \array_merge($this->setters[$filter::class], $readSetters); |
@@ -70,20 +73,25 @@ discard block |
||
70 | 73 | |
71 | 74 | private function markOptionalFilters(FilterInterface $filter, array $schema): array |
72 | 75 | { |
73 | - if (!isset($this->optionalFilters[$filter::class])) { |
|
76 | + if (!isset($this->optionalFilters[$filter::class])) |
|
77 | + { |
|
74 | 78 | $this->optionalFilters[$filter::class] = []; |
75 | - foreach ($schema as $field => $map) { |
|
76 | - if (!empty($map[Builder::SCHEMA_FILTER])) { |
|
79 | + foreach ($schema as $field => $map) |
|
80 | + { |
|
81 | + if (!empty($map[Builder::SCHEMA_FILTER])) |
|
82 | + { |
|
77 | 83 | $property = new \ReflectionProperty($filter, $field); |
78 | 84 | $type = $property->getType(); |
79 | - if ($type instanceof \ReflectionNamedType && $type->allowsNull()) { |
|
85 | + if ($type instanceof \ReflectionNamedType && $type->allowsNull()) |
|
86 | + { |
|
80 | 87 | $this->optionalFilters[$filter::class][] = $field; |
81 | 88 | } |
82 | 89 | } |
83 | 90 | } |
84 | 91 | } |
85 | 92 | |
86 | - foreach ($this->optionalFilters[$filter::class] as $field) { |
|
93 | + foreach ($this->optionalFilters[$filter::class] as $field) |
|
94 | + { |
|
87 | 95 | $schema[$field][Builder::SCHEMA_OPTIONAL] = true; |
88 | 96 | } |
89 | 97 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | private readonly FilterProviderInterface $provider, |
20 | 20 | private readonly SchemaProviderInterface $schemaProvider, |
21 | 21 | private readonly FilterFactory $filterFactory |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function map(array $mappingSchema, InputInterface $input, array $setters = []): array |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | $errors = []; |
28 | 28 | $result = $this->mapData($mappingSchema, $input, $setters); |
29 | 29 | |
30 | - foreach ($mappingSchema as $field => $map) { |
|
31 | - if (empty($map[Builder::SCHEMA_FILTER])) { |
|
30 | + foreach ($mappingSchema as $field => $map){ |
|
31 | + if (empty($map[Builder::SCHEMA_FILTER])){ |
|
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | 35 | $nested = $map[Builder::SCHEMA_FILTER]; |
36 | - if (empty($map[Builder::SCHEMA_ARRAY])) { |
|
36 | + if (empty($map[Builder::SCHEMA_ARRAY])){ |
|
37 | 37 | // slicing down |
38 | - try { |
|
38 | + try{ |
|
39 | 39 | $result[$field] = $this->provider->createFilter($nested, $input->withPrefix($map[Builder::SCHEMA_ORIGIN])); |
40 | - } catch (ValidationException $e) { |
|
41 | - if ($map[Builder::SCHEMA_OPTIONAL]) { |
|
40 | + }catch (ValidationException $e){ |
|
41 | + if ($map[Builder::SCHEMA_OPTIONAL]){ |
|
42 | 42 | $result[$field] = null; |
43 | 43 | continue; |
44 | 44 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $values = []; |
52 | 52 | |
53 | 53 | // List of "key" => "location in request" |
54 | - foreach ($this->iterate($map, $input) as $index => $origin) { |
|
55 | - try { |
|
54 | + foreach ($this->iterate($map, $input) as $index => $origin){ |
|
55 | + try{ |
|
56 | 56 | $values[$index] = $this->provider->createFilter($nested, $input->withPrefix($origin)); |
57 | - } catch (ValidationException $e) { |
|
57 | + }catch (ValidationException $e){ |
|
58 | 58 | $errors[$field][$index] = $e->errors; |
59 | 59 | } |
60 | 60 | } |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | public function mapData(array $mappingSchema, InputInterface $input, array $setters = []): array |
69 | 69 | { |
70 | 70 | $result = []; |
71 | - foreach ($mappingSchema as $field => $map) { |
|
72 | - if (empty($map[Builder::SCHEMA_FILTER])) { |
|
71 | + foreach ($mappingSchema as $field => $map){ |
|
72 | + if (empty($map[Builder::SCHEMA_FILTER])){ |
|
73 | 73 | $value = $input->getValue($map[Builder::SCHEMA_SOURCE], $map[Builder::SCHEMA_ORIGIN]); |
74 | 74 | |
75 | - if ($value !== null) { |
|
75 | + if ($value !== null){ |
|
76 | 76 | /** @var Setter $setter */ |
77 | - foreach ($setters[$field] ?? [] as $setter) { |
|
77 | + foreach ($setters[$field] ?? [] as $setter){ |
|
78 | 78 | $value = $setter->updateValue($value); |
79 | 79 | } |
80 | 80 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | continue; |
84 | 84 | } |
85 | 85 | |
86 | - if (empty($map[Builder::SCHEMA_ARRAY])) { |
|
86 | + if (empty($map[Builder::SCHEMA_ARRAY])){ |
|
87 | 87 | $filter = $this->filterFactory->createFilterInstance($map[Builder::SCHEMA_FILTER]); |
88 | 88 | $result[$field] = $this->mapData( |
89 | 89 | $this->schemaProvider->getSchema($filter), |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | $schema[Builder::SCHEMA_ITERATE_ORIGIN] |
107 | 107 | ); |
108 | 108 | |
109 | - if (empty($values) || !\is_array($values)) { |
|
109 | + if (empty($values) || !\is_array($values)){ |
|
110 | 110 | return []; |
111 | 111 | } |
112 | 112 | |
113 | - foreach (\array_keys($values) as $key) { |
|
114 | - yield $key => $schema[Builder::SCHEMA_ORIGIN] . '.' . $key; |
|
113 | + foreach (\array_keys($values) as $key){ |
|
114 | + yield $key => $schema[Builder::SCHEMA_ORIGIN].'.'.$key; |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | } |
@@ -27,18 +27,25 @@ discard block |
||
27 | 27 | $errors = []; |
28 | 28 | $result = $this->mapData($mappingSchema, $input, $setters); |
29 | 29 | |
30 | - foreach ($mappingSchema as $field => $map) { |
|
31 | - if (empty($map[Builder::SCHEMA_FILTER])) { |
|
30 | + foreach ($mappingSchema as $field => $map) |
|
31 | + { |
|
32 | + if (empty($map[Builder::SCHEMA_FILTER])) |
|
33 | + { |
|
32 | 34 | continue; |
33 | 35 | } |
34 | 36 | |
35 | 37 | $nested = $map[Builder::SCHEMA_FILTER]; |
36 | - if (empty($map[Builder::SCHEMA_ARRAY])) { |
|
38 | + if (empty($map[Builder::SCHEMA_ARRAY])) |
|
39 | + { |
|
37 | 40 | // slicing down |
38 | - try { |
|
41 | + try |
|
42 | + { |
|
39 | 43 | $result[$field] = $this->provider->createFilter($nested, $input->withPrefix($map[Builder::SCHEMA_ORIGIN])); |
40 | - } catch (ValidationException $e) { |
|
41 | - if ($map[Builder::SCHEMA_OPTIONAL]) { |
|
44 | + } |
|
45 | + catch (ValidationException $e) |
|
46 | + { |
|
47 | + if ($map[Builder::SCHEMA_OPTIONAL]) |
|
48 | + { |
|
42 | 49 | $result[$field] = null; |
43 | 50 | continue; |
44 | 51 | } |
@@ -51,10 +58,14 @@ discard block |
||
51 | 58 | $values = []; |
52 | 59 | |
53 | 60 | // List of "key" => "location in request" |
54 | - foreach ($this->iterate($map, $input) as $index => $origin) { |
|
55 | - try { |
|
61 | + foreach ($this->iterate($map, $input) as $index => $origin) |
|
62 | + { |
|
63 | + try |
|
64 | + { |
|
56 | 65 | $values[$index] = $this->provider->createFilter($nested, $input->withPrefix($origin)); |
57 | - } catch (ValidationException $e) { |
|
66 | + } |
|
67 | + catch (ValidationException $e) |
|
68 | + { |
|
58 | 69 | $errors[$field][$index] = $e->errors; |
59 | 70 | } |
60 | 71 | } |
@@ -68,13 +79,17 @@ discard block |
||
68 | 79 | public function mapData(array $mappingSchema, InputInterface $input, array $setters = []): array |
69 | 80 | { |
70 | 81 | $result = []; |
71 | - foreach ($mappingSchema as $field => $map) { |
|
72 | - if (empty($map[Builder::SCHEMA_FILTER])) { |
|
82 | + foreach ($mappingSchema as $field => $map) |
|
83 | + { |
|
84 | + if (empty($map[Builder::SCHEMA_FILTER])) |
|
85 | + { |
|
73 | 86 | $value = $input->getValue($map[Builder::SCHEMA_SOURCE], $map[Builder::SCHEMA_ORIGIN]); |
74 | 87 | |
75 | - if ($value !== null) { |
|
88 | + if ($value !== null) |
|
89 | + { |
|
76 | 90 | /** @var Setter $setter */ |
77 | - foreach ($setters[$field] ?? [] as $setter) { |
|
91 | + foreach ($setters[$field] ?? [] as $setter) |
|
92 | + { |
|
78 | 93 | $value = $setter->updateValue($value); |
79 | 94 | } |
80 | 95 | |
@@ -83,7 +98,8 @@ discard block |
||
83 | 98 | continue; |
84 | 99 | } |
85 | 100 | |
86 | - if (empty($map[Builder::SCHEMA_ARRAY])) { |
|
101 | + if (empty($map[Builder::SCHEMA_ARRAY])) |
|
102 | + { |
|
87 | 103 | $filter = $this->filterFactory->createFilterInstance($map[Builder::SCHEMA_FILTER]); |
88 | 104 | $result[$field] = $this->mapData( |
89 | 105 | $this->schemaProvider->getSchema($filter), |
@@ -106,11 +122,13 @@ discard block |
||
106 | 122 | $schema[Builder::SCHEMA_ITERATE_ORIGIN] |
107 | 123 | ); |
108 | 124 | |
109 | - if (empty($values) || !\is_array($values)) { |
|
125 | + if (empty($values) || !\is_array($values)) |
|
126 | + { |
|
110 | 127 | return []; |
111 | 128 | } |
112 | 129 | |
113 | - foreach (\array_keys($values) as $key) { |
|
130 | + foreach (\array_keys($values) as $key) |
|
131 | + { |
|
114 | 132 | yield $key => $schema[Builder::SCHEMA_ORIGIN] . '.' . $key; |
115 | 133 | } |
116 | 134 | } |