-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
You may add the possibility to specify a message ? Anyway that's awesome, thanks ! |
It’s in a corner of my mind, but I don’t know how do this smartly. |
FYI, there is typo in the title |
@sstok fixed, thank you. |
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 :) |
I see two points:
Of course, all new features is probably easy to implement… But, I think,
We are, at least, two persons who find this suffisamment helpful to take the time to make a PR. |
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()); |
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.
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.
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.
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?
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.
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))
I think we can go with this feature, the implementation is simple enough.
with Status: needs work |
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 |
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.
string|null
*/ | ||
public function isDeprecated() | ||
{ | ||
return $this->deprecatedMessage != null; |
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.
!==
* | ||
* @return bool | ||
*/ | ||
public function getDeprecationMessage($node, $path) |
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.
protected
?
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.
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() |
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.
you should test the placeholder replacements as well imo.
@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()); |
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.
let get rid of the $msg var and do things inline
*/ | ||
public function isDeprecated() | ||
{ | ||
return $this->deprecatedMessage !== null; |
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.
yoda style: null !== ...
@@ -29,6 +29,7 @@ | |||
protected $finalValidationClosures = array(); | |||
protected $allowOverwrite = true; | |||
protected $required = false; | |||
protected $deprecatedMessage = null; |
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.
$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 |
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.
let advertise setDeprecated
instead?
* | ||
* @return $this | ||
*/ | ||
public function isDeprecated($message = 'The child node "%node%" at path "%path%" 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.
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; |
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.
in Definition, we enforce that the placeholder is used, we should do the same here IMHO, for both placeholders
@nicolas-grekas thank you. |
…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. |
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.
Sets
* @param string $node the configuration node name | ||
* @param string $path the path of the node | ||
* | ||
* @return bool |
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.
@return string
@@ -142,6 +143,16 @@ public function setRequired($boolean) | |||
} | |||
|
|||
/** | |||
* Set this node as 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.
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. | |||
* |
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.
Same here for the special %node% and %path% vars.
$comments[] = sprintf( | ||
'Deprecated (%s)', | ||
$child->getDeprecationMessage($child->getName(), $child->getPath()) | ||
); |
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 be on one line.
$comments[] = sprintf( | ||
'Deprecated (%s)', | ||
$node->getDeprecationMessage($node->getName(), $node->getPath()) | ||
); |
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.
one line please
Target branch should also be changed to 3.4 instead of master. |
@fabpot fixed and rebased on the 3.4 branch. Thank you. |
Thank you @sanpii. |
…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
@fabpot why was it merged into the 4.0-dev branch ? |
@sanpii are there existing deprecated options that could leverage this PR (on 3.4)? Would you have time to create a PR for it? |
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php Lines 68 to 71 in 4173f13
Maybe here for instance? |
@nicolas-grekas good idea, but the PR was merged on master, not on 3.4 Here the deprecated configuration I found: https://github.com/symfony/symfony/blob/3.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L1199 |
…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
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
Now merged in 3.4 |
* 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 ...
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
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
…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
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).