@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function __construct( |
| 23 | 23 | private readonly FilterProviderInterface $provider, |
| 24 | 24 | private readonly ReaderInterface $reader |
| 25 | - ) { |
|
| 25 | + ){ |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -36,46 +36,46 @@ 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 | + 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) { |
|
| 53 | + }catch (ValidationException $e){ |
|
| 54 | 54 | $errors[$prefix] = $e->errors; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $schema[$property->getName()] = $attribute->getSchema($property); |
| 58 | - } elseif ($attribute instanceof NestedArray) { |
|
| 58 | + } elseif ($attribute instanceof NestedArray){ |
|
| 59 | 59 | $values = $attribute->getValue($input, $property); |
| 60 | 60 | $propertyValues = []; |
| 61 | 61 | |
| 62 | 62 | $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName(); |
| 63 | 63 | |
| 64 | - if (\is_array($values)) { |
|
| 65 | - foreach (\array_keys($values) as $key) { |
|
| 66 | - try { |
|
| 64 | + if (\is_array($values)){ |
|
| 65 | + foreach (\array_keys($values) as $key){ |
|
| 66 | + try{ |
|
| 67 | 67 | $propertyValues[$key] = $this->provider->createFilter( |
| 68 | 68 | $attribute->class, |
| 69 | - $input->withPrefix($prefix . '.' . $key) |
|
| 69 | + $input->withPrefix($prefix.'.'.$key) |
|
| 70 | 70 | ); |
| 71 | - } catch (ValidationException $e) { |
|
| 71 | + }catch (ValidationException $e){ |
|
| 72 | 72 | $errors[$property->getName()][$key] = $e->errors; |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $this->setValue($filter, $property, $propertyValues); |
| 78 | - $schema[$property->getName()] = [$attribute->class, $prefix . '.*']; |
|
| 78 | + $schema[$property->getName()] = [$attribute->class, $prefix.'.*']; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | $setter = $this->reader->firstPropertyMetadata($property, Setter::class); |
| 89 | 89 | |
| 90 | - if ($value === null) { |
|
| 90 | + if ($value === null){ |
|
| 91 | 91 | return; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ($setter) { |
|
| 94 | + if ($setter){ |
|
| 95 | 95 | $value = $setter->updateValue($value); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -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 | } |
@@ -87,11 +102,13 @@ discard block |
||
| 87 | 102 | { |
| 88 | 103 | $setter = $this->reader->firstPropertyMetadata($property, Setter::class); |
| 89 | 104 | |
| 90 | - if ($value === null) { |
|
| 105 | + if ($value === null) |
|
| 106 | + { |
|
| 91 | 107 | return; |
| 92 | 108 | } |
| 93 | 109 | |
| 94 | - if ($setter) { |
|
| 110 | + if ($setter) |
|
| 111 | + { |
|
| 95 | 112 | $value = $setter->updateValue($value); |
| 96 | 113 | } |
| 97 | 114 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | public function __construct( |
| 26 | 26 | private readonly ContainerInterface $container |
| 27 | - ) { |
|
| 27 | + ){ |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $bag = $parameters['filterBag']; |
| 36 | 36 | $filter = $core->callAction($controller, $action, $parameters); |
| 37 | 37 | |
| 38 | - if ($filter instanceof HasFilterDefinition) { |
|
| 38 | + if ($filter instanceof HasFilterDefinition){ |
|
| 39 | 39 | $this->validateFilter( |
| 40 | 40 | $filter->filterDefinition(), |
| 41 | 41 | $bag, |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | array $errors, |
| 54 | 54 | mixed $context |
| 55 | 55 | ): void { |
| 56 | - if ($definition instanceof ShouldBeValidated) { |
|
| 56 | + if ($definition instanceof ShouldBeValidated){ |
|
| 57 | 57 | $errorMapper = new ErrorMapper($bag->schema); |
| 58 | 58 | $validationProvider = $this->container->get(ValidationProviderInterface::class); |
| 59 | 59 | |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | ->getValidation($definition::class) |
| 62 | 62 | ->validate($bag, $definition->validationRules(), $context); |
| 63 | 63 | |
| 64 | - if (!$validator->isValid()) { |
|
| 64 | + if (!$validator->isValid()){ |
|
| 65 | 65 | throw new ValidationException( |
| 66 | 66 | $errorMapper->mapErrors(\array_merge($errors, $validator->getErrors())), |
| 67 | 67 | $context |
| 68 | 68 | ); |
| 69 | - } elseif ($errors !== []) { |
|
| 69 | + } elseif ($errors !== []){ |
|
| 70 | 70 | throw new ValidationException($errorMapper->mapErrors($errors), $context); |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -35,7 +35,8 @@ discard block |
||
| 35 | 35 | $bag = $parameters['filterBag']; |
| 36 | 36 | $filter = $core->callAction($controller, $action, $parameters); |
| 37 | 37 | |
| 38 | - if ($filter instanceof HasFilterDefinition) { |
|
| 38 | + if ($filter instanceof HasFilterDefinition) |
|
| 39 | + { |
|
| 39 | 40 | $this->validateFilter( |
| 40 | 41 | $filter->filterDefinition(), |
| 41 | 42 | $bag, |
@@ -53,7 +54,8 @@ discard block |
||
| 53 | 54 | array $errors, |
| 54 | 55 | mixed $context |
| 55 | 56 | ): void { |
| 56 | - if ($definition instanceof ShouldBeValidated) { |
|
| 57 | + if ($definition instanceof ShouldBeValidated) |
|
| 58 | + { |
|
| 57 | 59 | $errorMapper = new ErrorMapper($bag->schema); |
| 58 | 60 | $validationProvider = $this->container->get(ValidationProviderInterface::class); |
| 59 | 61 | |
@@ -61,12 +63,15 @@ discard block |
||
| 61 | 63 | ->getValidation($definition::class) |
| 62 | 64 | ->validate($bag, $definition->validationRules(), $context); |
| 63 | 65 | |
| 64 | - if (!$validator->isValid()) { |
|
| 66 | + if (!$validator->isValid()) |
|
| 67 | + { |
|
| 65 | 68 | throw new ValidationException( |
| 66 | 69 | $errorMapper->mapErrors(\array_merge($errors, $validator->getErrors())), |
| 67 | 70 | $context |
| 68 | 71 | ); |
| 69 | - } elseif ($errors !== []) { |
|
| 72 | + } |
|
| 73 | + elseif ($errors !== []) |
|
| 74 | + { |
|
| 70 | 75 | throw new ValidationException($errorMapper->mapErrors($errors), $context); |
| 71 | 76 | } |
| 72 | 77 | } |