|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Micro framework package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Micro\Library\DTO\Preparation\Processor\Property; |
|
15
|
|
|
|
|
16
|
|
|
use Micro\Library\DTO\ClassDef\ClassDefinition; |
|
17
|
|
|
use Micro\Library\DTO\ClassDef\PropertyDefinition; |
|
18
|
|
|
|
|
19
|
|
|
class AttributeValidationProcessor implements PropertyProcessorInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param iterable<PropertyProcessorInterface> $validatorProcessor |
|
23
|
|
|
*/ |
|
24
|
6 |
|
public function __construct( |
|
25
|
|
|
private iterable $validatorProcessor |
|
26
|
|
|
) { |
|
27
|
6 |
|
} |
|
28
|
|
|
|
|
29
|
1 |
|
public function process(PropertyDefinition $propertyDefinition, ClassDefinition $classDefinition, array $propertyData, array $classList): void |
|
30
|
|
|
{ |
|
31
|
1 |
|
if (!\array_key_exists('validation', $propertyData)) { |
|
32
|
1 |
|
return; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
$propertyValidationConstraints = $propertyData['validation']; |
|
36
|
1 |
|
foreach ($propertyValidationConstraints as $constraint) { |
|
37
|
1 |
|
$this->processAddConstraints($propertyDefinition, $classDefinition, $constraint, $classList); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param PropertyDefinition $propertyDefinition |
|
43
|
|
|
* @param ClassDefinition $classDefinition |
|
44
|
|
|
* @param array<array<string, mixed>> $constraints |
|
45
|
|
|
* @param string[] $classList |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
1 |
|
protected function processAddConstraints(PropertyDefinition $propertyDefinition, ClassDefinition $classDefinition, array $constraints, array $classList): void |
|
50
|
|
|
{ |
|
51
|
1 |
|
foreach ($constraints as $constraint) { |
|
52
|
1 |
|
foreach ($this->validatorProcessor as $processor) { |
|
53
|
|
|
/** |
|
54
|
|
|
* @phpstan-ignore-next-line |
|
55
|
|
|
* |
|
56
|
|
|
* @psalm-suppress InvalidArrayOffset |
|
57
|
|
|
*/ |
|
58
|
1 |
|
$processor->process($propertyDefinition, $classDefinition, [$constraint[0] => $constraint[1]], $classList); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|