Пример #1
0
 /**
  * @param CM_Http_Request_Abstract $request
  */
 public function rewrite(CM_Http_Request_Abstract $request)
 {
     if ($request->getPath() == '/') {
         $request->setPath('/index');
     }
 }
Пример #2
0
 public static function match(CM_Http_Request_Abstract $request)
 {
     return 0 === stripos($request->getPath(), '/resource-');
 }
Пример #3
0
 /**
  * @param CM_Http_Request_Abstract               $request
  * @param CM_Http_Response_Page_ProcessingResult $result
  * @throws CM_Exception
  * @throws Exception
  * @return boolean
  */
 private function _processPage(CM_Http_Request_Abstract $request, CM_Http_Response_Page_ProcessingResult $result)
 {
     return $this->_runWithCatching(function () use($request, $result) {
         $path = CM_Util::link($request->getPath(), $request->getQuery());
         $result->addPath($path);
         $this->getSite()->rewrite($request);
         $pageParams = CM_Params::factory($request->getQuery(), true);
         try {
             $className = CM_Page_Abstract::getClassnameByPath($this->getRender(), $request->getPath());
             $page = CM_Page_Abstract::factory($className, $pageParams);
         } catch (CM_Exception $ex) {
             throw new CM_Exception_Nonexistent('Cannot load page `' . $request->getPath() . '`: ' . $ex->getMessage());
         }
         $result->addPage($page);
         $environment = $this->getRender()->getEnvironment();
         $page->prepareResponse($environment, $this);
         if ($this->getRedirectUrl()) {
             $request->setUri($this->getRedirectUrl());
             return true;
         }
         if ($page->getCanTrackPageView()) {
             $this->getRender()->getServiceManager()->getTrackings()->trackPageView($environment, $result->getPathTracking());
         }
         $result->setHtml($this->_renderPage($page));
         return true;
     }, function (CM_Exception $ex, array $errorOptions) use($request) {
         $this->getRender()->getGlobalResponse()->clear();
         /** @var CM_Page_Abstract $errorPage */
         $errorPage = $errorOptions['errorPage'];
         $request->setPath($errorPage::getPath());
         $request->setQuery(array());
         return false;
     });
 }
Пример #4
0
 /**
  * @param CM_Http_Request_Abstract $request
  * @return bool
  * @throws CM_Exception
  */
 public function match(CM_Http_Request_Abstract $request)
 {
     return $this->isUrlMatch($request->getHost(), $request->getPath());
 }
Пример #5
0
 /**
  * @param CM_Http_Request_Abstract $request
  * @throws CM_Exception_Invalid
  * @return string|null
  */
 protected function _processPageLoop(CM_Http_Request_Abstract $request)
 {
     $count = 0;
     $paths = array($request->getPath());
     while (false === ($html = $this->_processPage($request))) {
         $paths[] = $request->getPath();
         if ($count++ > 10) {
             throw new CM_Exception_Invalid('Page dispatch loop detected (' . implode(' -> ', $paths) . ').');
         }
     }
     return $html;
 }