Exemple #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;
 }
Exemple #2
0
 /**
  * @param Request $request
  * @param Shop $shop
  * @return bool
  */
 protected function shouldRedirect(Request $request, Shop $shop)
 {
     return $request->isGet() && $request->getQuery('__shop') !== null && $request->getQuery('__shop') != $shop->getId() || $request->isPost() && $request->getPost('__shop') !== null && $request->getPost('__redirect') !== null;
 }
Exemple #3
0
 /**
  * Returns an array with all current values in _GET
  *
  * @return array
  */
 public function toArray()
 {
     return $this->request->getQuery();
 }