-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][Routing] Use a PSR-11 container in FrameworkBundle Router #24738
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
Conversation
For 4.1 is fine also, no need to hurry IMHO. |
But we'll keep the |
Public services don't really hurt anymore, and we'll always be able to find a way to make it privta later if we really want to. |
Moving the target to 4.1 as I agree with @nicolas-grekas, we need to restrict changes to important flaws and bug fixes. |
@ogizanagi Can you rebase this PR? Thanks. |
Rebased. Should we do anything further with this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of the param fetcher callable, but I don't have any better idea.
* @param LoggerInterface|null $logger | ||
*/ | ||
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null) | ||
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, callable $paramFetcher = null, LoggerInterface $logger = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rearranging the arguments is a BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it's not as the logger was added in 4.1 as well. Nevermind
I have one (two in fact):
|
See #25288 |
…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
@ogizanagi now that #25288 is merged, you can move forward on this one when you have some time. |
@@ -67,6 +68,7 @@ | |||
<argument key="matcher_cache_class">%router.cache_class_prefix%UrlMatcher</argument> | |||
</argument> | |||
<argument type="service" id="router.request_context" on-invalid="ignore" /> | |||
<argument type="service" id="parameter_bag" on-invalid="ignore" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on-invalid="ignore"
, because we still allow to install the Fwb 4.x with DI component 3.4
if ($parameters) { | ||
$this->paramFetcher = array($parameters, 'get'); | ||
} elseif ($container instanceof SymfonyContainerInterface) { | ||
$this->paramFetcher = array($container, 'getParameter'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be simplified by using new ContainerBag($container)
and always use $this->parameters->get()
instead of this callable $paramFetcher
property, but I'd be the one breaking the 3-cross-4 compat' 😄
Not true actually. The ContainerBag
only accepts a \Symfony\Component\DependencyInjection\Container
instance. Not the interface.
@nicolas-grekas : Done. Thanks for working on the PSR-11 ContainerBag feature and for the ping. I'm kinda out of the game currently. |
Changed to use a PSR-11 bag for parameters
*/ | ||
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, LoggerInterface $logger = null) | ||
public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null, ContainerInterface $parameters = null, LoggerInterface $logger = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new arg should be added last, otherwise that's a BC break, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it's not as the logger was added in 4.1 as well. Nevermind
:)
@@ -130,6 +138,10 @@ private function resolveParameters(RouteCollection $collection) | |||
*/ | |||
private function resolve($value) | |||
{ | |||
if (!$paramFetcher = $this->paramFetcher) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we throw instead in the constructor to prevent dealing with this case here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One could theoretically use this router without the need to resolve parameters, so instead we could rather move up this check in getRouteCollection
to never call resolveParameters
on no way to retrieve parameters.
But yes for now the exception looks fine to me. Updated.
(but failing test for now) |
…FrameworkBundle Router
This failure on deps="low" build means we must either:
For now, 2 is implemented. |
Thank you @ogizanagi. |
…rameworkBundle Router (ogizanagi) This PR was merged into the 4.1-dev branch. Discussion ---------- [FrameworkBundle][Routing] Use a PSR-11 container in FrameworkBundle Router | Q | A | ------------- | --- | Branch? | 4.1 <!-- see comment below --> | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | not yet <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | N/A <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | N/A ~3.4 because~ it allows to make the `routing.loader` service private and add sense into implementing the `ServiceSubscriberInterface` in the `Router` by injecting a ServiceLocator instead of the DI container. Should we deprecate passing a DI `ContainerInterface` instance without providing the `$paramFetcher` argument? Move the whole `Router::resolve()` method into a dedicated `callable $paramResolver` ? Commits ------- 5a2f295 [FrameworkBundle][Routing] Use a PSR-11 container & parameter bag in FrameworkBundle Router
3.4 becauseit allows to make therouting.loader
service private and add sense into implementing theServiceSubscriberInterface
in theRouter
by injecting a ServiceLocator instead of the DI container.Should we deprecate passing a DI
ContainerInterface
instance without providing the$paramFetcher
argument?Move the whole
Router::resolve()
method into a dedicatedcallable $paramResolver
?