本文整理汇总了PHP中Assetic\Asset\AssetCollection::ensureFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetCollection::ensureFilter方法的具体用法?PHP AssetCollection::ensureFilter怎么用?PHP AssetCollection::ensureFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\AssetCollection
的用法示例。
在下文中一共展示了AssetCollection::ensureFilter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateContent
protected function generateContent($templatePath, $contentType)
{
// We build these into a single string so that we can deploy this resume as a
// single file.
$assetPath = join(DIRECTORY_SEPARATOR, array($templatePath, $contentType));
if (!file_exists($assetPath)) {
return '';
}
$assets = array();
// Our PHAR deployment can't handle the GlobAsset typically used here
foreach (new \DirectoryIterator($assetPath) as $fileInfo) {
if ($fileInfo->isDot() || !$fileInfo->isFile()) {
continue;
}
array_push($assets, new FileAsset($fileInfo->getPathname()));
}
usort($assets, function (FileAsset $a, FileAsset $b) {
return strcmp($a->getSourcePath(), $b->getSourcePath());
});
$collection = new AssetCollection($assets);
switch ($contentType) {
case 'css':
$collection->ensureFilter(new Filter\LessphpFilter());
break;
}
return $collection->dump();
}
示例2: addCollection
public function addCollection($name, $assets)
{
$collection = new AssetCollection(array_map(function ($asset) {
return new FileAsset($this->guessPath($asset['src']));
}, $assets));
$collection->setTargetPath($name);
if (endsWith($name, '.css')) {
$collection->ensureFilter(new CssRewriteFilter());
}
$this->write($name, $collection->dump());
}
示例3: testDefault
public function testDefault()
{
$asset = __DIR__ . "/../../resources/test.coffee";
$assetCollection = new AssetCollection();
$assetCollection->add(new FileAsset($asset));
$assetCollection->ensureFilter(new CoffeeScriptPhpFilter());
$ret = $assetCollection->dump();
$exp = "var MyClass, myObject;";
$this->assertRegExp("/{$exp}/", $ret);
$exp = "Generated by CoffeeScript PHP";
$this->assertRegExp("/{$exp}/", $ret);
}
示例4: testIterationFilters
public function testIterationFilters()
{
$count = 0;
$filter = new CallablesFilter(function () use(&$count) {
++$count;
});
$coll = new AssetCollection();
$coll->add(new StringAsset(''));
$coll->ensureFilter($filter);
foreach ($coll as $asset) {
$asset->dump();
}
$this->assertEquals(1, $count, 'collection filters are called when child assets are iterated over');
}
示例5: newAssetCollection
/**
* @return AssetCollection
*/
protected function newAssetCollection()
{
// Aggregate all the assets into one file.
$assets = new AssetCollection();
if ($this->config->has('component-scriptFilters')) {
$filters = $this->config->get('component-scriptFilters');
if (isset($filters) && is_array($filters)) {
foreach ($filters as $filter => $filterParams) {
$reflection = new \ReflectionClass($filter);
/** @var \Assetic\Filter\FilterInterface $filter */
$filter = $reflection->newInstanceArgs($filterParams);
$assets->ensureFilter($filter);
}
}
}
return $assets;
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
$filesystem = $container->get('filesystem');
$languages = $container->getParameter('hatimeria_ext_js.locales');
$files = $container->getParameter('hatimeria_ext_js.compiled_files');
$domains = $container->getParameter("hatimeria_ext_js.translation_domains");
$vendorPath = $container->getParameter("hatimeria_ext_js.javascript_vendor_path");
$hdefault = new JavascriptController();
$hdefault->setContainer($container);
$dynamic = $hdefault->dynamicAction()->getContent();
$hdirect = new DirectController();
$hdirect->setContainer($container);
$api = $hdirect->getApiAction()->getContent();
$expose = $container->get('bazinga.exposetranslation.controller');
$routing = $container->get('fos_js_routing.controller');
$compressor = new JsCompressorFilter('vendor/bundles/Hatimeria/ExtJSBundle/Resources/jar/yuicompressor.jar');
$extjs = "web/bundles/hatimeriaextjs/js/extjs/";
// @todo recursive glob
foreach ($languages as $lang) {
$ac = new AssetCollection();
$ac->add(new FileAsset("web/" . $vendorPath . "/ext-all.js"));
$ac->add(new FileAsset($extjs . "/core/overrides.js"));
$ac->add(new StringAsset($dynamic));
$ac->add(new FileAsset($extjs . "/translation/Translation.js"));
foreach ($domains as $domain) {
$ac->add(new StringAsset($expose->exposeTranslationAction($domain, $lang, 'js')->getContent()));
}
$ac->add(new FileAsset("web/" . $vendorPath . "locale/ext-lang-" . $lang . ".js"));
$ac->add(new FileAsset($extjs . "/core/direct-api-handler.js"));
$ac->add(new FileAsset($extjs . "/routing/Routing.js"));
$ac->add(new GlobAsset($extjs . "/core/utils/*"));
$ac->add(new GlobAsset($extjs . "/core/mixins/*"));
$ac->add(new GlobAsset($extjs . "/core/store/*"));
$ac->add(new GlobAsset($extjs . "/core/model/*"));
$ac->add(new GlobAsset($extjs . "/core/grid/*"));
$ac->add(new GlobAsset($extjs . "/core/response/*"));
$ac->add(new GlobAsset($extjs . "/core/window/*"));
$ac->add(new FileAsset($extjs . "/core/form/BaseForm.js"));
$ac->add(new GlobAsset($extjs . "/core/form/*"));
$ac->add(new GlobAsset($extjs . "/core/field/*"));
$ac->add(new GlobAsset($extjs . "/core/user/*"));
$ac->add(new GlobAsset($extjs . "/treeselect/store/*"));
$ac->add(new GlobAsset($extjs . "/treeselect/panel/*"));
$ac->add(new GlobAsset($extjs . "/treeselect/field/*"));
$ac->add(new StringAsset($api));
$ac->add(new StringAsset($routing->indexAction('js')->getContent()));
foreach ($files as $file) {
$ac->add(new FileAsset('web/' . $file));
}
$ac->ensureFilter($compressor);
$compiled = $ac->dump();
@mkdir('web/compiled/js', 0755, true);
file_put_contents(sprintf("web/compiled/js/ext-%s.js", $lang), $compiled);
}
$output->writeln('Assets compiled');
}
示例7: testClearingFiltersWorksAfterCollectionHasBeenIterated
public function testClearingFiltersWorksAfterCollectionHasBeenIterated()
{
$coll = new AssetCollection();
$coll->add(new StringAsset(""));
$coll->ensureFilter(new CallablesFilter());
/* This iteration is necessary to internally prime the collection's
"clones" with one filter. */
foreach ($coll as $asset) {
$this->assertCount(1, $asset->getFilters());
}
$coll->clearFilters();
foreach ($coll as $asset) {
$this->assertCount(0, $asset->getFilters());
}
}
示例8: compile
/**
* Eejecuta la rutina de minificacion
*
* Los tipos de recursos aceptados son:
* Resources:CSS
* Resources:JS
* Resources:NONE
*
* @param int $compile El tipo de recurso a minificar
*/
public function compile($compile = Resources::NONE)
{
require_once __DIR__ . '/cssmin-v3.0.1.php';
require_once __DIR__ . '/jsmin.php';
$asset = new AssetCollection();
$this->resources->each(function ($key, $value) use(&$asset) {
if ($value->flag) {
$asset->add(new FileAsset($value->asset));
} else {
$asset->add(new GlobAsset($value->asset));
}
});
if ($compile == Resources::JS) {
$asset->ensureFilter(new \Assetic\Filter\JSMinFilter());
}
if ($compile == Resources::CSS) {
$asset->ensureFilter(new \Assetic\Filter\CssMinFilter());
}
// the code is merged when the asset is dumped
$bundles = \Raptor\Core\Location::get('web_bundles');
if (!file_exists($bundles . $this->bundleName)) {
mkdir($bundles . $this->bundleName, 0777, true);
}
if ($this->name[0] == '/' or $this->name[0] == DIRECTORY_SEPARATOR) {
unset($this->name[0]);
}
$dir = dirname($bundles . $this->bundleName . '/' . $this->name);
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
if ($this->force == true) {
file_put_contents($bundles . $this->bundleName . '/' . $this->name, $asset->dump());
} else {
if (!file_exists($bundles . $this->bundleName . '/' . $this->name)) {
file_put_contents($bundles . $this->bundleName . '/' . $this->name, $asset->dump());
}
}
}