1 | <?php |
||
9 | class JsonDefinitionArray implements DefinitionElementInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $name; |
||
15 | /** |
||
16 | * @var DefinitionElementInterface |
||
17 | */ |
||
18 | private $element; |
||
19 | |||
20 | /** |
||
21 | * Constructor |
||
22 | * |
||
23 | * @param string $name Field name |
||
24 | * @param DefinitionElementInterface $element Array item definition |
||
25 | */ |
||
26 | 42 | public function __construct($name, DefinitionElementInterface $element) |
|
31 | |||
32 | /** |
||
33 | * @return DefinitionElementInterface |
||
34 | */ |
||
35 | 14 | public function getElement() |
|
39 | |||
40 | /** |
||
41 | * Returns the name of this field |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | 6 | public function getName() |
|
49 | |||
50 | /** |
||
51 | * Returns the whole definition in array form |
||
52 | * |
||
53 | * @return array Definition |
||
54 | */ |
||
55 | 2 | public function getDefAsArray() |
|
56 | { |
||
57 | 2 | return array_replace( |
|
58 | 2 | $this->element->getDefAsArray(), |
|
59 | [ |
||
60 | 2 | 'name' => $this->getName(), |
|
61 | 2 | 'type' => $this->getType(), |
|
62 | 2 | 'doctrineType' => $this->getTypeDoctrine(), |
|
63 | 2 | 'serializerType' => $this->getTypeSerializer() |
|
64 | 1 | ], |
|
65 | 2 | $this->getHashAnonymousHashRequired() |
|
66 | 1 | ); |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Returns the field type in a doctrine-understandable way.. |
||
71 | * |
||
72 | * @return string Type |
||
73 | */ |
||
74 | 6 | public function getTypeDoctrine() |
|
78 | |||
79 | /** |
||
80 | * possible overrides. if the element is an anonymous hash, we will always |
||
81 | * default to required => false. |
||
82 | * |
||
83 | * @return array additional overrides |
||
84 | */ |
||
85 | 2 | private function getHashAnonymousHashRequired() |
|
86 | { |
||
87 | 2 | if ($this->element instanceof JsonDefinitionHash && $this->element->isAnonymous()) { |
|
88 | return ['required' => false]; |
||
89 | } |
||
90 | |||
91 | 2 | return []; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Returns the field type |
||
96 | * |
||
97 | * @return string Type |
||
98 | */ |
||
99 | 8 | public function getType() |
|
103 | |||
104 | /** |
||
105 | * Returns the field type in a serializer-understandable way.. |
||
106 | * |
||
107 | * @return string Type |
||
108 | */ |
||
109 | 6 | public function getTypeSerializer() |
|
120 | } |
||
121 |