本文整理汇总了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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
示例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'));
}
示例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);
}
示例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);
}
示例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');
}
示例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());
}
}
}
示例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;
}