本文整理汇总了PHP中Assetic\Asset\AssetCollection类的典型用法代码示例。如果您正苦于以下问题:PHP AssetCollection类的具体用法?PHP AssetCollection怎么用?PHP AssetCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AssetCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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();
}
示例4: runResolve
public function runResolve(framework\Request $request)
{
$theme = isset($request['theme_name']) ? $request['theme_name'] : framework\Settings::getThemeName();
if ($request->hasParameter('css')) {
$this->getResponse()->setContentType('text/css');
if (!$request->hasParameter('theme_name')) {
$basepath = THEBUGGENIE_PATH . 'public' . DS . 'css';
$asset = THEBUGGENIE_PATH . 'public' . DS . 'css' . DS . $request->getParameter('css');
} else {
$basepath = THEBUGGENIE_PATH . 'themes';
$asset = THEBUGGENIE_PATH . 'themes' . DS . $theme . DS . 'css' . DS . $request->getParameter('css');
}
} elseif ($request->hasParameter('js')) {
$this->getResponse()->setContentType('text/javascript');
if ($request->hasParameter('theme_name')) {
$basepath = THEBUGGENIE_PATH . 'themes';
$asset = THEBUGGENIE_PATH . 'themes' . DS . $theme . DS . 'js' . DS . $request->getParameter('js');
} elseif ($request->hasParameter('module_name') && framework\Context::isModuleLoaded($request['module_name'])) {
$module_path = framework\Context::isInternalModule($request['module_name']) ? THEBUGGENIE_INTERNAL_MODULES_PATH : THEBUGGENIE_MODULES_PATH;
$basepath = $module_path . $request['module_name'] . DS . 'public' . DS . 'js';
$asset = $module_path . $request['module_name'] . DS . 'public' . DS . 'js' . DS . $request->getParameter('js');
} else {
$basepath = THEBUGGENIE_PATH . 'public' . DS . 'js';
$asset = THEBUGGENIE_PATH . 'public' . DS . 'js' . DS . $request->getParameter('js');
}
} else {
throw new \Exception('The expected theme Asset type is not supported.');
}
$fileAsset = new AssetCollection(array(new FileAsset($asset, array(), $basepath)));
$fileAsset->load();
// Do not decorate the asset with the theme's header/footer
$this->getResponse()->setDecoration(framework\Response::DECORATE_NONE);
return $this->renderText($fileAsset->dump());
}
示例5: createGroup
/**
* Create a new AssetCollection instance for the given group.
*
* @param string $name
* @param bool $overwrite force writing
* @return \Assetic\Asset\AssetCollection
*/
public function createGroup($name, $overwrite = false)
{
if (isset($this->groups[$name])) {
return $this->groups[$name];
}
$assets = $this->createAssetArray($name);
$filters = $this->createFilterArray($name);
$coll = new AssetCollection($assets, $filters);
if ($output = $this->getConfig($name, 'output')) {
$coll->setTargetPath($output);
}
// check output cache
$write_output = true;
if (!$overwrite) {
if (file_exists($output = public_path($coll->getTargetPath()))) {
$output_mtime = filemtime($output);
$asset_mtime = $coll->getLastModified();
if ($asset_mtime && $output_mtime >= $asset_mtime) {
$write_output = false;
}
}
}
// store assets
if ($overwrite || $write_output) {
$writer = new AssetWriter(public_path());
$writer->writeAsset($coll);
}
return $this->groups[$name] = $coll;
}
示例6: filterDump
public function filterDump(AssetInterface $asset)
{
$content = "";
$files = array();
$extraFiles = array();
$absolutePath = $asset->getSourceRoot() . '/' . $asset->getSourcePath();
$this->parser->mime = $this->parser->mimeType($absolutePath);
if ($this->parser->mime === 'javascripts') {
$extraFiles = $this->parser->get("javascript_files", array());
}
if ($this->parser->mime === 'stylesheets') {
$extraFiles = $this->parser->get("stylesheet_files", array());
}
$absoluteFilePaths = $this->parser->getFilesArrayFromDirectives($absolutePath);
if ($absoluteFilePaths) {
$absoluteFilePaths = $extraFiles + $absoluteFilePaths;
}
foreach ($absoluteFilePaths as $absoluteFilePath) {
$files[] = $this->generator->file($absoluteFilePath, false);
}
if (!$absoluteFilePaths) {
$files[] = $this->generator->file($absolutePath, false);
}
$global_filters = $this->parser->get("sprockets_filters.{$this->parser->mime}", array());
$collection = new AssetCollection($files, $global_filters);
$asset->setContent($collection->dump());
}
示例7: testMinifyCss
public function testMinifyCss()
{
$assets = array(new FileAsset(TEST_PATH . 'dummy.css'));
$filters = array(new MinFilter('css'));
$collection = new AssetCollection($assets, $filters);
$this->assertEquals('.foo{display:block}', $collection->dump());
}
示例8: 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;
}
}
示例9: 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;
}
示例10: 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());
}
示例11: build
public function build($collection_name)
{
$build_path_setting = Config::get("assetie::build_path");
$build_directory = public_path() . DIRECTORY_SEPARATOR . $build_path_setting;
/**
* the designated name of the build, i.e. base_123.js
*/
$build_name = $collection_name . "." . $this->buildExtension;
$build_file = $build_directory . DIRECTORY_SEPARATOR . $build_name;
$buildExists = file_exists($build_file);
$build_url = URL::asset($build_path_setting . DIRECTORY_SEPARATOR . $build_name);
$debugMode = Config::get("app.debug");
if (!$buildExists || $debugMode) {
$files = \Collection::dump($collection_name)[$this->group];
$collection_hash = sha1(serialize($files));
$hash_in_cache = Cache::get("collection_" . $this->group . "_" . $collection_name);
$collectionChanged = $collection_hash != $hash_in_cache;
$src_dir = app_path() . DIRECTORY_SEPARATOR . Config::get("assetie::directories." . $this->group) . DIRECTORY_SEPARATOR;
$forceRebuild = false;
if ($collectionChanged) {
$forceRebuild = true;
} else {
if ($buildExists) {
/**
* only recompile if no compiled build exists or when in debug mode and
* build's source files or collections.php has been changed
*/
$forceRebuild = $this->checkModification($build_file, $files, $src_dir);
}
}
if (!$buildExists || $forceRebuild) {
$am = new AssetManager();
$assets = [];
foreach ($files as $file) {
$filters = $this->getFilters($file);
$assets[] = new FileAsset($src_dir . $file, $filters);
}
$collection = new AssetCollection($assets);
// , $filters
$collection->setTargetPath($build_name);
$am->set('collection', $collection);
$writer = new AssetWriter($build_directory);
$writer->writeManagerAssets($am);
}
// Cache::forever("collection_" . $collection_name, $collection_hash);
$cache_key = "collection_" . $this->group . "_" . $collection_name;
if (Cache::has($cache_key) && $collectionChanged) {
Cache::forget($cache_key);
}
if ($collectionChanged) {
Cache::put($cache_key, $collection_hash, 60);
// 1 hour
}
}
return $build_url;
}
示例12: dump
public function dump()
{
$file = array(new FileAsset($this->file));
$this->set_type_filter($this->type);
if ($this->config->minify) {
$this->set_minify_filter($this->type);
}
$result = new AssetCollection($file, $this->filters);
return $result->dump();
}
示例13: stylesheets
/**
* Dumps out the stylesheets for this file
*
* If we should concat then this should probably be a
* manifest file so we should process directives inside
*
* @param [type] $path [description]
* @return [type] [description]
*/
public function stylesheets($path)
{
$filters = array();
$files = array($this->getFullPath($path, 'stylesheets'));
if ($this->shouldConcat()) {
$files = $this->directives->getFilesFrom($this->getFullPath($path, 'stylesheets'));
}
$styles = new AssetCollection($this->getStyleAssets($files), $filters);
return $styles->dump();
}
示例14: testOne
public function testOne()
{
$uglify = new UglifyJs2Filter("/usr/bin/uglifyjs", "/usr/bin/node");
$uglify->setCompress(true);
$uglify->setMangle(true);
$uglify->setCompress(true);
$js = new AssetCollection(array(new GlobAsset(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "assets/src/*", array($uglify))));
echo $js->dump();
echo PHP_EOL;
}
示例15: createVersion
public function createVersion($request, $componentData, $component, $versionType = false, $branch = 'master')
{
$em = $this->_em;
/**
* manage versionType name
*
* If is additional branch add brnach name at end.
*/
if ($branch != 'master' && $branch != false) {
if ($versionType) {
$versionType = $versionType . '-' . $branch;
} else {
$versionType = $componentData['version']['value'] . '-' . $branch;
}
} else {
if ($versionType) {
$versionType = $versionType;
} else {
$versionType = $componentData['version']['value'];
}
}
if (!$versionType) {
$version = new \FWM\CraftyComponentsBundle\Entity\Versions();
$version->setValue($versionType);
} else {
$componentData['version']['value'] = $versionType;
$version = $em->getRepository('FWMCraftyComponentsBundle:Versions')->findOneBy(array('component' => $component->getId(), 'value' => $versionType));
if (!$version) {
$version = new \FWM\CraftyComponentsBundle\Entity\Versions();
$version->setValue($versionType);
}
}
$version->setSha($componentData['version']['sha']);
$version->setComponent($component);
$version->setFileContent($componentData['componentFilesValue']);
$version->setCreatedAt(new \DateTime());
//complete all files
foreach (ArrayService::objectToArray(json_decode($componentData['componentFilesValue'])) as $value) {
$tempFileContent[] = base64_decode($value);
}
$file = implode(' ', $tempFileContent);
$path = $request->server->get('DOCUMENT_ROOT') . '/uploads/components/' . strtolower($componentData['name']) . '-' . strtolower($versionType);
//create uncompressed version
file_put_contents($path . '-uncompressed.js', $file);
//minify uncompressed version
try {
$js = new AssetCollection(array(new FileAsset($path . '-uncompressed.js')), array(new Yui\JsCompressorFilter($request->server->get('DOCUMENT_ROOT') . '/../app/Resources/java/yuicompressor.jar')));
$minifidedFile = $js->dump();
} catch (\Exception $e) {
$minifidedFile = $file;
}
// create minified version
file_put_contents($path . '.js', $minifidedFile);
return $version;
}