Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] incorrect getters mapping #5219

Copy link
Copy link
Closed
@Fludimir

Description

@Fludimir
Issue body actions
<?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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.