1 | <?php |
||
29 | class Required implements ValidatorInterface |
||
30 | { |
||
31 | /** |
||
32 | * |
||
33 | * @var number[]|string[] |
||
34 | */ |
||
35 | protected $items = []; |
||
36 | |||
37 | 87 | public function setSpecification($specification = null) |
|
46 | |||
47 | 85 | private function specificationItemisValidOrThrowException($item) |
|
48 | { |
||
49 | 85 | if (!is_string($item) || is_numeric($item)) { |
|
50 | 2 | throw new UnspecifiedValidatorException( |
|
51 | 'The validator Required is being initialized without a valid array' |
||
52 | 2 | ); |
|
53 | } |
||
54 | 84 | } |
|
55 | |||
56 | 87 | private function specificationIsArrayOrThrowException($specification) |
|
57 | { |
||
58 | 87 | if (!is_array($specification) || empty($specification)) { |
|
59 | 2 | throw new UnspecifiedValidatorException( |
|
60 | 'The validator Required is being initialized without an array' |
||
61 | 2 | ); |
|
62 | } |
||
63 | 85 | } |
|
64 | |||
65 | 85 | public function validate($value) |
|
66 | { |
||
67 | 85 | if (is_array($value)) { |
|
68 | 5 | return $this->validateArray($value); |
|
69 | } |
||
70 | 80 | if ($value instanceof \stdClass) { |
|
71 | 79 | return $this->validateObject($value); |
|
72 | } |
||
73 | |||
74 | 1 | return false; |
|
75 | } |
||
76 | |||
77 | 79 | private function validateObject(\stdClass $object) |
|
87 | |||
88 | 5 | private function validateArray(array $array) |
|
98 | } |
||
99 |