/**
  * @test
  */
 public function uploadAndDeleteOnePhotoWorks()
 {
     $photoId = new PhotoId();
     $resourceId = new ResourceId('test');
     $photoName = new PhotoName('test');
     $photoFile = new PhotoFile(__DIR__ . '/photo_to_upload.png');
     $altCollection = new PhotoAltCollection();
     $this->storage->upload(new Photo($photoId, $resourceId, $photoName, $this->storage->getPhotoHttpUrlBy($photoId, $resourceId, $photoName, $photoFile), $altCollection, new Position(), $photoFile));
     $uploadedPhoto = $this->config->storagePath() . '/' . $this->getMd5Path($resourceId->id()) . '/' . $photoId->id() . '/' . $photoName->slug() . '.' . $photoFile->format();
     $this->assertTrue(file_exists($uploadedPhoto));
     $this->assertTrue($this->storage->remove(new Photo($photoId, $resourceId, $photoName, $this->storage->getPhotoHttpUrlBy($photoId, $resourceId, $photoName, $photoFile), $altCollection, new Position(), new PhotoFile($uploadedPhoto))));
 }
Beispiel #2
0
 /**
  * @return PhotoStorage
  */
 public function getPhotoStorage()
 {
     switch ($this->storage->driver()) {
         case Storage::STORAGE_LOCAL:
             return new PhotoLocalStorage(LocalStorageConfig::getInstanceByArray($this->storage->config()));
             break;
         case Storage::STORAGE_S3_AMAZON:
             return new AmazonS3PhotoStorage(AmazonS3Config::getInstanceByArray($this->storage->config()), $this->thumbGeneratorConfig);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Invalid storage driver "%s"', $this->storage->driver()));
             break;
     }
 }
 /**
  * @param PhotoId $photoId
  * @param ResourceId $resourceId
  * @param PhotoName $photoName
  * @param PhotoThumbSize $photoThumbSize
  * @param PhotoFormat $photoFormat
  * @return HttpUrl
  */
 public function getPhotoThumbHttpUrlBy(PhotoId $photoId, ResourceId $resourceId, PhotoName $photoName, PhotoThumbSize $photoThumbSize, PhotoFormat $photoFormat)
 {
     $urlBase = $this->localStorageConfig->urlBase();
     $urlBase = $urlBase[strlen($urlBase) - 1] === '/' ? substr($urlBase, 0, -1) : $urlBase;
     return new HttpUrl(implode('/', [$urlBase, $this->getMd5Path($resourceId->id()), $photoId->id(), $photoName->slug()]) . '_' . $photoThumbSize->width() . 'x' . $photoThumbSize->height() . '.' . $photoFormat->value());
 }