コード例 #1
0
 /**
  * @param PhotoThumb $thumb
  * @return void
  */
 public function save(PhotoThumb $thumb)
 {
     $sentence = $this->pdo->prepare("INSERT INTO photo_thumb(\"uuid\",\"photo_uuid\",\"httpUrl\",\"height\",\"width\",\"filePath\") " . "VALUES(:uuid, :photo_uuid, :httpUrl, :height, :width, :filePath)");
     $sentence->bindValue(':uuid', $thumb->id(), \PDO::PARAM_STR);
     $sentence->bindValue(':photo_uuid', $thumb->photoId(), \PDO::PARAM_STR);
     $sentence->bindValue(':httpUrl', $thumb->photoThumbHttpUrl(), \PDO::PARAM_STR);
     $sentence->bindValue(':height', $thumb->height(), \PDO::PARAM_INT);
     $sentence->bindValue(':width', $thumb->width(), \PDO::PARAM_INT);
     $filePath = is_null($thumb->photoThumbFile()) ? null : $thumb->photoThumbFile()->filePath();
     $filePathType = is_null($thumb->photoThumbFile()) ? \PDO::PARAM_NULL : \PDO::PARAM_STR;
     $sentence->bindValue(':filePath', $filePath, $filePathType);
     $sentence->execute();
 }
コード例 #2
0
 /**
  * @test
  */
 public function photoThumbWorks()
 {
     $thumbId = new ThumbId();
     $photoId = new PhotoId();
     $photoFile = new PhotoFile(__DIR__ . '/pixel.png');
     $photoThumb = new PhotoThumb($thumbId, $photoId, new HttpUrl('http://works'), new PhotoThumbSize(10, 10), $photoFile);
     $this->assertEquals($thumbId->id(), $photoThumb->id());
     $this->assertEquals($photoId->id(), $photoThumb->photoId());
     $this->assertEquals('http://works', $photoThumb->photoThumbHttpUrl());
     $this->assertEquals(10, $photoThumb->height());
     $this->assertEquals(10, $photoThumb->width());
     $this->assertEquals($photoFile->filePath(), __DIR__ . '/pixel.png');
     $photoThumb->updatePhotoThumbFile(null);
     $this->assertNull($photoThumb->photoThumbFile());
 }
コード例 #3
0
 /**
  * @param PhotoThumb $thumb
  * @param Photo $photo
  * @return null|PhotoFile
  */
 public function uploadThumb(PhotoThumb $thumb, Photo $photo)
 {
     $this->s3->putObject(['Bucket' => $this->config->bucket(), 'Key' => $this->getThumbUri($photo->id(), $photo->slug(), $thumb->width(), $thumb->height(), $thumb->photoThumbFile()->format()), 'Body' => fopen($thumb->photoThumbFile()->filePath(), 'r'), 'ContentType' => $thumb->photoThumbFile()->mimeType(), 'ACL' => 'public-read']);
 }
コード例 #4
0
 /**
  * @param PhotoThumb $thumb
  * @param Photo $photo
  * @return null|PhotoFile
  */
 public function uploadThumb(PhotoThumb $thumb, Photo $photo)
 {
     $destinyPath = $this->localStorageConfig->storagePath() . '/' . $this->getMd5Path($photo->resourceId()) . '/' . $photo->id();
     $this->createPathIfNotExists($destinyPath);
     $newPhotoFilePath = sprintf('%s/%s_%dx%d.%s', $destinyPath, $photo->slug(), $thumb->width(), $thumb->height(), $thumb->photoThumbFile()->format());
     copy($thumb->photoThumbFile()->filePath(), $newPhotoFilePath);
     return new PhotoFile($newPhotoFilePath);
 }