-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
fix #17993 - Deprecated callable strings #18020
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
Thank you, I didn't understand the issue correctly. I've changed my fix. |
@@ -163,6 +175,8 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, | |||
|
|||
if (is_string($preferredChoices) && !is_callable($preferredChoices)) { | |||
$preferredChoices = new PropertyPath($preferredChoices); | |||
} elseif(is_string($preferredChoices) && is_callable($preferredChoices)) { |
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.
missing space after elseif
Not on these methods for sure. |
@@ -86,6 +86,8 @@ public function createListFromChoices($choices, $value = null) | |||
{ | |||
if (is_string($value) && !is_callable($value)) { | |||
$value = new PropertyPath($value); | |||
} elseif (is_string($value) && is_callable($value)) { | |||
@trigger_error('createListFromChoices() treats callable strings as callable and is deprecated since version 3.0.', E_USER_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.
since version 3.1 (for now)
You could perhaps wrap the callable string in a closure inside those elseif (is_string($label) && is_callable($label)) {
@trigger_error('createView() - $label - treats callable strings as callable and is deprecated since version 3.0.', E_USER_DEPRECATED);
$label = function ($choice) use ($label) {
return $label($choice);
};
} |
I have no errors doing the tests except of one in PasswordEncoder. Thanks @HeahDude for the help |
@@ -86,6 +86,11 @@ public function createListFromChoices($choices, $value = null) | |||
{ | |||
if (is_string($value) && !is_callable($value)) { | |||
$value = new PropertyPath($value); | |||
} elseif (is_string($value) && is_callable($value)) { | |||
@trigger_error('createListFromChoices() treats callable strings as callable and is deprecated since version 3.1.', E_USER_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.
If it's deprecated, what's the recommended thing to do instead? What will happen in 4.0? Please add this to the deprecation messages (and upgrade guide)
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.
@iltar is right. You should change each message to something like :
'Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead.'
What error are you talking about ? |
Nevermind, no error anymore |
@Simperfit What about adding some unit tests? |
@fabpot I added one, will add one for each method |
Looks like this needs another rebase. It contains some unrelated changes. Status: Needs work |
@xabbuh Sorry for the unrelated changes, I've missed my rebase. |
return $value($choices); | ||
}; | ||
|
||
return $value($choices); |
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.
Do we need to do all the stuff beside triggering the deprecation? Shouldn't the following code already handle the callback properly?
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've followed the instruction of someone since I don't wanted to make bad things,
But you're right, adding the test without any code is the right thing to do.
Thanks
cd2bf8e
to
22f8264
Compare
@fabpot I've added one test for each method, is it ok like that ? Thank you. |
* Using callable strings as choice options in ChoiceType has been deprecated | ||
in favor of `PropertyPath`. Use a "\Closure" instead | ||
|
||
Before: |
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.
Ok now you got one extra here
I've rebased and added/removed the space :p |
c3b996d
to
12975bd
Compare
```php | ||
'choice_value' => 'range', | ||
'choice_label' => function ($choice) { | ||
return strtoupper($choice); |
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 misunderstood the "four" space here mean four for this line only.
Now on got one extra space from line 23 to 37 and missing 3 here one 35 :p
Sorry, after that we're done, thank you for working on this PR :)
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 hope this time it's ok :p
Np :)
@@ -55,6 +75,8 @@ FrameworkBundle | |||
- `"form.type.submit"` | |||
- `"form.type.reset"` | |||
|
|||
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed |
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.
to not conflict with master it must be before your change
ok just remove it
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.
oops sorry
Looks perfect now :) Thanks @Simperfit! This one is ready to merge now. Deprecate or revert 470b140 ? ping @symfony/decoders |
@@ -16,6 +16,26 @@ Form | |||
|
|||
* Support for data objects that implements both `Traversable` and | |||
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed. | |||
|
|||
* Using callable strings as choice options in ChoiceType has been deprecated | |||
in favor of `PropertyPath`. Use a "\Closure" instead |
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.
The sentence as is must be added to the UPGRADE-3.1.md
file. In this file it should read like "Using callable strings as choice options in ChoiceType has been removed in favor of passing PropertyPath
instances."
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.
👍
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.
@@ -16,6 +16,25 @@ Form | |||
|
|||
* Support for data objects that implements both `Traversable` and | |||
`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed. | |||
|
|||
* Using callable strings as choice options in ChoiceType has been removed in favor of passing PropertyPath instances. | |||
|
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 would replace "has been removed" by "is not supported anymore".
But please wait for a symfony decider to tell you if it's ok. Thanks :)
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 are right. That sounds a bit better.
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.
done :)
@@ -7,6 +7,9 @@ CHANGELOG | |||
* deprecated the "choices_as_values" option of ChoiceType | |||
* deprecated support for data objects that implements both `Traversable` and | |||
`ArrayAccess` in `ResizeFormListener::preSubmit` method | |||
|
|||
* Using callable strings as choice options in `ChoiceType` has been deprecated | |||
and will be used as `PropertyPath` instead of callable in Symfony 4.0. |
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.
missing space at the beginning of the line
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.
@fabpot space added.
i've rebased with master. |
IIRC, we were waiting for @Tobion's opinion about merging or reverting instead. |
I would revert but I'm ok with both ways. |
Thank you @Simperfit. |
This PR was merged into the 3.1-dev branch. Discussion ---------- fix #17993 - Deprecated callable strings | Q | A | ------------- | --- | Branch | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | no | Fixed tickets | #17993 | License | MIT | Doc PR | Is this ok ? - [x] Rebase when #18057 is merged Commits ------- 191b495 fix #17993 - Deprecated callable strings
NP @fabpot. |
Is this ok ?