1 | <?php |
||
51 | class Item implements ItemInterface |
||
52 | { |
||
53 | /** |
||
54 | * Item type(s) |
||
55 | * |
||
56 | * @var string[] |
||
57 | */ |
||
58 | protected $type; |
||
59 | |||
60 | /** |
||
61 | * Item properties |
||
62 | * |
||
63 | * @var PropertyList |
||
64 | */ |
||
65 | protected $properties; |
||
66 | |||
67 | /** |
||
68 | * Item ID |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $itemId; |
||
73 | |||
74 | /** |
||
75 | * Alias factory |
||
76 | * |
||
77 | * @var AliasFactoryInterface |
||
78 | */ |
||
79 | protected $aliasFactory; |
||
80 | |||
81 | /** |
||
82 | * Item constructor |
||
83 | * |
||
84 | * @param string|\stdClass|\stdClass[] $type Item type(s) |
||
85 | * @param array[] $properties Item properties |
||
86 | * @param string|null $itemId Item id |
||
87 | * @param AliasFactoryInterface $aliasFactory Alias factory |
||
88 | */ |
||
89 | 31 | public function __construct( |
|
100 | |||
101 | /** |
||
102 | * Validate and sanitize the item types |
||
103 | * |
||
104 | * @param \stdClass[] $types Item types |
||
105 | * @return array Validated item types |
||
106 | * @throws InvalidArgumentException If there are no valid types |
||
107 | */ |
||
108 | 31 | protected function validateTypes(array $types) |
|
122 | |||
123 | /** |
||
124 | * Validate the item properties |
||
125 | * |
||
126 | * @param array $properties Item properties |
||
127 | * @return PropertyList Validated item properties |
||
128 | * @throws InvalidArgumentException If the property name is empty |
||
129 | */ |
||
130 | 29 | protected function validateProperties(array $properties) |
|
141 | |||
142 | /** |
||
143 | * Return the item types |
||
144 | * |
||
145 | * @return string[] Item types |
||
146 | */ |
||
147 | 16 | public function getType() |
|
151 | |||
152 | /** |
||
153 | * Return the item ID (if any) |
||
154 | * |
||
155 | * @return string|null Item id |
||
156 | */ |
||
157 | 14 | public function getId() |
|
161 | |||
162 | /** |
||
163 | * Return all item properties |
||
164 | * |
||
165 | * @return PropertyList Item properties list |
||
166 | */ |
||
167 | 15 | public function getProperties() |
|
171 | |||
172 | /** |
||
173 | * Return the values of a particular property |
||
174 | * |
||
175 | * @param string $name Property name |
||
176 | * @param string|null $profile Property profile |
||
177 | * @return array Item property values |
||
178 | */ |
||
179 | 4 | public function getProperty($name, $profile = null) |
|
184 | |||
185 | /** |
||
186 | * Return whether the value should be considered empty |
||
187 | * |
||
188 | * @return boolean Value is empty |
||
189 | */ |
||
190 | 9 | public function isEmpty() |
|
194 | |||
195 | /** |
||
196 | * Validate a single property |
||
197 | * |
||
198 | * @param \stdClass $property Property |
||
199 | * @return \stdClass Validated property |
||
200 | */ |
||
201 | 20 | protected function validateProperty($property) |
|
222 | |||
223 | /** |
||
224 | * Validate the structure of a property object |
||
225 | * |
||
226 | * @param \stdClass $property Property object |
||
227 | * @throws InvalidArgumentException If the property object is invalid |
||
228 | */ |
||
229 | 20 | protected function validatePropertyStructure($property) |
|
244 | |||
245 | /** |
||
246 | * Validate a property name |
||
247 | * |
||
248 | * @param \stdClass $property Property |
||
249 | * @return string Property name |
||
250 | */ |
||
251 | 18 | protected function validatePropertyName($property) |
|
265 | |||
266 | /** |
||
267 | * Validate a list of property values |
||
268 | * |
||
269 | * @param array $values Property values |
||
270 | * @return array Validated property values |
||
271 | * @throws InvalidArgumentException If the value is not a nested item |
||
272 | */ |
||
273 | 17 | protected function validatePropertyValues(array $values) |
|
295 | |||
296 | /** |
||
297 | * Validate a single item type |
||
298 | * |
||
299 | * @param \stdClass|string $type Item type |
||
300 | * @return \stdClass|null Validated item type |
||
301 | * @throws InvalidArgumentException If the item type object is invalid |
||
302 | */ |
||
303 | 31 | protected function validateType($type) |
|
308 | } |
||
309 |