Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different (wrong) assets names when use function jpegoptim in web request and assetic:dump command #849

Open
PeterZhukov opened this issue Apr 20, 2017 · 1 comment

Comments

@PeterZhukov
Copy link

PeterZhukov commented Apr 20, 2017

My config:

assetic:
    debug:          '%kernel.debug%'
    #use_controller: '%kernel.debug%'
    use_controller: false
    filters:
        cssrewrite:
            apply_to: '\.css$'
        jpegoptim:
            bin: "%kernel.root_dir%/../bin/jpegoptim.exe"
            max: 100
    twig:
        functions:
            jpegoptim: ~

Template:
{{ jpegoptim('@AppBundle/Resources/public/images/example2.jpg') }}

When I refresh page in broser I get following string:
/symfony/web/assetic/d05ce4a.jpg
But when I execute command assetic:dump, I get following assets intalled:
11:17:23 [file+] D:\www\testphp.local\symfony\app/../web/assetic/b3aed8d.jpg

Why this happens:

When page is refreshed, next functions calls happens:

AsseticFilterInvoker : invoke,
AssetFactory : createAsset,
AssetFactory : generateAssetName

in AssetFactory : createAsset this happens:

        if (!isset($options['output'])) {
            $options['output'] = $this->output;
        }
...
        if (!isset($options['debug'])) {
            $options['debug'] = $this->debug;
        }
...
        if (!isset($options['root'])) {
            $options['root'] = array($this->root);
        } else {
            if (!is_array($options['root'])) {
                $options['root'] = array($options['root']);
            }

            $options['root'][] = $this->root;
        }

so basically, $options['debug'], $options['root'] keys are always set to something, then in AssetFactory : generateAssetName function filters $options keys not in 'output', 'debug', 'root', and then creates name based on $inputs, $filters (this 2 doesn't matter for this issue) and $options:
return substr(sha1(serialize($inputs).serialize($filters).serialize($options)), 0, 7);

But when i ussue command: assetic:dump, then next functions calls happens:

AsseticNodeVisitor : checkNode,
AssetFactory : generateAssetName

in AsseticNodeVisitor : checkNode there is not setting for $options['output'], $options['debug'], $options['root'] like in AssetFactory : createAsset, so in AssetFactory : generateAssetName $options becomes empty array (AsseticNodeVisitor : checkNode even doesn't send $options to AssetFactory : generateAssetName).
Then next functions calls happens:

TwigFormulaLoader : loadNode (here - } elseif ($node instanceof AsseticFilterNode) { - branch will be execute),
AssetFactory : generateAssetName

again, there is no settings for $options['debug'], $options['root'] and so on (but in this case $options is passed to AssetFactory : generateAssetName, but it is different array then in web request because of ['debug'] and ['root'] settings in AssetFactory : createAsset in web request).

Because of this - result assets names are different, and it is impossible to use jpegoptim in production mode (use_controller: false).

May be I'm doing something wrong?

@PeterZhukov PeterZhukov changed the title Wrong asset name when use function jpegoptim Different assets names when use function jpegoptim in web request and assetic:dump command Apr 20, 2017
@PeterZhukov PeterZhukov changed the title Different assets names when use function jpegoptim in web request and assetic:dump command Different (wrong) assets names when use function jpegoptim in web request and assetic:dump command Apr 20, 2017
@PeterZhukov
Copy link
Author

Same issue in symfony/assetic-bundle: https://github.com/symfony/assetic-bundle/issues/434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant