当前位置: 首页>>代码示例>>PHP>>正文


PHP AssetCollection::add方法代码示例

本文整理汇总了PHP中Assetic\Asset\AssetCollection::add方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetCollection::add方法的具体用法?PHP AssetCollection::add怎么用?PHP AssetCollection::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Assetic\Asset\AssetCollection的用法示例。


在下文中一共展示了AssetCollection::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testProcess_withAssetCollection_shouldHash

 public function testProcess_withAssetCollection_shouldHash()
 {
     $collection = new AssetCollection();
     $collection->add($this->getFileAsset('asset.txt'));
     $collection->add($this->getStringAsset('string', 'string.txt'));
     $collection->setTargetPath('collection.txt');
     $this->getCacheBustingWorker()->process($collection, $this->getAssetFactory());
     $this->assertSame('collection-ae851400.txt', $collection->getTargetPath());
 }
开发者ID:jeroenvdheuvel,项目名称:assetic-cache-busting-worker,代码行数:9,代码来源:CacheBustingWorkerTest.php

示例2: getAssets

 /**
  * @return AssetCollectionInterface
  */
 public function getAssets()
 {
     if ($this->dirty) {
         $this->assets = new AssetCollection([], [], TL_ROOT);
         ksort($this->sortedAssets);
         foreach ($this->sortedAssets as $assets) {
             foreach ($assets as $asset) {
                 $this->assets->add($asset);
             }
         }
         $this->dirty = false;
     }
     return $this->assets;
 }
开发者ID:bit3,项目名称:contao-theme-plus,代码行数:17,代码来源:CollectAssetsEvent.php

示例3: resolve

 /**
  * {@inheritDoc}
  */
 public function resolve($name)
 {
     if (!isset($this->collections[$name])) {
         return null;
     }
     if (!is_array($this->collections[$name])) {
         throw new \RuntimeException("Collection with name {$name} is not an array.");
     }
     $collection = new AssetCollection();
     $mimeType = 'application/javascript';
     $collection->setTargetPath($name);
     foreach ($this->collections[$name] as $asset) {
         if (!is_string($asset)) {
             throw new \RuntimeException('Asset should be of type string. got ' . gettype($asset));
         }
         if (null === ($content = $this->riotTag->__invoke($asset))) {
             throw new \RuntimeException("Riot tag '{$asset}' could not be found.");
         }
         $res = new StringAsset($content);
         $res->mimetype = $mimeType;
         $asset .= ".js";
         $this->getAssetFilterManager()->setFilters($asset, $res);
         $collection->add($res);
     }
     $collection->mimetype = $mimeType;
     return $collection;
 }
开发者ID:prooph,项目名称:link-app-core,代码行数:30,代码来源:RiotTagCollectionResolver.php

示例4: resolvePlugins

 /**
  * Resolve to the plugins for this module (expand).
  *
  * @throws \SxBootstrap\Exception\RuntimeException
  * @return \Assetic\Asset\AssetCollection
  */
 protected function resolvePlugins()
 {
     $config = $this->config;
     $pluginFiles = $this->getPluginNames($config->getMakeFile());
     $includedPlugins = $config->getIncludedPlugins();
     $excludedPlugins = $config->getExcludedPlugins();
     if (!empty($excludedPlugins) && !empty($includedPlugins)) {
         throw new Exception\RuntimeException('You may not set both excluded and included plugins.');
     }
     $pluginsAsset = new AssetCollection();
     $mimeType = null;
     foreach ($pluginFiles as $plugin) {
         if (!empty($excludedPlugins) && in_array($plugin, $excludedPlugins)) {
             continue;
         } elseif (!empty($includedPlugins) && !in_array($plugin, $includedPlugins)) {
             continue;
         }
         $res = $this->getAggregateResolver()->resolve('js/bootstrap-' . $plugin . '.js');
         if (null === $res) {
             throw new Exception\RuntimeException("Asset '{$plugin}' could not be found.");
         }
         if (!$res instanceof AssetInterface) {
             throw new Exception\RuntimeException("Asset '{$plugin}' does not implement Assetic\\Asset\\AssetInterface.");
         }
         if (null !== $mimeType && $res->mimetype !== $mimeType) {
             throw new Exception\RuntimeException(sprintf('Asset "%s" from collection "%s" doesn\'t have the expected mime-type "%s".', $plugin, $config->getPluginAlias(), $mimeType));
         }
         $mimeType = $res->mimetype;
         $this->getAssetFilterManager()->setFilters($plugin, $res);
         $pluginsAsset->add($res);
     }
     $pluginsAsset->mimetype = $mimeType;
     return $pluginsAsset;
 }
开发者ID:spoonx,项目名称:sxbootstrap,代码行数:40,代码来源:BootstrapResolver.php

示例5: process

 /**
  * {@inheritdoc}
  */
 public function process()
 {
     $filters = new FilterCollection(array(new CssRewriteFilter()));
     $assets = new AssetCollection();
     $styles = $this->packageStyles($this->packages);
     foreach ($styles as $package => $packageStyles) {
         foreach ($packageStyles as $style => $paths) {
             foreach ($paths as $path) {
                 // The full path to the CSS file.
                 $assetPath = realpath($path);
                 // The root of the CSS file.
                 $sourceRoot = dirname($path);
                 // The style path to the CSS file when external.
                 $sourcePath = $package . '/' . $style;
                 // Where the final CSS will be generated.
                 $targetPath = $this->componentDir;
                 // Build the asset and add it to the collection.
                 $asset = new FileAsset($assetPath, $filters, $sourceRoot, $sourcePath);
                 $asset->setTargetPath($targetPath);
                 $assets->add($asset);
             }
         }
     }
     $css = $assets->dump();
     if (file_put_contents($this->componentDir . '/require.css', $css) === FALSE) {
         $this->io->write('<error>Error writing require.css to destination</error>');
         return false;
     }
 }
开发者ID:ICHydro,项目名称:anaconda,代码行数:32,代码来源:RequireCssProcess.php

示例6: parseInput

 /**
  * Adds support for pipeline assets.
  *
  * {@inheritdoc}
  */
 protected function parseInput($input, array $options = array())
 {
     if (is_string($input) && '|' == $input[0]) {
         switch (pathinfo($options['output'], PATHINFO_EXTENSION)) {
             case 'js':
                 $type = 'js';
                 break;
             case 'css':
                 $type = 'css';
                 break;
             default:
                 throw new \RuntimeException('Unsupported pipeline asset type provided: ' . $input);
         }
         $assets = new AssetCollection();
         foreach ($this->locator->locatePipelinedAssets(substr($input, 1), $type) as $formula) {
             $filters = array();
             if ($formula['filter']) {
                 $filters[] = $this->getFilter($formula['filter']);
             }
             $asset = new FileAsset($formula['root'] . '/' . $formula['file'], $filters, $options['root'][0], $formula['file']);
             $asset->setTargetPath($formula['file']);
             $assets->add($asset);
         }
         return $assets;
     }
     return parent::parseInput($input, $options);
 }
开发者ID:nmariani,项目名称:KnpRadBundle,代码行数:32,代码来源:PipelineAssetFactory.php

示例7: createAsset

 protected function createAsset($name, array $assets)
 {
     $inputs = array();
     $collection = new AssetCollection();
     $filters = array();
     foreach ($assets as $type => $value) {
         if ($type === 'filters') {
             $filters = $value;
         } elseif (!is_array($value) && $value[0] === '@') {
             $collection->add(new AssetReference($this->am, substr_replace($value, '', 0, 1)));
         } elseif ($type === 'files') {
             foreach ($value as $keyOrSource => $sourceOrFilter) {
                 if (!is_array($sourceOrFilter)) {
                     $collection->add(new \Assetic\Asset\FileAsset($sourceOrFilter));
                 } else {
                     $filter = array();
                     foreach ($sourceOrFilter as $filterName) {
                         $filter[] = $this->fm->get($filterName);
                     }
                     $collection->add(new \Assetic\Asset\FileAsset($keyOrSource, $filter));
                 }
             }
         } elseif ($type === 'globs') {
             foreach ($value as $keyOrGlob => $globOrFilter) {
                 if (!is_array($globOrFilter)) {
                     $collection->add(new \Assetic\Asset\GlobAsset($globOrFilter));
                 } else {
                     $filter = array();
                     foreach ($globOrFilter as $filterName) {
                         $filter[] = $this->fm->get($filterName);
                     }
                     $collection->add(new \Assetic\Asset\GlobAsset($keyOrGlob, $filter));
                 }
             }
         }
     }
     $this->am->set($name, new AssetCache($collection, new \Assetic\Cache\FilesystemCache($this->config['cacheDir'] . '/chunks')));
     $filename = str_replace('_', '.', $name);
     $this->_compiledAssets[$name] = "{$this->config['baseUrl']}/" . $filename;
     file_put_contents("{$this->config['assetDir']}/{$filename}", $this->factory->createAsset("@{$name}", $filters)->dump());
     @chmod($filename, 0777);
 }
开发者ID:cynode,项目名称:asset-manager,代码行数:42,代码来源:Component.php

示例8: js

 public function js(array $params)
 {
     $jsfiles = Registry::getInstance()->assets['js'];
     $collection = new AssetCollection();
     foreach ($jsfiles as $file) {
         $collection->add(new FileAsset($file, array(new JsCompressorFilter(APP_PATH . "/vendor/bin/yuicompressor.jar"))));
     }
     $cache = new AssetCache($collection, new FilesystemCache(APP_PATH . "/cache/assetic/js"));
     header('Content-Type: text/javascript');
     echo $cache->dump();
 }
开发者ID:kingboard,项目名称:kingboard,代码行数:11,代码来源:Assetic.php

示例9: process

 /**
  * {@inheritdoc}
  */
 public function process()
 {
     $filters = array(new CssRewriteFilter());
     if ($this->config->has('component-styleFilters')) {
         $customFilters = $this->config->get('component-styleFilters');
         if (isset($customFilters) && is_array($customFilters)) {
             foreach ($customFilters as $filter => $filterParams) {
                 $reflection = new \ReflectionClass($filter);
                 $filters[] = $reflection->newInstanceArgs($filterParams);
             }
         }
     }
     $filterCollection = new FilterCollection($filters);
     $assets = new AssetCollection();
     $styles = $this->packageStyles($this->packages);
     foreach ($styles as $package => $packageStyles) {
         $packageAssets = new AssetCollection();
         $packagePath = $this->componentDir . '/' . $package;
         foreach ($packageStyles as $style => $paths) {
             foreach ($paths as $path) {
                 // The full path to the CSS file.
                 $assetPath = realpath($path);
                 // The root of the CSS file.
                 $sourceRoot = dirname($path);
                 // The style path to the CSS file when external.
                 $sourcePath = $package . '/' . $style;
                 //Replace glob patterns with filenames.
                 $filename = basename($style);
                 if (preg_match('~^\\*(\\.[^\\.]+)$~', $filename, $matches)) {
                     $sourcePath = str_replace($filename, basename($assetPath), $sourcePath);
                 }
                 // Where the final CSS will be generated.
                 $targetPath = $this->componentDir;
                 // Build the asset and add it to the collection.
                 $asset = new FileAsset($assetPath, $filterCollection, $sourceRoot, $sourcePath);
                 $asset->setTargetPath($targetPath);
                 $assets->add($asset);
                 // Add asset to package collection.
                 $sourcePath = preg_replace('{^.*' . preg_quote($package) . '/}', '', $sourcePath);
                 $asset = new FileAsset($assetPath, $filterCollection, $sourceRoot, $sourcePath);
                 $asset->setTargetPath($packagePath);
                 $packageAssets->add($asset);
             }
         }
         if (file_put_contents($packagePath . '/' . $package . '-built.css', $packageAssets->dump()) === FALSE) {
             $this->io->write("<error>Error writing {$package}-built.css to destination</error>");
         }
     }
     if (file_put_contents($this->componentDir . '/require.css', $assets->dump()) === FALSE) {
         $this->io->write('<error>Error writing require.css to destination</error>');
         return false;
     }
     return null;
 }
开发者ID:SylvainSimon,项目名称:Metinify,代码行数:57,代码来源:RequireCssProcess.php

示例10: jsPackAction

 public function jsPackAction()
 {
     $collection = new AssetCollection();
     foreach ($this->container->getParameter('cms.cms_resources.js_pack') as $asset) {
         $collection->add(new FileAsset($asset));
     }
     $content = $this->container->getCache()->fetch('cms_assets', 'js_pack', function () use($collection) {
         return $collection->dump();
     }, $collection->getLastModified());
     return new Response($content, 200, array('Content-Type' => 'text/javascript'));
 }
开发者ID:sitesupra,项目名称:sitesupra,代码行数:11,代码来源:ResourceController.php

示例11: 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);
 }
开发者ID:kohkimakimoto,项目名称:assetic-extension,代码行数:12,代码来源:CoffeeScriptPhpFilterTest.php

示例12: init

 public function init()
 {
     $css = new AssetCollection();
     $js = new AssetCollection();
     $path =& $this->path;
     array_walk($this->config['css'], function ($v, $i) use(&$css, $path) {
         $asset = new FileAsset($path . $v, [new \Assetic\Filter\CssMinFilter()]);
         $css->add($asset);
     });
     array_walk($this->config['js'], function ($v, $i) use(&$js, $path) {
         $asset = new FileAsset($path . $v);
         $js->add($asset);
     });
     $css->setTargetPath('/theme/' . $this->skin . '_styles.css');
     $js->setTargetPath('/theme/' . $this->skin . '_scripts.js');
     $this->am->set('css', $css);
     $this->am->set('js', $js);
 }
开发者ID:onefasteuro,项目名称:theme,代码行数:18,代码来源:Assets.php

示例13: 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');
 }
开发者ID:richardmiller,项目名称:assetic,代码行数:14,代码来源:AssetCollectionTest.php

示例14: 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());
         }
     }
 }
开发者ID:williamamed,项目名称:Raptor2,代码行数:48,代码来源:AssetCompiler.php

示例15: _to_collection

 protected function _to_collection($files)
 {
     $collection = new AssetCollection();
     foreach ($files as $file) {
         $file = Helpers::remove_prepending_forward_slash($file);
         if (strpos($file, '*') === false) {
             $asset = new FileAsset($this->_get_asset_path() . $file);
         } else {
             $asset = new GlobAsset($this->_get_asset_path() . $file);
         }
         $collection->add($asset);
     }
     return $collection;
 }
开发者ID:kloy,项目名称:assetix,代码行数:14,代码来源:Compiler.php


注:本文中的Assetic\Asset\AssetCollection::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。