Skip to content

[Validator] incorrect getters mapping #5219

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy