Skip to content

Commit

Permalink
Bugfix if file not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bitboxrk committed Jan 30, 2019
1 parent 1377708 commit 5414eca
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/services/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use bitboxde\minifier\minify\JS;
use craft\base\Component;
use craft\helpers\ArrayHelper;
use yii\base\Exception;

class View extends Component
{
Expand Down Expand Up @@ -45,26 +46,31 @@ protected function addFile($type, $url, $options = [], $targetFile = null) {
$url = str_replace('//', '/', $url);

if($this->doMinify && $this->canMinifyFile($url)) {
$rootAlias = \Yii::getRootAlias($url);
$originUrl = $url;
$url = \Yii::getAlias($url);

if(!file_exists($url) && !$rootAlias) {
return $this->$registerMethod('@webroot' . '/' . $originUrl, $options, $targetFile);
if(file_exists($url)) {
if(!$targetFile) {
$options['hash'] = true;
ksort($options);
$targetFile = md5('hash-' . implode('-', $options));
}

$getMinifierMethod = sprintf('get%sMinifier', $type);

/** @var CSS|JS $cssMinifier */
$cssMinifier = $this->$getMinifierMethod($targetFile);
$cssMinifier->add($url);
$cssMinifier->addOptions($options);
} else {
if(!\Yii::getRootAlias($originUrl)) {
if(!$this->$registerMethod('@webroot' . '/' . $originUrl, $options, $targetFile)) {
throw new Exception(sprintf('The file "%s" does not exist.', $originUrl));
}
} else {
return false;
}
}

if(!$targetFile) {
$options['hash'] = true;
ksort($options);
$targetFile = md5('hash-' . implode('-', $options));
}

$getMinifierMethod = sprintf('get%sMinifier', $type);

/** @var CSS|JS $cssMinifier */
$cssMinifier = $this->$getMinifierMethod($targetFile);
$cssMinifier->add($url);
$cssMinifier->addOptions($options);
} else {
\Craft::$app->getView()->$registerMethod($url, $options, $targetFile);
}
Expand Down

0 comments on commit 5414eca

Please sign in to comment.