Note that there are some explanatory texts on larger screens.

plurals
  1. POAssetic AssetFactory::createAsset(array $input, ...) - $input doesn't accept \Assetic\Asset\* elements
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COWhat happens? Do you get an error? What result do you expect, and what result actually occurs? I'm not familiar with AssetFactory, but more information would be helpful.
      singulars
    2. CONo, my methods work fine. No errors. But I need to extend them with original Assetic Assets. When I try to add Assets instead of path strings to the `AssetFactory::createAsset()` method it'll fail with the following error: __Fatal error: Cannot use object of type Assetic\Asset\FileAsset as array in [...]\lib\vendor\Assetic\src\Assetic\Factory\AssetFactory.php on line 270__, which is expected but not intended.
      singulars
    3. COI think we're getting somewhere. I looked around a little bit to see what we're dealing with. The createAsset method *must* consume a string or an array of strings, and an object of any type will always fail. When processing your inputs, it calls parseInput() on your objects, and as per the error on line 270, it treats the input as an array. With a string, it's just accessing the first character. With an object, it produces a fatal error. You can't do what you want. Why do you need to pass Assetic Assets as opposed to strings?
      singulars
 

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