Dans un formulaire, il y a un champ avec un nom « fileAttachment » et de type « file ». On souhaite mettre une contrainte dans un CallBackValidator, pour que la taille du fichier uploadé ne dépasse pas 7168 kiloOctets.
Mise en place de la contrainte :
$constraintStartDate = $attachmentForm->get("fileAttachment");
$validator = new FileValidator();
$data = $attachmentForm->getData();
$test = new File(array(
'maxSize' => '7168k',
'maxSizeMessage' => 'myMessage')
);
if(!$validator->isValid($constraintStartDate->getData(), $test))
{
$constraintStartDate->addError( new FormError( "This field is not valid (only alphanumeric characters separated by hyphens)" ) );
}