當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。