widmogrod / zf2-assetic-module

Zend Framework module for Assetic
146 stars 62 forks source link

problem with move_raw option #118

Open countless-integers opened 9 years ago

countless-integers commented 9 years ago

I want to use the move_raw option to copy images and fonts to public dir from module's asset directories, however I get a fatal from Assetic:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'There is no "flexslider_fonts" asset.' in /path/to/project/vendor/kriswallsmith/assetic/src/Assetic/AssetManager.php on line 37

My asset collection config:

                 'flexslider_fonts' => array(                                                                    
                     'assets' => array(                                                                       
                         'fonts/flexslider-icon.svg',                                                         
                         'fonts/flexslider-icon.woff',                                                        
                         'fonts/flexslider-icon.ttf',                                                         
                     ),                                                                                       
                     'options' => array(                                                                      
                         'move_raw' => true,                                                                  
                     ),                                                                                       
                 ),

Weird thing is the assets do get moved to public/fonts but I get the fatal after that. Tried the same thing with images. Any suggestions?

I'm using the latest stable release on a zf2 2.3.1

widmogrod commented 9 years ago

Could it be that you have name mismatch? galeria_fonts should be flexslider_fonts

Or other way around.

countless-integers commented 9 years ago

My bad, I've made a mistake pasting the code (corrected now). Anyway the names are fine, as far as I can tell. I even tried to change and reorder them (hence the mismatch in the code samples I pasted -- each from a run with different asset collection names).

widmogrod commented 9 years ago

I you could paste:

countless-integers commented 9 years ago

Ok, I had to redact it a bit (company policy), but it've tried to keep it relevant. First, config:

return array(
    'assetic_configuration' => array(
        'webPath' => realpath('public'),
        'cachePath' => realpath('data/assetic'),
        'basePath' => 'p',
        'default' => array(
            'assets' => array(
                '@common_front_css',
                -100 => '@head_common_js',
            ),
            'options' => array(
                'mixin' => true,
            ),
        ),
        'rendererToStrategy' => array(
            'Zend\View\Renderer\PhpRenderer' => 'Zend\View\Renderer\PhpRenderer',
        ),
        'debug' => true,
            'buildOnRequest' => true,
            'cacheEnabled' => false,
            'combine' => false,
            'baseUrl' => $host,
        ),
        'routes' => array(
            // ...
            'article/content' => array(
                '@head_front_js',
                '@search_js',
                '@flexslider_js',
                '@flexslider_css',
                '@flexslider_fonts',
            ),
            // ...
        ),
        'modules' => array(
            'Article' => array(
                'root_path' => realpath('module/Article/assets/'),
                'collections' => array(
                    'flexslider_js' => array(
                        'assets' => array(
                            'js/vendor/jquery.flexslider.js',
                            'js/ligthbox.js',
                        ),
                        'options' => array(
                            'output' => 'js/combined/gallery.js'
                        ),
                        'filters' => array(
                            '?YUIJsCompressor',
                        ),
                    ),
                    'flexslider_css' => array(
                        'assets' => array(
                            'css/vendor/flexslider.css',
                        ),
                        'options' => array(
                            'output' => 'css/combined/gallery.css'
                        ),
                        'filters' => array(
                            '?YUICssCompressor',
                        ),
                    ),
                    'flexslider_fonts' => array(
                        'assets' => array(
                            'fonts/flexslider-icon.svg',
                            'fonts/flexslider-icon.woff',
                            'fonts/flexslider-icon.ttf',
                        ),
                        'options' => array(
                            'move_raw' => true,
                        ),
                    ),
                ),
            ),
        ),
    ),
);

And the stacktrace:

PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'There is no "flexslider_fonts" asset.' in /redacted/path/vendor/kriswallsmith/assetic/src/Assetic/AssetManager.php:37
Stack trace:
#0 /redacted/path/vendor/widmogrod/zf2-assetic-module/src/AsseticBundle/Service.php(315): Assetic\AssetManager->get('galeria_img')
#1 /redacted/path/vendor/widmogrod/zf2-assetic-module/src/AsseticBundle/Service.php(250): AsseticBundle\Service->setupRendererFromOptions(Object(Zend\View\Renderer\PhpRenderer), Array)
#2 /redacted/path/vendor/widmogrod/zf2-assetic-module/src/AsseticBundle/Listener.php(79): AsseticBundle\Service->setupRenderer(Object(Zend\View\Renderer\PhpRenderer))
#3 [internal function]: AsseticBundle\Listener->renderAssets(Object(Zend\Mvc\MvcEvent))
#4 /redacted/path/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array in /redacted/path/vendor/kriswallsmith/assetic/src/Assetic/AssetManager.php on line 37

BTW. are other types of assets supported, besides collections? Like a single file asset?

widmogrod commented 9 years ago

It's look like it crash when try to get('galeria_img') but I don't see this configuration here.

Hard to say where lies the problem.

If you could write a test, that reproduce this error and create a pull request. That would help to debug it.

stephaun commented 9 years ago

I have been having this same issue for months. Like countless-integers has said, the assets get moved regardless, so the temporary workaround is to just comment image/font assets:

'default' => array(
    'assets' => array(
        //'@font_awesome_fonts',
        '@font_awesome_css',
        '@jquery',
        //'@bootstrap_fonts',
        '@bootstrap_css',
        '@bootstrap_js',
        //'@jquery_ui_img',
        '@jquery_ui_css',
        '@jquery_ui_js',
    ),
),

Will try and come up with a fix in my free time...