Пробывал сделать кастомный валидатор, скопировал всё с документации
https://symfony.com/doc/3.4/validation/custom_cons...
Выдаёт такую ошибку [Semantical Error] The annotation "@AppBundle\Validator\Constraints\ContainsAlphanumeric" in property AppBundle\Entity\Category::$name does not exist, or could not be auto-loaded.
Может ктонибудь помочь?
<?php
/* File AppBundle\Validator\Constraints\ContainsAlphunumeric.php */
namespace AppBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class ContainsAlphanumeric extends Constraint
{
public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
public function validatedBy()
{
return get_class($this).'Validator';
}
}
?>
<?php
/* File AppBundle\Validator\Constraints\ContainsAlphanumericValidator.php */
namespace AppBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class ContainsAlphanumericValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
if (!preg_match('/^[a-zA-Z0-9]+$/', $value, $matches)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ string }}', $value)
->addViolation();
}
}
}
?>
<?php
/* File AppBundle\Entity\Category.php*/
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Validator\Constraints\ContainsAlphanumeric;
/*....*/
/**
* @ORM\Column(name="name", type="string", length=255, nullable=true)
* @Groups({"Self"})
* @ContainsAlphanumeric
*/
protected $name;
?>