1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Xervice\Validator; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Xervice\Core\Business\Model\Dependency\Provider\AbstractDependencyProvider; |
8
|
|
|
use Xervice\Core\Business\Model\Dependency\DependencyContainerInterface; |
9
|
|
|
use Xervice\Validator\Communication\Plugin\ValidatorType\ClosureValidatorPlugin; |
10
|
|
|
use Xervice\Validator\Communication\Plugin\ValidatorType\IsRequiredPlugin; |
11
|
|
|
use Xervice\Validator\Communication\Plugin\ValidatorType\IsTypePlugin; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @method \Xervice\Core\Locator\Locator getLocator() |
15
|
|
|
*/ |
16
|
|
|
class ValidatorDependencyProvider extends AbstractDependencyProvider |
17
|
|
|
{ |
18
|
|
|
public const VALIDATOR_TYPE_PLUGINS = 'validator.type.plugins'; |
19
|
|
|
public const ARRAY_HANDLER_FACADE = 'validator.array.handler.facade'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
23
|
|
|
* |
24
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
25
|
|
|
*/ |
26
|
2 |
|
public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface |
27
|
|
|
{ |
28
|
2 |
|
$container = $this->addValidatorTypePlugins($container); |
29
|
2 |
|
$container = $this->addArrayHandlerFacade($container); |
30
|
|
|
|
31
|
2 |
|
return $container; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
36
|
|
|
* |
37
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
38
|
|
|
*/ |
39
|
2 |
|
protected function addValidatorTypePlugins(DependencyContainerInterface $container): DependencyContainerInterface |
40
|
|
|
{ |
41
|
|
|
$container[static::VALIDATOR_TYPE_PLUGINS] = function (DependencyContainerInterface $container) { |
|
|
|
|
42
|
|
|
return [ |
43
|
1 |
|
new IsRequiredPlugin(), |
44
|
1 |
|
new IsTypePlugin(), |
45
|
1 |
|
new ClosureValidatorPlugin() |
46
|
|
|
]; |
47
|
|
|
}; |
48
|
|
|
|
49
|
2 |
|
return $container; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container |
54
|
|
|
* |
55
|
|
|
* @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface |
56
|
|
|
*/ |
57
|
2 |
|
protected function addArrayHandlerFacade(DependencyContainerInterface $container): DependencyContainerInterface |
58
|
|
|
{ |
59
|
|
|
$container[static::ARRAY_HANDLER_FACADE] = function (DependencyContainerInterface $container) { |
60
|
1 |
|
return $container->getLocator()->arrayHandler()->facade(); |
|
|
|
|
61
|
|
|
}; |
62
|
2 |
|
return $container; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.