1 | <?php |
||
9 | trait HasChildrenTrait |
||
10 | { |
||
11 | /** |
||
12 | * List of the child element |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $elements = array(); |
||
17 | |||
18 | /** |
||
19 | * Value to keep track of the order the elements were added |
||
20 | * |
||
21 | * @var int |
||
22 | */ |
||
23 | protected $elementsIndex = PHP_INT_MAX; |
||
24 | |||
25 | /** |
||
26 | * @var ElementFactory |
||
27 | */ |
||
28 | protected $elementFactory; |
||
29 | |||
30 | /** |
||
31 | * Generates the actual name that will be used to identify the element in the input object |
||
32 | * For input objects the name of the child is the same as the name provided, |
||
33 | * For field-sets the name of the child is prefixed/name-spaced with the name of the field-set |
||
34 | * For collections the name of the child is prefixed with the name of the collection and an index placeholder |
||
35 | * |
||
36 | * @param string $name |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | 12 | protected function getFullChildName($name) |
|
44 | |||
45 | /** |
||
46 | * Sets the element factory. |
||
47 | * Objects that have children (eg: Fieldset, Collection) must be factory-aware |
||
48 | * This is passed down from form to fieldsets, collections or other elements that have children |
||
49 | * |
||
50 | * @param ElementFactory $elementFactory |
||
51 | * @return $this |
||
52 | */ |
||
53 | 9 | public function setElementFactory(ElementFactory $elementFactory) |
|
60 | |||
61 | /** |
||
62 | * Add an element to the children list |
||
63 | * |
||
64 | * @param string|\Sirius\Input\Element $nameOrElement |
||
65 | * @param array $specs |
||
66 | * |
||
67 | * @throws \RuntimeException |
||
68 | * @return $this |
||
69 | */ |
||
70 | 19 | public function addElement($nameOrElement, $specs = array()) |
|
104 | |||
105 | /** |
||
106 | * Make sure a Group type element is added to the children if the element has a group |
||
107 | * |
||
108 | * @param Element $element |
||
109 | */ |
||
110 | 18 | protected function ensureGroupExists(Element $element) { |
|
121 | |||
122 | /** |
||
123 | * Create the children using the factory. |
||
124 | * This will be called by elements that are factory-aware (eg: Fieldsets) |
||
125 | */ |
||
126 | 9 | protected function createChildren() |
|
135 | |||
136 | /** |
||
137 | * Retrieve an element by name |
||
138 | * |
||
139 | * @param string $name |
||
140 | * |
||
141 | * @return \Sirius\Input\Element |
||
142 | */ |
||
143 | 10 | public function getElement($name) |
|
147 | |||
148 | /** |
||
149 | * Removes an element from the children list |
||
150 | * |
||
151 | * @param string $name |
||
152 | * |
||
153 | * @throws \RuntimeException |
||
154 | * @return $this |
||
155 | */ |
||
156 | 4 | public function removeElement($name) |
|
164 | |||
165 | /** |
||
166 | * Returns whether an element exist in the children list |
||
167 | * |
||
168 | * @param string $name |
||
169 | * |
||
170 | * @return boolean |
||
171 | */ |
||
172 | 4 | public function hasElement($name) |
|
176 | |||
177 | /** |
||
178 | * Input comparator callback |
||
179 | * |
||
180 | * @param \ArrayObject $childA |
||
181 | * @param \ArrayObject $childB |
||
182 | * |
||
183 | * @return integer |
||
184 | */ |
||
185 | 7 | protected function childComparator($childA, $childB) |
|
207 | |||
208 | /** |
||
209 | * Returns the list of the elements organized by priority |
||
210 | * |
||
211 | * @return array |
||
212 | */ |
||
213 | 17 | public function getElements() |
|
220 | |||
221 | |||
222 | /** |
||
223 | * Unset the group property for elements without a valid group (ie: existing group) |
||
224 | */ |
||
225 | 11 | protected function cleanUpMissingGroups() |
|
234 | |||
235 | } |
||
236 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: