Skip to content

Commit

Permalink
Adjusted asset types to enable extension of assets class (#2937)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Thomas <Jack.Thomas@elavon.com>
  • Loading branch information
jackthomasatl and Jack Thomas authored Jun 22, 2020
1 parent da7df9f commit 25461f7
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions system/src/Grav/Common/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Assets extends PropertyObject

const CSS_COLLECTION = 'assets_css';
const JS_COLLECTION = 'assets_js';
const CSS_TYPE = 'Css';
const JS_TYPE = 'Js';
const INLINE_CSS_TYPE = 'InlineCss';
const INLINE_JS_TYPE = 'InlineJs';
const CSS_TYPE = Assets\Css::Class;
const JS_TYPE = Assets\Js::Class;
const INLINE_CSS_TYPE = Assets\InlineCss::Class;
const INLINE_JS_TYPE = Assets\InlineJs::Class;

/** @const Regex to match CSS and JavaScript files */
const DEFAULT_REGEX = '/.\.(css|js)$/i';
Expand Down Expand Up @@ -207,8 +207,7 @@ protected function addType($collection, $type, $asset, $options)
$options['order'] = \count($this->$collection);

// Create asset of correct type
$asset_class = "\\Grav\\Common\\Assets\\{$type}";
$asset_object = new $asset_class();
$asset_object = new $type();

// If exists
if ($asset_object->init($asset, $options)) {
Expand All @@ -225,7 +224,7 @@ protected function addType($collection, $type, $asset, $options)
*/
public function addCss($asset)
{
return $this->addType(Assets::CSS_COLLECTION, Assets::CSS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), Assets::CSS_TYPE));
return $this->addType($this::CSS_COLLECTION, $this::CSS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), $this::CSS_TYPE));
}

/**
Expand All @@ -235,7 +234,7 @@ public function addCss($asset)
*/
public function addInlineCss($asset)
{
return $this->addType(Assets::CSS_COLLECTION, Assets::INLINE_CSS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), Assets::INLINE_CSS_TYPE));
return $this->addType($this::CSS_COLLECTION, $this::INLINE_CSS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), $this::INLINE_CSS_TYPE));
}

/**
Expand All @@ -245,7 +244,7 @@ public function addInlineCss($asset)
*/
public function addJs($asset)
{
return $this->addType(Assets::JS_COLLECTION, Assets::JS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), Assets::JS_TYPE));
return $this->addType($this::JS_COLLECTION, $this::JS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), $this::JS_TYPE));
}

/**
Expand All @@ -255,7 +254,7 @@ public function addJs($asset)
*/
public function addInlineJs($asset)
{
return $this->addType(Assets::JS_COLLECTION, Assets::INLINE_JS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), Assets::INLINE_JS_TYPE));
return $this->addType($this::JS_COLLECTION, $this::INLINE_JS_TYPE, $asset, $this->unifyLegacyArguments(\func_get_args(), $this::INLINE_JS_TYPE));
}


Expand Down

0 comments on commit 25461f7

Please sign in to comment.