1 | <?php |
||
50 | trait ItemSetupTrait |
||
51 | { |
||
52 | /** |
||
53 | * Property list factory |
||
54 | * |
||
55 | * @var PropertyListFactoryInterface |
||
56 | */ |
||
57 | protected $propertyListFactory; |
||
58 | |||
59 | /** |
||
60 | * Item type(s) |
||
61 | * |
||
62 | * @var \stdClass[] |
||
63 | */ |
||
64 | protected $type; |
||
65 | |||
66 | /** |
||
67 | * Item properties |
||
68 | * |
||
69 | * @var PropertyListInterface |
||
70 | */ |
||
71 | protected $properties; |
||
72 | |||
73 | /** |
||
74 | * Item ID |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $itemId; |
||
79 | |||
80 | /** |
||
81 | * Item language |
||
82 | * |
||
83 | * @var string |
||
84 | */ |
||
85 | protected $itemLanguage; |
||
86 | |||
87 | /** |
||
88 | * Setup the item |
||
89 | * |
||
90 | * @param PropertyListFactoryInterface $propertyListFactory Property list factory |
||
91 | * @param string[]|\stdClass[] $type Item type(s) |
||
92 | * @param \stdClass[] $properties Item properties |
||
93 | * @param string $itemId Item ID |
||
94 | * @param string $itemLanguage Item language |
||
95 | */ |
||
96 | 56 | protected function setup( |
|
109 | |||
110 | /** |
||
111 | * Validate and sanitize the item types |
||
112 | * |
||
113 | * @param string[]|\stdClass[] $types Item types |
||
114 | * |
||
115 | * @return array Validated item types |
||
116 | * @throws InvalidArgumentException If there are no valid types |
||
117 | */ |
||
118 | 56 | protected function valTypes(array $types) |
|
132 | |||
133 | /** |
||
134 | * Validate the item properties |
||
135 | * |
||
136 | * @param array $properties Item properties |
||
137 | * |
||
138 | * @return PropertyListInterface Validated item properties |
||
139 | * @throws InvalidArgumentException If the property name is empty |
||
140 | */ |
||
141 | 54 | protected function valProperties(array $properties) |
|
152 | |||
153 | /** |
||
154 | * Validate a single property |
||
155 | * |
||
156 | * @param \stdClass $property Property |
||
157 | * |
||
158 | * @return \stdClass Validated property |
||
159 | */ |
||
160 | 42 | protected function valProp($property) |
|
181 | |||
182 | /** |
||
183 | * Validate the structure of a property object |
||
184 | * |
||
185 | * @param \stdClass $property Property object |
||
186 | * |
||
187 | * @throws InvalidArgumentException If the property object is invalid |
||
188 | */ |
||
189 | 42 | protected function valPropStructure($property) |
|
199 | |||
200 | /** |
||
201 | * Validate the properties of a property |
||
202 | * |
||
203 | * @param \stdClass $property Property |
||
204 | * |
||
205 | * @return bool Property properties are valid |
||
206 | */ |
||
207 | 42 | protected function valPropProperties($property) |
|
214 | |||
215 | /** |
||
216 | * Validate a property name |
||
217 | * |
||
218 | * @param \stdClass $property Property |
||
219 | * |
||
220 | * @return string Property name |
||
221 | */ |
||
222 | 40 | protected function valPropName($property) |
|
236 | |||
237 | /** |
||
238 | * Validate a list of property values |
||
239 | * |
||
240 | * @param array $values Property values |
||
241 | * |
||
242 | * @return array Validated property values |
||
243 | * @throws InvalidArgumentException If the value is not a nested item |
||
244 | */ |
||
245 | 39 | protected function valPropValues(array $values) |
|
257 | |||
258 | /** |
||
259 | * Process a (non-empty) property value |
||
260 | * |
||
261 | * @param ValueInterface $value Property value |
||
262 | * @param array $validPropertyValues Non-empty property values |
||
263 | */ |
||
264 | 39 | protected function procPropValue($value, array &$validPropertyValues) |
|
279 | |||
280 | /** |
||
281 | * Validate a single item type |
||
282 | * |
||
283 | * @param \stdClass|Iri|string $type Item type |
||
284 | * |
||
285 | * @return Iri|null Validated item type |
||
286 | * @throws InvalidArgumentException If the item type object is invalid |
||
287 | */ |
||
288 | 56 | protected function valType($type) |
|
294 | } |
||
295 |