/**
  * Initializes the request handler.
  */
 public function __construct()
 {
     // set request object
     $this->setRequest(new HttpRequest($this->getRequestUri(), EnvironmentUtil::getEnvironmentVariable('REQUEST_METHOD'), $this->getRequestHttpVersion(), $this->getRequestHeaders(), $_GET, $_POST, $this->getRequestCookies()));
     // get the URLs we need
     $frontendBaseUrl = new Uri(rtrim(rtrim(EnvironmentUtil::getSiteUrl()->toString(), '/') . Application::getConfig()->get('frontend.basePath'), '/'));
     $backendBaseUrl = new Uri(rtrim(rtrim(EnvironmentUtil::getSiteUrl()->toString(), '/') . Application::getConfig()->get('backend.basePath'), '/'));
     $requestPath = $this->getRequest()->getUri()->getPath();
     // set whether we have a frontend request
     $this->isFrontendRequest = $this->checkIsFrontendRequest($frontendBaseUrl, $backendBaseUrl, $this->getRequest()->getUri()->getHost(), $requestPath);
     // determine module base path
     $this->moduleBasePath = '/' . explode('/', trim(StringUtil::getSubstring($requestPath, StringUtil::getLength($this->isFrontendRequest ? $frontendBaseUrl->getPath() : $backendBaseUrl->getPath())), '/'), 2)[0];
     // get requested module
     $this->requestedModule = Application::getModuleManager()->findModuleByBasePath($this->moduleBasePath, $this->isFrontendRequest);
     // make sure module base path points to an existing module
     if ($this->requestedModule === null || !$this->requestedModule->isActive()) {
         $this->moduleBasePath = '/';
         $this->requestedModule = Application::getModuleManager()->findModuleByBasePath($this->moduleBasePath, $this->isFrontendRequest);
     }
     // set module request URI
     $this->setModuleRequestUri(new Uri('/' . ltrim(StringUtil::getSubstring($requestPath, StringUtil::getLength($this->isFrontendRequest ? $frontendBaseUrl->getPath() : $backendBaseUrl->getPath()) + StringUtil::getLength($this->moduleBasePath)), '/')));
     $this->getModuleRequestUri()->setQuery($this->getRequest()->getUri()->getQuery());
 }
 /**
  * Sends cookies.
  *
  * @return void
  */
 private function sendCookies()
 {
     if (!$this->getResponse()->getCookies()->isEmpty()) {
         // get default path
         $defaultPath = EnvironmentUtil::getSitePath();
         // get default domain (prepend dot (.) to make cookie available at sub-domains)
         $defaultDomain = sprintf('.%s', EnvironmentUtil::getSiteUrl()->getHost());
         // set all the cookies
         /** @var \Ableron\Lib\Http\HttpCookie $cookie */
         foreach ($this->getResponse()->getCookies() as $cookie) {
             // make sure cookie path is at least the site path
             if ($cookie->getPath() === '/') {
                 $cookie->setPath($defaultPath);
             }
             // make sure domain is set (do not set localhost as domain as this causes cookies not to be set in Opera/Chrome/IE)
             if ($cookie->getDomain() === '' && $defaultDomain !== '.localhost') {
                 $cookie->setDomain($defaultDomain);
             }
             // set cookie
             setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpirationTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
         }
     }
 }