Esempio n. 1
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 {
         /*
          * Handle short url with Url rewriting
          */
         $expander = new ShortUrlExpander($request);
         $expander->injectParamsToRequest($queryString, $filename);
         /*
          * Handle main image request
          */
         $iRequest = new InterventionRequest($this->getService('interventionRequestConfiguration'), $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']);
     }
 }
Esempio n. 2
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']);
     }
 }
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']);
}
/*
 * Handle main image request
 */
$iRequest = new InterventionRequest($conf, $request, $log);
$iRequest->handle();
$iRequest->getResponse()->send();