1 | <?php |
||
55 | abstract class AbstractElementProcessor 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 | 'METER' => 'value', |
||
77 | 'TIME' => 'datetime' |
||
78 | ]; |
||
79 | /** |
||
80 | * HTML mode |
||
81 | * |
||
82 | * @var boolean |
||
83 | */ |
||
84 | protected $html; |
||
85 | |||
86 | /** |
||
87 | * Element processor constructor |
||
88 | * |
||
89 | * @param bool $html HTML mode |
||
90 | */ |
||
91 | 13 | public function __construct($html = false) |
|
95 | |||
96 | /** |
||
97 | * Process a DOM element's child |
||
98 | * |
||
99 | * @param \DOMElement $element DOM element |
||
100 | * @param ContextInterface $context Context |
||
101 | * @return ContextInterface Context for children |
||
102 | */ |
||
103 | 13 | public function processElementChildren(\DOMElement $element, ContextInterface $context) |
|
108 | |||
109 | /** |
||
110 | * Create a nested child |
||
111 | * |
||
112 | * @param \DOMElement $element DOM element |
||
113 | * @param ContextInterface $context Context |
||
114 | * @return ContextInterface Context for children |
||
115 | */ |
||
116 | abstract protected function processChild(\DOMElement $element, ContextInterface $context); |
||
117 | |||
118 | /** |
||
119 | * Create a property |
||
120 | * |
||
121 | * @param \DOMElement $element DOM element |
||
122 | * @param ContextInterface $context Inherited Context |
||
123 | * @return ContextInterface Local context for this element |
||
124 | */ |
||
125 | abstract protected function processProperty(\DOMElement $element, ContextInterface $context); |
||
126 | |||
127 | /** |
||
128 | * Split a property into prefix and name |
||
129 | * |
||
130 | * @param string $property Prefixed property |
||
131 | * @return array Prefix and name |
||
132 | */ |
||
133 | 5 | protected function splitProperty($property) |
|
140 | |||
141 | /** |
||
142 | * Create a property by prefix and name |
||
143 | * |
||
144 | * @param string $prefix Property prefix |
||
145 | * @param string $name Property name |
||
146 | * @param \DOMElement $element DOM element |
||
147 | * @param ContextInterface $context Inherited Context |
||
148 | * @return ContextInterface Local context for this element |
||
149 | */ |
||
150 | 7 | protected function processPropertyPrefixName($prefix, $name, \DOMElement $element, ContextInterface $context) |
|
159 | |||
160 | |||
161 | /** |
||
162 | * Return a vocabulary by prefix with fallback to the default vocabulary |
||
163 | * |
||
164 | * @param string $prefix Vocabulary prefix |
||
165 | * @param ContextInterface $context Context |
||
166 | * @return VocabularyInterface Vocabulary |
||
167 | */ |
||
168 | abstract protected function getVocabulary($prefix, ContextInterface $context); |
||
169 | |||
170 | /** |
||
171 | * Add a single property |
||
172 | * |
||
173 | * @param \DOMElement $element DOM element |
||
174 | * @param ContextInterface $context Inherited Context |
||
175 | * @param string $name Property name |
||
176 | * @param VocabularyInterface $vocabulary Property vocabulary |
||
177 | * @return ContextInterface Local context for this element |
||
178 | */ |
||
179 | 7 | protected function addProperty( |
|
202 | |||
203 | /** |
||
204 | * Return the resource ID |
||
205 | * |
||
206 | * @param \DOMElement $element DOM element |
||
207 | * @return string|null Resource ID |
||
208 | */ |
||
209 | abstract protected function getResourceId(\DOMElement $element); |
||
210 | |||
211 | /** |
||
212 | * Return a property value (type and tag name dependent) |
||
213 | * |
||
214 | * @param \DOMElement $element DOM element |
||
215 | * @param ContextInterface $context Context |
||
216 | * @return ThingInterface|string Property value |
||
217 | */ |
||
218 | abstract protected function getPropertyValue(\DOMElement $element, ContextInterface $context); |
||
219 | |||
220 | /** |
||
221 | * Return a thing by typeof value |
||
222 | * |
||
223 | * @param string $typeof Thing type |
||
224 | * @param string $resourceId Resource ID |
||
225 | * @param ContextInterface $context Context |
||
226 | * @return Thing Thing |
||
227 | */ |
||
228 | 13 | protected function getThing($typeof, $resourceId, ContextInterface $context) |
|
236 | |||
237 | /** |
||
238 | * Return a thing by prefix and type |
||
239 | * |
||
240 | * @param string $prefix Prefix |
||
241 | * @param string $typeName Type |
||
242 | * @param string $resourceId Resource ID |
||
243 | * @param ContextInterface $context Context |
||
244 | * @return Thing Thing |
||
245 | * @throws RuntimeException If the default vocabulary is empty |
||
246 | * @throws OutOfBoundsException If the vocabulary prefix is unknown |
||
247 | */ |
||
248 | 13 | protected function getThingByPrefixType($prefix, $typeName, $resourceId, ContextInterface $context) |
|
274 | |||
275 | /** |
||
276 | * Return a property value (type and tag name dependent) |
||
277 | * |
||
278 | * @param \DOMElement $element DOM element |
||
279 | * @return ThingInterface|string Property value |
||
280 | */ |
||
281 | 7 | protected function getPropertyStringValue(\DOMElement $element) |
|
299 | } |
||
300 |