10000 [Validator] incorrect getters mapping · Issue #5219 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Validator] incorrect getters mapping #5219
Closed
@Fludimir

Description

@Fludimir
<?php
namespace Application\MyBundle\Entity

use Symfony\Component\Validator\Constraints as Assert;

class User
{
    public function getRoles()
    {
        throw new \Exception("getRoles should not be called");
    }

    /**
     * @Assert\True
    */
    public function isRoles()
    {
        return true;
    }
}
<?php
//some controller-action
$user = new User;
$list = $this->get('validator')->validate($user);

You may expect that entity is valid, because method with Assert\True always returns true, but instead this exception will be thrown - Validator\Mapping\GetterMetadata firstly checks 'get%Prop' than 'is%Prop' methods.

Looks like main problem is that all constraints basically binded to properties, even constraints on getters. This also doesn't described properly in docs, what causes such funny issues as described above.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0