本文整理汇总了PHP中Assetic\Factory\AssetFactory::createAsset方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetFactory::createAsset方法的具体用法?PHP AssetFactory::createAsset怎么用?PHP AssetFactory::createAsset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Factory\AssetFactory
的用法示例。
在下文中一共展示了AssetFactory::createAsset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* {@inheritDoc}
*/
public function parse(\Twig_Token $token)
{
$inputs = $this->assets;
$filters = [];
$attributes = ['output' => $this->output, 'var_name' => 'asset_url', 'vars' => []];
$stream = $this->parser->getStream();
while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
if ($stream->test(\Twig_Token::NAME_TYPE, 'filter')) {
$filters = array_merge($filters, array_filter(array_map('trim', explode(',', $this->parseValue($stream, false)))));
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'output')) {
$attributes['output'] = $this->parseValue($stream, false);
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'debug')) {
$attributes['debug'] = $this->parseValue($stream);
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'combine')) {
$attributes['combine'] = $this->parseValue($stream);
} else {
$token = $stream->getCurrent();
throw new \Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', \Twig_Token::typeToEnglish($token->getType(), $token->getLine()), $token->getValue()), $token->getLine());
}
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse([$this, 'testEndTag'], true);
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
$nameUnCompress = $this->factory->generateAssetName($inputs['compress'][0], $filters, $attributes);
$nameCompress = substr(sha1(serialize($inputs['uncompress'][0]) . 'oro_assets'), 0, 7);
return new OroAsseticNode(['compress' => $this->factory->createAsset($inputs['compress'][0], $filters, $attributes + ['name' => $nameCompress, 'debug' => false]), 'un_compress' => $this->factory->createAsset($inputs['uncompress'][0], [], $attributes + ['name' => $nameUnCompress, 'debug' => true])], ['un_compress' => $nameUnCompress, 'compress' => $nameCompress], $filters, $inputs, $body, $attributes, $token->getLine(), $this->getTag());
}
示例2: getMinifiedAsset
private function getMinifiedAsset()
{
if (!(new SplFileInfo($this->asset->getPath()))->isWritable()) {
throw new Exception("path " . $this->asset->getPath() . " is not writable");
}
$factory = new AssetFactory($this->asset->getPath());
$factory->addWorker(new CacheBustingWorker());
$factory->setDefaultOutput('*');
$fm = new FilterManager();
$fm->set('min', $this->filter);
$factory->setFilterManager($fm);
$asset = $factory->createAsset(call_user_func(function ($files) {
$r = [];
foreach ($files as $file) {
$r[] = $file['fs'];
}
return $r;
}, $this->files), ['min'], ['name' => $this->asset->getBasename()]);
// only write the asset file if it does not already exist..
if (!file_exists($this->asset->getPath() . DIRECTORY_SEPARATOR . $asset->getTargetPath())) {
$writer = new AssetWriter($this->asset->getPath());
$writer->writeAsset($asset);
// TODO: write some code to garbage collect files of a certain age?
// possible alternative, modify CacheBustingWorker to have option
// to append a timestamp instead of a hash
}
return $asset;
}
示例3: testNoFilterManager
public function testNoFilterManager()
{
$this->setExpectedException('LogicException', 'There is no filter manager.');
$factory = new AssetFactory('.');
$factory->createAsset(array('foo'), array('foo'));
}
示例4: setAsset
public function setAsset($asset)
{
$assets = $this->assetFactory->createAsset($asset)->all();
$asset = $assets[0];
$absolutePath = $asset->getSourceRoot() . DIRECTORY_SEPARATOR . $asset->getSourcePath();
$pathInfo = pathinfo($absolutePath);
list($width, $height, $imageType) = getimagesize($absolutePath);
$this->absolutePath = $absolutePath;
$this->width = $width;
$this->height = $height;
$this->imageType = $imageType;
$this->ratio = $width / $height;
$this->fileName = $pathInfo['filename'];
$this->extension = $pathInfo['extension'];
return $this;
}
示例5: createDebugAsseticNode
/**
* @param \Twig_NodeInterface $body
* @param array $filters
* @param array $attributes
* @param int $lineno
* @return AsseticNode
*/
protected function createDebugAsseticNode(\Twig_NodeInterface $body, array $filters, array $attributes, $lineno)
{
$inputs = $this->assetsConfiguration->getCssFiles(true);
$name = $this->assetFactory->generateAssetName($inputs, $filters, $attributes);
$asset = $this->assetFactory->createAsset($inputs, $filters, $attributes + array('name' => $name));
return new DebugAsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $this->getTag());
}
示例6: getChildren
public function getChildren(AssetFactory $factory, $content, $loadPath = null)
{
$children = array();
$includePaths = $this->includePaths;
if (null !== $loadPath && !in_array($loadPath, $includePaths)) {
array_unshift($includePaths, $loadPath);
}
if (empty($includePaths)) {
return $children;
}
foreach (CssUtils::extractImports($content) as $reference) {
if ('.css' === substr($reference, -4)) {
continue;
}
// the reference may or may not have an extension or be a partial
if (pathinfo($reference, PATHINFO_EXTENSION)) {
$needles = array($reference, $this->partialize($reference));
} else {
$needles = array($reference . '.scss', $this->partialize($reference) . '.scss');
}
foreach ($includePaths as $includePath) {
foreach ($needles as $needle) {
if (file_exists($file = $includePath . '/' . $needle)) {
$child = $factory->createAsset($file, array(), array('root' => $includePath));
$children[] = $child;
$child->load();
$children = array_merge($children, $this->getChildren($factory, $child->getContent(), $includePath));
}
}
}
}
return $children;
}
示例7: getChildren
public function getChildren(AssetFactory $factory, $content, $loadPath = null)
{
$hash = md5($content);
if ($this->cache->has($hash)) {
return $factory->createAsset($this->cache->get($hash), array(), array('root' => $loadPath));
} else {
return parent::getChildren($factory, $content, $loadPath);
}
}
示例8: buildFormula
/**
* Builds assetic attributes from parameters extracted from template
* source.
*
* @param string $blockName Smarty block name
* @param array $params Block attributes
*
* @return An array with assetic attributes ready to append to $formulae.
*/
protected function buildFormula($blockName, array $params = array())
{
// inject the block name into the $params array
$params[AsseticExtension::OPTION_SMARTY_BLOCK_NAME] = $blockName;
list($inputs, $filters, $options) = $this->extension->buildAttributes($params);
$asset = $this->factory->createAsset($inputs, $filters, $options);
$options['output'] = $asset->getTargetPath();
unset($options[AsseticExtension::OPTION_SMARTY_BLOCK_NAME]);
return array($options['name'] => array($inputs, $filters, $options));
}
示例9: createAsset
/**
* {@inheritDoc}
*/
public function createAsset($inputs = array(), $filters = array(), array $options = array())
{
// Fixes problem with generated output
if (!is_array($inputs)) {
$inputs = array($inputs);
}
// set output the same as output if only one input
if (count($inputs) === 1 && (!isset($options['output']) || $options['output'] === "*")) {
$options['output'] = reset($inputs);
}
return parent::createAsset($inputs, $filters, $options);
}
示例10: addAssets
/**
* Add assets from array to this collection.
*
* @param array $assets
* @throws Exceptions\UnexpectedValueException
*/
public function addAssets(array $assets)
{
// \0 is hack. NULL do not work because is internally converted to "" and str_pos(..., "") throw error
$sourceRoot = $this->getSourceRoot() !== NULL ? $this->getSourceRoot() : "";
$assetFactory = new AssetFactory($sourceRoot);
foreach ($assets as $asset) {
if (is_string($asset)) {
$this->add($assetFactory->createAsset($asset));
} else {
if ($asset instanceof AssetInterface) {
$this->add($asset);
} else {
throw new UnexpectedValueException("Unexpected asset type. Expected string or AssetInterface. Given " . (is_object($asset) ? get_class($asset) : gettype($asset)));
}
}
}
}
示例11: createAsset
/**
* Create the combined assets from a set of inputs and store the cog
* namespace for later use.
*
* @param array $inputs
* @param array $filters
* @param array $options
* @return \Assetic\Asset\AssetCollection
*/
public function createAsset($inputs = array(), $filters = array(), array $options = array())
{
if (!is_array($inputs)) {
$inputs = array($inputs);
}
$paths = $this->_getFullPaths($inputs);
$namespaces = $this->_getNamespaces($inputs);
$collection = parent::createAsset($paths, $filters, $options);
// Store the cog namespace against each asset for use in the cogule filter
foreach ($collection as $asset) {
if (!isset($namespaces[$asset->getSourceRoot() . '/' . $asset->getSourcePath()])) {
continue;
}
$asset->cogNamespace = $namespaces[$asset->getSourceRoot() . '/' . $asset->getSourcePath()];
}
return $collection;
}
示例12: getChildren
public function getChildren(AssetFactory $factory, $content, $loadPath = null)
{
$loadPaths = $this->loadPaths;
if ($loadPath) {
array_unshift($loadPaths, $loadPath);
}
if (!$loadPaths) {
return array();
}
$children = array();
foreach (CssUtils::extractImports($content) as $reference) {
if ('.css' === substr($reference, -4)) {
// skip normal css imports
// todo: skip imports with media queries
continue;
}
// the reference may or may not have an extension or be a partial
if (pathinfo($reference, PATHINFO_EXTENSION)) {
$needles = array($reference, self::partialize($reference));
} else {
$needles = array($reference . '.scss', $reference . '.sass', self::partialize($reference) . '.scss', self::partialize($reference) . '.sass');
}
foreach ($loadPaths as $loadPath) {
foreach ($needles as $needle) {
if (file_exists($file = $loadPath . '/' . $needle)) {
$coll = $factory->createAsset($file, array(), array('root' => $loadPath));
foreach ($coll as $leaf) {
/** @var $leaf AssetInterface */
$leaf->ensureFilter($this);
$children[] = $leaf;
goto next_reference;
}
}
}
}
next_reference:
}
return $children;
}
示例13: createAsset
/**
* Creates a new asset.
*
* @param array|string $inputs An array of input strings
* @param array|string $filters An array of filter names
* @param array $options An array of options
*
* @return \Assetic\Asset\AssetCollection An asset collection
*/
public function createAsset($inputs = array(), $filters = array(), array $options = array())
{
$am = $this->getAssetManager();
if ($am instanceof LazyAssetManager) {
if (isset($options['name'])) {
$name = $options['name'];
} else {
$name = $options['name'] = $this->generateAssetName($inputs, $filters, $options);
}
$am->setFormula($name, [$inputs, $filters, $options]);
}
return parent::createAsset($inputs, $filters, $options);
}
示例14: getUrlToAssets
//.........这里部分代码省略.........
if (is_scalar($assets)) {
$assets = array($assets);
// just a single path name
}
if ($filters == 'default') {
if (isset($this->default_filters[$type])) {
$filters = $this->default_filters[$type];
} else {
$filters = '';
}
}
if (!is_array($filters)) {
if (empty($filters)) {
$filters = array();
} else {
$filters = explode(',', str_replace(' ', '', $filters));
}
}
if (isset($this->default_output[$type])) {
$output = $this->default_output[$type];
} else {
$output = '';
}
$xoops = \Xoops::getInstance();
if (isset($target)) {
$target_path = $target;
} else {
$target_path = $xoops->path('assets');
}
try {
$am = $this->assetManager;
$fm = new FilterManager();
foreach ($filters as $filter) {
if (is_object($filter) && $filter instanceof $this->filterInterface) {
$filterArray[] = $filter;
} else {
switch (ltrim($filter, '?')) {
case 'cssembed':
$fm->set('cssembed', new Filter\PhpCssEmbedFilter());
break;
case 'cssmin':
$fm->set('cssmin', new Filter\CssMinFilter());
break;
case 'cssimport':
$fm->set('cssimport', new Filter\CssImportFilter());
break;
case 'cssrewrite':
$fm->set('cssrewrite', new Filter\CssRewriteFilter());
break;
case 'lessphp':
$fm->set('lessphp', new Filter\LessphpFilter());
break;
case 'scssphp':
$fm->set('scssphp', new Filter\ScssphpFilter());
break;
case 'jsmin':
$fm->set('jsmin', new Filter\JSMinFilter());
break;
default:
throw new \Exception(sprintf('%s filter not implemented.', $filter));
break;
}
}
}
// Factory setup
$factory = new AssetFactory($target_path);
$factory->setAssetManager($am);
$factory->setFilterManager($fm);
$factory->setDefaultOutput($output);
$factory->setDebug($this->debug);
$factory->addWorker(new CacheBustingWorker());
// Prepare the assets writer
$writer = new AssetWriter($target_path);
// Translate asset paths, remove duplicates
$translated_assets = array();
foreach ($assets as $k => $v) {
// translate path if not a reference or absolute path
if (0 == preg_match("/^\\/|^\\\\|^[a-zA-Z]:|^@/", $v)) {
$v = $xoops->path($v);
}
if (!in_array($v, $translated_assets)) {
$translated_assets[] = $v;
}
}
// Create the asset
$asset = $factory->createAsset($translated_assets, $filters);
$asset_path = $asset->getTargetPath();
if (!is_readable($target_path . $asset_path)) {
$xoops->events()->triggerEvent('debug.timer.start', array('writeAsset', $asset_path));
$oldumask = umask(02);
$writer->writeAsset($asset);
umask($oldumask);
$xoops->events()->triggerEvent('debug.timer.stop', 'writeAsset');
}
return $xoops->url('assets/' . $asset_path);
} catch (\Exception $e) {
$xoops->events()->triggerEvent('core.exception', $e);
return null;
}
}
示例15: renderThemeAssets
public function renderThemeAssets()
{
$conf = (array) $this->getThemeAssets();
$factory = new Factory\AssetFactory($conf['root_path']);
$factory->setAssetManager($this->getAssetManager());
$factory->setFilterManager($this->getFilterManager());
$factory->setDebug($this->configuration->isDebug());
$mobileDetect = $this->serviceManager->get('dxMobileDetect');
$isTablet = $mobileDetect->isTablet();
$assetName = 'assets';
$filterName = 'filters';
$optionName = 'options';
$outputName = 'output';
if ($mobileDetect->isMobile()) {
$assetName = $assetName . 'Mobile';
$filterName = $filterName . 'Mobile';
$optionName = $optionName . 'Mobile';
$outputName = $outputName . 'Mobile';
}
if ($mobileDetect->isTablet()) {
$assetName = $assetName . 'Tablet';
$filterName = $filterName . 'Tablet';
$optionName = $optionName . 'Tablet';
$outputName = $outputName . 'Mobile';
}
$collections = (array) $conf['collections'];
foreach ($collections as $name => $options) {
$assets = isset($options[$assetName]) ? $options[$assetName] : isset($options['assets']) ? $options['assets'] : array();
$filtersx = isset($options[$filterName]) ? $options[$filterName] : isset($options['filters']) ? $options['filters'] : array();
$options = isset($options[$optionName]) ? $options[$optionName] : isset($options['options']) ? $options['options'] : array();
$options['output'] = isset($options[$outputName]) ? $options[$outputName] : isset($options['output']) ? $options['output'] : $name;
$filters = $this->initFilters($filtersx);
/** @var $asset \Assetic\Asset\AssetCollection */
$asset = $factory->createAsset($assets, $filters, $options);
# allow to move all files 1:1 to new directory
# its particulary usefull when this assets are images.
if (isset($options['move_raw']) && $options['move_raw']) {
foreach ($asset as $key => $value) {
$name = md5($value->getSourceRoot() . $value->getSourcePath());
$value->setTargetPath($value->getSourcePath());
$value = $this->cache($value);
$this->assetManager->set($name, $value);
}
} else {
$asset = $this->cache($asset);
$this->assetManager->set($name, $asset);
}
}
$writer = new AssetWriter($this->configuration->getWebPath());
$writer->writeManagerAssets($this->assetManager);
}