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

Skip to content

[config] Add abbitily to deprecate a node #22382

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 3 commits into from
Aug 26, 2017
Merged

[config] Add abbitily to deprecate a node #22382

merged 3 commits into from
Aug 26, 2017

Conversation

sanpii
Copy link
Contributor

@sanpii sanpii commented Apr 11, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? maybe
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR symfony/symfony-docs#7794

For BC breaks, I don’t know if modifying the Xml and Yaml dumper output is considering as a BC break (it’s just a comment).

@Nek-
Copy link
Contributor

Nek- commented Apr 11, 2017

You may add the possibility to specify a message ? Anyway that's awesome, thanks !

@HeahDude
Copy link
Contributor

Hello @sanpii, thanks for proposing this. For the record, this was proposed before #21051.

@sanpii
Copy link
Contributor Author

sanpii commented Apr 12, 2017

You may add the possibility to specify a message ?

It’s in a corner of my mind, but I don’t know how do this smartly.

@sstok
Copy link
Contributor

sstok commented Apr 12, 2017

FYI, there is typo in the title depreciate -> deprecate 😉
depreciate is to devalue something.

@sanpii sanpii changed the title [config] Add abbitily to depreciate a node [config] Add abbitily to deprecate a node Apr 12, 2017
@sanpii
Copy link
Contributor Author

sanpii commented Apr 12, 2017

@sstok fixed, thank you.

@ro0NL
Copy link
Contributor

ro0NL commented Apr 12, 2017

To clarify, my goal with #21051 was to not include/define deprecated nodes in the tree; and solely focus on bridging the old situation to a new situation (as a normalization step).

Im 👎 on this. You should checkout why mine was rejected :)

@sanpii
Copy link
Contributor Author

sanpii commented Apr 12, 2017

You should checkout why mine was rejected :)

I see two points:

is quite easily implemented directly in the code

Of course, all new features is probably easy to implement… But, I think, trigger_error is a low level function and symfony is here to abstract its.

I don't see the need for end user projects to deprecate options

We are, at least, two persons who find this suffisamment helpful to take the time to make a PR.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Apr 13, 2017
@ro0NL
Copy link
Contributor

ro0NL commented Apr 13, 2017

I still think it's a good feature.. in case you thought different.

Maybe this approach is good enough, as it's kinda the same we do for services. Personally i like the normalization to happen, otherwise people still need to take care of old/new nodes at implementation level, e.g. in an extension.

@@ -234,6 +234,11 @@ protected function finalizeValue($value)
}

foreach ($this->children as $name => $child) {
if ($child->isDeprecated()) {
$msg = sprintf('The child node "%s" at path "%s" is deprecated.', $name, $this->getPath());
Copy link
Member

Choose a reason for hiding this comment

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

Typically, deprecation message should also mention the version since it's been deprecated, the outcome in the next major version, and the alternative if any. Would be great to allow + encourage doing so here also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I’m agree with you. But I did’t find a good way to do this.

Maybe by passing an optionnal argument to isDeprecated() method?

Copy link
Contributor

@Taluu Taluu May 2, 2017

Choose a reason for hiding this comment

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

I think that customizing the message would solve the thing (with mandatory place holders like %node_name% and %node_path%. A bit like what is done on deprecating services, which has a mandatory %service_id% placeholder (or something like that))

@nicolas-grekas
Copy link
Member

I think we can go with this feature, the implementation is simple enough.
I propose this API:

public function setDeprecated($message)
public function isDeprecated()
public function getDeprecationMessage($node, $path)

with $message allowing %node% and %path placeholders.

Status: needs work

@sanpii
Copy link
Contributor Author

sanpii commented Jul 7, 2017

PR updated according to @nicolas-grekas’ propositions.

@@ -142,6 +143,16 @@ public function setRequired($boolean)
}

/**
* Set this node as deprecated.
*
* @param string $message Deprecated message
Copy link
Contributor

Choose a reason for hiding this comment

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

string|null

*/
public function isDeprecated()
{
return $this->deprecatedMessage != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

!==

*
* @return bool
*/
public function getDeprecationMessage($node, $path)
Copy link
Contributor

Choose a reason for hiding this comment

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

protected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not now, it’s used by Xml and Yaml dumper.

@@ -35,6 +35,8 @@ public function getConfigTreeBuilder()
->scalarNode('scalar_array_empty')->defaultValue(array())->end()
->scalarNode('scalar_array_defaults')->defaultValue(array('elem1', 'elem2'))->end()
->scalarNode('scalar_required')->isRequired()->end()
->scalarNode('scalar_deprecated')->isDeprecated()->end()
->scalarNode('scalar_deprecated_with_message')->isDeprecated('Deprecation custom message')->end()
Copy link
Contributor

@ro0NL ro0NL Jul 7, 2017

Choose a reason for hiding this comment

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

you should test the placeholder replacements as well imo.

@sanpii
Copy link
Contributor Author

sanpii commented Jul 8, 2017

@ro0NL Fixed, thank you for your review.

@@ -234,6 +234,11 @@ protected function finalizeValue($value)
}

foreach ($this->children as $name => $child) {
if ($child->isDeprecated()) {
$msg = $child->getDeprecationMessage($name, $this->getPath());
Copy link
Member

Choose a reason for hiding this comment

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

let get rid of the $msg var and do things inline

*/
public function isDeprecated()
{
return $this->deprecatedMessage !== null;
Copy link
Member

Choose a reason for hiding this comment

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

yoda style: null !== ...

@@ -29,6 +29,7 @@
protected $finalValidationClosures = array();
protected $allowOverwrite = true;
protected $required = false;
protected $deprecatedMessage = null;
Copy link
Member

Choose a reason for hiding this comment

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

$deprecationMessage (same below)

@@ -9,6 +9,7 @@ CHANGELOG
* made `ClassExistenceResource` work with interfaces and traits
* added `ConfigCachePass` (originally in FrameworkBundle)
* added `castToArray()` helper to turn any config value into an array
* added `isDeprecated()` method to indicate a deprecated node
Copy link
Member

Choose a reason for hiding this comment

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

let advertise setDeprecated instead?

*
* @return $this
*/
public function isDeprecated($message = 'The child node "%node%" at path "%path%" is deprecated.')
Copy link
Member

Choose a reason for hiding this comment

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

should be named setDeprecated.
Not sure about the default value, there is always more to add than the default (not a string opinion, just noting.)

*/
public function isDeprecated($message = 'The child node "%node%" at path "%path%" is deprecated.')
{
$this->deprecatedMessage = $message;
Copy link
Member

Choose a reason for hiding this comment

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

in Definition, we enforce that the placeholder is used, we should do the same here IMHO, for both placeholders

@sanpii
Copy link
Contributor Author

sanpii commented Jul 11, 2017

@nicolas-grekas thank you.

Nyholm and others added 2 commits August 26, 2017 06:08
…iff2.0 (Nyholm)

This PR was squashed before being merged into the 3.4 branch (closes #23947).

Discussion
----------

[Translation] Adding the ability do load <notes> in xliff2.0

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | ~~~~yes~~~ no (sorry)
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Since #23890 we can dump `<notes>`. We should also have the ability to load them back.

Commits
-------

b0cdb53 [Translation] Adding the ability do load <notes> in xliff2.0
@@ -142,6 +143,16 @@ public function setRequired($boolean)
}

/**
* Set this node as deprecated.
Copy link
Member

Choose a reason for hiding this comment

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

Sets

* @param string $node the configuration node name
* @param string $path the path of the node
*
* @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.

@return string

@@ -142,6 +143,16 @@ public function setRequired($boolean)
}

/**
* Set this node as deprecated.
*
Copy link
Member

Choose a reason for hiding this comment

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

You should hint here that %node% and %path% have a special meaning in a deprecated message.

@@ -169,6 +170,20 @@ public function isRequired()
}

/**
* Sets the node as deprecated.
*
Copy link
Member

Choose a reason for hiding this comment

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

Same here for the special %node% and %path% vars.

$comments[] = sprintf(
'Deprecated (%s)',
$child->getDeprecationMessage($child->getName(), $child->getPath())
);
Copy link
Member

Choose a reason for hiding this comment

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

should be on one line.

$comments[] = sprintf(
'Deprecated (%s)',
$node->getDeprecationMessage($node->getName(), $node->getPath())
);
Copy link
Member

Choose a reason for hiding this comment

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

one line please

@fabpot
Copy link
Member

fabpot commented Aug 26, 2017

Target branch should also be changed to 3.4 instead of master.

@sanpii
Copy link
Contributor Author

sanpii commented Aug 26, 2017

@fabpot fixed and rebased on the 3.4 branch. Thank you.

@fabpot
Copy link
Member

fabpot commented Aug 26, 2017

Thank you @sanpii.

@fabpot fabpot merged commit 31d2250 into symfony:master Aug 26, 2017
fabpot added a commit that referenced this pull request Aug 26, 2017
…pot, sanpii)

This PR was merged into the 4.0-dev branch.

Discussion
----------

[config] Add abbitily to deprecate a node

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | maybe
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | symfony/symfony-docs#7794

For BC breaks, I don’t know if modifying the Xml and Yaml dumper output is considering as a BC break (it’s just a comment).

Commits
-------

31d2250 [config] Add abbitily to deprecate a node
3b6442f feature #23947 [Translation] Adding the ability do load <notes> in xliff2.0 (Nyholm)
b0cdb53 [Translation] Adding the ability do load <notes> in xliff2.0
@stof
Copy link
Member

stof commented Aug 28, 2017

@fabpot why was it merged into the 4.0-dev branch ?

@nicolas-grekas
Copy link
Member

@sanpii are there existing deprecated options that could leverage this PR (on 3.4)? Would you have time to create a PR for it?

@maidmaid
Copy link
Contributor

maidmaid commented Aug 29, 2017

->arrayNode('trusted_proxies')
->beforeNormalization()
->ifTrue(function ($v) {
@trigger_error('The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED);

Maybe here for instance?

nicolas-grekas pushed a commit that referenced this pull request Aug 29, 2017
…pot, sanpii)

This PR was merged into the 3.4-dev branch.

Discussion
----------

[config] Add abbitily to deprecate a node

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | maybe
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | symfony/symfony-docs#7794

For BC breaks, I don’t know if modifying the Xml and Yaml dumper output is considering as a BC break (it’s just a comment).

Commits
-------

31d2250 [config] Add abbitily to deprecate a node
3b6442f feature #23947 [Translation] Adding the ability do load <notes> in xliff2.0 (Nyholm)
b0cdb53 [Translation] Adding the ability do load <notes> in xliff2.0
nicolas-grekas added a commit that referenced this pull request Aug 29, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[config] Add ability to deprecate a node

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

This is #22382 on 3.4

Commits
-------

a00a4ff [config] Add ability to deprecate a node
@nicolas-grekas
Copy link
Member

Now merged in 3.4

chalasr pushed a commit to chalasr/symfony that referenced this pull request Aug 29, 2017
* 3.4: (38 commits)
  Fix merge
  [Lock] Expose an expiringDate and isExpired method in Lock
  [VarDumper] fix DateCasterTest
  [config] Add ability to deprecate a node
  feature symfony#22382 [config] Add abbitily to deprecate a node (Nyholm, fabpot, sanpii)
  Fix segfault in period caster
  Create an interface for TranslationReader and moved TranslationLoader to Translation component
  Always require symfony/polyfill-apcu to provide APCuIterator everywhere
  [Lock] Fix some tests that require pcntl_sigwaitinfo() function
  bumped Symfony version to 3.3.9
  updated VERSION for 3.3.8
  updated CHANGELOG for 3.3.8
  [DI] Fix tracking env var placeholders nested in object graphs
  bumped Symfony version to 3.3.8
  updated VERSION for 3.3.7
  updated CHANGELOG for 3.3.7
  Add period caster
  [DI] improve psr4-based service discovery with namespace option
  [DI] Fix tracking env vars when merging configs (bis)
  removed obsolete comment
  ...
nicolas-grekas added a commit that referenced this pull request Sep 4, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

Fix ability to deprecate a config node

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | not yet released
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22382
| License       | MIT
| Doc PR        | n/a

Unlocks #24025

Commits
-------

fc91869 Fix ability to deprecate a config node
nicolas-grekas added a commit that referenced this pull request Sep 4, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

Use new configuration depreciation method

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

In keeping with #22382

Commits
-------

4a62cc6 Do not trigger deprecation if node has not been explicitly filled
012e381 Use new configuration node depreciation method
xabbuh added a commit to symfony/symfony-docs that referenced this pull request Oct 13, 2017
…ereguiluz)

This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #7794).

Discussion
----------

[config] Add a note about deprecated a node

Documentation for symfony/symfony#22382

Commits
-------

1939371 Explained the possibility of defining custom deprecation messages
d6a8624 [config] Add a note about deprecated a node
@fabpot fabpot mentioned this pull request Oct 19, 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.