8000 [3.0][FrameworkBundle] Asset helpers should not be in the request scope · Issue #11653 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[3.0][FrameworkBundle] Asset helpers should not be in the request scope #11653
Closed
@csarrazi

Description

@csarrazi

Right now, using the asset twig function results in the following error:

[Symfony\Component\DependencyInjection\Exception\ScopeWideningInjectionException]

Scope Widening Injection detected: The definition "templating.asset.default_package" references the service "request" which belongs to a narrower scope. Generally, it is safer to either move "templating.asset.default_package" to scope "request" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "request" each time it is needed. In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.

As one may want to rely on the asset helper to generate URIs outside from a request (i.e., in a command-line, for sending e-mails), it should not depend on the request service, but rather on request_stack, in order to be available in a wider scope.

This would also allow the simplification of Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension, by removing calls to the setScope() methods, once support for scopes is dropped for 3.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0