1 | <?php |
||
48 | class Item implements ItemInterface |
||
49 | { |
||
50 | /** |
||
51 | * Item type(s) |
||
52 | * |
||
53 | * @var string[] |
||
54 | */ |
||
55 | protected $type; |
||
56 | |||
57 | /** |
||
58 | * Item properties |
||
59 | * |
||
60 | * @var array[] |
||
61 | */ |
||
62 | protected $properties; |
||
63 | |||
64 | /** |
||
65 | * Item ID |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $itemId; |
||
70 | |||
71 | /** |
||
72 | * Item constructor |
||
73 | * |
||
74 | * @param string|array $type Item type(s) |
||
75 | * @param array[] $properties Item properties |
||
76 | * @param string|null $itemId Item id |
||
77 | */ |
||
78 | 16 | public function __construct($type, array $properties = [], $itemId = null) |
|
84 | |||
85 | /** |
||
86 | * Validate and sanitize the item types |
||
87 | * |
||
88 | * @param array $types Item types |
||
89 | * @return array Validated item types |
||
90 | * @throws InvalidArgumentException If there are no valid types |
||
91 | */ |
||
92 | 16 | protected function validateTypes(array $types) |
|
106 | |||
107 | /** |
||
108 | * Validate the item properties |
||
109 | * |
||
110 | * @param array $properties Item properties |
||
111 | * @return array Validated item properties |
||
112 | * @throws InvalidArgumentException If the property name is empty |
||
113 | */ |
||
114 | 15 | protected function validateProperties(array $properties) |
|
139 | |||
140 | /** |
||
141 | * Validate a list of property values |
||
142 | * |
||
143 | * @param array $values Property values |
||
144 | * @return array Validated property values |
||
145 | * @throws InvalidArgumentException If the value is not a nested item |
||
146 | */ |
||
147 | 8 | protected function validatePropertyValues(array $values) |
|
175 | |||
176 | /** |
||
177 | * Return the item types |
||
178 | * |
||
179 | * @return string[] Item types |
||
180 | */ |
||
181 | 11 | public function getType() |
|
185 | |||
186 | /** |
||
187 | * Return the item ID (if any) |
||
188 | * |
||
189 | * @return string|null Item id |
||
190 | */ |
||
191 | 11 | public function getId() |
|
195 | |||
196 | /** |
||
197 | * Return all item properties |
||
198 | * |
||
199 | * @return array[] Item properties list |
||
200 | */ |
||
201 | 11 | public function getProperties() |
|
205 | |||
206 | /** |
||
207 | * Return the values of a particular property |
||
208 | * |
||
209 | * @param string $name Property name |
||
210 | * @return array Item property values |
||
211 | * @throws OutOfBoundsException If the property is unknown |
||
212 | */ |
||
213 | 2 | public function getProperty($name) |
|
225 | } |
||
226 |