1 | <?php |
||
54 | abstract class AbstractElementProcessor implements ElementProcessorInterface |
||
55 | { |
||
56 | /** |
||
57 | * Tag name / attribute map |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | protected static $tagNameAttributes = [ |
||
62 | 'META' => 'content', |
||
63 | 'AUDIO' => 'src', |
||
64 | 'EMBED' => 'src', |
||
65 | 'IFRAME' => 'src', |
||
66 | 'IMG' => 'src', |
||
67 | 'SOURCE' => 'src', |
||
68 | 'TRACK' => 'src', |
||
69 | 'VIDEO' => 'src', |
||
70 | 'A' => 'href', |
||
71 | 'AREA' => 'href', |
||
72 | 'LINK' => 'href', |
||
73 | 'OBJECT' => 'data', |
||
74 | 'DATA' => 'value', |
||
75 | 'METER' => 'value', |
||
76 | 'TIME' => 'datetime' |
||
77 | ]; |
||
78 | /** |
||
79 | * HTML mode |
||
80 | * |
||
81 | * @var boolean |
||
82 | */ |
||
83 | protected $html; |
||
84 | |||
85 | /** |
||
86 | * Element processor constructor |
||
87 | * |
||
88 | * @param bool $html HTML mode |
||
89 | */ |
||
90 | 13 | public function __construct($html = false) |
|
94 | |||
95 | /** |
||
96 | * Process a DOM element's child |
||
97 | * |
||
98 | * @param \DOMElement $element DOM element |
||
99 | * @param ContextInterface $context Context |
||
100 | * @return ContextInterface Context for children |
||
101 | */ |
||
102 | 13 | public function processElementChildren(\DOMElement $element, ContextInterface $context) |
|
107 | |||
108 | /** |
||
109 | * Create a nested child |
||
110 | * |
||
111 | * @param \DOMElement $element DOM element |
||
112 | * @param ContextInterface $context Context |
||
113 | * @return ContextInterface Context for children |
||
114 | */ |
||
115 | abstract protected function processChild(\DOMElement $element, ContextInterface $context); |
||
116 | |||
117 | /** |
||
118 | * Create a property |
||
119 | * |
||
120 | * @param \DOMElement $element DOM element |
||
121 | * @param ContextInterface $context Inherited Context |
||
122 | * @return ContextInterface Local context for this element |
||
123 | */ |
||
124 | abstract protected function processProperty(\DOMElement $element, ContextInterface $context); |
||
125 | |||
126 | /** |
||
127 | * Split a property into prefix and name |
||
128 | * |
||
129 | * @param string $property Prefixed property |
||
130 | * @return array Prefix and name |
||
131 | */ |
||
132 | 5 | protected function splitProperty($property) |
|
139 | |||
140 | /** |
||
141 | * Create a property by prefix and name |
||
142 | * |
||
143 | * @param string $prefix Property prefix |
||
144 | * @param string $name Property name |
||
145 | * @param \DOMElement $element DOM element |
||
146 | * @param ContextInterface $context Inherited Context |
||
147 | * @return ContextInterface Local context for this element |
||
148 | */ |
||
149 | 7 | protected function processPropertyPrefixName($prefix, $name, \DOMElement $element, ContextInterface $context) |
|
158 | |||
159 | |||
160 | /** |
||
161 | * Return a vocabulary by prefix with fallback to the default vocabulary |
||
162 | * |
||
163 | * @param string $prefix Vocabulary prefix |
||
164 | * @param ContextInterface $context Context |
||
165 | * @return VocabularyInterface Vocabulary |
||
166 | */ |
||
167 | abstract protected function getVocabulary($prefix, ContextInterface $context); |
||
168 | |||
169 | /** |
||
170 | * Add a single property |
||
171 | * |
||
172 | * @param \DOMElement $element DOM element |
||
173 | * @param ContextInterface $context Inherited Context |
||
174 | * @param string $name Property name |
||
175 | * @param VocabularyInterface $vocabulary Property vocabulary |
||
176 | * @return ContextInterface Local context for this element |
||
177 | */ |
||
178 | 7 | protected function addProperty( |
|
201 | |||
202 | /** |
||
203 | * Return the resource ID |
||
204 | * |
||
205 | * @param \DOMElement $element DOM element |
||
206 | * @return string|null Resource ID |
||
207 | */ |
||
208 | abstract protected function getResourceId(\DOMElement $element); |
||
209 | |||
210 | /** |
||
211 | * Return a property value (type and tag name dependent) |
||
212 | * |
||
213 | * @param \DOMElement $element DOM element |
||
214 | * @param ContextInterface $context Context |
||
215 | * @return ThingInterface|string Property value |
||
216 | */ |
||
217 | abstract protected function getPropertyValue(\DOMElement $element, ContextInterface $context); |
||
218 | |||
219 | /** |
||
220 | * Return a thing by typeof value |
||
221 | * |
||
222 | * @param string $typeof Thing type |
||
223 | * @param string $resourceId Resource ID |
||
224 | * @param ContextInterface $context Context |
||
225 | * @return Thing Thing |
||
226 | */ |
||
227 | 13 | protected function getThing($typeof, $resourceId, ContextInterface $context) |
|
235 | |||
236 | /** |
||
237 | * Return a thing by prefix and type |
||
238 | * |
||
239 | * @param string $prefix Prefix |
||
240 | * @param string $type Type |
||
241 | * @param string $resourceId Resource ID |
||
242 | * @param ContextInterface $context Context |
||
243 | * @return Thing Thing |
||
244 | * @throws RuntimeException If the default vocabulary is empty |
||
245 | * @throws OutOfBoundsException If the vocabulary prefix is unknown |
||
246 | */ |
||
247 | 13 | protected function getThingByPrefixType($prefix, $type, $resourceId, ContextInterface $context) |
|
272 | |||
273 | /** |
||
274 | * Return a property value (type and tag name dependent) |
||
275 | * |
||
276 | * @param \DOMElement $element DOM element |
||
277 | * @return ThingInterface|string Property value |
||
278 | */ |
||
279 | 7 | protected function getPropertyStringValue(\DOMElement $element) |
|
297 | } |
||
298 |