Ejemplo n.º 1
0
 /**
  * Check the domain is a known domain for the CMS.  If not the primary, it will
  * redirect the user to the primary domain.  Useful for multiple domain sites.
  *
  * @param MvcEvent $event Zend MVC Event
  *
  * @return null|Response
  */
 public function checkDomain(MvcEvent $event)
 {
     if ($this->isConsoleRequest()) {
         return null;
     }
     $currentDomain = $this->siteService->getCurrentDomain();
     $site = $this->siteService->getCurrentSite($currentDomain);
     $redirectUrl = $this->domainRedirectService->getSiteNotAvailableRedirectUrl($site);
     if (!$site->isSiteAvailable() && empty($redirectUrl)) {
         $response = new Response();
         $response->setStatusCode(404);
         $event->stopPropagation(true);
         return $response;
     }
     if ($redirectUrl) {
         $response = new Response();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', '//' . $redirectUrl);
         $event->stopPropagation(true);
         return $response;
     }
     $redirectUrl = $this->domainRedirectService->getPrimaryRedirectUrl($site);
     if ($redirectUrl) {
         $response = new Response();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', '//' . $redirectUrl);
         $event->stopPropagation(true);
         return $response;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * __invoke
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param callable|null     $next
  *
  * @return ResponseInterface
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     if ($this->isConsoleRequest()) {
         return $next($request, $response);
     }
     $currentDomain = $this->siteService->getCurrentDomain();
     $site = $this->siteService->getCurrentSite($currentDomain);
     $redirectUrl = $this->domainRedirectService->getSiteNotAvailableRedirectUrl($site);
     if (!$site->isSiteAvailable() && empty($redirectUrl)) {
         return $response->withStatus(404);
     }
     if ($redirectUrl) {
         $response = $response->withHeader('Location', '//' . $redirectUrl);
         return $response->withStatus(302);
     }
     $redirectUrl = $this->domainRedirectService->getPrimaryRedirectUrl($site);
     if ($redirectUrl) {
         $response = $response->withHeader('Location', '//' . $redirectUrl);
         return $response->withStatus(302);
     }
     return $next($request, $response);
 }