Esempio n. 1
0
 /**
  * This method controls the default routing. Don't be called when the
  * Enlight_Controller_Router_Route event canceled the default routing.
  * The default routing uses the dispatcher of the front controller to route
  * the request to the corresponding controller method.
  *
  * @param Enlight_Controller_Request_RequestHttp $request
  * @return array
  */
 public function routeDefault(Enlight_Controller_Request_Request $request)
 {
     $path = trim($request->getPathInfo(), $this->separator);
     if (empty($path)) {
         return array();
     }
     $dispatcher = $this->front->Dispatcher();
     $query = array();
     $params = array();
     foreach (explode($this->separator, $path) as $routePart) {
         $routePart = urldecode($routePart);
         if (empty($query[$request->getModuleKey()]) && $dispatcher->isValidModule($routePart)) {
             $query[$request->getModuleKey()] = $routePart;
         } elseif (empty($query[$request->getControllerKey()])) {
             $query[$request->getControllerKey()] = $routePart;
         } elseif (empty($query[$request->getActionKey()])) {
             $query[$request->getActionKey()] = $routePart;
         } else {
             $params[] = $routePart;
         }
     }
     if ($params) {
         $chunks = array_chunk($params, 2, false);
         foreach ($chunks as $chunk) {
             if (isset($chunk[1])) {
                 $query[$chunk[0]] = $chunk[1];
             } else {
                 $query[$chunk[0]] = '';
             }
         }
     }
     return $query;
 }
Esempio n. 2
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;
 }
Esempio n. 3
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);
 }