1
votes

I have a custom password validator that someone gave me in an answer to another question. The validator looks like this:

<?php
namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\ConstraintValidator,
    Symfony\Component\Validator\Constraint,
    Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface,
    Symfony\Component\Security\Core\SecurityContextInterface,
    JMS\DiExtraBundle\Annotation\Validator,
    JMS\DiExtraBundle\Annotation\InjectParams,
    JMS\DiExtraBundle\Annotation\Inject;

/**
 * @Validator("user.validator.current_password")
 */
class CurrentPasswordValidator extends ConstraintValidator
{
  // ...
}

The place where I'm trying to use this validator is in my User entity, which looks like this:

<?php

namespace VNN\PressboxBundle\Entity;

use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinTable as JoinTable;
use Doctrine\ORM\Mapping\JoinColumn as JoinColumn;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContext;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\MaxLength;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\CurrentPassword;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * VNN\PressboxBundle\Entity\User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User implements UserInterface, \Serializable
{
    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addPropertyConstraint('current_password', new CurrentPassword());
    }
}

(I've omitted some code, of course, for clarity.)

The problem I'm having is that my validator class is not being recognized:

Fatal error: Class 'Symfony\Component\Validator\Constraints\CurrentPassword' not found in /home/jason/pressbox/src/VNN/PressboxBundle/Entity/User.php on line 438

Why could this be happening?

1

1 Answers

1
votes

You have to write the constraint yourself. It doesn't come with Symfony2.