8000 [DependencyInjection] Create a new trait or class to resolve values with the container · Issue #17160 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Create a new trait or class to resolve values with the container #17160

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
GuilhemN opened this issue Dec 28, 2015 · 3 comments

Comments

@GuilhemN
Copy link
Contributor

Actually, to resolve a value we can use ParameterBag::resolveValue() which is accessible in the Container.
This works fine but the problem is when we want to resolve a value at runtime and we have a custom ContainerInterface instance.

So I would like to have a trait or a class which would allow to resolve values without an access to a ParameterBag instance.

You can find an example of use case in FOSRestBundle where we need to resolve values at runtime.
We actually use a trait but I'd prefer to use something from the core.

@xabbuh
Copy link
Member
xabbuh commented Dec 29, 2015

Generally, this should be possible. We would need something like a ParameterResolver service. The only issue I see is that the ContainerInterface and the ParameterBag class have different ways to access a value. So we would need to create the resolver with a callback which knows how to retrieve the underlying value. We can then reuse this class in the ParameterBag itself.

@GuilhemN
Copy link
Contributor Author

I created a new ParameterResolver in #17192.

nicolas-grekas added a commit that referenced this issue Dec 8, 2017
…ess parameters as-a-service (nicolas-grekas, sroze)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[DI][FrameworkBundle] Add PSR-11 "ContainerBag" to access parameters as-a-service

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

There is one thing that prevents us from not injecting the container: access to the parameter bag.
This PR fixes this limitation by providing a PSR-11 `ContainerBagInterface` + related implementation, and wiring it as a service that ppl can then also autowire using the new interface as a type hint, or `ParameterBagInterface`.

Needed to complete e.g. #24738

Commits
-------

561cd7e Add tests on the ContainerBag
0e18d3e [DI][FrameworkBundle] Add PSR-11 "ContainerBag" to access parameters as-a-service
@javiereguiluz
Copy link
Member

Closing as fixed by #25288.

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

3 participants
0