[DI] Added support for deprecating aliases#29968
[DI] Added support for deprecating aliases#29968nicolas-grekas merged 2 commits intosymfony:masterfrom renanbr:deprecate-aliases
Conversation
stof
left a comment
There was a problem hiding this comment.
This also seems to miss warning (at compile-time) when a service is referencing a deprecated alias (before resolving them, otherwise we won't have any such reference)
| if (!\in_array($key, ['alias', 'public'])) { | ||
| if (!\in_array($key, ['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)); | ||
| continue; |
| * Whether this alias is deprecated, that means it should not be called | ||
| * anymore. | ||
| * | ||
| * @param bool $status Defaults to true |
There was a problem hiding this comment.
the description should describe what it does
nicolas-grekas
left a comment
There was a problem hiding this comment.
I think we're good thank you!
Here are some minor comments.
Please squash all your commits also keep only two.
| } | ||
|
|
||
| /** | ||
| * Whether this alias is deprecated, that means it should not be called |
| /** | ||
| * Returns whether this alias is deprecated. | ||
| * | ||
| * @return bool |
There was a problem hiding this comment.
the whole docblock can be removed and replaced by a real return type
| * | ||
| * @return string | ||
| */ | ||
| public function getDeprecationMessage($id) |
There was a problem hiding this comment.
should use real argument+return type + remove docblock
| } | ||
| } | ||
|
|
||
| $allowedTags = ['deprecated']; |
There was a problem hiding this comment.
no need for the temporary variable, isn't it? better remove it.
| { | ||
| $container = new ContainerBuilder(); | ||
|
|
||
| $container->register('foo', '\stdClass'); |
There was a problem hiding this comment.
no need for the \ (same below)
|
|
||
| $aliasDeprecated = new Alias('foo'); | ||
| $aliasDeprecated->setDeprecated(true); | ||
| $container->setAlias('foo_aliased', $aliasDeprecated); |
There was a problem hiding this comment.
maybe name it deprecated_foo_alias instead of foo_aliased?
|
|
||
| $dumper = new PhpDumper($container); | ||
| $this->assertStringEqualsFile(self::$fixturesPath.'/php/container_alias_deprecation.php', $dumper->dump()); | ||
| eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Aliases_Deprecation'])); |
There was a problem hiding this comment.
better dump only once (see previous line)
| /** | ||
| * Gets the public 'alias_for_foo_deprecated' alias. | ||
| * | ||
| * @return object An instance returned by "getFooService()" |
There was a problem hiding this comment.
Maybe this message should be The "foo" service.?
|
changes applied, commits squashed |
|
Fabbot complains :) |
|
Thank you @renanbr. |
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
|
And thank you @j92 ! |
| private $deprecated; | ||
| private $deprecationTemplate; | ||
|
|
||
| private static $defaultDeprecationTemplate = 'The "%service_id%" service alias is deprecated. You should stop using it, as it will soon be removed.'; |
There was a problem hiding this comment.
I know this PR is merged, but I've just reviewed its code and I wondered if the %service_id% placeholder name is confusing to other people too. To me, this placeholder would be easier to understand if it was called %alias_id%.
Also, this -> ... as it will soon be removed. could be -> ... as it will be removed in the future.
Thanks.
… is found (nicolas-grekas) This PR was merged into the 4.3-dev branch. Discussion ---------- [DI] add id of referencing service when a deprecated alias is found | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Improves #29968 a bit for DX. Commits ------- b124fb7 [DI] add id of referencing service when a deprecated alias is found
…iluz) This PR was squashed before being merged into the master branch (closes #10937). Discussion ---------- Documented the deprecation of service aliases It documents symfony/symfony#29968 but it contains the changes of the pending PR symfony/symfony#29995 Commits ------- d5d87e6 Documented the deprecation of service aliases
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ebug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR symfony#29968 and symfony#29995
…ed aliases in debug:autowiring (XuruDragon) This PR was merged into the 4.3-dev branch. Discussion ---------- [DependencyInjection] Added information about deprecated aliases in debug:autowiring | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a Fix and improves a bit PR #29968 and #29995  Commits ------- 3d2378d [DependencyInjection] Added information about deprecated aliases in debug:autowiring
This PR is a continuity of #24707