src/Controller/Glide/GlideDeciderController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Glide;
  3. use Erichard\GlideBundle\Controller\GlideController;
  4. use League\Glide\Filesystem\FileNotFoundException;
  5. use League\Glide\Signatures\SignatureException;
  6. use League\Glide\Signatures\SignatureFactory;
  7. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. class GlideDeciderController extends GlideController
  11. {
  12.     /**
  13.      * @param Request $request
  14.      * @param string $server
  15.      * @param string $path
  16.      * @param string $_format
  17.      *
  18.      * @return Response
  19.      */
  20.     public function resizeAction(Request $request$server$path$_format)
  21.     {
  22.         if ($_format === 'svg') {
  23.             return new BinaryFileResponse("{$path}.{$_format}");
  24.         }
  25.         $serverId "erichard_glide.${server}_server";
  26.         if (!$this->has($serverId)) {
  27.             throw $this->createAccessDeniedException('Unkown glide server');
  28.         }
  29.         $signatureKey $this->getParameter('erichard_glide.sign_key');
  30.         if (null !== $signatureKey) {
  31.             try {
  32.                 SignatureFactory::create($signatureKey)
  33.                     ->validateRequest(urldecode($request->getPathInfo()), $request->query->all());
  34.             } catch (SignatureException $e) {
  35.                 throw $this->createAccessDeniedException('Invalid image signature');
  36.             }
  37.         }
  38.         $server $this->get($serverId);
  39.         try {
  40.             return $server->getImageResponse("{$path}.{$_format}"$request->query->all());
  41.         } catch (FileNotFoundException $exception) {
  42.             throw $this->createNotFoundException();
  43.         }
  44.     }
  45. }