1 | <?php |
||
50 | class Item implements ItemInterface |
||
51 | { |
||
52 | /** |
||
53 | * Item type(s) |
||
54 | * |
||
55 | * @var string[] |
||
56 | */ |
||
57 | protected $type; |
||
58 | |||
59 | /** |
||
60 | * Item properties |
||
61 | * |
||
62 | * @var PropertyList |
||
63 | */ |
||
64 | protected $properties; |
||
65 | |||
66 | /** |
||
67 | * Item ID |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $itemId; |
||
72 | |||
73 | /** |
||
74 | * Item constructor |
||
75 | * |
||
76 | * @param string|\stdClass|\stdClass[] $type Item type(s) |
||
77 | * @param array[] $properties Item properties |
||
78 | * @param string|null $itemId Item id |
||
79 | */ |
||
80 | 25 | public function __construct($type, array $properties = [], $itemId = null) |
|
86 | |||
87 | /** |
||
88 | * Validate and sanitize the item types |
||
89 | * |
||
90 | * @param \stdClass[] $types Item types |
||
91 | * @return array Validated item types |
||
92 | * @throws InvalidArgumentException If there are no valid types |
||
93 | */ |
||
94 | 25 | protected function validateTypes(array $types) |
|
108 | |||
109 | /** |
||
110 | * Validate the item properties |
||
111 | * |
||
112 | * @param array $properties Item properties |
||
113 | * @return PropertyList Validated item properties |
||
114 | * @throws InvalidArgumentException If the property name is empty |
||
115 | */ |
||
116 | 24 | protected function validateProperties(array $properties) |
|
127 | |||
128 | /** |
||
129 | * Return the item types |
||
130 | * |
||
131 | * @return string[] Item types |
||
132 | */ |
||
133 | 13 | public function getType() |
|
137 | |||
138 | /** |
||
139 | * Return the item ID (if any) |
||
140 | * |
||
141 | * @return string|null Item id |
||
142 | */ |
||
143 | 12 | public function getId() |
|
147 | |||
148 | /** |
||
149 | * Return all item properties |
||
150 | * |
||
151 | * @return PropertyList Item properties list |
||
152 | */ |
||
153 | 13 | public function getProperties() |
|
157 | |||
158 | /** |
||
159 | * Return the values of a particular property |
||
160 | * |
||
161 | * @param string $name Property name |
||
162 | * @param string|null $profile Property profile |
||
163 | * @return array Item property values |
||
164 | * @throws OutOfBoundsException If the property is unknown |
||
165 | */ |
||
166 | 2 | public function getProperty($name, $profile = null) |
|
171 | |||
172 | /** |
||
173 | * Return whether the value should be considered empty |
||
174 | * |
||
175 | * @return boolean Value is empty |
||
176 | */ |
||
177 | 7 | public function isEmpty() |
|
181 | |||
182 | /** |
||
183 | * Validate a single property |
||
184 | * |
||
185 | * @param \stdClass $property Property |
||
186 | * @return \stdClass Validated property |
||
187 | */ |
||
188 | 15 | protected function validateProperty($property) |
|
209 | |||
210 | /** |
||
211 | * Validate the structure of a property object |
||
212 | * |
||
213 | * @param \stdClass $property Property object |
||
214 | * @throws InvalidArgumentException If the property object is invalid |
||
215 | */ |
||
216 | 15 | protected function validatePropertyStructure($property) |
|
231 | |||
232 | /** |
||
233 | * Validate a property name |
||
234 | * |
||
235 | * @param \stdClass $property Property |
||
236 | * @return string Property name |
||
237 | */ |
||
238 | 15 | protected function validatePropertyName($property) |
|
252 | |||
253 | /** |
||
254 | * Validate a list of property values |
||
255 | * |
||
256 | * @param array $values Property values |
||
257 | * @return array Validated property values |
||
258 | * @throws InvalidArgumentException If the value is not a nested item |
||
259 | */ |
||
260 | 14 | protected function validatePropertyValues(array $values) |
|
282 | |||
283 | /** |
||
284 | * Validate a single item type |
||
285 | * |
||
286 | * @param \stdClass|string $type Item type |
||
287 | * @return \stdClass|null Validated item type |
||
288 | * @throws InvalidArgumentException If the item type object is invalid |
||
289 | */ |
||
290 | 25 | protected function validateType($type) |
|
295 | } |
||
296 |