nineskeletor/src/Validator/GrouplabelValidator.php

30 lines
897 B
PHP
Executable File

<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @Annotation
*/
class GrouplabelValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
/*
$tmp=$this->getEntityBy("App:Group","label",$value);
if($tmp) $form->addError(new FormError('Un groupe utilise déjà ce label'));
$tmp=$this->getEntityBy("App:Niveau02","label",$data->getLabel());
if($tmp) $form->addError(new FormError('Un niveau de rang 02 utilise déjà ce label'));
*/
// On s'assure que le label ne contient pas des caractères speciaux
$string = preg_replace('~[^ éèêôöàïî\'@a-zA-Z0-9._-]~', '', $value);
if ($string != $value) {
$this->context->addViolation($constraint->message);
}
}
}