kevbaldwyn/css-path-rewrite

此包最新版本(0.1.3)没有可用的许可信息。

重写CSS文件中的路径,包括对Assetic的过滤器

0.1.3 2015-01-19 14:22 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:38:53 UTC


README

将CSS文件中的路径重写为类似本地到远程(或任何其他)的图像。目前仅处理“根相对”URL路径,即以 / 开头的URL。

## 使用Composer进行安装

"require": {
    ...
    "kevbaldwyn/css-path-rewrite":"0.*"
    ...
}

Composer Update

$ composer update kevbaldwyn/css-path-rewrite

## 使用方法:简单重写CSS文件中的URL

$cssFileContent = file_get_contents('/path/to/my/file.css');
$writer = new KevBaldwyn\CssPathRewrite\Rewriter($cssFileContent, 'http://www.example.com');
$output = $writer->rewrite();
file_put_contents('/path/to/my/file.css', $output);

如果使用Assetic,只需将其包含在您的过滤器数组中

$css = new AssetCollection(array(
    new FileAsset('/path/to/src/styles.less', array(new LessFilter())),
    new GlobAsset('/path/to/css/*'),
), array(
    new KevBaldwyn\CssPathRewrite\Assetic\Filter('http://www.example.com'),
));