8000 [DI] Deprecate ContainerBuilder::set by ro0NL · Pull Request #19644 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Deprecate ContainerBuilder::set #19644

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
wants to merge 1 commit into from
Closed

[DI] Deprecate ContainerBuilder::set #19644

wants to merge 1 commit into from

Conversation

ro0NL
Copy link
Contributor
@ro0NL ro0NL commented Aug 16, 2016
Q A
Branch? "master"
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? not yet
Fixed tickets comma-separated list of tickets fixed by the PR, if any
License MIT
Doc PR reference to the documentation PR, if any

Currently the behavior for synthetic services and the container builder is unclear;

  • set() is always allowed (when mapped to a defintion)
  • get() is disallowed, but only before compilation (we ignore a potential synthetic service being validly available at this point)

This lead to some discussion in #19619

IMO there are 2 acceptable/consistent solutions, either disallow set fully/before compilation, or allow get for synthetic services at all time. This reflects simple set/get behavior.

Deprecating set before compilation would make it clear the ContainerBuilder only works as as Container after compilation. Ie. you'd still have best of both.

@ro0NL
Copy link
Contributor Author
ro0NL commented Aug 16, 2016

This somewhat limits the ContainerBuilder being a Container, so maybe fixing this on the get side makes more sense...

I guess, if we technically want the ContainerBuilder to be a Container only after compilation (like get somewhat implies now) we should deprecate set also before compilation.

@@ -401,20 +403,20 @@ public function has($id)
*/
public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
{
$id = strtolower($id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why moving those lines up ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently you get a deprecation error for each possible alias (by the looks of the code 👼), so i tend to resolve aliases first and then logic of get. Consider it an early return.

Ill dig into this to expose the side effects.

@linaori
Copy link
Contributor
linaori commented Aug 17, 2016

In my opinion, the builder should not be the container. Right now building the container and using the container is overlapping the same functionality. I think it would be in the best interest to have the Builder build it only.

@ro0NL
Copy link
Contributor Author
ro0NL commented Aug 17, 2016

I think we need to respect ContainerBuilder extends Container somehow.

However, we can make a design choice here;

  • the builder is a container only after compilation for synthetics
  • the builder is a container at all time for synthetics
  • the builder is a container for services by definition only

@ogizanagi
Copy link
Contributor

I think it should behaves like a Container once and only once compiled.
Before, no get, no set.

@ro0NL
Copy link
Contributor Author
ro0NL commented Aug 17, 2016

@ogizanagi tests are not easy to fix. Mostly due aliases..

Try and fix the deprecation for ContainerBuilderTest::testSetReplacesAlias ;-)

@nicolas-grekas
Copy link
Member

See #19708

@ro0NL ro0NL closed this Aug 22, 2016
@ro0NL ro0NL deleted the di/containerbuilder-set branch August 22, 2016 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0