src/Controller/ImageCropper/ImageController.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\ImageCropper;
  4. use App\Helper\Image\ImageHelper;
  5. use App\Helper\Image\ImageResponseInterface;
  6. use App\Helper\Image\ImageTypeEnum;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. /**
  14.  * @IsGranted("PUBLIC_ACCESS")
  15.  */
  16. class ImageController extends AbstractController
  17. {
  18.     public function crop(ImageHelper $imageHelperstring $typestring $dimensionsstring $image): Response
  19.     {
  20.         if (false === \in_array($typearray_column(ImageTypeEnum::cases(), 'value'), true)) {
  21.             throw new NotFoundHttpException(ImageResponseInterface::IMAGE_CROP_TYPE_NOT_EXIST);
  22.         }
  23.         return new BinaryFileResponse(
  24.             $imageHelper->crop($type$dimensions$image),
  25.             Response::HTTP_OK,
  26.             [
  27.                 'Content-Type' => 'image',
  28.                 AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER => 'true',
  29.                 'Cache-Control' => 'max-age=31536000, public',
  30.             ]
  31.         );
  32.     }
  33. }