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