1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package: Chapi |
4
|
|
|
* |
5
|
|
|
* @author: msiebeneicher |
6
|
|
|
* @since: 2016-11-10 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Chapi\Service\JobValidator; |
11
|
|
|
|
12
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Command; |
13
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Constraints; |
14
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Container; |
15
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Epsilon; |
16
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\IsArray; |
17
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\IsBoolean; |
18
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\JobName; |
19
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\NotEmpty; |
20
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Retries; |
21
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Schedule; |
22
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
23
|
|
|
|
24
|
|
|
class ValidatorFactory implements ValidatorFactoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string[] |
28
|
|
|
*/ |
29
|
|
|
private static $validatorMap = [ |
30
|
|
|
self::NOT_EMPTY_VALIDATOR => NotEmpty::DIC_NAME, |
31
|
|
|
self::NAME_VALIDATOR => JobName::DIC_NAME, |
32
|
|
|
self::EPSILON_VALIDATOR => Epsilon::DIC_NAME, |
33
|
|
|
self::BOOLEAN_VALIDATOR => IsBoolean::DIC_NAME, |
34
|
|
|
self::SCHEDULE_VALIDATOR => Schedule::DIC_NAME, |
35
|
|
|
self::ARRAY_VALIDATOR => IsArray::DIC_NAME, |
36
|
|
|
self::RETRY_VALIDATOR => Retries::DIC_NAME, |
37
|
|
|
self::CONSTRAINTS_VALIDATOR => Constraints::DIC_NAME, |
38
|
|
|
self::CONTAINER_VALIDATOR => Container::DIC_NAME, |
39
|
|
|
self::COMMAND_VALIDATOR => Command::DIC_NAME, |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ContainerInterface |
44
|
|
|
*/ |
45
|
|
|
private $serviceContainer; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* ValidatorFactory constructor. |
49
|
|
|
* @param ContainerInterface $oServiceContainer |
50
|
|
|
*/ |
51
|
|
|
public function __construct(ContainerInterface $oServiceContainer) |
52
|
|
|
{ |
53
|
|
|
$this->serviceContainer = $oServiceContainer; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $validator |
58
|
|
|
* @return PropertyValidatorInterface |
59
|
|
|
*/ |
60
|
|
|
public function getValidator($validator) |
61
|
|
|
{ |
62
|
|
|
if (!isset(self::$validatorMap[$validator])) { |
63
|
|
|
throw new \InvalidArgumentException(sprintf('Unknown validator type "%s"', $validator)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this->serviceContainer->get(self::$validatorMap[$validator]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|