-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Check for privates before shared services #22866
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
CI is red :) |
@nicolas-grekas this is because of composer/composer#6342 |
Kinda clueless here... trying to fix patched however these 2 assertions pass for all provided debug modes, indiviudally; $this->assertSaneContainer($this->getDumpedContainer(), '', array('web_profiler.csp.handler'));
if ($listenerInjected) {
$this->assertSame($listenerEnabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
} the combination seems to trigger a deprecation 😕 |
first patch.. lets see what happens :) |
is there a clean way to silence expected deprecations.. or should we do something else here. @stof see deprecations at appveyor ;) |
well, the test should either not access a private service, or be marked as legacy. If the test is not meant to be removed in 4.0, marking it as legacy is not an option, and the test should be rewritten instead. |
Updated.. this should do. But i dont like it really :) but i guess we have no choice as we never decided how privates reflects a compiled containerbuilder. @stof to clarify.. the root issue is |
$this->compileContainer($container); | ||
|
||
$tokenParsers = $container->get('twig.extension.debug.stopwatch')->getTokenParsers(); | ||
$tokenParsers = $container->get('test_debug_stopwatch')->stopwatch->getTokenParsers(); |
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.
a better solution would be to use $container->get('twig')->getExtension(StopwatchExtension::class)
to access the extension, which avoids registering an extra service
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
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.
seems to break stuff :/
1) Symfony\Bundle\TwigBundle\Tests\DependencyInjection\TwigExtensionTest::testStopwatchExtensionAvailability with data set "debug-and-stopwatch-enabled" (true, true, true)
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "twig.loader".
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.
reverted the whole change, as with privates being empty it keeps working :)
this test should fail whenever we decide to change behavior.
@@ -262,6 +262,10 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE | |||
if (isset($this->aliases[$id])) { | |||
$id = $this->aliases[$id]; | |||
} | |||
if (isset($this->privates[$id]) && !$this instanceof ContainerBuilder) { |
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.
why the check on ContainerBuilder ? this is useless ($this->privates
will be empty for them anyway)
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.
but this definitely fixes tests :)
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.
i think ContainerBuilder
needs to behave the same as Container
, after compilation. But that could be a separate PR i guess. The changelog doesnt mention ContainerBuilder
really...
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.
well, once compiled, the array is not empty anymore, but we do want the deprecation in this case. So please remove the extra check you added there (which was not there before moving the notice btw, so you are the one adding a difference in the behavior)
I think we should move this to 3.3: it will trigger more notices in 3.2 apps and break some strict CI for no real benefit. |
3.2 is truly buggy though.. (@stof's comment in previous PR) i think the otherwise, could you just commit the changelog against 3.2 :)) but you probably prefer a separate PR for that :P |
@ro0NL the ContainerBuilder check does not solve anything in 3.2. |
@stof im still a bit confused.. (ive reverted the containerbuilder checks). moving the private check up (above checking for shared services), truly fixes your comments from #22801, i.e. https://github.com/symfony/symfony/pull/22866/files#diff-8aeba2b88d0347062017ee160a6beb49R408 fails otherwise. imo. it needs a fix for 3.2 (properly deprecating private services), but im missing something regarding the container builder. AFAIK the issue is Updating this call to |
Think this approach https://github.com/symfony/symfony/blob/v3.2.8/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L1488 needs to be done in container builder after compilation... ie. bypasssing |
My 2 cts: |
For me,
ContainerBuilder is a bootstrap-stage thing, and private/public is a "compiled-container" only thing. |
Agree. I figured it out ;) i tend to qualify it a bug though.. as my perception is would be nice if Squahsed&rebased. Ready for review :) Sorry for the inconvenience, but this should do. |
@nicolas-grekas currently, you can keep using a ContainerBuilder after compilation (which is what some projects do as they don't dump the container to the cache, for instance Behat) |
may i recall #20643 :) as containerbuilder is open for anything keeping privates empty is in line with that, and so a bugfix. but the behavior is still wrong, however currently it's half right, half wrong. |
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 discussed this with @nicolas-grekas and here is the summary of changes we would want to get:
@ro0NL can you work on it ? Otherwise, I can take this PR over this evening to finish it |
@stof i will finish it tonight :) so no changes for 3.2 right?
so we dont allow fetching privates using containerbuilder right (after compiling). |
@stof |
Thank you @ro0NL. |
This PR was merged into the 3.2 branch. Discussion ---------- [DI] Check for privates before shared services | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22801 (comment), #22801 (comment) | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> cc @stof Commits ------- 4f683a9 [DI] Check for privates before shared services
3.2 now merged into 3.3 so that next steps can happen on 3.3 |
This PR was merged into the 3.2 branch. Discussion ---------- [DI] Check for privates before shared services | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#22801 (comment), symfony#22801 (comment) | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> cc @stof Commits ------- 4f683a9 [DI] Check for privates before shared services
cc @stof