Esempio n. 1
0
 /**
  * @test
  */
 public function fileUploadShouldBeReplacable()
 {
     $upload = new FileUpload(ROOT_TESTS . '/data/self-lussing-manatee.jpg');
     $folder = $this->getMockedFolder();
     $profile = $this->getMockedFileProfile();
     $event = new FileUploadEvent($upload, $folder, $profile);
     $upload2 = $event->getFileUpload();
     $this->assertSame($upload, $upload2);
     $upload3 = new FileUpload(ROOT_TESTS . '/data/refcard.pdf');
     $event->setFileUpload($upload3);
     $upload4 = $event->getFileUpload();
     $this->assertSame($upload3, $upload4);
 }
Esempio n. 2
0
 /**
  * @param FileUploadEvent $event
  */
 public function beforeUpload(FileUploadEvent $event)
 {
     if (!$this->belongsToProfile($event->getProfile()->getIdentifier())) {
         return;
     }
     $upload = $event->getFileUpload();
     if (!preg_match("/^image/", $upload->getMimeType())) {
         return;
     }
     $helper = new ImageMagickHelper($upload->getRealPath(), $this->tempFiles, $this->commandDefinitions);
     $tempnam = $helper->execute();
     $pinfo = pathinfo($upload->getUploadFilename());
     $nupload = new FileUpload($tempnam);
     $mimeTypes = new MimeTypes();
     $extension = $mimeTypes->mimeTypeToExtension($nupload->getMimeType());
     $nupload->setOverrideFilename($pinfo['filename'] . '.' . $extension);
     $event->setFileUpload($nupload);
 }