29 lines
904 B
PHP
29 lines
904 B
PHP
|
<?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);
|
||
|
}
|
||
|
}
|
||
|
}
|