Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
fabpot merged 2 commits intosymfony:masterfromchalasr:remove-container-injections
Feb 28, 2017

Conversation

@chalasr
Copy link
Member

@chalasrchalasr commentedFeb 15, 2017
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#21553 (comment)
LicenseMIT
Doc PRn/a

}else {
$logger =null;
}
}
Copy link
MemberAuthor

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.

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)

@chalasrchalasrforce-pushed theremove-container-injections branch frombee8bac to404200aCompareFebruary 16, 2017 13:03
$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);
Copy link
Contributor

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.
Copy link
Contributor

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/

@chalasrchalasrforce-pushed theremove-container-injections branch 2 times, most recently from1d3ef15 to2675b30CompareFebruary 16, 2017 14:35
<services>
<serviceid="fragment.handler"class="Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler">
<argumenttype="service"id="service_container" />
<argument/><!-- fragment renderer locator-->

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!

Copy link
MemberAuthor

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?

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
MemberAuthor

@chalasrchalasrFeb 17, 2017
edited
Loading

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

Copy link
MemberAuthor

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

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?

Copy link
Member

@stofstofFeb 17, 2017
edited
Loading

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.

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);

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;
}
}

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) {

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])) {

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

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());
Copy link
Member

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;
Copy link
Member

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]);
Copy link
Member

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');
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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 ?

Copy link
Member

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.

Copy link
MemberAuthor

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.

Copy link
MemberAuthor

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?

Copy link
MemberAuthor

@chalasrchalasrFeb 17, 2017
edited
Loading

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
Copy link
MemberAuthor

Thanks for the reviews.

Status: needs work

"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"
Copy link
Member

@fabpotfabpotFeb 17, 2017
edited
Loading

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.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

constraint fixed

@chalasrchalasrforce-pushed theremove-container-injections branch fromc89b788 to097856eCompareFebruary 17, 2017 18:34
"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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry, should be1.32.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

@chalasrchalasrforce-pushed theremove-container-injections branch 3 times, most recently froma4a4b3b to550f877CompareFebruary 17, 2017 19:03
fabpot added a commit to twigphp/Twig that referenced this pull requestFeb 17, 2017
This PR was merged into the 1.x branch.Discussion----------Add ContainerRuntimeLoaderNext tosymfony/symfony#21625 (comment)Commits-------964a51b Add ContainerRuntimeLoader
@chalasrchalasrforce-pushed theremove-container-injections branch 3 times, most recently from85c30a0 to961234eCompareFebruary 17, 2017 20:11
@chalasrchalasrforce-pushed theremove-container-injections branch 2 times, most recently fromce55cd6 to2e5f25eCompareFebruary 26, 2017 10:15
@chalasrchalasr changed the titleRemove some container injections in favor of service locators/getter injectionRemove some container injections in favor of service locatorsFeb 26, 2017
@chalasrchalasrforce-pushed theremove-container-injections branch 2 times, most recently fromc37ac4d tof891b7eCompareFebruary 26, 2017 10:25
@chalasr
Copy link
MemberAuthor

*SessionListener deprecated and moved to HttpKernel, note that the naming change was required.
Status: needs review

@chalasrchalasrforce-pushed theremove-container-injections branch 4 times, most recently from7d6f58f to23662b2CompareFebruary 26, 2017 12:50
@chalasrchalasrforce-pushed theremove-container-injections branch from23662b2 to8293b75CompareFebruary 26, 2017 13:01
fabpot added a commit that referenced this pull requestFeb 26, 2017
…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
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull requestFeb 26, 2017
…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
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍

@fabpot
Copy link
Member

Thank you@chalasr.

@fabpotfabpot merged commit8293b75 intosymfony:masterFeb 28, 2017
fabpot added a commit that referenced this pull requestFeb 28, 2017
…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
Copy link
Member

This PR breaks the test suite of SensioFrameworkExtraBundle.@chalasr Can you have a look at it?

@chalasr
Copy link
MemberAuthor

@fabpot see#21794

nicolas-grekas added a commit that referenced this pull requestFeb 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
@fabpotfabpot mentioned this pull requestMay 1, 2017
nicolas-grekas added a commit that referenced this pull requestMay 21, 2017
…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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@stofstofstof requested changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+2 more reviewers

@hhamonhhamonhhamon left review comments

@GuilhemNGuilhemNGuilhemN left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

8 participants

@chalasr@weaverryan@fabpot@nicolas-grekas@hhamon@stof@GuilhemN@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp