You do not need to create a callback for this. Just make sure:
1) Set the enable_annotations parameter as true in your /config/config.yml application:
# app/config/config.yml framework: validation: { enable_annotations: true }
2) Include the correct validation restrictions on the entity file.
// YourEntity.php use Symfony\Component\Validator\Constraints as Assert;
3) Use annotation correctly. Example:
// YourEntity.php /** * @Assert\File( * maxSize="5242880", * mimeTypes = { * "image/png", * "image/jpeg", * "image/jpg", * "image/gif", * "application/pdf", * "application/x-pdf" * } * ) */ private $arquivo;
The above code works fine on my Symfony 2.3.9.
[] S
brunoric
source share