/** * @test */ public function testGetByHash() { $this->repository->expects($this->once())->method('getByHash')->with($this->equalTo(self::DUMMY_HASH))->will($this->returnValue($this->getDummyAttachment())); $this->file->expects($this->atLeastOnce())->method('getFilename')->will($this->returnValue(self::DUMMY_FILE_NAME)); $attach = $this->service->getByHash(self::DUMMY_HASH); $this->assertEquals(self::DUMMY_HASH, $attach->getHash()); $this->assertEquals(self::DUMMY_FILE_NAME, $attach->getFile()->getFilename()); }
/** * @param File $value * @param AbstractPlatform $platform * @return string * @throws \RuntimeException */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (!$value) { return ''; } if (false === $value instanceof File) { throw new \RuntimeException("Value should be a File type."); } /** @var $value File */ return parent::convertToDatabaseValue($value->getPathname(), $platform); }
public function testGetExtension() { $this->file = new File('test.ext'); $ext = $this->file->getExtension(); $this->assertEquals('ext', $ext); }
protected function getDropboxName(File $file, $hash) { return sprintf('/%s/%s.%s', basename(dirname($file->getPathname())), $hash, $file->getExtension()); }
/** * @return string */ public function getFilename() { return $this->file->getFilename(); }
/** * @param \Diamante\DeskBundle\Model\Attachment\File $file * @param $hash * @param $fileNamePrefix * @return \Imagine\Image\ManipulatorInterface */ public function createThumbnail(File $file, $hash, $fileNamePrefix) { $image = $this->loader->getImagine()->open($file->getPathname()); $thumbnail = $image->thumbnail(new Box(100, 100)); $destinationFolder = sprintf('%s/thumbnails', $this->getDestination($fileNamePrefix)); try { if (!file_exists($destinationFolder)) { mkdir($destinationFolder); chmod($destinationFolder, 0777); } $destination = sprintf("%s/%s.%s", $destinationFolder, $hash, self::DEFAULT_THUMB_EXT); $thumbnail->save($destination); } catch (\Exception $e) { $this->logger->error(sprintf('Attachment directory is not accessible! Reason: %s', $e->getMessage())); throw new \RuntimeException('Thumbnail could not be created. ' . $e->getMessage()); } }