Skip to content
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

fix #17993 - Deprecated callable strings #18020

Merged
merged 1 commit into from Apr 15, 2016
Merged

fix #17993 - Deprecated callable strings #18020

merged 1 commit into from Apr 15, 2016

Conversation

@Simperfit
Copy link
Contributor

@Simperfit Simperfit commented Mar 5, 2016

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 ?

  • Rebase when #18057 is merged
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Mar 5, 2016

Thank you, I didn't understand the issue correctly.

I've changed my fix.

@javiereguiluz javiereguiluz added the Form label Mar 5, 2016
@@ -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)) {

This comment has been minimized.

@Tobion

Tobion Mar 5, 2016
Member

missing space after elseif

* @return ChoiceListInterface The choice list
*/
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null)
{
if (is_string($value) && !is_callable($value)) {
$value = new PropertyPath($value);
} elseif(is_string($value) && is_callable($value)) {

This comment has been minimized.

@Tobion

Tobion Mar 5, 2016
Member

missing space after elseif

* @return ChoiceListInterface The choice list
*/
public function createListFromChoices($choices, $value = null)
{
if (is_string($value) && !is_callable($value)) {
$value = new PropertyPath($value);
} elseif(is_string($value) && is_callable($value)) {

This comment has been minimized.

@Tobion

Tobion Mar 5, 2016
Member

missing space after elseif

This comment has been minimized.

@Simperfit

Simperfit Mar 5, 2016
Author Contributor

I've changed it all

@@ -80,12 +80,16 @@ public function getDecoratedFactory()
* @param null|callable|string|PropertyPath $value The callable or path for
* generating the choice values
*
* @deprecated We should not treat callable strings as callable

This comment has been minimized.

@Tobion

Tobion Mar 5, 2016
Member

this should not be added as the whole method will be marked as deprecated

This comment has been minimized.

@Simperfit

Simperfit Mar 5, 2016
Author Contributor

Thank you,

In this case, I don't have to add any "@deprecated" at all ?

@HeahDude
Copy link
Member

@HeahDude HeahDude commented Mar 5, 2016

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);

This comment has been minimized.

@HeahDude

HeahDude Mar 5, 2016
Member

since version 3.1 (for now)

@HeahDude
Copy link
Member

@HeahDude HeahDude commented Mar 5, 2016

You could perhaps wrap the callable string in a closure inside those elseif to prevent the fatal error.

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);
    };
}
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Mar 5, 2016

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);

This comment has been minimized.

@linaori

linaori Mar 5, 2016
Contributor

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)

This comment has been minimized.

@HeahDude

HeahDude Mar 5, 2016
Member

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

@HeahDude HeahDude commented Mar 5, 2016

I have no errors doing the tests except of one in PasswordEncoder.

What error are you talking about ?

@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Mar 5, 2016

Nevermind, no error anymore

@fabpot
Copy link
Member

@fabpot fabpot commented Mar 6, 2016

@Simperfit What about adding some unit tests?

@Simperfit Simperfit force-pushed the Simperfit:master branch from 9255f75 to 39e9859 Mar 6, 2016
@Simperfit Simperfit force-pushed the Simperfit:master branch from 35c2c52 to b070941 Mar 6, 2016
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Mar 6, 2016

@fabpot I added one, will add one for each method

@xabbuh
Copy link
Member

@xabbuh xabbuh commented Mar 7, 2016

Looks like this needs another rebase. It contains some unrelated changes.

Status: Needs work

@Simperfit Simperfit force-pushed the Simperfit:master branch from b070941 to 4ae9bf6 Mar 7, 2016
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Mar 7, 2016

@xabbuh Sorry for the unrelated changes, I've missed my rebase.

return $value($choices);
};

return $value($choices);

This comment has been minimized.

@xabbuh

xabbuh Mar 7, 2016
Member

Do we need to do all the stuff beside triggering the deprecation? Shouldn't the following code already handle the callback properly?

This comment has been minimized.

@Simperfit

Simperfit Mar 7, 2016
Author Contributor

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

@Simperfit Simperfit force-pushed the Simperfit:master branch 4 times, most recently from cd2bf8e to 22f8264 Mar 7, 2016
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Mar 7, 2016

@fabpot I've added one test for each method, is it ok like that ? Thank you.

@Simperfit Simperfit force-pushed the Simperfit:master branch from edec798 to c6625c9 Apr 1, 2016
* Using callable strings as choice options in ChoiceType has been deprecated
in favor of `PropertyPath`. Use a "\Closure" instead

Before:

This comment has been minimized.

@HeahDude

HeahDude Apr 1, 2016
Member

Ok now you got one extra here

```php
'choice_value' => 'range',
'choice_label' => function ($choice) {
return strtoupper($choice);

This comment has been minimized.

@HeahDude

HeahDude Apr 1, 2016
Member

and still missing four here

This comment has been minimized.

@HeahDude

HeahDude Apr 1, 2016
Member

You need to get rid of this comment :)

This comment has been minimized.

@Simperfit

Simperfit Apr 1, 2016
Author Contributor

done :)

@Simperfit Simperfit force-pushed the Simperfit:master branch from c6625c9 to 4747e35 Apr 1, 2016
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Apr 1, 2016

I've rebased and added/removed the space :p

@Simperfit Simperfit force-pushed the Simperfit:master branch 2 times, most recently from c3b996d to 12975bd Apr 1, 2016
```php
'choice_value' => 'range',
'choice_label' => function ($choice) {
return strtoupper($choice);

This comment has been minimized.

@HeahDude

HeahDude Apr 1, 2016
Member

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 :)

This comment has been minimized.

@Simperfit

Simperfit Apr 1, 2016
Author Contributor

I hope this time it's ok :p

Np :)

@Simperfit Simperfit force-pushed the Simperfit:master branch from 12975bd to 4f2108f Apr 1, 2016
@@ -55,6 +75,8 @@ FrameworkBundle
- `"form.type.submit"`
- `"form.type.reset"`

`ArrayAccess` in `ResizeFormListener::preSubmit` method has been removed

This comment has been minimized.

@HeahDude

HeahDude Apr 1, 2016
Member

to not conflict with master it must be before your change

ok just remove it

This comment has been minimized.

@Simperfit

Simperfit Apr 2, 2016
Author Contributor

oops sorry

@Simperfit Simperfit force-pushed the Simperfit:master branch from 4f2108f to a56a32b Apr 2, 2016
@HeahDude
Copy link
Member

@HeahDude HeahDude commented Apr 2, 2016

Looks perfect now :) Thanks @Simperfit!

This one is ready to merge now.

Deprecate or revert 470b140 ? ping @symfony/decoders

@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Apr 2, 2016

@@ -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

This comment has been minimized.

@xabbuh

xabbuh Apr 5, 2016
Member

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."

This comment has been minimized.

This comment has been minimized.

@Simperfit

Simperfit Apr 5, 2016
Author Contributor

is it ok like this @HeahDude @xabbuh ?

@Simperfit Simperfit force-pushed the Simperfit:master branch from a56a32b to d2f6434 Apr 5, 2016
@@ -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.

This comment has been minimized.

@HeahDude

HeahDude Apr 5, 2016
Member

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 :)

This comment has been minimized.

@xabbuh

xabbuh Apr 5, 2016
Member

You are right. That sounds a bit better.

This comment has been minimized.

@Simperfit

Simperfit Apr 5, 2016
Author Contributor

done :)

@Simperfit Simperfit force-pushed the Simperfit:master branch from d2f6434 to b8aa179 Apr 5, 2016
@@ -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.

This comment has been minimized.

@fabpot

fabpot Apr 6, 2016
Member

missing space at the beginning of the line

This comment has been minimized.

@Simperfit

Simperfit Apr 6, 2016
Author Contributor

@fabpot space added.

@Simperfit Simperfit force-pushed the Simperfit:master branch from b8aa179 to 560d229 Apr 6, 2016
hamza
ext
@Simperfit Simperfit force-pushed the Simperfit:master branch from 560d229 to 191b495 Apr 15, 2016
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Apr 15, 2016

i've rebased with master.
ping @fabpot @webmozart @Tobion

@fabpot
Copy link
Member

@fabpot fabpot commented Apr 15, 2016

IIRC, we were waiting for @Tobion's opinion about merging or reverting instead.

@Tobion
Copy link
Member

@Tobion Tobion commented Apr 15, 2016

I would revert but I'm ok with both ways.

@fabpot
Copy link
Member

@fabpot fabpot commented Apr 15, 2016

Thank you @Simperfit.

@fabpot fabpot merged commit 191b495 into symfony:master Apr 15, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details
fabpot added a commit that referenced this pull request Apr 15, 2016
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
@Simperfit
Copy link
Contributor Author

@Simperfit Simperfit commented Apr 17, 2016

NP @fabpot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

10 participants