1 | <?php |
||
60 | class JsonLD extends AbstractParser |
||
61 | { |
||
62 | /** |
||
63 | * Vocabulary cache |
||
64 | * |
||
65 | * @var VocabularyCache |
||
66 | */ |
||
67 | protected $vocabularyCache; |
||
68 | /** |
||
69 | * Context loader |
||
70 | * |
||
71 | * @var CachingContextLoader |
||
72 | */ |
||
73 | protected $contextLoader; |
||
74 | /** |
||
75 | * Format |
||
76 | * |
||
77 | * @var int |
||
78 | */ |
||
79 | const FORMAT = Format::JSON_LD; |
||
80 | /** |
||
81 | * Regex pattern for matching leading comments in a JSON string |
||
82 | * |
||
83 | * @var string |
||
84 | */ |
||
85 | const JSON_COMMENT_PATTERN = '#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#'; |
||
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) |
|
125 | |||
126 | /** |
||
127 | * Parse a JSON-LD document |
||
128 | * |
||
129 | * @param string $jsonLDDocSource JSON-LD document |
||
130 | * @return array Items |
||
131 | */ |
||
132 | 4 | protected function parseDocument($jsonLDDocSource) |
|
149 | |||
150 | /** |
||
151 | * Parse a JSON-LD root node |
||
152 | * |
||
153 | * @param \stdClass $jsonLDRoot JSON-LD root node |
||
154 | */ |
||
155 | 2 | protected function parseRootNode($jsonLDRoot) |
|
174 | |||
175 | /** |
||
176 | * Parse a JSON-LD fragment |
||
177 | * |
||
178 | * @param NodeInterface|LanguageTaggedString|TypedValue|array $jsonLD JSON-LD fragment |
||
179 | * @return \stdClass|string|array Parsed fragment |
||
180 | */ |
||
181 | 2 | protected function parse($jsonLD) |
|
201 | |||
202 | /** |
||
203 | * Parse a JSON-LD node |
||
204 | * |
||
205 | * @param NodeInterface $node Node |
||
206 | * @return \stdClass Item |
||
207 | */ |
||
208 | 2 | protected function parseNode(NodeInterface $node) |
|
216 | |||
217 | /** |
||
218 | * Parse the type of a JSON-LD node |
||
219 | * |
||
220 | * @param NodeInterface $node Node |
||
221 | * @return array Item type |
||
222 | */ |
||
223 | 2 | protected function parseNodeType(NodeInterface $node) |
|
228 | |||
229 | /** |
||
230 | * Parse the properties of a JSON-LD node |
||
231 | * |
||
232 | * @param NodeInterface $node Node |
||
233 | * @return array Item properties |
||
234 | */ |
||
235 | 2 | protected function parseNodeProperties(NodeInterface $node) |
|
255 | |||
256 | /** |
||
257 | * Initialize a JSON-LD node property (if necessary) |
||
258 | * |
||
259 | * @param string $name Property name |
||
260 | * @param array $properties Item properties |
||
261 | */ |
||
262 | 2 | protected function initializeNodeProperty($name, array &$properties) |
|
269 | |||
270 | /** |
||
271 | * Process a property value |
||
272 | * |
||
273 | * @param string $name Property name |
||
274 | * @param \stdClass|array|string $value Property value |
||
275 | * @param array $properties Item properties |
||
276 | */ |
||
277 | 2 | protected function processNodeProperty($name, $value, array &$properties) |
|
292 | |||
293 | /** |
||
294 | * Process a property value object |
||
295 | * |
||
296 | * @param string $name Property name |
||
297 | * @param \stdClass $value Property value |
||
298 | * @param array $properties Properties |
||
299 | */ |
||
300 | 2 | protected function processNodePropertyObject($name, $value, array &$properties) |
|
310 | |||
311 | /** |
||
312 | * Parse a language tagged string |
||
313 | * |
||
314 | * @param LanguageTaggedString $value Language tagged string |
||
315 | * @return \stdClass Value |
||
316 | */ |
||
317 | 1 | protected function parseLanguageTaggedString(LanguageTaggedString $value) |
|
321 | |||
322 | /** |
||
323 | * Parse a typed value |
||
324 | * |
||
325 | * @param TypedValue $value Typed value |
||
326 | * @return string Value |
||
327 | */ |
||
328 | 2 | protected function parseTypedValue(TypedValue $value) |
|
332 | } |
||
333 |