1 | <?php |
||
55 | class RdfaLiteElementProcessor implements ElementProcessorInterface |
||
56 | { |
||
57 | /** |
||
58 | * Tag name / attribute map |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | protected static $tagNameAttributes = [ |
||
63 | 'META' => 'content', |
||
64 | 'AUDIO' => 'src', |
||
65 | 'EMBED' => 'src', |
||
66 | 'IFRAME' => 'src', |
||
67 | 'IMG' => 'src', |
||
68 | 'SOURCE' => 'src', |
||
69 | 'TRACK' => 'src', |
||
70 | 'VIDEO' => 'src', |
||
71 | 'A' => 'href', |
||
72 | 'AREA' => 'href', |
||
73 | 'LINK' => 'href', |
||
74 | 'OBJECT' => 'data', |
||
75 | 'DATA' => 'value', |
||
76 | 'TIME' => 'datetime' |
||
77 | ]; |
||
78 | |||
79 | /** |
||
80 | * Process a DOM element |
||
81 | * |
||
82 | * @param \DOMElement $element DOM element |
||
83 | * @param Context $context Inherited Context |
||
84 | * @return Context Local context for this element |
||
85 | */ |
||
86 | 8 | public function processElement(\DOMElement $element, Context $context) |
|
98 | |||
99 | /** |
||
100 | * Process changes of the default vocabulary |
||
101 | * |
||
102 | * @param \DOMElement $element DOM element |
||
103 | * @param Context $context Inherited Context |
||
104 | * @return Context Local context for this element |
||
105 | */ |
||
106 | 8 | protected function processVocab(\DOMElement $element, Context $context) |
|
115 | |||
116 | /** |
||
117 | * Process vocabulary prefixes |
||
118 | * |
||
119 | * @param \DOMElement $element DOM element |
||
120 | * @param Context $context Inherited Context |
||
121 | * @return Context Local context for this element |
||
122 | */ |
||
123 | 8 | protected function processPrefix(\DOMElement $element, Context $context) |
|
136 | |||
137 | /** |
||
138 | * Create a property |
||
139 | * |
||
140 | * @param \DOMElement $element DOM element |
||
141 | * @param Context $context Inherited Context |
||
142 | * @return Context Local context for this element |
||
143 | */ |
||
144 | 8 | protected function processProperty(\DOMElement $element, Context $context) |
|
153 | |||
154 | /** |
||
155 | * Split a property into prefix and name |
||
156 | * |
||
157 | * @param string $property Prefixed property |
||
158 | * @return array Prefix and name |
||
159 | */ |
||
160 | 4 | protected function splitProperty($property) |
|
167 | |||
168 | /** |
||
169 | * Create a property |
||
170 | * |
||
171 | * @param string $prefix Property prefix |
||
172 | * @param string $name Property name |
||
173 | * @param \DOMElement $element DOM element |
||
174 | * @param Context $context Inherited Context |
||
175 | * @return Context Local context for this element |
||
176 | */ |
||
177 | 4 | protected function processPropertyPrefixName($prefix, $name, \DOMElement $element, Context $context) |
|
186 | |||
187 | /** |
||
188 | * Return a vocabulary by prefix with fallback to the default vocabulary |
||
189 | * |
||
190 | * @param string $prefix Vocabulary prefix |
||
191 | * @param Context $context Context |
||
192 | * @return VocabularyInterface Vocabulary |
||
193 | */ |
||
194 | 8 | protected function getVocabulary($prefix, Context $context) |
|
198 | |||
199 | /** |
||
200 | * Create properties |
||
201 | * |
||
202 | * @param \DOMElement $element DOM element |
||
203 | * @param Context $context Inherited Context |
||
204 | * @param string $name Property name |
||
205 | * @param VocabularyInterface $vocabulary Property vocabulary |
||
206 | * @return Context Local context for this element |
||
207 | */ |
||
208 | 4 | protected function addProperty(\DOMElement $element, Context $context, $name, VocabularyInterface $vocabulary) |
|
228 | |||
229 | /** |
||
230 | * Return a property value (type and tag name dependent) |
||
231 | * |
||
232 | * @param \DOMElement $element DOM element |
||
233 | * @param Context $context Context |
||
234 | * @return ThingInterface|string Property value |
||
235 | */ |
||
236 | 4 | protected function getPropertyValue(\DOMElement $element, Context $context) |
|
250 | |||
251 | /** |
||
252 | * Return a thing by typeof value |
||
253 | * |
||
254 | * @param string $typeof Thing type |
||
255 | * @param string $resourceId Resource ID |
||
256 | * @param Context $context Context |
||
257 | * @return ThingInterface Thing |
||
258 | */ |
||
259 | 8 | protected function getThing($typeof, $resourceId, Context $context) |
|
267 | |||
268 | /** |
||
269 | * Return a thing by prefix and type |
||
270 | * |
||
271 | * @param string $prefix Prefix |
||
272 | * @param string $type Type |
||
273 | * @param string $resourceId Resource ID |
||
274 | * @param Context $context Context |
||
275 | * @return ThingInterface Thing |
||
276 | * @throws RuntimeException If the default vocabulary is empty |
||
277 | * @throws OutOfBoundsException If the vocabulary prefix is unknown |
||
278 | */ |
||
279 | 8 | protected function getThingByPrefixType($prefix, $type, $resourceId, Context $context) |
|
304 | |||
305 | /** |
||
306 | * Return a property value (type and tag name dependent) |
||
307 | * |
||
308 | * @param \DOMElement $element DOM element |
||
309 | * @return ThingInterface|string Property value |
||
310 | */ |
||
311 | 4 | protected function getPropertyStringValue(\DOMElement $element) |
|
327 | |||
328 | /** |
||
329 | * Process a DOM element's children |
||
330 | * |
||
331 | * @param \DOMElement $element DOM element |
||
332 | * @param Context $context Context |
||
333 | * @return Context Context for children |
||
334 | */ |
||
335 | 8 | public function processElementChildren(\DOMElement $element, Context $context) |
|
340 | |||
341 | /** |
||
342 | * Create nested children |
||
343 | * |
||
344 | * @param \DOMElement $element DOM element |
||
345 | * @param Context $context Context |
||
346 | * @return Context Context for children |
||
347 | */ |
||
348 | 8 | protected function processTypeof(\DOMElement $element, Context $context) |
|
364 | } |
||
365 |