1 | <?php |
||
53 | class ItemFactory |
||
54 | { |
||
55 | /** |
||
56 | * Parser format |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $format; |
||
61 | /** |
||
62 | * Property lit factory |
||
63 | * |
||
64 | * @var PropertyListFactoryInterface |
||
65 | */ |
||
66 | protected $propertyListFactory; |
||
67 | |||
68 | /** |
||
69 | * Item factory constructor |
||
70 | * |
||
71 | * @param int $format Parser format |
||
72 | */ |
||
73 | 18 | public function __construct($format) |
|
78 | |||
79 | /** |
||
80 | * Prepare a single property value |
||
81 | * |
||
82 | * @param mixed $propertyValue Property Value |
||
83 | * @return ValueInterface Value |
||
84 | */ |
||
85 | 14 | protected function processPropertyValue($propertyValue) |
|
99 | |||
100 | /** |
||
101 | * Process a language tagged property value |
||
102 | * |
||
103 | * @param string|\stdClass $propertyValue Property value |
||
104 | * @return array Language and property value |
||
105 | * @throws RuntimeException If this is an invalid language tagged value |
||
106 | */ |
||
107 | 14 | protected function processLanguageTaggedPropertyValue($propertyValue) |
|
124 | |||
125 | /** |
||
126 | * Create an item instance |
||
127 | * |
||
128 | * The item object is expected to be layed out like this: |
||
129 | * |
||
130 | * { |
||
131 | * format: 2, // Parser formag |
||
132 | * type: 'type', // String / IRI object (see below) or list of strings / IRI objects |
||
133 | * properties: [...], // List of item property objects (see below) |
||
134 | * value: 'Item value', // Item value (optional) |
||
135 | * id: 'item-1', // Item ID (optional) |
||
136 | * children: [...] // Nested item objects (optional) |
||
137 | * } |
||
138 | * |
||
139 | * The item property objects are expected to be layed out like this: |
||
140 | * |
||
141 | * { |
||
142 | * name: 'name', // Property name |
||
143 | * profile: 'http://microformats.org/profile/', // Profile |
||
144 | * values: [...] // List of property values |
||
145 | * } |
||
146 | * |
||
147 | * Item property values may be either |
||
148 | * |
||
149 | * - a string: Interpreted as simple value |
||
150 | * - an array: Interpreted as alternate simple values |
||
151 | * - an object: Interpreted as an object property (recursively processed) |
||
152 | * |
||
153 | * IRI objects are expected to be layed out like this: |
||
154 | * |
||
155 | * { |
||
156 | * name: 'h-entry', |
||
157 | * profile: 'http://microformats.org/profile/', // Profile (optional) |
||
158 | * } |
||
159 | * |
||
160 | * @param \stdClass $item Raw item |
||
161 | * @return ItemInterface Item instance |
||
162 | */ |
||
163 | 17 | public function __invoke(\stdClass $item) |
|
182 | |||
183 | /** |
||
184 | * Normalize an empty item value |
||
185 | * |
||
186 | * @param \stdClass $item Item |
||
187 | * @param string $property Property name |
||
188 | * @return string|null Normalized property value |
||
189 | */ |
||
190 | 17 | protected function normalizeEmptyValue(\stdClass $item, $property) |
|
194 | |||
195 | /** |
||
196 | * Prepare item properties |
||
197 | * |
||
198 | * @param \stdClass $item Item |
||
199 | * @return array Properties |
||
200 | */ |
||
201 | 17 | protected function getProperties(\stdClass $item) |
|
211 | |||
212 | |||
213 | /** |
||
214 | * Process a property |
||
215 | * |
||
216 | * @param array $properties Properties |
||
217 | * @param \stdClass $property Property |
||
218 | */ |
||
219 | 16 | protected function processProperty(array &$properties, $property) |
|
232 | |||
233 | /** |
||
234 | * Validate if an object is a valid property |
||
235 | * |
||
236 | * @param \stdClass $property Property |
||
237 | * @return bool Is a valid property |
||
238 | */ |
||
239 | 16 | protected function validatePropertyStructure($property) |
|
243 | |||
244 | /** |
||
245 | * Prepare item property values |
||
246 | * |
||
247 | * @param array $propertyValues Property values |
||
248 | * @return array Expanded property values |
||
249 | * @throws InvalidArgumentException If it's not a list of property values |
||
250 | */ |
||
251 | 15 | protected function getPropertyValues($propertyValues) |
|
263 | } |
||
264 |