Skip to content

Commit

Permalink
Fixed building path to files for Yii version 2.0.39 and higher with n…
Browse files Browse the repository at this point in the history
…on-empty BaseUrl. The issue was discussed here yiisoft/yii2#18414
  • Loading branch information
nomelodic committed Jan 15, 2021
1 parent 1c4b301 commit c4b6ada
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/AssetsAutoCompressComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c4b6ada

Please sign in to comment.