Esempio n. 1
0
 /**
  * Sets the shopware cache headers
  */
 public function setCacheHeaders()
 {
     $controllerName = $this->buildControllerName($this->request);
     $cacheControllers = $this->getCacheControllers();
     if (!isset($cacheControllers[$controllerName])) {
         return false;
     }
     if (strpos($this->request->getPathInfo(), '/widgets/index/refreshStatistic') !== false) {
         return false;
     }
     if (strpos($this->request->getPathInfo(), '/captcha/index/rand/') !== false) {
         return false;
     }
     $allowNoCache = $this->getNoCacheTagsForController($controllerName);
     $noCacheCookies = $this->getNoCacheTagsFromCookie($this->request);
     $hasMatchingNoCacheCookie = $this->hasArrayIntersection($allowNoCache, $noCacheCookies);
     if ($this->response->isRedirect()) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     if ($hasMatchingNoCacheCookie) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     $allowNoCacheControllers = $this->getAllowNoCacheControllers();
     if (isset($allowNoCacheControllers[$controllerName]) && $this->request->getQuery('nocache') !== null) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     // Don't cache when using admin session
     if (Shopware()->Session()->Admin) {
         return false;
     }
     // Don't cache filled basket or wishlist
     if ($controllerName == 'widgets/checkout' && (!empty(Shopware()->Session()->sBasketQuantity) || !empty(Shopware()->Session()->sNotesQuantity))) {
         $this->response->setHeader('Cache-Control', 'private, no-cache');
         return false;
     }
     $cacheTime = (int) $cacheControllers[$controllerName];
     $this->request->setParam('__cache', $cacheTime);
     $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime);
     if (!empty($allowNoCache)) {
         $this->response->setHeader('x-shopware-allow-nocache', implode(', ', $allowNoCache));
     }
     $cacheIds = $this->getCacheIdsFromController($this->action);
     $this->setCacheIdHeader($cacheIds);
     return true;
 }
 /**
  * @param Request $request
  * @param ShopContextInterface $context
  * @return Criteria
  */
 private function getSearchCriteria(Request $request, ShopContextInterface $context)
 {
     if (!$request->has('sSort')) {
         $request->setParam('sSort', StoreFrontCriteriaFactory::SORTING_SEARCH_RANKING);
     }
     $criteria = $this->createCriteriaFromRequest($request, $context);
     if (!$criteria->hasCondition('category')) {
         $categoryId = $context->getShop()->getCategory()->getId();
         $criteria->addBaseCondition(new CategoryCondition([$categoryId]));
     }
     return $criteria;
 }
Esempio n. 3
0
 /**
  * The handle error function checks for an exception and
  * allows the error handler controller the option to forward
  *
  * @param Enlight_Controller_Front $front
  * @param Enlight_Controller_Request_Request $request
  * @return mixed
  * @throws mixed
  */
 protected function handleError($front, Enlight_Controller_Request_Request $request)
 {
     if ($front->getParam('noErrorHandler')) {
         return;
     }
     $response = $front->Response();
     if ($this->_isInsideErrorHandlerLoop) {
         $exceptions = $response->getException();
         if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
             // Exception thrown by error handler; tell the front controller to throw it
             $front->throwExceptions(true);
             throw array_pop($exceptions);
         }
     }
     // check for an exception AND allow the error handler controller the option to forward
     if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
         $this->_isInsideErrorHandlerLoop = true;
         // Get exception information
         $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
         $exceptions = $response->getException();
         $exception = $exceptions[0];
         $error->exception = $exception;
         switch (true) {
             case $exception instanceof Zend_Controller_Router_Exception:
                 if (404 == $exception->getCode()) {
                     $error->type = self::EXCEPTION_NO_ROUTE;
                 } else {
                     $error->type = self::EXCEPTION_OTHER;
                 }
                 break;
             case $exception instanceof Zend_Controller_Dispatcher_Exception:
                 $error->type = self::EXCEPTION_NO_CONTROLLER;
                 break;
             case $exception instanceof Zend_Controller_Action_Exception:
                 if (404 == $exception->getCode()) {
                     $error->type = self::EXCEPTION_NO_ACTION;
                 } else {
                     $error->type = self::EXCEPTION_OTHER;
                 }
                 break;
             default:
                 $error->type = self::EXCEPTION_OTHER;
                 break;
         }
         // Keep a copy of the original request
         $error->request = clone $request;
         // get a count of the number of exceptions encountered
         $this->_exceptionCountAtFirstEncounter = count($exceptions);
         // Forward to the error handler
         $request->setParam('error_handler', $error)->setControllerName('error')->setActionName('error')->setDispatched(false);
         //->setModuleName($this->getErrorHandlerModule())
         //->setControllerName($this->getErrorHandlerController())
         //->setActionName($this->getErrorHandlerAction())
     }
 }
Esempio n. 4
0
 public function assembleRoute(Request $request, Response $response)
 {
     $path = $request->getPathInfo();
     $path = explode('/', trim($path, '/'));
     $path = array_pad($path, 7, null);
     array_shift($path);
     $tmp = array_shift($path);
     $matches = array();
     if (preg_match('/^v([1-9])$/', $tmp, $matches) === 1) {
         $version = (int) $matches[1];
         $type = array_shift($path);
     } else {
         $version = 1;
         $type = $tmp;
     }
     $id = !empty($path[0]) ? $path[0] : false;
     $subType = !empty($path[1]) ? $path[1] : false;
     $subId = !empty($path[2]) ? $path[2] : false;
     $request->setControllerName($type);
     $request->setParam('id', $id);
     $request->setParam('subId', $subId);
     $request->setParam('version', $version);
     $method = strtoupper($request->getParam('_method', $request->getMethod()));
     $action = 'invalid';
     if ($method === 'GET' && $id === false) {
         $action = 'index';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'GET') {
         $action = 'get';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'PUT' && $id === false) {
         $action = 'batch';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'PUT') {
         $action = 'put';
     } elseif ($method === 'POST') {
         $action = 'post';
         // Set default http status code for successfull request
         $response->setHttpResponseCode(201);
     } elseif ($method === 'DELETE' && $id === false) {
         $action = 'batchDelete';
         $response->setHttpResponseCode(200);
     } elseif ($method === 'DELETE') {
         $response->setHttpResponseCode(200);
         $action = 'delete';
     }
     if ($action == 'invalid') {
         $request->setControllerName('index');
         $request->setActionName($action);
         return;
     }
     if (!$subType) {
         $request->setActionName($action);
         return;
     }
     if ($action == 'get' && $subId === false) {
         $subAction = $subType . 'Index';
     } else {
         $subAction = $subType;
     }
     $action = $action . ucfirst($subAction);
     $request->setActionName($action);
 }
Esempio n. 5
0
 /**
  * The handle error function checks for an exception and
  * allows the error handler controller the option to forward
  *
  * @param Enlight_Controller_Front $front
  * @param Enlight_Controller_Request_Request $request
  * @return mixed
  * @throws mixed
  */
 protected function handleError($front, Enlight_Controller_Request_Request $request)
 {
     if ($front->getParam('noErrorHandler')) {
         return;
     }
     $response = $front->Response();
     if ($this->_isInsideErrorHandlerLoop) {
         $exceptions = $response->getException();
         if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
             // Exception thrown by error handler; tell the front controller to throw it
             $front->throwExceptions(true);
             throw array_pop($exceptions);
         }
     }
     // check for an exception AND allow the error handler controller the option to forward
     if ($response->isException() && !$this->_isInsideErrorHandlerLoop) {
         $this->_isInsideErrorHandlerLoop = true;
         // Get exception information
         $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
         $exceptions = $response->getException();
         $exception = $exceptions[0];
         $error->exception = $exception;
         // Keep a copy of the original request
         $error->request = clone $request;
         // get a count of the number of exceptions encountered
         $this->_exceptionCountAtFirstEncounter = count($exceptions);
         // Forward to the error handler
         $request->setParam('error_handler', $error)->setControllerName('error')->setActionName('error')->setDispatched(false);
     }
 }