Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI] Added support for deprecating aliases #29968

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 2 commits into from
Jan 25, 2019
Merged

[DI] Added support for deprecating aliases #29968

merged 2 commits into from
Jan 25, 2019

Conversation

renanbr
Copy link
Contributor

@renanbr renanbr commented Jan 23, 2019

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

@nicolas-grekas nicolas-grekas added this to the next milestone Jan 23, 2019
Copy link
Member

@stof stof left a comment

Choose a reason for hiding this comment

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

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)

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;
Copy link
Member

Choose a reason for hiding this comment

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

this continue is dead code

* Whether this alias is deprecated, that means it should not be called
* anymore.
*
* @param bool $status Defaults to true
Copy link
Contributor

Choose a reason for hiding this comment

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

the description should describe what it does

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I think we're good thank you!
Here are some minor comments.
Please squash all your commits also keep only two.

@@ -78,6 +85,58 @@ public function isPrivate()
return $this->private;
}

/**
* Whether this alias is deprecated, that means it should not be called
Copy link
Member

Choose a reason for hiding this comment

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

s/called/referenced

/**
* Returns whether this alias is deprecated.
*
* @return bool
Copy link
Member

Choose a reason for hiding this comment

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

the whole docblock can be removed and replaced by a real return type

*
* @return string
*/
public function getDeprecationMessage($id)
Copy link
Member

Choose a reason for hiding this comment

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

should use real argument+return type + remove docblock

@@ -667,8 +671,12 @@ private function validateAlias(\DOMElement $alias, $file)
}
}

$allowedTags = ['deprecated'];
Copy link
Member

Choose a reason for hiding this comment

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

no need for the temporary variable, isn't it? better remove it.

{
$container = new ContainerBuilder();

$container->register('foo', '\stdClass');
Copy link
Member

Choose a reason for hiding this comment

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

no need for the \ (same below)


$aliasDeprecated = new Alias('foo');
$aliasDeprecated->setDeprecated(true);
$container->setAlias('foo_aliased', $aliasDeprecated);
Copy link
Member

Choose a reason for hiding this comment

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

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']));
Copy link
Member

Choose a reason for hiding this comment

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

better dump only once (see previous line)

/**
* Gets the public 'alias_for_foo_deprecated' alias.
*
* @return object An instance returned by "getFooService()"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this message should be The "foo" service.?

@nicolas-grekas nicolas-grekas changed the title Added support for deprecating aliases [DI] Added support for deprecating aliases Jan 24, 2019
@renanbr
Copy link
Contributor Author

renanbr commented Jan 24, 2019

changes applied, commits squashed
@stof, @OskarStark, @nicolas-grekas

@nicolas-grekas
Copy link
Member

Fabbot complains :)

@nicolas-grekas
Copy link
Member

Thank you @renanbr.

@nicolas-grekas nicolas-grekas merged commit 6c571ad into symfony:master Jan 25, 2019
nicolas-grekas added a commit that referenced this pull request Jan 25, 2019
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
@nicolas-grekas
Copy link
Member

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.';
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

updated in #29995, please review

nicolas-grekas added a commit that referenced this pull request Jan 28, 2019
… 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
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Jan 29, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 4, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 4, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 4, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 4, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 5, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 6, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 6, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 6, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 6, 2019
…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
XuruDragon pushed a commit to XuruDragon/symfony that referenced this pull request Feb 7, 2019
…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
nicolas-grekas added a commit that referenced this pull request Feb 8, 2019
…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

![Screenshot](https://i.imgur.com/GDj2NIY.png)

Commits
-------

3d2378d [DependencyInjection] Added information about deprecated aliases in debug:autowiring
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
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.

7 participants