diff --git a/composer.json b/composer.json index dea5633..d19bc57 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "yiisoft/yii2": "*", "natxet/cssmin":"3.*", "tedivm/jshrink":"1.*", - "packagist/yuicompressor-bin":"*", - "packagist/closurecompiler-bin":"*" + "packagelist/yuicompressor-bin":"*", + "packagelist/closurecompiler-bin":"*" }, "autoload": { "psr-4": { diff --git a/src/Combiner.php b/src/Combiner.php index 583cddc..49443a7 100644 --- a/src/Combiner.php +++ b/src/Combiner.php @@ -13,7 +13,7 @@ * @author Lajos Molnár * @since 1.0 */ -class Combiner extends \yii\base\Object +class Combiner extends \yii\base\BaseObject { /** @@ -36,15 +36,25 @@ class Combiner extends \yii\base\Object */ public $combinedFilesPath = '/lajax-asset-minifier'; + /** + * @var string the Web-accessible directory that contains the asset files in this bundle. + */ + public $basePath; + + /** + * @var string the base URL for the relative asset files listed in [[js]] and [[css]]. + */ + public $baseUrl; + /** * @var array List of JavaScript és StyleSheet files grouped by positions. */ - private $_files = []; + protected $_files = []; /** * @var \yii\web\AssetBundle[] List of AssetBundle objects handling combined files. */ - private $_assetBundles = []; + protected $_assetBundles = []; /** * @inheritdoc @@ -52,8 +62,13 @@ class Combiner extends \yii\base\Object public function init() { parent::init(); - - FileHelper::createDirectory(Yii::getAlias('@webroot/assets' . $this->combinedFilesPath), 0777); + if(empty($this->basePath)) { + $this->basePath = \Yii::$app->assetManager->basePath . '/' . $this->combinedFilesPath; + } + if(empty($this->baseUrl)) { + $this->baseUrl = \Yii::$app->assetManager->baseUrl . '/' . $this->combinedFilesPath; + } + FileHelper::createDirectory(Yii::getAlias($this->basePath), 0777); } /** @@ -74,7 +89,10 @@ public function process() foreach (array_keys(Yii::$app->view->assetBundles) as $name) { $this->combineAssetBundles($name); } - + // If empty position is not created, do it now for CSS + if (!isset($this->_assetBundles[''])) { + $this->getAssetBundles(); + } $this->saveAssetFiles(); } @@ -210,8 +228,8 @@ protected function getAssetBundles($position = null) { if (!isset($this->_assetBundles[$position])) { $config = [ - 'basePath' => Yii::getAlias('@webroot/assets' . $this->combinedFilesPath), - 'baseUrl' => Yii::getAlias('@web/assets' . $this->combinedFilesPath) + 'basePath' => Yii::getAlias($this->basePath), + 'baseUrl' => Yii::getAlias($this->baseUrl) ]; if ($position) { @@ -220,7 +238,6 @@ protected function getAssetBundles($position = null) $this->_assetBundles[$position] = new AssetBundle($config); } - return $this->_assetBundles[$position]; } diff --git a/src/Component.php b/src/Component.php index a8758e4..8b5d88d 100644 --- a/src/Component.php +++ b/src/Component.php @@ -23,7 +23,7 @@ * @author Lajos Molnár * @since 1.0 */ -class Component extends \yii\base\Object +class Component extends \yii\base\BaseObject { /** diff --git a/src/Minifier.php b/src/Minifier.php index ab35f2a..db9e281 100644 --- a/src/Minifier.php +++ b/src/Minifier.php @@ -13,7 +13,7 @@ * @author Lajos Molnár * @since 1.0 */ -class Minifier extends \yii\base\Object +class Minifier extends \yii\base\BaseObject { /** diff --git a/src/minifiers/CliMinifier.php b/src/minifiers/CliMinifier.php index 21323ac..00f02d8 100644 --- a/src/minifiers/CliMinifier.php +++ b/src/minifiers/CliMinifier.php @@ -8,7 +8,7 @@ * @author Lajos Molnár * @since 1.0 */ -class CliMinifier extends \yii\base\Object implements MinifierInterface +class CliMinifier extends \yii\base\BaseObject implements MinifierInterface { /** diff --git a/src/minifiers/PhpCssMinifier.php b/src/minifiers/PhpCssMinifier.php index 1befbc9..3543958 100644 --- a/src/minifiers/PhpCssMinifier.php +++ b/src/minifiers/PhpCssMinifier.php @@ -10,7 +10,7 @@ * @author Lajos Molnár * @since 1.0 */ -class PhpCssMinifier extends \yii\base\Object implements MinifierInterface +class PhpCssMinifier extends \yii\base\BaseObject implements MinifierInterface { /** diff --git a/src/minifiers/PhpJsMinifier.php b/src/minifiers/PhpJsMinifier.php index 2427186..f2493ba 100644 --- a/src/minifiers/PhpJsMinifier.php +++ b/src/minifiers/PhpJsMinifier.php @@ -10,7 +10,7 @@ * @author Lajos Molnár * @since 1.0 */ -class PhpJsMinifier extends \yii\base\Object implements MinifierInterface +class PhpJsMinifier extends \yii\base\BaseObject implements MinifierInterface { /** diff --git a/src/minifiers/WebMinifier.php b/src/minifiers/WebMinifier.php index d5fc116..3e01d74 100644 --- a/src/minifiers/WebMinifier.php +++ b/src/minifiers/WebMinifier.php @@ -8,7 +8,7 @@ * @author Lajos Molnár * @since 1.0 */ -class WebMinifier extends \yii\base\Object implements MinifierInterface +class WebMinifier extends \yii\base\BaseObject implements MinifierInterface { /**