$uriVariables * @param array $context * * @throws FileNotFoundException */ public function provide(Operation $operation, array $uriVariables = [], array $context = []): Response|RedirectResponse { if ($operation instanceof GetCollection) { throw new \RuntimeException('not supported', 500); } $uncropped = isset($context['filters']['uncropped']) && ($context['filters']['uncropped'] === '1' || $context['filters']['uncropped'] === 'true'); return $this->getImage($uriVariables['fileId'], $uriVariables['size'], $uncropped); } /** * @throws FileNotFoundException */ protected function getImage(int $fileId, string $size, bool $uncropped = false): Response { $file = $this->fileRepository->find($fileId); if (empty($file)) { throw new \RuntimeException('Image '.$fileId.' does not exist; abort.'); } if ($file->getStatus() !== FileStatusEnum::READY) { throw new \RuntimeException('Image '.$fileId.' has '.$file->getStatus().' status; abort.'); } if (!$this->fileUtils->isImage($file)) { throw new \RuntimeException('File '.$fileId.' is not an image.'); } $content = $this->fileManager->getImageUrl($file, $size, false, $uncropped); return new Response($content); } }