/**
  * @return Response
  */
 public function getResponse()
 {
     if (null !== $this->response) {
         $this->response->setPublic();
         $this->response->setPrivate();
         $this->response->setMaxAge($this->configuration->getTtl());
         $this->response->setSharedMaxAge($this->configuration->getTtl());
         $this->response->setCharset('UTF-8');
         $this->response->prepare($this->request);
         return $this->response;
     } else {
         throw new \RuntimeException("Request had not been handled. Use handle() method before getResponse()", 1);
     }
 }
Пример #2
0
 /**
  * @param Pimple\Container $container [description]
  */
 public function register(Container $container)
 {
     $container['interventionRequestConfiguration'] = function ($c) {
         $cacheDir = ROADIZ_ROOT . '/cache/rendered';
         if (!file_exists($cacheDir)) {
             mkdir($cacheDir);
         }
         $imageDriver = !empty($c['config']['assetsProcessing']['driver']) ? $c['config']['assetsProcessing']['driver'] : 'gd';
         $defaultQuality = !empty($c['config']['assetsProcessing']['defaultQuality']) ? (int) $c['config']['assetsProcessing']['defaultQuality'] : 90;
         $conf = new Configuration();
         $conf->setCachePath($cacheDir);
         $conf->setImagesPath(ROADIZ_ROOT . '/files');
         $conf->setDriver($imageDriver);
         $conf->setDefaultQuality($defaultQuality);
         return $conf;
     };
     return $container;
 }
Пример #3
0
 /**
  *
  * @param  Request $request
  * @param  string  $queryString
  * @param  string  $filename
  * @return Response
  */
 public function interventionRequestAction(Request $request, $queryString, $filename)
 {
     $log = new Logger('InterventionRequest');
     $log->pushHandler(new StreamHandler(ROADIZ_ROOT . '/logs/interventionRequest.log', Logger::INFO));
     try {
         $cacheDir = ROADIZ_ROOT . '/cache/rendered';
         if (!file_exists($cacheDir)) {
             mkdir($cacheDir);
         }
         $conf = new Configuration();
         $conf->setCachePath($cacheDir);
         $conf->setImagesPath(ROADIZ_ROOT . '/files');
         /*
          * Handle short url with Url rewriting
          */
         $expander = new ShortUrlExpander($request);
         $expander->injectParamsToRequest($queryString, $filename);
         /*
          * Handle main image request
          */
         $iRequest = new InterventionRequest($conf, $request, $log);
         $iRequest->handle();
         return $iRequest->getResponse();
     } catch (\Exception $e) {
         if (null !== $log) {
             $log->error($e->getMessage());
         }
         return new Response($e->getMessage(), Response::HTTP_NOT_FOUND, ['content-type' => 'text/plain']);
     }
 }
// include composer autoload
require 'vendor/autoload.php';
// import the Intervention Image Manager Class
use AM\InterventionRequest\Configuration;
use AM\InterventionRequest\InterventionRequest;
use AM\InterventionRequest\ShortUrlExpander;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
$log = new Logger('InterventionRequest');
$log->pushHandler(new StreamHandler('interventionRequest.log', Logger::INFO));
/*
 * A test configuration
 */
$conf = new Configuration();
$conf->setCachePath(APP_ROOT . '/cache');
$conf->setImagesPath(APP_ROOT . '/test');
$conf->setJpegoptimPath('/usr/local/bin/jpegoptim');
$conf->setPngquantPath('/usr/local/bin/pngquant');
$conf->setUseFileChecksum(false);
/*
 * Handle short url with Url rewriting
 */
$expander = new ShortUrlExpander($request);
$params = $expander->parsePathInfo();
if (null !== $params) {
    // this will convert rewritten path to request with query params
    $expander->injectParamsToRequest($params['queryString'], $params['filename']);
}
/*