/**
  * @test
  */
 public function getBaseHttpUrlByResourceIdReturnsExpected()
 {
     $photoId = new PhotoId();
     $resourceId = new ResourceId('test');
     $name = new PhotoName('test');
     $file = new PhotoFile(__DIR__ . '/photo_to_upload.png');
     $this->assertEquals(implode('/', [$this->urlBase, $this->getMd5Path($resourceId->id()), $photoId->id(), $name->slug()]) . '.' . $file->format(), $this->storage->getPhotoHttpUrlBy($photoId, $resourceId, $name, $file)->value());
 }
 /**
  * @param ResourceId $resourceId
  * @return PhotoCollection;
  * @throws CollectionNotFoundException
  */
 public function findCollectionBy(ResourceId $resourceId)
 {
     $photos = [];
     foreach ($this->photos as $photo) {
         if ($photo->resourceId() === $resourceId->id()) {
             $photos[] = $photo;
         }
     }
     if (empty($photos)) {
         throw new CollectionNotFoundException(sprintf('Collection of resource %s not found', $resourceId->id()));
     }
     return new PhotoCollection($photos);
 }
Esempio n. 3
0
 /**
  * @return string
  */
 public function resourceId()
 {
     return $this->resourceId->id();
 }
 /**
  * @param ResourceId $resourceId
  * @return PhotoCollection;
  * @throws CollectionNotFoundException
  */
 public function findCollectionBy(ResourceId $resourceId)
 {
     $sentence = $this->pdo->prepare("SELECT * FROM \"photo\" WHERE resourceId=:resourceId");
     $sentence->bindValue(':resourceId', $resourceId->id(), \PDO::PARAM_STR);
     $sentence->execute();
     $rows = $sentence->fetchAll(\PDO::FETCH_ASSOC);
     if ($rows) {
         $photos = new PhotoCollection();
         foreach ($rows as $row) {
             $photos[] = $this->createPhotoByRow($row);
         }
         return $photos;
     }
     throw new CollectionNotFoundException(sprintf('Photos with resource id %s not found', $resourceId->id()));
 }
 /**
  * @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());
 }