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 | 54 | protected function setup( |
|
109 | |||
110 | /** |
||
111 | * Validate and sanitize the item types |
||
112 | * |
||
113 | * @param string[]|\stdClass[] $types Item types |
||
114 | * @return array Validated item types |
||
115 | * @throws InvalidArgumentException If there are no valid types |
||
116 | */ |
||
117 | 54 | protected function valTypes(array $types) |
|
131 | |||
132 | /** |
||
133 | * Validate the item properties |
||
134 | * |
||
135 | * @param array $properties Item properties |
||
136 | * @return PropertyListInterface Validated item properties |
||
137 | * @throws InvalidArgumentException If the property name is empty |
||
138 | */ |
||
139 | 52 | protected function valProperties(array $properties) |
|
150 | |||
151 | /** |
||
152 | * Validate a single property |
||
153 | * |
||
154 | * @param \stdClass $property Property |
||
155 | * @return \stdClass Validated property |
||
156 | */ |
||
157 | 41 | protected function valProp($property) |
|
178 | |||
179 | /** |
||
180 | * Validate the structure of a property object |
||
181 | * |
||
182 | * @param \stdClass $property Property object |
||
183 | * @throws InvalidArgumentException If the property object is invalid |
||
184 | */ |
||
185 | 41 | protected function valPropStructure($property) |
|
195 | |||
196 | /** |
||
197 | * Validate the properties of a property |
||
198 | * |
||
199 | * @param \stdClass $property Property |
||
200 | * @return bool Property properties are valid |
||
201 | */ |
||
202 | 41 | protected function valPropProperties($property) |
|
209 | |||
210 | /** |
||
211 | * Validate a property name |
||
212 | * |
||
213 | * @param \stdClass $property Property |
||
214 | * @return string Property name |
||
215 | */ |
||
216 | 39 | protected function valPropName($property) |
|
230 | |||
231 | /** |
||
232 | * Validate a list of property values |
||
233 | * |
||
234 | * @param array $values Property values |
||
235 | * @return array Validated property values |
||
236 | * @throws InvalidArgumentException If the value is not a nested item |
||
237 | */ |
||
238 | 38 | protected function valPropValues(array $values) |
|
250 | |||
251 | /** |
||
252 | * Process a (non-empty) property value |
||
253 | * |
||
254 | * @param ValueInterface $value Property value |
||
255 | * @param array $validPropertyValues Non-empty property values |
||
256 | */ |
||
257 | 38 | protected function procPropValue($value, array &$validPropertyValues) |
|
272 | |||
273 | /** |
||
274 | * Validate a single item type |
||
275 | * |
||
276 | * @param \stdClass|Iri|string $type Item type |
||
277 | * @return Iri|null Validated item type |
||
278 | * @throws InvalidArgumentException If the item type object is invalid |
||
279 | */ |
||
280 | 54 | protected function valType($type) |
|
285 | } |
||
286 |