8000 Choice assert with callback fails inside the All assert · Issue #21706 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Choice assert with callback fails inside the All assert #21706

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

Closed
murilolobato opened this issue Feb 21, 2017 · 1 comment
Closed

Choice assert with callback fails inside the All assert #21706

murilolobato opened this issue Feb 21, 2017 · 1 comment

Comments

@murilolobato
Copy link
murilolobato commented Feb 21, 2017
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.8.14

If I try to use the Assert\Choice inside the Assert\All, like following I receive a The choice constraint expects a valid callback error message.

// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class User
{
    /**
     * @Assert\Count(min="1")
     * @Assert\All({
     *     @Assert\Choice(callback={"getValidColors"})
     * })
     */
     protected $favoriteColors = array();

     public static function getValidColors()
     {
          return array('red', 'green', 'blue');
     }
}

The error message:
image

To walkaround this problem, I've added the full-qualified-class-name to the first paramater of the callback option of the Assert\Choice, as follow:

// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class User
{
    /**
     * @Assert\Count(min="1")
     * @Assert\All({
     *     @Assert\Choice(callback={"AppBundle\Entity\User", "getValidColors"})
     * })
     */
     protected $favoriteColors = array();

     public static function getValidColors()
     {
          return array('red', 'green', 'blue');
     }
}

And this way it has worked, but this method is not covered at any documentation. I'm willing to help if I know what needs to be done.

@xabbuh
Copy link
Member
xabbuh commented Feb 23, 2017

The cause of this behaviour probably basically is the same as in #20477.

@xabbuh xabbuh removed the Unconfirmed label Mar 5, 2017
fabpot added a commit that referenced this issue Jan 3, 2018
… constraint (ostrolucky)

This PR was merged into the 2.7 branch.

Discussion
----------

[Validator] Fix access to root object when using composite constraint

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12315, #20477, #21706
| License       | MIT
| Doc PR        |

Commits
-------

b18cdcf [Validator] Fix access to root object when using composite constraint
@fabpot fabpot closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0