/**
  * This action applies a given filter to a given image, optionally saves the image and outputs it to the browser at the same time.
  *
  * @param Request $request
  * @param string  $hash
  * @param string  $path
  * @param string  $filter
  *
  * @throws \RuntimeException
  * @throws BadRequestHttpException
  *
  * @return RedirectResponse
  */
 public function filterRuntimeAction(Request $request, $hash, $path, $filter)
 {
     try {
         $filters = $request->query->get('filters', array());
         if (!is_array($filters)) {
             throw new NotFoundHttpException(sprintf('Filters must be an array. Value was "%s"', $filters));
         }
         if (true !== $this->signer->check($hash, $path, $filters)) {
             throw new BadRequestHttpException(sprintf('Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', $path, $filter, json_encode($filters)));
         }
         try {
             $binary = $this->dataManager->find($filter, $path);
         } catch (NotLoadableException $e) {
             if ($defaultImageUrl = $this->dataManager->getDefaultImageUrl($filter)) {
                 return new RedirectResponse($defaultImageUrl);
             }
             throw new NotFoundHttpException(sprintf('Source image could not be found for path "%s" and filter "%s"', $path, $filter), $e);
         }
         $rcPath = $this->cacheManager->getRuntimePath($path, $filters);
         $this->cacheManager->store($this->filterManager->applyFilter($binary, $filter, array('filters' => $filters)), $rcPath, $filter);
         return new RedirectResponse($this->cacheManager->resolve($rcPath, $filter), 301);
     } catch (NonExistingFilterException $e) {
         $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $hash . '/' . $path, $e->getMessage());
         if (null !== $this->logger) {
             $this->logger->debug($message);
         }
         throw new NotFoundHttpException($message, $e);
     } catch (RuntimeException $e) {
         throw new \RuntimeException(sprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', $hash . '/' . $path, $filter, $e->getMessage()), 0, $e);
     }
 }
 /**
  * Returns a web accessible URL.
  *
  * @param string $path          The path where the resolved file is expected.
  * @param string $filter        The name of the imagine filter in effect.
  * @param array  $runtimeConfig
  *
  * @return string
  */
 public function generateUrl($path, $filter, array $runtimeConfig = array())
 {
     $params = array('path' => ltrim($path, '/'), 'filter' => $filter);
     if (empty($runtimeConfig)) {
         $filterUrl = $this->router->generate('liip_imagine_filter', $params, true);
     } else {
         $params['filters'] = $runtimeConfig;
         $params['hash'] = $this->signer->sign($path, $runtimeConfig);
         $filterUrl = $this->router->generate('liip_imagine_filter_runtime', $params, true);
     }
     return $filterUrl;
 }
 /**
  * Returns a web accessible URL.
  *
  * @param string $path          The path where the resolved file is expected.
  * @param string $filter        The name of the imagine filter in effect.
  * @param array  $runtimeConfig
  * @param string $resolver
  *
  * @return string
  */
 public function generateUrl($path, $filter, array $runtimeConfig = array(), $resolver = null)
 {
     $params = array('path' => ltrim($path, '/'), 'filter' => $filter);
     if ($resolver) {
         $params['resolver'] = $resolver;
     }
     if (empty($runtimeConfig)) {
         $filterUrl = $this->router->generate('liip_imagine_filter', $params, UrlGeneratorInterface::ABSOLUTE_URL);
     } else {
         $params['filters'] = $runtimeConfig;
         $params['hash'] = $this->signer->sign($path, $runtimeConfig);
         $filterUrl = $this->router->generate('liip_imagine_filter_runtime', $params, UrlGeneratorInterface::ABSOLUTE_URL);
     }
     return $filterUrl;
 }
 /**
  * This action applies a given filter to a given image, optionally saves the image and outputs it to the browser at the same time.
  *
  * @param Request $request
  * @param string  $hash
  * @param string  $path
  * @param string  $filter
  *
  * @throws \RuntimeException
  * @throws BadRequestHttpException
  *
  * @return RedirectResponse
  */
 public function filterRuntimeAction(Request $request, $hash, $path, $filter)
 {
     try {
         $filters = $request->query->get('filters', array());
         if (true !== $this->signer->check($hash, $path, $filters)) {
             throw new BadRequestHttpException(sprintf('Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', $path, $filter, json_encode($filters)));
         }
         try {
             $binary = $this->dataManager->find($filter, $path);
         } catch (NotLoadableException $e) {
             throw new NotFoundHttpException(sprintf('Source image could not be found for path "%s" and filter "%s"', $path, $filter), $e);
         }
         $cachePrefix = 'rc/' . $hash;
         $this->cacheManager->store($this->filterManager->applyFilter($binary, $filter, array('filters' => $filters)), $cachePrefix . '/' . $path, $filter);
         return new RedirectResponse($this->cacheManager->resolve($cachePrefix . '/' . $path, $filter), 301);
     } catch (RuntimeException $e) {
         throw new \RuntimeException(sprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', $hash . '/' . $path, $filter, $e->getMessage()), 0, $e);
     }
 }