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)); } }
public function it_can_execute_a_request(RequestInterface $request, File $file, ImageInterface $image) { $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); $response = $this->executeRequest($request); $response->shouldHaveType(ResponseInterface::class); $response->getResponseName()->shouldReturn('images.getEdited'); $response->offsetGet('image')->shouldReturn($image); $response->offsetGet('file')->shouldReturn($file); }
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); }
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)); } }