Ejemplo n.º 1
0
 public function it_will_error_on_error_during_request_execution(RequestInterface $request)
 {
     $fullPath = '/path/to/file.ext';
     $request->offsetGet('path')->willReturn($fullPath);
     $request->getAcceptContentType()->willReturn('*/*');
     $this->imageRepository->getByFullPath($fullPath)->willThrow(new \RuntimeException());
     $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request);
 }
Ejemplo n.º 2
0
 public function executeRequest(RequestInterface $request) : ResponseInterface
 {
     try {
         $file = $this->imageRepository->getByFullPath($request['path']);
         $image = $this->imageEditor->process($file, $request['operations']);
         return new Response(self::MESSAGE, ['image' => $image, 'file' => $file], $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));
     }
 }
Ejemplo n.º 3
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));
     }
 }