Skip to content

[2.7][Asset] Framework config to support custom version strategy #15554

Closed
@xavierbriand

Description

@xavierbriand

The Framework bundle only implements two asset version strategies: empty and static (defaults provided by the Asset component).

If I want to use a custom strategy for my package (eg. to add the locale its path) without overriding the defaults, the recommended solution is to:

  • create a new service (my strategy)
  • use a compiler pass to extract the version and version format parameters from the default static strategy my package is compiled with
  • update the definition of my service with previously extracted parameters

If I have two packages with the same custom strategy but different versions, I need to duplicate my service declaration and update my compiler. And I cannot create services on-demand during the compiler pass. I could also create my own package configuration for my bundle that would override or extend the default assets.packages service.

It's neither convenient nor elegant.

I propose to add an optional parameter to set custom strategies:

#app/config/config.yml

framework:
    #...
    assets:
        base_urls: //my.cdn.com
        packages:
            pdf:
                version: %version%
                version_format: /name/space/%%2$s/pdf%%1$s
            localized_doc:
                version: %version%
                version_strategy: my.abstract.service.id # default is assets.static_version_strategy falling back on assets.empty_version_strategy if version is null (current behavior)
                version_format: /name/space/%%2$s/doc/%%3$s%/abc%1$s #%3$s would be my locale

A convenient abstract BaseVersionStrategy class could be provided that would declare setVersion and setVersionFormat to inject said parameters.

This solves a particular problem I have where I want to inject known parameters in an asset base_urls or base_path. Please provide your thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions