-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Added support for deprecating aliases #24707
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
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.
Thanks for implementing this, great job so far!
private $deprecated; | ||
private $deprecationTemplate; | ||
|
||
private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.'; |
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.
Maybe "service alias" instead of just "service"?
"With \rs" => array("invalid \r message %service_id%"), | ||
"With \ns" => array("invalid \n message %service_id%"), | ||
'With */s' => array('invalid */ message %service_id%'), | ||
'message not containing require %service_id% variable' => array('this is 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.
"required"
c709de5
to
ced5f49
Compare
This PR needs to be rebase on master and target 4.1, it's too late to merge in into 3.4. |
@nicolas-grekas Thanks for the feedback. I will add the missing part, do some more testing and target 4.1. |
I am currently figuring out how to handle the trigger of the deprecation notice in the dumped container. Especially with deprecated private aliases, which are removed from the container in the For public aliases I had the idea to deprecate the actual definition in the @greg0ire Maybe you have an idea that will push me in the right direction here? |
Not sure if this is an issue. IMO, the deprecations should be triggered when compiling the container, because that is when they are used. You don't want deprecations to be triggered for every unrelated http requests.
If you do that, people will not be able to get rid of the deprecation by referencing the actual service definition, will they? |
@greg0ire Sorry for the late reply, I didn't have a lot of time to work on this issue. Are you sure that the deprecations should be triggered when compiling the container? As far as I can see and understand it, the notices are added in the dumper classes like the |
That's my point. Wouldn't that make a lot of deprecations, irrelevant to the current page? Not sure what's best. |
That makes a lot of deprecations indeed, but that's also how it's done for services at the moment. Deprecating a service, triggers a notice on every request. So my guess is that we want the same behaviour for service aliases right? |
Correct. Go with it then. |
Okay, I will then. To come back to my original question, I am wondering about the comment of @nicolas-grekas :
Is it enough to implement the deprecation notices in the several dumpers like the PhpDumper and the XmlDumper, so that when they are loaded, the ContainerBuilder triggers the deprecation notice? Or I am missing other places which should trigger the deprecation notice as well? |
Ok, I think there is a time to take a dust from this issue ;) First of all I don’t believe it’s enough to implement them in dumpers, this will lead to poor DX. I spent some time with the code and I have few ideas. Two steps are necessary regardless of the solution choosen:
Then we get into interesting part - how to trigger deprecation on runtime?
WDYT @nicolas-grekas? @fabpot? |
@kiler129 thanks for the heads up. I think we should go for D (no need for a special name for the method, the existing "generateMethodName" logic is good enough), but of course only for public aliases that cannot be inlined. Thus, the current state of the PR looks good to me. It just needs to handle two more cases:
As a general design note, I don't think it matter that the symbol being deprecated is an alias or a service: that's an implementation detail of the service graph. What matters is that a symbol that is being planned for removal triggers a warning when referenced/used. This may mean that we don't need to put the word "alias" in the messages, and use "service" all the time. WDYT? @j92 does that make sense for you? Ok to continue? |
I think we're on the right track.
After thinking for a while I believe the idea of treating services and aliases equally is right - it's an implementation detail after all. Other messages in DIC component (except obvious places like @j92 Are you willing to rebase onto master and implement additional logic discussed? |
ResolveReferencesToAliasesPass looks like the good place to me for now |
@kiler129 Thanks for dusting of this issue;) Yes, I am willing to rebase this branch and will start to implement the additional logic asap. |
ced5f49
to
3bffe61
Compare
@j92: Any news? Sorry for poking you, but I just periodically visit PRs which are relevant to what I do ;) |
@nicolas-grekas Can you review this one again? |
It's ok @j92 :). Let's just finish this PR when you have time. I'm here because we just had a use-case for this in DoctrineBundle. But, no need to rush - we're after the 4.1 feature freeze. But, yes, let's definitely try to get this in there for 4.2! |
@@ -346,8 +346,13 @@ private function parseDefinition($id, $service, $file, array $defaults) | |||
} | |||
|
|||
foreach ($service as $key => $value) { | |||
if (!in_array($key, array('alias', 'public'))) { | |||
if (!in_array($key, array('alias', 'public', 'deprecated'))) { | |||
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public".', $key, $id, $file)); |
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 the message be updated, too? Now it includes hardcoded keys for service aliases are "alias" and "public"
.
@nicolas-grekas I think we need your input here :) |
This PR was merged into the 4.3-dev branch. Discussion ---------- [DI] Added support for deprecating aliases | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? |no | Tests pass? | yes | Fixed tickets | #24507 | License | MIT | Doc PR | TBD This PR is a continuity of #24707 Commits ------- 6c571ad Added support for deprecating aliases (runtime+dumper) 0eb071b Added support for deprecating an alias
This pr adds support for deprecating aliases. I applied the same logic as for services, so we can deprecate an alias like this:
Or we can deprecate an alias providing a deprecation template:
I submitted a WIP pull request to get early feedback. Please let me know if I am on the right track, so I can finish the work in the various file loaders and dumpers. Docs and changelog will be updated after the feedback.
Thanks!