Пример #1
0
 public function it_can_execute_a_request(RequestInterface $request, File $file, ImageInterface $image, File $newImage)
 {
     $fullPath = '/path/to/file.ext';
     $operations = ['resize' => ['width' => 320, 'height' => 480]];
     $request->offsetGet('path')->willReturn($fullPath);
     $request->offsetGet('operations')->willReturn($operations);
     $request->getAcceptContentType()->willReturn('*/*');
     $this->imageRepository->getByFullPath($fullPath)->willReturn($file);
     $this->imageEditor->process($file, $operations)->willReturn($image);
     $this->imageEditor->output($file, $image)->willReturn('abcdefg');
     $this->imageRepository->createImage($file, new Argument\Token\TypeToken('resource'))->willReturn($newImage);
     $response = $this->executeRequest($request);
     $response->shouldHaveType(ResponseInterface::class);
     $response->offsetGet('data')->shouldReturn($newImage);
 }
Пример #2
0
 public function executeRequest(RequestInterface $request) : ResponseInterface
 {
     try {
         // Fetch existing image and process operations on it
         $file = $this->imageRepository->getByFullPath($request['path']);
         $image = $this->imageEditor->process($file, $request['operations']);
         // Get resulting image and store in stream
         $contents = tmpfile();
         fwrite($contents, $this->imageEditor->output($file, $image));
         $newImage = $this->imageRepository->createImage($file, $contents);
         return new Response(self::MESSAGE, ['data' => $newImage], $request);
     } catch (NoUniqueResultException $e) {
         return new NotFoundResponse([], $request);
     } catch (\Throwable $exception) {
         $this->log(LogLevel::ERROR, $exception->getMessage());
         throw new ResponseException('An error occurred during GetEditedImageHandler.', new ServerErrorResponse([], $request));
     }
 }