simplify asset collections in a single array

This commit is contained in:
Andy Miller
2022-01-09 14:35:16 -07:00
parent c962201bae
commit 756b088ada
3 changed files with 24 additions and 23 deletions

View File

@@ -61,11 +61,7 @@ class Assets extends PropertyObject
protected $assets_url;
/** @var array */
protected $assets_css = [];
/** @var array */
protected $assets_js = [];
/** @var array */
protected $assets_js_module = [];
protected $assets= [];
// Following variables come from the configuration:
/** @var bool */
@@ -120,6 +116,11 @@ class Assets extends PropertyObject
$this->assets_dir = $locator->findResource('asset://');
$this->assets_url = $locator->findResource('asset://', false);
// Initialize asset collection storage
$this->assets[self::CSS_COLLECTION] = [];
$this->assets[self::JS_COLLECTION] = [];
$this->assets[self::JS_MODULE_COLLECTION] = [];
$this->config($asset_config);
// Register any preconfigured collections
@@ -285,7 +286,7 @@ class Assets extends PropertyObject
// If exists
if ($asset_object->init($asset, $options)) {
$this->$collection[md5($asset)] = $asset_object;
$this->assets[$collection][md5($asset)] = $asset_object;
}
return $this;
@@ -431,11 +432,11 @@ class Assets extends PropertyObject
$pipeline_output = '';
$after_output = '';
$assets = 'assets_' . $type;
$collection = 'assets_' . $type;
$pipeline_enabled = $type . '_pipeline';
$render_pipeline = 'render' . ucfirst($type);
$group_assets = $this->filterAssets($this->$assets, 'group', $group);
$group_assets = $this->filterAssets($this->assets[$collection], 'group', $group);
$pipeline_assets = $this->filterAssets($group_assets, 'position', 'pipeline', true);
$before_assets = $this->filterAssets($group_assets, 'position', 'before', true);
$after_assets = $this->filterAssets($group_assets, 'position', 'after', true);

View File

@@ -30,7 +30,7 @@ trait TestingAssetsTrait
*/
public function exists($asset)
{
return isset($this->collections[$asset]) || isset($this->assets_css[$asset]) || isset($this->assets_js[$asset]);
return isset($this->collections[$asset]) || isset($this->assets[self::CSS_COLLECTION][$asset]) || isset($this->assets[self::JS_COLLECTION][$asset]);
}
/**
@@ -69,10 +69,10 @@ trait TestingAssetsTrait
if (null !== $key) {
$asset_key = md5($key);
return $this->assets_css[$asset_key] ?? null;
return $this->assets[self::CSS_COLLECTION][$asset_key] ?? null;
}
return $this->assets_css;
return $this->assets[self::CSS_COLLECTION];
}
/**
@@ -88,10 +88,10 @@ trait TestingAssetsTrait
if (null !== $key) {
$asset_key = md5($key);
return $this->assets_js[$asset_key] ?? null;
return $this->assets[self::JS_COLLECTION][$asset_key] ?? null;
}
return $this->assets_js;
return $this->assets[self::JS_COLLECTION];
}
/**
@@ -102,7 +102,7 @@ trait TestingAssetsTrait
*/
public function setCss($css)
{
$this->assets_css = $css;
$this->assets[self::CSS_COLLECTION] = $css;
return $this;
}
@@ -115,7 +115,7 @@ trait TestingAssetsTrait
*/
public function setJs($js)
{
$this->assets_js = $js;
$this->assets[self::JS_COLLECTION] = $js;
return $this;
}
@@ -129,8 +129,8 @@ trait TestingAssetsTrait
public function removeCss($key)
{
$asset_key = md5($key);
if (isset($this->assets_css[$asset_key])) {
unset($this->assets_css[$asset_key]);
if (isset($this->assets[self::CSS_COLLECTION][$asset_key])) {
unset($this->assets[self::CSS_COLLECTION][$asset_key]);
}
return $this;
@@ -145,8 +145,8 @@ trait TestingAssetsTrait
public function removeJs($key)
{
$asset_key = md5($key);
if (isset($this->assets_js[$asset_key])) {
unset($this->assets_js[$asset_key]);
if (isset($this->assets[self::JS_COLLECTION][$asset_key])) {
unset($this->assets[self::JS_COLLECTION][$asset_key]);
}
return $this;
@@ -201,7 +201,7 @@ trait TestingAssetsTrait
*/
public function resetJs()
{
$this->assets_js = [];
$this->assets[self::JS_COLLECTION] = [];
return $this;
}
@@ -213,7 +213,7 @@ trait TestingAssetsTrait
*/
public function resetCss()
{
$this->assets_css = [];
$this->assets[self::CSS_COLLECTION] = [];
return $this;
}

View File

@@ -28,8 +28,8 @@ assets:
css_pipeline: false
css_minify: true
css_rewrite: true
js_pipeline: true
js_module_pipeline: true
js_pipeline: false
js_module_pipeline: false
js_minify: true
errors: