|
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
|
|
|
|
|
13
|
|
|
use Chapi\Entity\Chronos\JobEntity; |
|
14
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Command; |
|
15
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Constraints; |
|
16
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Container; |
|
17
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Epsilon; |
|
18
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\IsArray; |
|
19
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\IsBoolean; |
|
20
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\JobName; |
|
21
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\NotEmpty; |
|
22
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Retries; |
|
23
|
|
|
use Chapi\Service\JobValidator\PropertyValidator\Schedule; |
|
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
25
|
|
|
|
|
26
|
|
|
class ValidatorFactory implements ValidatorFactoryInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var PropertyValidatorInterface[] |
|
30
|
|
|
*/ |
|
31
|
|
|
private static $aValidatorMap = [ |
|
32
|
|
|
self::NOT_EMPTY_VALIDATOR => NotEmpty::DIC_NAME, |
|
33
|
|
|
self::NAME_VALIDATOR => JobName::DIC_NAME, |
|
34
|
|
|
self::EPSILON_VALIDATOR => Epsilon::DIC_NAME, |
|
35
|
|
|
self::BOOLEAN_VALIDATOR => IsBoolean::DIC_NAME, |
|
36
|
|
|
self::SCHEDULE_VALIDATOR => Schedule::DIC_NAME, |
|
37
|
|
|
self::ARRAY_VALIDATOR => IsArray::DIC_NAME, |
|
38
|
|
|
self::RETRY_VALIDATOR => Retries::DIC_NAME, |
|
39
|
|
|
self::CONSTRAINTS_VALIDATOR => Constraints::DIC_NAME, |
|
40
|
|
|
self::CONTAINER_VALIDATOR => Container::DIC_NAME, |
|
41
|
|
|
self::COMMAND_VALIDATOR => Command::DIC_NAME, |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var ContainerInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
private $oServiceContainer; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* ValidatorFactory constructor. |
|
51
|
|
|
* @param ContainerInterface $oServiceContainer |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct(ContainerInterface $oServiceContainer) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->oServiceContainer = $oServiceContainer; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param int $iValidator |
|
60
|
|
|
* @return PropertyValidatorInterface |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getValidator($iValidator) |
|
63
|
|
|
{ |
|
64
|
|
|
if (!isset(self::$aValidatorMap[$iValidator])) |
|
65
|
|
|
{ |
|
66
|
|
|
throw new \InvalidArgumentException(sprintf('Unknown validator type "%s"', $iValidator)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->oServiceContainer->get(self::$aValidatorMap[$iValidator]); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: