1 | <?php |
||
24 | class RequiredConstraint implements Constraint |
||
25 | { |
||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 373 | public function keywords() |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 357 | public function supports($type) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 26 | public function normalize(stdClass $schema, Context $context, Walker $walker) |
|
46 | { |
||
47 | 26 | $context->enterNode('required'); |
|
48 | |||
49 | 26 | if (!is_array($schema->required)) { |
|
50 | 1 | throw new InvalidTypeException($context, Types::TYPE_ARRAY); |
|
51 | } |
||
52 | |||
53 | 25 | if (0 === $requiredCount = count($schema->required)) { |
|
54 | 1 | throw new EmptyArrayException($context); |
|
55 | } |
||
56 | |||
57 | 24 | foreach ($schema->required as $index => $property) { |
|
58 | 24 | if (!is_string($property)) { |
|
59 | 1 | $context->enterNode($index); |
|
60 | |||
61 | 1 | throw new InvalidTypeException($context, Types::TYPE_STRING); |
|
62 | } |
||
63 | 24 | } |
|
64 | |||
65 | 23 | if ($requiredCount !== count(array_unique($schema->required))) { |
|
66 | 1 | throw new NotUniqueException($context); |
|
67 | } |
||
68 | |||
69 | 22 | $context->leaveNode(); |
|
70 | 22 | } |
|
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | 22 | public function apply($instance, stdClass $schema, Context $context, Walker $walker) |
|
83 | } |
||
84 |