public function ViewsJsonQuery::apath in Views Json Source 1.x
Same name and namespace in other branches
- 8 src/Plugin/views/query/ViewsJsonQuery.php \Drupal\views_json_source\Plugin\views\query\ViewsJsonQuery::apath()
Fetch data in array according to apath.
Parameters
string $apath: Something like '1/name/0'.
array $array: The json document content.
Return value
array The json document matching the path.
1 call to ViewsJsonQuery::apath()
- ViewsJsonQuery::parse in src/
Plugin/ views/ query/ ViewsJsonQuery.php - Parse.
File
- src/
Plugin/ views/ query/ ViewsJsonQuery.php, line 196
Class
- ViewsJsonQuery
- Base query handler for views_json_source.
Namespace
Drupal\views_json_source\Plugin\views\queryCode
public function apath($apath, array $array) {
$r =& $array;
$paths = explode('/', trim($apath, '//'));
foreach ($paths as $path) {
if ($path == '%') {
// Replace with the contextual filter value.
$key = $this
->getCurrentContextualFilter();
$r = $r[$key];
}
elseif (is_array($r) && isset($r[$path])) {
$r =& $r[$path];
}
elseif (is_object($r)) {
$r =& $r->{$path};
}
else {
break;
}
}
return $r;
}