Class to decode JSON data that contains path-based references.
The language data file for highlight.js are written as JavaScript classes
and therefore may contain variables. This allows for inner references in
the language data. This kind of data can be converterd to JSON using the
path based references. This class can be used to decode such JSON
structures. It follows the conventions for path based referencing as
used in dojox.json.ref form the Dojo toolkit (Javascript). A typical
example of such a structure is as follows:
{
"name":"Kris Zyp",
"children":[{"name":"Jennika Zyp"},{"name":"Korban Zyp"}],
"spouse":{
"name":"Nicole Zyp",
"spouse":{"$ref":"#"},
"children":{"$ref":"#children"}
},
"oldestChild":{"$ref":"#children.0"}
}
Usage example:
$jr = new JsonRef();
$data = $jr->decode(file_get_contents("data.json"));
echo $data->spouse->spouse->name; // echos 'Kris Zyp'
echo $data->oldestChild->name; // echos 'Jennika Zyp'
- todo In Highlight.php 10.x, mark this class final with a keyword.
- since 9.16.0.0Class has been marked as final
- final
- internal
Methods |
public
decodeRef
(
$json
) Decode JSON data that may contain path based references.
|
Properties |
private
$paths
Array to hold all data paths in the given JSON data.
|
Methods |
private
getPaths
(
$s
,
$r
=
'#'
) Recurse through the data tree and fill an array of paths that reference
|
private
resolvePathReferences
(
$s
,
$limit
=
20
,
$depth
=
1
) Recurse through the data tree and resolve all path references.
|