/**
  * Validate a submited file
  *
  * @param ValidationEvent $event
  * @throws \Oneup\UploaderBundle\Uploader\Exception\ValidationException
  */
 public function onValidate(ValidationEvent $event)
 {
     try {
         $this->validator->validate($event->getType(), $event->getFile(), 'upload_validators');
     } catch (JbFileUploaderValidationException $e) {
         throw new ValidationException($e->getMessage(), null, $e);
     }
 }
Exemplo n.º 2
0
 /**
  * Crop an image
  *
  * @param string $endpoint
  * @param array $data
  *
  * @return string
  */
 public function crop($endpoint, array $data)
 {
     // Throw ValidationException if there is an error
     $this->validator->validate($endpoint, $data, 'crop_validators');
     // Generate croped image
     $cropedFile = $this->cropManager->transformFile($data);
     // Save it to filesystem using gaufrette
     $this->cropManager->saveTransformedFile($endpoint, $cropedFile, $data);
     // Return data
     return array('filepath' => $this->resolvers->getResolver($this->getCropResolver($endpoint))->getUrl($data['filename']), 'filename' => $data['filename']);
 }