Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[2.7][Asset] Empty version strategy for package #14832

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

Closed
badlamer opened this issue Jun 2, 2015 · 15 comments
Closed

[2.7][Asset] Empty version strategy for package #14832

badlamer opened this issue Jun 2, 2015 · 15 comments

Comments

@badlamer
Copy link

badlamer commented Jun 2, 2015

Hello! In ~2.6 version was EmptyVersionStrategy for images package. In 2.7 replaced default version from framework.assets

framework:
    assets:
        version: %assets_version%
        base_urls: %cdn_urls%
        packages:
            images:
                version:              ~
                version_format:       null
                base_urls: %cdn_urls%

From app/cache/prod/appProdProjectContainer.php

    protected function getAssets_VersionDefaultService()
    {
        return $this->services['assets._version__default'] = new \Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy('test', '%s?%s');
    }
    protected function getAssets_ContextService()
    {
        return $this->services['assets.context'] = new \Symfony\Component\Asset\Context\RequestStackContext($this->get('request_stack'));
    }
    protected function getAssets_PackagesService()
    {
        $a = $this->get('assets._version__default');
        $b = $this->get('assets.context');
        return $this->services['assets.packages'] = new \Symfony\Component\Asset\Packages(new \Symfony\Component\Asset\UrlPackage(array(0 => 'http://s1.cdn.ru', 1 => 'http://s2.cdn.ru'), $a, $b), array('images' => new \Symfony\Component\Asset\UrlPackage(array(0 => 'http://s1.cdn.ru', 1 => 'http://s2.cdn.ru'), $a, $b)));
    }
@badlamer badlamer changed the title [2.7][Asset] CDN & Empty version strategy for package [2.7][Asset] Empty version strategy for package Jun 2, 2015
@xabbuh xabbuh added the Asset label Jun 2, 2015
@XWB
Copy link
Contributor

XWB commented Jun 19, 2015

I'm having the same issue.

Prior to Symfony 2.7, the above configuration would result into:

{{ asset('test.png', 'images') }} => http://localhost.com/test.png]

Since Symfony 2.7 the query parameter is always appended, even if the value is empty:

{{ asset('test.png', 'images') }} => http://localhost.com/test.png?v=

Ping @fabpot @stof

@stof
Copy link
Member

stof commented Jun 19, 2015

@XWB are you using null or an empty string as asset version ?

@XWB
Copy link
Contributor

XWB commented Jun 19, 2015

@stof I'm using the following config:

framework:
    assets:
        assets_version: %app_version%
        assets_version_format: "%%s?v=%%s"
        packages:
            images:
                version: ~
                version_format: ~

@stof
Copy link
Member

stof commented Jun 19, 2015

and what is the value of the app_version parameter ?

@XWB
Copy link
Contributor

XWB commented Jun 19, 2015

A string:

class MyBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->setParameter('app_version', '2.3.4');
    }
}

@XWB
Copy link
Contributor

XWB commented Jun 25, 2015

@stof @fabpot Any idea?

@dosten
Copy link
Contributor

dosten commented Jun 25, 2015

Can you replicate it in a fresh Symfony install?

@XWB
Copy link
Contributor

XWB commented Jun 25, 2015

@dosten Yes I can.

@stof
Copy link
Member

stof commented Jun 25, 2015

@XWB a comment from you which has been removed said it was related to the casting in f74a1f2#diff-5e7347edce37c5886ec67b7ba02f3a9cR81 Does it actually work if you removing the string casting there ?

@XWB
Copy link
Contributor

XWB commented Jun 25, 2015

@stof I tried, removing the string cast will just set the package version to the default version. So that does not work either.

@XWB
Copy link
Contributor

XWB commented Jun 25, 2015

I uploaded a fresh Symfony install:

https://github.com/XWB/asset

  1. Checkout
  2. Composer install
  3. Navigate to /web/app/example

Modified files:

https://github.com/XWB/asset/blob/master/app/Resources/views/default/index.html.twig#L6
https://github.com/XWB/asset/blob/master/app/config/config.yml#L24:L29

@XWB
Copy link
Contributor

XWB commented Jun 26, 2015

Found it:

f74a1f2#diff-0e793081ceb720201745c982a568903fR619

Changing null === $version back to !$version makes it working again.

@xabbuh
Copy link
Member

xabbuh commented Oct 7, 2015

@badlamer I think we should not close here. The issue is still present and I still want to find some time to fix it. #15108 was not closed because this issue is invalid, but just because the proposed fix was not the right one.

@ewgRa
Copy link
Contributor

ewgRa commented Nov 9, 2015

PR for this issue - #16509

@ewgRa
Copy link
Contributor

ewgRa commented Nov 11, 2015

Also #16522 kind of PR for this issue, can help also, but in another way.

fabpot added a commit that referenced this issue Jan 24, 2016
…ages (ewgRa)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7][Asset] Ability to set empty version strategy in packages

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no, but not sure, as for me test was wrong
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14832
| License       | MIT
| Doc PR        |

Comment about '' thing. As you can see in xml test - we can't for attribute set null value. And for xml version '' empty string considered as null value, that affect all others formats and test is changed.

Commits
-------

646fc9c Ability to set empty version strategy in packages
@fabpot fabpot closed this as completed Jan 24, 2016
fabpot added a commit that referenced this issue Jan 25, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[2.7][Asset] Add defaultNull to version configuration

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14832, #16511
| License       | MIT
| Doc PR        |

In #16511 PR was omitted defaultNull version for one case.

Commits
-------

65adb72 add defaultNull to version
fabpot added a commit that referenced this issue Jan 26, 2016
This PR was squashed before being merged into the 3.1-dev branch (closes #17532).

Discussion
----------

[Asset] Version as service

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

While I working on #14832 I realize that all this problems and hidden magic can be avoided, if we will have ability to set asset version strategy as service.

This PR implementation of this idea.

Now it is possible to do something like this:

```yaml
framework:
    assets:
        version_strategy: assets.custom_version_strategy
        base_urls: http://cdn.example.com
        packages:
            foo:
                base_urls: ["https://example.com"]
                version_strategy: assets.custom_version_strategy
```

There is can be some conflicts with #16511 when it will be in master

Commits
-------

52d116b [Asset] Version as service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants