1 | <?php |
||
52 | class RdfaLiteElementProcessor extends AbstractElementProcessor |
||
53 | { |
||
54 | /** |
||
55 | * Process a DOM element |
||
56 | * |
||
57 | * @param \DOMElement $element DOM element |
||
58 | * @param ContextInterface $context Inherited Context |
||
59 | * @return ContextInterface Local context for this element |
||
60 | */ |
||
61 | 13 | public function processElement(\DOMElement $element, ContextInterface $context) |
|
72 | |||
73 | /** |
||
74 | * Process changes of the default vocabulary |
||
75 | * |
||
76 | * @param \DOMElement $element DOM element |
||
77 | * @param ContextInterface $context Inherited Context |
||
78 | * @return ContextInterface Local context for this element |
||
79 | */ |
||
80 | 13 | protected function processVocab(\DOMElement $element, ContextInterface $context) |
|
89 | |||
90 | /** |
||
91 | * Process vocabulary prefixes |
||
92 | * |
||
93 | * @param \DOMElement $element DOM element |
||
94 | * @param ContextInterface $context Inherited Context |
||
95 | * @return ContextInterface Local context for this element |
||
96 | */ |
||
97 | 13 | protected function processPrefix(\DOMElement $element, ContextInterface $context) |
|
110 | |||
111 | /** |
||
112 | * Create a property |
||
113 | * |
||
114 | * @param \DOMElement $element DOM element |
||
115 | * @param ContextInterface $context Inherited Context |
||
116 | * @return ContextInterface Local context for this element |
||
117 | */ |
||
118 | 13 | protected function processProperty(\DOMElement $element, ContextInterface $context) |
|
136 | |||
137 | /** |
||
138 | * Split a value into a vocabulary prefix and a name |
||
139 | * |
||
140 | * @param string $prefixName Prefixed name |
||
141 | * @return array Prefix and name |
||
142 | */ |
||
143 | 13 | protected function getPrefixName($prefixName) |
|
150 | |||
151 | /** |
||
152 | * Create a nested child |
||
153 | * |
||
154 | * @param \DOMElement $element DOM element |
||
155 | * @param ContextInterface $context Context |
||
156 | * @return ContextInterface Context for children |
||
157 | */ |
||
158 | 13 | protected function processChild(\DOMElement $element, ContextInterface $context) |
|
159 | { |
||
160 | 13 | if ($element->hasAttribute('typeof') |
|
161 | 13 | && (empty($element->getAttribute('property')) || $context->getParentThing() instanceof RootThing) |
|
162 | 13 | ) { |
|
163 | 13 | $context = $this->createAndAddChild($element, $context); |
|
164 | 7 | } |
|
165 | |||
166 | 13 | return $context; |
|
167 | } |
||
168 | |||
169 | /** |
||
170 | * Create and add a nested child |
||
171 | * |
||
172 | * @param \DOMElement $element DOM element |
||
173 | * @param ContextInterface $context Context |
||
174 | * @return ContextInterface Context for children |
||
175 | */ |
||
176 | 13 | protected function createAndAddChild(\DOMElement $element, ContextInterface $context) |
|
177 | { |
||
178 | 13 | $thing = $this->getThing( |
|
179 | 13 | $element->getAttribute('typeof'), |
|
180 | 13 | trim($element->getAttribute('resource')) ?: null, |
|
181 | $context |
||
182 | 13 | ); |
|
183 | |||
184 | // Add the new thing as a child to the current context |
||
185 | // and set the thing as parent thing for nested iterations |
||
186 | 7 | return $context->addChild($thing)->setParentThing($thing); |
|
187 | } |
||
188 | |||
189 | |||
190 | /** |
||
191 | * Return a property child value |
||
192 | * |
||
193 | * @param \DOMElement $element DOM element |
||
194 | * @param ContextInterface $context Context |
||
195 | * @return ThingInterface|null Property child value |
||
196 | */ |
||
197 | 7 | protected function getPropertyChildValue(\DOMElement $element, ContextInterface $context) |
|
198 | { |
||
199 | // If the property creates a new thing |
||
200 | 7 | if ($element->hasAttribute('typeof')) { |
|
201 | 4 | return $this->getThing( |
|
202 | 4 | $element->getAttribute('typeof'), |
|
203 | 4 | trim($element->getAttribute('resource')) ?: null, |
|
204 | $context |
||
205 | 4 | ); |
|
206 | } |
||
207 | |||
208 | 7 | return null; |
|
209 | } |
||
210 | |||
211 | /** |
||
212 | * Return the resource ID |
||
213 | * |
||
214 | * @param \DOMElement $element DOM element |
||
215 | * @return string|null Resource ID |
||
216 | */ |
||
217 | 7 | protected function getResourceId(\DOMElement $element) |
|
221 | |||
222 | /** |
||
223 | * Return a vocabulary by prefix with fallback to the default vocabulary |
||
224 | * |
||
225 | * @param string $prefix Vocabulary prefix |
||
226 | * @param ContextInterface $context Context |
||
227 | * @return VocabularyInterface Vocabulary |
||
228 | */ |
||
229 | 13 | protected function getVocabulary($prefix, ContextInterface $context) |
|
234 | } |
||
235 |