本文整理汇总了PHP中Assetic\Asset\StringAsset::ensureFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP StringAsset::ensureFilter方法的具体用法?PHP StringAsset::ensureFilter怎么用?PHP StringAsset::ensureFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\StringAsset
的用法示例。
在下文中一共展示了StringAsset::ensureFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFilterDump
public function testFilterDump()
{
$expected = 'body{baz:foo;foo:new;too:me}div.other,div.test{border:1px solid black}';
$inputCss = 'body { foo:bar; too: me;} body { baz:foo; } body { foo: new }
div.test { border: 1px solid black; }
div.other { border: 1px solid black} ';
$asset = new StringAsset($inputCss);
$asset->ensureFilter($this->filter);
$result = $asset->dump();
$this->assertEquals($expected, $result);
}
示例2: processFile
public function processFile($path, $config = [])
{
$rel = b::param('rel', false, $config);
$url = b::param('url', false, $config);
$useGlobalFilters = b::param('useGlobalFilters', true, $config);
// get the file
$file = $this->getFile($path);
$root = pathinfo($path)['dirname'];
$ext = pathinfo($path)['extension'];
// get it's tree
$content = $file->getContent();
if (empty($content)) {
return $content;
}
$inc = [];
// parse the string
$found = $this->parseString($content, $root);
if (b::param('filterOnly', false, $config) === 'true') {
$found = ['filter' => $found['filter']];
}
$tree = $this->getCombinedTree($found, $ext);
$reduce = function ($items, $reduce) {
$resp = [];
foreach ($items as $key => $files) {
$resp[] = $key;
$resp += $reduce($files, $reduce);
}
return $resp;
};
// loop through each file and append
foreach (array_unique($reduce($tree, $reduce)) as $f) {
if ($f === $path) {
continue;
}
$inc[] = $this->processFile($f);
}
$source = false;
$sourcePath = false;
$targetPath = false;
if ($url) {
$parts = parse_url($url);
$source = "{$parts['scheme']}://{$parts['host']}";
$targetPath = trim($parts['path'], '/');
$sourcePath = $targetPath . '/' . trim($rel, '/');
}
$inc[] = $content;
$a = new StringAsset(implode("\n", $inc), [], $source, $sourcePath);
if ($targetPath) {
$a->setTargetPath($targetPath);
}
// use filters
if ($useGlobalFilters !== false) {
if (array_key_exists($ext, $this->_filters)) {
foreach ($this->_filters[$ext] as $filter) {
if ($filter[1] === false and b::env() === 'dev') {
continue;
}
$a->ensureFilter(new $filter[0]());
}
}
foreach ($this->_filters['*'] as $filter) {
if ($filter[1] === false and b::env() === 'dev') {
continue;
}
$a->ensureFilter(new $filter[0]());
}
}
$a->ensureFilter(new CssRewriteFilter());
return trim($a->dump());
}
示例3: getStringAsset
/**
* Gets the string asset
*
* @param string $content
* @return StringAsset
*/
private function getStringAsset($content)
{
$stringAsset = new StringAsset($content);
$stringAsset->ensureFilter($this->filter);
return $stringAsset;
}