/**
  * @param BackendController $moduleController
  * @param string $moduleName
  */
 public function __construct(BackendController $moduleController, $moduleName)
 {
     parent::__construct($moduleController, $moduleName);
     $this->baseLink = '/backend/module/' . $moduleName;
     $this->messages = $this->setMessages();
 }
 /**
  * Generates a CmsPage object according to the given route, renders it and creates the framework
  * response for it.
  * 
  * @return HttpResponse The rendered page with all headers set ready to send back to the client
  * @throws CMSException
  * @throws HttpException
  * @throws \Exception
  */
 public function deliverCMSPage()
 {
     $pageModel = new PageModel($this->db);
     $this->cmsRoute = $pageModel->getRouteByURI($this->httpRequest->getPath());
     if ($this->cmsRoute === null) {
         //throw new HttpException('Could not find route: ' . $this->httpRequest->getPath(), 404);
         return $this->deliverPreviewCMSPage();
     }
     if ($this->cmsRoute->isSSLRequired() && $this->httpRequest->getProtocol() !== HttpRequest::PROTOCOL_HTTPS) {
         RequestHandler::redirect($this->httpRequest->getURL(HttpRequest::PROTOCOL_HTTPS));
     } elseif ($this->auth->isLoggedIn() === false && $this->cmsRoute->isSSLForbidden() && $this->httpRequest->getProtocol() !== HttpRequest::PROTOCOL_HTTP) {
         RequestHandler::redirect($this->httpRequest->getURL(HttpRequest::PROTOCOL_HTTP));
     }
     // Update httpRequest object
     if ($this->cmsRoute->isRegex()) {
         preg_match('@^' . $this->cmsRoute->getPattern() . '$@', $this->httpRequest->getPath(), $res);
         array_shift($res);
         $this->route->setParams($res);
     } elseif ($this->cmsRoute->getModuleID() !== null) {
         preg_match('@^' . $this->cmsRoute->getPattern() . '(/.+)?$@', $this->httpRequest->getPath(), $res);
         array_shift($res);
         $this->route->setParams($res);
     }
     if ($this->cmsRoute->getPageID() !== null) {
         $this->cmsPage = $pageModel->getPageByID($this->cmsRoute->getPageID());
         if ($this->cmsRoute->getModuleID() !== null) {
             try {
                 $modId = $this->cmsRoute->getModuleID();
                 $modInfo = $this->moduleModel->getModuleById($modId);
                 if ($modInfo === null) {
                     throw new CMSException('The module with ID ' . $modId . ' has no frontend controller defined');
                 }
                 if (isset($this->loadedModules[$modInfo->name]) === false) {
                     $cmsModuleInstance = new $modInfo->frontendcontroller($this, $modInfo->name);
                 } else {
                     $cmsModuleInstance = $this->loadedModules[$modInfo->name];
                 }
                 if ($cmsModuleInstance instanceof CmsModuleFrontendController === false) {
                     throw new CMSException('The module frontend controller for module ' . $modInfo->name . ' is none of type CmsModuleFrontendController');
                 }
                 /** @var CmsModuleFrontendController $cmsModuleInstance */
                 $this->cmsModule = $cmsModuleInstance;
                 if (($response = $this->cmsModule->callMethodByPath($path = $this->route->getParam(0))) instanceof HttpResponse) {
                     return $response;
                 }
             } catch (HttpException $e) {
                 if ($e->getCode() === 404) {
                     $this->eventDispatcher->dispatch('cms.page_not_found', new PageNotFoundEvent($this->httpRequest));
                 } elseif ($e->getCode() === 403) {
                     $this->eventDispatcher->dispatch('cms.page_access_denied', new PageAccessDeniedEvent($this->httpRequest));
                 }
                 throw $e;
             }
         }
         return $this->generateCMSPage($pageModel);
     } elseif ($this->cmsRoute->getExternalSource() !== null) {
         if ($this->cmsRoute->isRegex()) {
             $redirectLocation = preg_replace('@' . str_replace('@', '\\@', $this->cmsRoute->getPattern()) . '@', $this->cmsRoute->getExternalSource(), $this->httpRequest->getPath());
         } else {
             $redirectLocation = $this->cmsRoute->getExternalSource();
         }
         return new HttpResponse(301, null, array('Location' => $redirectLocation));
     } elseif ($this->cmsRoute->getRedirectRoute() !== null) {
         return new HttpResponse(301, null, array('Location' => $this->cmsRoute->getRedirectRoute()->getPattern()));
     }
 }
 /**
  * @param FrontendController $frontendController
  * @param string $moduleName
  */
 public function __construct(FrontendController $frontendController, $moduleName)
 {
     parent::__construct($frontendController, $moduleName);
     $this->services = array();
 }