コード例 #1
0
 /**
  * @param UploadRecipeImageCommand $command
  * @throws RecipeNotFoundException
  * @throws RuntimeException
  */
 public function handle(UploadRecipeImageCommand $command)
 {
     $recipe = $this->recipes->findBySlug($command->slug);
     if (is_null($recipe)) {
         throw new RecipeNotFoundException();
     }
     if (!$command->image instanceof \SplFileInfo) {
         throw new RuntimeException("UploadRecipeImageHandler expected image to implement \\SplFileInfo");
     }
     $image = new Image($command->slug . '.' . $command->extension, $this->filesystem->read($command->image->getRealPath()));
     $this->imageStorage->saveImageFor($image, $command->slug);
 }
コード例 #2
0
 /**
  * @param string $slug
  * @return Recipe
  * @throws RecipeNotFoundException
  */
 public function fetchBySlug($slug)
 {
     if (!$this->filesystem->has($this->generateFileNameFromSlug($slug))) {
         throw new RecipeNotFoundException(sprintf("Recipe with slug \"%s\" does not exists", $slug));
     }
     $json = $this->filesystem->read($this->generateFileNameFromSlug($slug));
     return $this->serializer->deserialize($json, Recipe::class);
 }
コード例 #3
0
 function it_updates_recipe_description(Recipes $recipes, ImageStorage $imageStorage, Filesystem $filesystem)
 {
     $recipes->findBySlug("screwdriver")->willReturn(new Recipe(new Name("Screwdriver")));
     $command = new UploadRecipeImageCommand();
     $command->slug = 'screwdriver';
     $command->image = new FakeFile("fake_image.jpg");
     $command->extension = 'jpg';
     $filesystem->read('fake_image.jpg')->willReturn('content');
     $imageStorage->saveImageFor(Argument::type(Image::class), "screwdriver")->shouldBeCalled();
     $this->handle($command);
 }