diff --git a/PackageCompressor.php b/PackageCompressor.php index ff1ed61..08f7094 100644 --- a/PackageCompressor.php +++ b/PackageCompressor.php @@ -19,6 +19,13 @@ class PackageCompressor extends CClientScript */ public $combineOnly = false; + /** + * Only effective when $enableCompression is set to "true" + * + * @var bool wheter to rewrite URLs in CSS files to an absolute path before combining + */ + public $rewriteCssUris = false; + /** * If this is enabled, during compression all other requests will wait until the compressing * process has completed. If disabled, the uncompressed files will be delivered for these @@ -84,7 +91,7 @@ public function compressPackage($name) $info = array(); $am = Yii::app()->assetManager; - $basePath = Yii::getPathOfAlias('webroot'); + $basePath = realpath(Yii::getPathOfAlias('webroot')); // /www/root/sub -> /www/root (baseUrl=/sub) if(($baseUrl = Yii::app()->request->baseUrl)!=='') @@ -126,8 +133,17 @@ public function compressPackage($name) { $files = array(); $urls = array(); - foreach(array_keys($this->cssFiles) as $file) - $files[] = $basePath.$file; + + foreach(array_keys($this->cssFiles) as $file) { + if ($this->rewriteCssUris) { + $inFile = $basePath.$file; + $outFile = $basePath.$file.'-rewrite.css'; + file_put_contents($outFile, Minify_CSS_UriRewriter::rewrite(file_get_contents($inFile), dirname($inFile), $basePath)); + } else { + $outFile = $basePath.$file; + } + $files[] = $outFile; + } $fileName = $this->compressFiles($name,'css',$files); if(isset($this->packages[$name]['baseUrl'])) diff --git a/composer.json b/composer.json index 82cbec4..64e1a6f 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ } ], "require": { - "php": ">=5.0.0" + "php": ">=5.0.0", + "mrclay/minify": "2.1.*" } }