Adds get_path method to JsonManifest
This commit is contained in:
@@ -32,6 +32,24 @@ class JsonManifest {
|
|||||||
public function get() {
|
public function get() {
|
||||||
return $this->manifest;
|
return $this->manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPath($key = '', $default = null) {
|
||||||
|
$collection = $this->manifest;
|
||||||
|
if (is_null($key)) {
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
if (isset($collection[$key])) {
|
||||||
|
return $collection[$key];
|
||||||
|
}
|
||||||
|
foreach (explode('.', $key) as $segment) {
|
||||||
|
if (!isset($collection[$segment])) {
|
||||||
|
return $default;
|
||||||
|
} else {
|
||||||
|
$collection = $collection[$segment];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function asset_path($filename) {
|
function asset_path($filename) {
|
||||||
@@ -43,11 +61,10 @@ function asset_path($filename) {
|
|||||||
if (empty($manifest)) {
|
if (empty($manifest)) {
|
||||||
$manifest_path = get_template_directory() . '/dist/assets.json';
|
$manifest_path = get_template_directory() . '/dist/assets.json';
|
||||||
$manifest = new JsonManifest($manifest_path);
|
$manifest = new JsonManifest($manifest_path);
|
||||||
$manifest = $manifest->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WP_ENV !== 'development' && array_key_exists($file, $manifest)) {
|
if (WP_ENV !== 'development' && array_key_exists($file, $manifest->get())) {
|
||||||
return $dist_path . $directory . $manifest[$file];
|
return $dist_path . $directory . $manifest->get()[$file];
|
||||||
} else {
|
} else {
|
||||||
return $dist_path . $directory . $file;
|
return $dist_path . $directory . $file;
|
||||||
}
|
}
|
||||||
@@ -59,14 +76,13 @@ function bower_map_to_cdn($dependency, $fallback) {
|
|||||||
if (empty($bower)) {
|
if (empty($bower)) {
|
||||||
$bower_path = get_template_directory() . '/bower.json';
|
$bower_path = get_template_directory() . '/bower.json';
|
||||||
$bower = new JsonManifest($bower_path);
|
$bower = new JsonManifest($bower_path);
|
||||||
$bower = $bower->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$templates = [
|
$templates = [
|
||||||
'google' => '//ajax.googleapis.com/ajax/libs/%name%/%version%/%file%'
|
'google' => '//ajax.googleapis.com/ajax/libs/%name%/%version%/%file%'
|
||||||
];
|
];
|
||||||
|
|
||||||
$version = $bower['dependencies'][$dependency['name']];
|
$version = $bower->getPath('dependencies.' . $dependency['name']);
|
||||||
|
|
||||||
if (isset($version) && preg_match('/^(\d+\.){2}\d+$/', $version)) {
|
if (isset($version) && preg_match('/^(\d+\.){2}\d+$/', $version)) {
|
||||||
$search = ['%name%', '%version%', '%file%'];
|
$search = ['%name%', '%version%', '%file%'];
|
||||||
|
|||||||
Reference in New Issue
Block a user