コード例 #1
0
ファイル: Page.php プロジェクト: NicolasSchmutz/cm
 /**
  * @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;
     });
 }
コード例 #2
0
ファイル: Page.php プロジェクト: aladin1394/CM
 /**
  * @param CM_Http_Request_Abstract $request
  * @throws CM_Exception_Nonexistent
  * @throws CM_Exception
  * @throws CM_Exception_Nonexistent
  * @return string|null|boolean
  */
 private function _processPage(CM_Http_Request_Abstract $request)
 {
     return $this->_runWithCatching(function () use($request) {
         $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());
         }
         $this->_setStringRepresentation(get_class($page));
         $page->prepareResponse($this->getRender()->getEnvironment(), $this);
         if ($this->getRedirectUrl()) {
             $request->setUri($this->getRedirectUrl());
             return null;
         }
         $html = $this->_renderPage($page);
         $this->_page = $page;
         $this->_pageParams = $pageParams;
         return $html;
     }, 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;
     });
 }