Skip to content

[DI] Remove synthetic services from methodMap + generated methods #21244

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

Merged
merged 1 commit into from
Jan 15, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jan 12, 2017

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

For synthetic services, the generated methods are just dead code to fill opcache ;)
And having them in "methodMap" prevents using the property for checking if a service comes from a (non-synthetic) definition or not.
This prepares some changes that we'd like to do in 4.0, see #19668.

@@ -285,15 +285,15 @@ public function testGetCircularReference()
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
Copy link
Contributor

Choose a reason for hiding this comment

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

We go from \RuntimeException to \InvalidArgumentException now.. minor BC break :)

👍 for master, as it's needed to keep things simple.

@stof
Copy link
Member

stof commented Jan 12, 2017

The generated method (and it existence in the method map) has another purpose: it allows has() to know about the service, and means that get('kernel') gives you a meaningful message if it is not set yet (same for other synthetic services).

@nicolas-grekas
Copy link
Member Author

@stof, yes, and my point is that we don't care, because these are erroneous situations anyway. The fact the current behavior prevents meaningful progress largely wins over the small&rare DX+ that it provides.
For "has", I don't expect anyone to rely on a faulty behavior (userland side) anyway :)

@fabpot
Copy link
Member

fabpot commented Jan 12, 2017

👍

@nicolas-grekas
Copy link
Member Author

@stof no blocker for you? I'd like to merge to unlock progress in #19668.

@ro0NL
Copy link
Contributor

ro0NL commented Jan 13, 2017

It makes sense right? Ie. we dont have kernel till it's set. has() returning true, while get() throws is weird..

Imo. the exception is even better now, service not found.

@ro0NL
Copy link
Contributor

ro0NL commented Jan 14, 2017

What if an alias refers a pre-defined service? I think has() needs an update so that $id is set first, and continue checks based on the aliased id (basically what get() does).

@nicolas-grekas
Copy link
Member Author

@ro0NL updated, was that what you meant?

@ro0NL
Copy link
Contributor

ro0NL commented Jan 15, 2017

Yep 👍

@lyrixx
Copy link
Member

lyrixx commented Jan 15, 2017

👍

@fabpot
Copy link
Member

fabpot commented Jan 15, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit c1e1e99 into symfony:master Jan 15, 2017
fabpot added a commit that referenced this pull request Jan 15, 2017
…ted methods (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Remove synthetic services from methodMap + generated methods

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

For synthetic services, the generated methods are just dead code to fill opcache ;)
And having them in "methodMap" prevents using the property for checking if a service comes from a (non-synthetic) definition or not.
This prepares some changes that we'd like to do in 4.0, see #19668.

Commits
-------

c1e1e99 [DI] Remove synthetic services from methodMap + generated methods
@nicolas-grekas nicolas-grekas deleted the di-synthetic branch January 22, 2017 09:19
@fabpot fabpot mentioned this pull request May 1, 2017
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.

6 participants