/**
  * @param File $file
  */
 public function setFile(File $file)
 {
     $this->file = $file;
     $this->media->setContent($file);
     $this->media->setContentType($file->getMimeType());
     $this->media->setUrl('/uploads/media/' . $this->media->getUuid() . '.' . $this->media->getContent()->getExtension());
 }
 /**
  * @covers Kunstmaan\MediaBundle\Helper\File\PdfHandler::canHandle
  */
 public function testCannotHandleNonPdfFiles()
 {
     $media = new Media();
     $media->setContentType('image/jpg');
     $this->assertFalse($this->object->canHandle($media));
     $this->assertFalse($this->object->canHandle(new \stdClass()));
 }
 /**
  * @param mixed $data
  *
  * @return Media
  */
 public function createNew($data)
 {
     if ($data instanceof File) {
         /** @var $data File */
         $media = new Media();
         if (method_exists($data, 'getClientOriginalName')) {
             $media->setOriginalFilename($data->getClientOriginalName());
         } else {
             $media->setOriginalFilename($data->getFilename());
         }
         $media->setContent($data);
         $contentType = $this->mimeTypeGuesser->guess($media->getContent()->getPathname());
         $media->setContentType($contentType);
         return $media;
     }
     return null;
 }
Пример #4
0
 /**
  * @covers Kunstmaan\MediaBundle\Entity\Media::getContentType
  * @covers Kunstmaan\MediaBundle\Entity\Media::getContentTypeShort
  * @covers Kunstmaan\MediaBundle\Entity\Media::setContentType
  */
 public function testGetSetContentType()
 {
     $this->object->setContentType('image/jpeg');
     $this->assertEquals('image/jpeg', $this->object->getContentType());
     $this->assertEquals('jpeg', $this->object->getContentTypeShort());
 }