1 | <?php |
||
53 | abstract class AbstractElementProcessor implements ElementProcessorInterface |
||
54 | { |
||
55 | /** |
||
56 | * Use the property processor methods |
||
57 | */ |
||
58 | use PropertyProcessorTrait; |
||
59 | |||
60 | /** |
||
61 | * Tag name / attribute map |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected static $tagNameAttributes = [ |
||
66 | 'META' => 'content', |
||
67 | 'AUDIO' => 'src', |
||
68 | 'EMBED' => 'src', |
||
69 | 'IFRAME' => 'src', |
||
70 | 'IMG' => 'src', |
||
71 | 'SOURCE' => 'src', |
||
72 | 'TRACK' => 'src', |
||
73 | 'VIDEO' => 'src', |
||
74 | 'A' => 'href', |
||
75 | 'AREA' => 'href', |
||
76 | 'LINK' => 'href', |
||
77 | 'OBJECT' => 'data', |
||
78 | 'DATA' => 'value', |
||
79 | 'METER' => 'value', |
||
80 | 'TIME' => 'datetime' |
||
81 | ]; |
||
82 | /** |
||
83 | * Property cache |
||
84 | * |
||
85 | * @var array |
||
86 | */ |
||
87 | protected static $propertyCache = []; |
||
88 | /** |
||
89 | * HTML mode |
||
90 | * |
||
91 | * @var boolean |
||
92 | */ |
||
93 | protected $html; |
||
94 | |||
95 | /** |
||
96 | * Enable / disable HTML element value resolution |
||
97 | * |
||
98 | * @param bool $html Enable HTML element value resolution |
||
99 | * @return ElementProcessorInterface Self reference |
||
100 | */ |
||
101 | 11 | public function setHtml($html) |
|
106 | |||
107 | /** |
||
108 | * Process a DOM element's child |
||
109 | * |
||
110 | * @param \DOMElement $element DOM element |
||
111 | * @param ContextInterface $context Context |
||
112 | * @return ContextInterface Context for children |
||
113 | */ |
||
114 | 14 | public function processElementChildren(\DOMElement $element, ContextInterface $context) |
|
119 | |||
120 | /** |
||
121 | * Create a nested child |
||
122 | * |
||
123 | * @param \DOMElement $element DOM element |
||
124 | * @param ContextInterface $context Context |
||
125 | * @return ContextInterface Context for children |
||
126 | */ |
||
127 | abstract protected function processChild(\DOMElement $element, ContextInterface $context); |
||
128 | |||
129 | /** |
||
130 | * Return the resource ID |
||
131 | * |
||
132 | * @param \DOMElement $element DOM element |
||
133 | * @return string|null Resource ID |
||
134 | */ |
||
135 | abstract protected function getResourceId(\DOMElement $element); |
||
136 | |||
137 | /** |
||
138 | * Return a thing by typeof value |
||
139 | * |
||
140 | * @param string|null $typeof Thing type |
||
141 | * @param string|null $resourceId Resource ID |
||
142 | * @param ContextInterface $context Context |
||
143 | * @return Thing Thing |
||
144 | * @throws RuntimeException If the default vocabulary is empty |
||
145 | */ |
||
146 | 14 | protected function getThing($typeof, $resourceId, ContextInterface $context) |
|
158 | |||
159 | /** |
||
160 | * Instanciate a type |
||
161 | * |
||
162 | * @param string $prefixedType Prefixed type |
||
163 | * @param ContextInterface $context Context |
||
164 | * @return TypeInterface Type |
||
165 | */ |
||
166 | 13 | protected function getType($prefixedType, ContextInterface $context) |
|
180 | |||
181 | /** |
||
182 | * Split a value into a vocabulary prefix and a name |
||
183 | * |
||
184 | * @param string $prefixName Prefixed name |
||
185 | * @return array Prefix and name |
||
186 | */ |
||
187 | abstract protected function getPrefixName($prefixName); |
||
188 | |||
189 | /** |
||
190 | * Return a vocabulary by prefix with fallback to the default vocabulary |
||
191 | * |
||
192 | * @param string $prefix Vocabulary prefix |
||
193 | * @param ContextInterface $context Context |
||
194 | * @return VocabularyInterface Vocabulary |
||
195 | */ |
||
196 | abstract protected function getVocabulary($prefix, ContextInterface $context); |
||
197 | } |
||
198 |