|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Xervice\Validator\Business\Model; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Xervice\ArrayHandler\Business\ArrayHandlerFacade; |
|
8
|
|
|
use Xervice\ArrayHandler\Dependency\FieldHandlerPluginInterface; |
|
9
|
|
|
use Xervice\Validator\Business\Dependency\ValidatorConfigurationProviderPluginInterface; |
|
10
|
|
|
use Xervice\Validator\Business\Exception\ValidationException; |
|
11
|
|
|
|
|
12
|
|
|
class ValidatorProvider implements ValidatorProviderInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var \Xervice\ArrayHandler\Business\ArrayHandlerFacade |
|
16
|
|
|
*/ |
|
17
|
|
|
private $arrayHandlerFacade; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Xervice\Validator\Business\Dependency\ValidatorConfigurationProviderPluginInterface[] |
|
21
|
|
|
*/ |
|
22
|
|
|
private $configurationPlugins; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \Xervice\ArrayHandler\Dependency\FieldHandlerPluginInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $arrayFieldHandlerPlugin; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Validator constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Xervice\ArrayHandler\Business\ArrayHandlerFacade $arrayHandlerFacade |
|
33
|
|
|
* @param \Xervice\Validator\Business\Dependency\ValidatorConfigurationProviderPluginInterface[] $configurationPlugins |
|
34
|
|
|
* @param \Xervice\ArrayHandler\Dependency\FieldHandlerPluginInterface $arrayFieldHandlerPlugin |
|
35
|
|
|
*/ |
|
36
|
5 |
|
public function __construct( |
|
37
|
|
|
ArrayHandlerFacade $arrayHandlerFacade, |
|
38
|
|
|
array $configurationPlugins, |
|
39
|
|
|
FieldHandlerPluginInterface $arrayFieldHandlerPlugin |
|
40
|
|
|
) { |
|
41
|
5 |
|
$this->arrayHandlerFacade = $arrayHandlerFacade; |
|
42
|
5 |
|
$this->configurationPlugins = $configurationPlugins; |
|
43
|
5 |
|
$this->arrayFieldHandlerPlugin = $arrayFieldHandlerPlugin; |
|
44
|
5 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param array $data |
|
49
|
|
|
* |
|
50
|
|
|
* @throws \Xervice\Validator\Business\Exception\ValidationException |
|
51
|
|
|
*/ |
|
52
|
5 |
|
public function validate(array $data): void |
|
53
|
|
|
{ |
|
54
|
|
|
try { |
|
55
|
5 |
|
foreach ($this->configurationPlugins as $configurationPlugin) { |
|
56
|
5 |
|
$this->arrayHandlerFacade->handleArray( |
|
57
|
5 |
|
$this->arrayFieldHandlerPlugin, |
|
58
|
5 |
|
$data, |
|
59
|
5 |
|
$configurationPlugin->getValidatorConfiguration() |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
4 |
|
} catch (ValidationException $exception) { |
|
63
|
4 |
|
throw new ValidationException( |
|
64
|
4 |
|
sprintf( |
|
65
|
4 |
|
'Data not valid. %s', |
|
66
|
4 |
|
$exception->getMessage() |
|
67
|
|
|
) |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |