first commit symfony 6
This commit is contained in:
29
src/Validator/GrouplabelValidator.php
Normal file
29
src/Validator/GrouplabelValidator.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user