-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[OptionsResolver] Allow deprecations to be overridden with an empty s… #62345
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
|
I'm not sold by this change. Could you elaborate a bit more on when this would be useful? |
|
It looks to me like a new feature intended to remove a deprecation notice. |
|
Hi @yceruto, thanks for the feedback. You are absolutely right, this changes an existing behaviour. My apologies for misclassifying it. The use case I had in mind is to allow child classes to override a deprecation set by a parent class. Without this change, it's impossible for a child class to cancel a deprecation. Imagine a base // In MyBundle/Form/BaseType.php
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefined(['hostname', 'host'])
->setDeprecated(
'hostname',
'my/bundle',
'1.0',
'The option "%name%" is deprecated, use "host" instead.'
);
}Now, in a child class extending it, you might want to re-enable 'hostname' without deprecation (maybe for backward compatibility in a specific context): // In src/Form/AppType.php
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
// This call is the new behavior
$resolver->setDeprecated('hostname', 'my/bundle', '1.1', ''); // Should disable the prior deprecation
}Do you think this capability is a valuable addition? If so, I am happy to close this PR and re-open it against the Please let me know what you think. |
|
Hi, thanks for clarifying the use case. I don't think that change is needed though, you can already redefine the same option even if it's marked as deprecated. The resolver will apply your new definition, and you can simply ignore the deprecation triggered by the parent class. Once the deprecated option is eventually removed upstream, your redefinition will seamlessly take over without issues. |
|
I'm still considering whether this is a valid use case, and why you can't use the |
|
Another alternative is to remove the option before redefining it, clearing any parent definition. $resolver->remove('hostname');
$resolver->define('hostname');I just checked the remove method, and it seems we missed unsetting the deprecated option, if any. PR welcome! |
|
I'm like Yonel. There need to be a real world use case and I'm not sure there's one at the moment. We might actually consider that an empty deprecation message should throw. If we did so, would any use case be impossible? I don't see when. |
|
Hi @yceruto and @nicolas-grekas, thank you both for your feedback. You are right, my original use case was flawed. Using @nicolas-grekas To answer your question: I agree. After this discussion, and assuming I have just created the new PR to fix As this PR is not the correct approach, I am closing it. |
…status (yoeunes) This PR was merged into the 6.4 branch. Discussion ---------- [OptionsResolver] Ensure remove() also unsets deprecation status | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT This ensures `remove()` fully clears an option, including any deprecation, allowing clean overrides in child configs (as suggested by `@yceruto` in #62345). Commits ------- 5ffa260 [OptionsResolver] Ensure remove() also unsets deprecation status
This PR fixes a bug that prevented a previously set deprecation from being cancelled. If
setDeprecated()was called with an empty string, it would returnvoidwithout removing the existing deprecation entry.This made it impossible for child classes or subsequent configurations to override and disable a deprecation set by a parent configuration.
The fix ensures that calling
setDeprecated('...', '')activelyunset()s the deprecation from the internal array, restoring the expected override behavior.Example:
Given a base configuration (e.g., a parent class) that deprecates the
hostnameoption, based on the documentation's example:A child configuration attempts to annul this deprecation:
Before (The Bug):
The
isDeprecated('hostname')method still returnedtrue, and resolving['hostname' => '...']would incorrectly trigger anE_USER_DEPRECATEDerror.After (The Fix):
The deprecation is correctly removed.
isDeprecated('hostname')now returnsfalse, and no deprecation error is triggered when resolving the option.