Note that there are some explanatory texts on larger screens.

plurals
  1. POAssetic AssetFactory::createAsset(array $input, ...) - $input doesn't accept \Assetic\Asset\* elements
    text
    copied!<p>I have a couple of methods which combine many CSS assets to one, minify them and dump them (cached) to a generated filename like "/assetic/6bad22c.css". I achieve this by making use of the following:</p> <p>Currently I use AssetFactory</p> <pre><code>private static function getCssAssetFactory() { $fm = new FilterManager(); $fm-&gt;set('less', new Filter\LessphpFilter()); $fm-&gt;set('import', new Filter\CssImportFilter()); $fm-&gt;set('rewrite', new Filter\CssRewriteFilter()); $fm-&gt;set('min', new Filter\CssMinFilter()); $factory = new AssetFactory(self::getAssetBuildPath()); $factory-&gt;setFilterManager($fm); return $factory; } </code></pre> <p>and create an Asset via</p> <pre><code>public static function dumpStylesheets() { $asset = self::getCssAssetFactory()-&gt;createAsset ( self::$stylesheets , array ( 'less' // Less CSS Compiler , 'import' // Solves @imports , 'rewrite' // Rewrites Base URLs when moving to another URL , 'min' // Minifies the script ) , array('output' =&gt; 'assetic/*.css') ); $cache = self::getAssetCache($asset); self::getAssetWriter()-&gt;writeAsset($cache); return self::basePath().'/'.$asset-&gt;getTargetPath(); } </code></pre> <p>Here are the referenced methods:</p> <pre><code>private static function getAssetWriter() { if (is_null(self::$AssetWriter)) { self::$AssetWriter = new AssetWriter(self::getAssetBuildPath()); } return self::$AssetWriter; } private static function getAssetCache($asset) { return new AssetCache ( $asset , new FilesystemCache(self::getAssetBuildPath().'/cache') ); } </code></pre> <p>No magic here so far. My problem is, that the <code>self::$stylesheets</code> array, by <a href="https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Factory/AssetFactory.php#L153" rel="nofollow">definition</a>, just contains path-strings to the assets. But I <strong>need</strong> to use real Assetic Assets like this way:</p> <pre><code>self::$stylesheets = array ( new Asset\FileAsset('path/to/style.css') , new Asset\StringAsset('.some-class {text-decoration: none;}'); , new Asset\HttpAsset('http://domain.tld/assets/style.css'); ); </code></pre> <p>But <code>AssetFactory::createAsset()</code> doesn't accept its own Assets. I need the possibility to use <code>StringAsset</code> because I have to change some values in CSS / JS, serverside.</p> <p>Is there another way to achieve this other than using <code>AssetFactory::createAsset()</code>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload