Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Remove some container injections in favor of service locators#21625
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
6d9025c tobee8bacCompare| }else { | ||
| $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.
Suggestions to make this deprecation better are welcomed.
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.
missing type check when the 2nd arg is not an array (LoggerInterface|null)
bee8bac to404200aCompare| $this->mapping =$mapping; | ||
| // BC 3.x, to be removed in 4.0, re-adding the LoggerInterface typehint to the $logger argument | ||
| if (is_array($logger)) { | ||
| @trigger_error(sprintf('The second argument of %s() is deprecated since symfony 3.3 and will be removed, passing something else than a %s instance will trigger an error in 4.0.',__METHOD__, LoggerInterface::class),E_USER_DEPRECATED); |
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.
/symfony 3.3/Symfony 3.3/
| /** | ||
| * @group legacy | ||
| * @expectedDeprecation The second argument of Symfony\Bundle\TwigBundle\ContainerAwareRuntimeLoader::__construct() is deprecated since symfony 3.3 and will be removed, passing something else than a Psr\Log\LoggerInterface instance will trigger an error in 4.0. |
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.
/symfony 3.3/Symfony 3.3/
1d3ef15 to2675b30Compare| <services> | ||
| <serviceid="fragment.handler"class="Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler"> | ||
| <argumenttype="service"id="service_container" /> | ||
| <argument/><!-- fragment renderer locator--> |
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.
you can do getter injection on this one very easily!
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.
are you talking aboutgetSession() in the session listener instead? If no, could you elaborate?
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.
yes, that's what I mean
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.
@chalasr yeah, this seems to be on the wrong service.
for the SessionListener, I'm in favor of leaving the FrameworkBundle class unchanged, deprecating it, and using getter injection on the component class itself.
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 FrameworkBundle class was just doing getter injection implemented manually.
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, added as last commita4a4b3b
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.
ReflectionClass::newInstanceWithoutConstructor breaks on 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.
is newInstanceWithoutConstructor called inside ContainerBuilder or inside the dumped container?
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.
@nicolas-grekas in the compiler pass, when registering the subscriber in a dummy event dispatcher to collect subscribed events and register it lazily.
however, I don't even understand why we do this: In Symfony stable releases, the ContainerAwareEventDispatcher calls the staticgetSubscribedEvents statically. We don't need an instance for that.
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.
that's because ofhttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/EventDispatcher/EventDispatcher.php#L127 which requires an instance
but this PR now has a fix you will like :)
| $this->mapping =$mapping; | ||
| // BC 3.x, to be removed in 4.0, re-adding the LoggerInterface typehint to the $logger argument | ||
| if (is_array($logger)) { | ||
| @trigger_error(sprintf('The second argument of %s() is deprecated since version 3.3 and will be removed, passing something else than a %s instance will trigger an error in 4.0.',__METHOD__, LoggerInterface::class),E_USER_DEPRECATED); |
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 $mapping argument..." (the 2nd won't be removed since it will expect the logger)
| }else { | ||
| $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.
missing type check when the 2nd arg is not an array (LoggerInterface|null)
| if (is_array($logger)) { | ||
| @trigger_error(sprintf('The second argument of %s() is deprecated since version 3.3 and will be removed, passing something else than a %s instance will trigger an error in 4.0.',__METHOD__, LoggerInterface::class),E_USER_DEPRECATED); | ||
| if (2 <func_num_args() &&func_get_arg(3)instanceof LoggerInterface) { |
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 needed if the constructor signature is changed to__construct(ContainerInterface $container, $mapping = null, LoggerInterface $logger = null)
| */ | ||
| publicfunctionload($class) | ||
| { | ||
| if (isset($this->mapping[$class])) { |
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.
when $mapping is provided as an array, we should still use it
| /** | ||
| * Adds a service as a fragment renderer. | ||
| * | ||
| * @deprecated since version 3.3, to be removed in 4.0 |
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.
should always be put last, after@param
| */ | ||
| publicfunctiontestSecondConstructorArgumentIsDeprecated() | ||
| { | ||
| $loader =newContainerAwareRuntimeLoader($this->getMockBuilder(ContainerInterface::class)->getMock(),array()); |
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.
you also need to test that the existing behavior (using a mapping) keeps working. Copy the existingtestLoad method for that.
| */ | ||
| publicfunctionaddRendererService($name,$renderer) | ||
| { | ||
| $this->rendererIds[$name] =$renderer; |
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.
removing the implementation is wrong. It means that the feature does not work anymore, which is a BC break
| if (isset($this->rendererIds[$renderer])) { | ||
| $this->addRenderer($this->container->get($this->rendererIds[$renderer])); | ||
| unset($this->rendererIds[$renderer]); |
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.
you must keep using$this->rendererIds for the BC layer
| publicfunctiontestAddRendererServiceIsDeprecated() | ||
| { | ||
| $handler =newLazyLoadingFragmentHandler($this->getMockBuilder('Psr\Container\ContainerInterface')->getMock(),$this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock()); | ||
| $handler->addRendererService('foo','bar'); |
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.
you must keep the existing tests of the class here, to ensure that the 3.2 way of using the class keeps working
| useSymfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
| useSymfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
| useSymfony\Component\DependencyInjection\Reference; | ||
| useSymfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; |
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.
We tend to sort new use statements (without touching existing ones, to avoid a nightmare when merging branches). So please move this one at the beginning
| namespaceSymfony\Bundle\TwigBundle; | ||
| usePsr\Container\ContainerInterface; | ||
| usePsr\Log\LoggerInterface; |
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.
@fabpot as this class now depends only on PSR classes, should we add it in Twig itself ?
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.
Indeed, that's probably a good idea.
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.
ok I'll do a twig PR in parallel.
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.
@stof This means deprecating this class and bump the twig requirement to 2.x in TwigBundle to use the twig class instead, right?
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.
updated to use the twig class, it will break tests untiltwigphp/Twig#2401 is merged and released
chalasr commentedFeb 17, 2017
Thanks for the reviews. Status: needs work |
2675b30 to3e0b7f6Compare3e0b7f6 toc89b788Compare| "symfony/http-foundation":"~2.8|~3.0", | ||
| "symfony/http-kernel":"~2.8.16|~3.1.9|^3.2.2", | ||
| "twig/twig":"~1.28|~2.0" | ||
| "twig/twig":"~2.2" |
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.
That's not possible. We cannot drop support for Twig 1.x. But the good news is that we are still maintaining Twig 1.x and 2.x. So the constraint can be^1.32|^2.2.
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.
constraint fixed
c89b788 to097856eCompare| "symfony/http-foundation":"~2.8|~3.0", | ||
| "symfony/http-kernel":"~2.8.16|~3.1.9|^3.2.2", | ||
| "twig/twig":"~1.28|~2.0" | ||
| "twig/twig":"^1.29|^2.2" |
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, should be1.32.
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.
fixed
a4a4b3b to550f877CompareThis PR was merged into the 1.x branch.Discussion----------Add ContainerRuntimeLoaderNext tosymfony/symfony#21625 (comment)Commits-------964a51b Add ContainerRuntimeLoader
85c30a0 to961234eComparece55cd6 to2e5f25eComparec37ac4d tof891b7eComparechalasr commentedFeb 26, 2017
*SessionListener deprecated and moved to HttpKernel, note that the naming change was required. |
7d6f58f to23662b2Compare23662b2 to8293b75Compare…ument type (chalasr)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Remove experimental status from service-locator argument type| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#21625 (comment),#21625 (comment),#21710| License | MITThe `service-locator` argument type is not controversial to me. We know its scope, nothing really surprising, just a map of services to be lazily loaded like `iterator` is (which is not experimental) but keyed.About its api, it's just PSR-11 restricted to objects, nothing that can't be changed safely in the future.As stated in#21625 (comment), it proven its usefulness already. I think what we were looking for by flagging it experimental is just to see it in action, we've 3 opened PRs for that (#21625,#21690,#21730).This allows introducing deprecations for making use of the feature in the core, thus unlocks#21625 and#21690.Commits-------46dc47a [DI] Remove experimental status from service-locator argument type
…ument type (chalasr)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Remove experimental status from service-locator argument type| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |symfony/symfony#21625 (comment),symfony/symfony#21625 (comment), #21710| License | MITThe `service-locator` argument type is not controversial to me. We know its scope, nothing really surprising, just a map of services to be lazily loaded like `iterator` is (which is not experimental) but keyed.About its api, it's just PSR-11 restricted to objects, nothing that can't be changed safely in the future.As stated insymfony/symfony#21625 (comment), it proven its usefulness already. I think what we were looking for by flagging it experimental is just to see it in action, we've 3 opened PRs for that (#21625, #21690, #21730).This allows introducing deprecations for making use of the feature in the core, thus unlocks #21625 and #21690.Commits-------46dc47af11 [DI] Remove experimental status from service-locator argument type
nicolas-grekas left a comment
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.
👍
fabpot commentedFeb 28, 2017
Thank you@chalasr. |
…ocators (nicolas-grekas, chalasr)This PR was merged into the 3.3-dev branch.Discussion----------Remove some container injections in favor of service locators| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#21553 (comment)| License | MIT| Doc PR | n/aCommits-------8293b75 Replace some container injections by service locators0be9ea8 [EventDispatcher] Fix abstract event subscribers registration
fabpot commentedFeb 28, 2017
This PR breaks the test suite of SensioFrameworkExtraBundle.@chalasr Can you have a look at it? |
chalasr commentedFeb 28, 2017
…ence values (chalasr)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Fix ServiceLocatorArgument::setValues() for non-reference values| Q | A| ------------- | ---| Branch? | master| Fixed tickets |#21625 (comment)| Tests pass? | yes| License | MIT`ResolveInvalidReferencesPass` [calls `setValues()`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php#L91) with resolved invalid reference (null), the `Reference` type check should occurs at construction only.Commits-------256b836 [DI] Fix ServiceLocatorArgument::setValues() for non-reference values
…sses (chalasr)This PR was merged into the 4.0-dev branch.Discussion----------Remove deprecated container injections and compiler passes| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | yes| Deprecations? | no| Tests pass? | yes| Fixed tickets | ~~#21451#21625#21284#22010~~#22805| License | MIT| Doc PR | n/aCommits-------16a2fcf Remove deprecated container injections and compiler passes
Uh oh!
There was an error while loading.Please reload this page.