简体   繁体   中英

Symfony - Assetic sometimes don't apply filters to named assets created form bundle

In my project I use code below to add to assetic some named assets and one of them use lessphp filter.

public function prepend(ContainerBuilder $container)
{
    $configs = $container->getExtensionConfig($this->getAlias());
    $config = $this->processConfiguration(new Configuration(), $configs);

    $this->configureAsseticBundle($container, $config);
}

protected function configureAsseticBundle(ContainerBuilder $container, array $config)
{
    foreach (array_keys($container->getExtensions()) as $name) {
        switch ($name) {
            case 'assetic':
                $container->prependExtensionConfig(
                    $name,
                    array(
                        'assets' => array(
                            'some_less' => array(
                                'inputs' => array(
                                    '@SomeBundle/Resources/public/less/some.less'
                                ),
                                'filters' => array('lessphp'),
                            ),
                        )
                    )
                );
                break;
        }
    }
}

When I dump assets using assetic:dump everything is working fine in production enviroment but in dev enviroment lessphp filter for this named asset works only after few page refresh and after some time it doesn't work anymore and I need to remove all cache. After remove cache it work fine again... for few minutes...

I also noticed that it stop working when I edit any bundle extension class (DependencyInjection/[BundleName]Extension.php).

Does anyone have any idea what i did wrong?

I suspect this is because of the issue reported here . There's a bug in the Assetic code that will incorrectly "clear" out the filters for an asset during rendering, so they are never applied.

You should be able to reliably reproduce it by clearing the cache with php app/console cache:clear . But you should then be able to "fix" it by completely removing the dev cache files and reloading the page.

The PR I referenced is not get committed (it's waiting for a test), but it's a couple lines of a code you can manually add just to confirm it's the fix you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM