Skip to content

[Validator] StaticMethodLoader invokes wrong method #3179

Closed
@o

Description

interface FooInterface {

    public static function loadValidatorMetadata($metadata);
}

class Bar implements FooInterface {

    private $baz = 'bogus';

    public static function loadValidatorMetadata($metadata) {
        $metadata->addPropertyConstraint('baz', new Assert\MinLength(10));
    }

}

$validator = new Validator(
                new ClassMetadataFactory(new StaticMethodLoader()),
                new ConstraintValidatorFactory()
);
$violations = $validator->validate(new Bar);
if ($violations->count()) {
    throw new \Exception($violations);
}

I have classes that needs to be validated with Symfony\Component\Validator and this classes uses StaticMethodLoader strategy for validation. I declared loadValidatorMetadata method in interface but StaticMethodLoader invokes wrong method and following error occures.

Fatal error: Uncaught exception 'ReflectionException' with message 'Trying to invoke abstract method FooInterface::loadValidatorMetadata()' in Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php on line 44

ReflectionException: Trying to invoke abstract method Heatbeat\FooInterface::loadValidatorMetadata() in /Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php on line 44

Looks like there is a problem with Reflection.

Metadata

Assignees

No one assigned

    Labels

    BugGood first issueIdeal for your first contribution! (some Symfony experience may be required)Validator

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions