1 | <?php |
||
60 | class JsonLD extends AbstractParser |
||
61 | { |
||
62 | /** |
||
63 | * Format |
||
64 | * |
||
65 | * @var int |
||
66 | */ |
||
67 | const FORMAT = Format::JSON_LD; |
||
68 | /** |
||
69 | * Regex pattern for matching leading comments in a JSON string |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | const JSON_COMMENT_PATTERN = '#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#'; |
||
74 | /** |
||
75 | * Vocabulary cache |
||
76 | * |
||
77 | * @var VocabularyCache |
||
78 | */ |
||
79 | protected $vocabularyCache; |
||
80 | /** |
||
81 | * Context loader |
||
82 | * |
||
83 | * @var CachingContextLoader |
||
84 | */ |
||
85 | protected $contextLoader; |
||
86 | |||
87 | /** |
||
88 | * JSON-LD parser constructor |
||
89 | * |
||
90 | * @param UriInterface $uri Base URI |
||
91 | * @param LoggerInterface $logger Logger |
||
92 | */ |
||
93 | 5 | public function __construct(UriInterface $uri, LoggerInterface $logger) |
|
99 | |||
100 | /** |
||
101 | * Parse a DOM document |
||
102 | * |
||
103 | * @param \DOMDocument $dom DOM Document |
||
104 | * @return ParsingResultInterface Micro information items |
||
105 | */ |
||
106 | 4 | public function parseDom(\DOMDocument $dom) |
|
126 | |||
127 | /** |
||
128 | * Parse a JSON-LD document |
||
129 | * |
||
130 | * @param string $jsonLDDocSource JSON-LD document |
||
131 | * @return array Items |
||
132 | */ |
||
133 | 4 | protected function parseDocument($jsonLDDocSource) |
|
150 | |||
151 | /** |
||
152 | * Parse a JSON-LD root node |
||
153 | * |
||
154 | * @param \stdClass $jsonLDRoot JSON-LD root node |
||
155 | */ |
||
156 | 2 | protected function parseRootNode($jsonLDRoot) |
|
175 | |||
176 | /** |
||
177 | * Parse a JSON-LD node |
||
178 | * |
||
179 | * @param NodeInterface $node Node |
||
180 | * @return \stdClass Item |
||
181 | */ |
||
182 | 2 | protected function parseNode(NodeInterface $node) |
|
190 | |||
191 | /** |
||
192 | * Parse the type of a JSON-LD node |
||
193 | * |
||
194 | * @param NodeInterface $node Node |
||
195 | * @return array Item type |
||
196 | */ |
||
197 | 2 | protected function parseNodeType(NodeInterface $node) |
|
202 | |||
203 | /** |
||
204 | * Parse the properties of a JSON-LD node |
||
205 | * |
||
206 | * @param NodeInterface $node Node |
||
207 | * @return array Item properties |
||
208 | */ |
||
209 | 2 | protected function parseNodeProperties(NodeInterface $node) |
|
229 | |||
230 | /** |
||
231 | * Initialize a JSON-LD node property (if necessary) |
||
232 | * |
||
233 | * @param string $name Property name |
||
234 | * @param array $properties Item properties |
||
235 | */ |
||
236 | 2 | protected function initializeNodeProperty($name, array &$properties) |
|
243 | |||
244 | /** |
||
245 | * Process a property value |
||
246 | * |
||
247 | * @param string $name Property name |
||
248 | * @param \stdClass|array|string $value Property value |
||
249 | * @param array $properties Item properties |
||
250 | */ |
||
251 | 2 | protected function processNodeProperty($name, $value, array &$properties) |
|
268 | |||
269 | /** |
||
270 | * Process a property value object |
||
271 | * |
||
272 | * @param string $name Property name |
||
273 | * @param \stdClass $value Property value |
||
274 | * @param array $properties Properties |
||
275 | */ |
||
276 | 2 | protected function processNodePropertyObject($name, $value, array &$properties) |
|
286 | |||
287 | /** |
||
288 | * Parse a JSON-LD fragment |
||
289 | * |
||
290 | * @param NodeInterface|LanguageTaggedString|TypedValue|array $jsonLD JSON-LD fragment |
||
291 | * @return \stdClass|string|array Parsed fragment |
||
292 | */ |
||
293 | 2 | protected function parse($jsonLD) |
|
313 | |||
314 | /** |
||
315 | * Parse a language tagged string |
||
316 | * |
||
317 | * @param LanguageTaggedString $value Language tagged string |
||
318 | * @return \stdClass Value |
||
319 | */ |
||
320 | 1 | protected function parseLanguageTaggedString(LanguageTaggedString $value) |
|
324 | |||
325 | /** |
||
326 | * Parse a typed value |
||
327 | * |
||
328 | * @param TypedValue $value Typed value |
||
329 | * @return string Value |
||
330 | */ |
||
331 | 2 | protected function parseTypedValue(TypedValue $value) |
|
335 | } |
||
336 |