diff --git a/src/AssetsAutoCompressComponent.php b/src/AssetsAutoCompressComponent.php index 835166e..90a5185 100644 --- a/src/AssetsAutoCompressComponent.php +++ b/src/AssetsAutoCompressComponent.php @@ -411,6 +411,7 @@ protected function _processingJsFiles($files = []) if (!$this->jsFileRemouteCompile) { foreach ($files as $fileCode => $fileTag) { if (!Url::isRelative($fileCode)) { + $fileCode = $this->getFileCode($fileCode); $resultFiles[$fileCode] = $fileTag; } } @@ -429,6 +430,7 @@ protected function _processingJsFiles($files = []) foreach ($files as $fileCode => $fileTag) { if (Url::isRelative($fileCode)) { if ($pos = strpos($fileCode, "?")) { + $fileCode = $this->getFileCode($fileCode); $fileCode = substr($fileCode, 0, $pos); } @@ -600,6 +602,7 @@ protected function _processingCssFiles($files = []) if (!$this->cssFileRemouteCompile) { foreach ($files as $fileCode => $fileTag) { if (!Url::isRelative($fileCode)) { + $fileCode = $this->getFileCode($fileCode); $resultFiles[$fileCode] = $fileTag; } } @@ -616,6 +619,7 @@ protected function _processingCssFiles($files = []) $resultFiles = []; foreach ($files as $fileCode => $fileTag) { if (Url::isRelative($fileCode)) { + $fileCode = $this->getFileCode($fileCode); $fileCodeLocal = $fileCode; if ($pos = strpos($fileCode, "?")) { $fileCodeLocal = substr($fileCodeLocal, 0, $pos); @@ -726,6 +730,18 @@ protected function _processingHtml($html) return $html; } + /** + * Fix for Yii version 2.0.39 and higher if the project has a non-empty baseUrl + * + * @param string $fileCode Path to file + * + * @return string + * @link https://github.com/yiisoft/yii2/issues/18414 + */ + protected function getFileCode($fileCode) + { + return !empty(\Yii::$app->request->getBaseUrl()) ? str_replace(\Yii::$app->request->getBaseUrl(), '', $fileCode) : $fileCode; + } /** * @param $value