Ejemplo n.º 1
0
 /**
  * Check the defined redirects.  If requested URL is found, redirect to the
  * new location.
  *
  * @param MvcEvent $event Zend MVC Event
  *
  * @return null|Response
  */
 public function checkRedirect(MvcEvent $event)
 {
     $siteId = $this->currentSite->getSiteId();
     if (empty($siteId)) {
         return null;
     }
     /** @var \Zend\Http\PhpEnvironment\Request $request */
     $request = $event->getRequest();
     $serverParam = $request->getServer();
     $requestUri = $serverParam->get('REQUEST_URI');
     $baseUri = explode('?', $requestUri);
     $requestUrl = $baseUri[0];
     $redirect = $this->redirectRepo->getRedirect($requestUrl, $siteId);
     if (!empty($redirect)) {
         header('Location: ' . $redirect->getRedirectUrl(), true, 302);
         exit;
         /* Below is the ZF2 way but Response is not short-circuiting the event like it should */
         //            $response = new Response();
         //            $response->setStatusCode(302);
         //            $response->getHeaders()
         //                ->addHeaderLine(
         //                    'Location',
         //                    $redirect->getRedirectUrl()
         //                );
         //            $event->stopPropagation(true);
         //
         //            return $response;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * getRedirectUrl
  *
  * @param int|null    $siteId
  * @param string|null $requestUrl
  *
  * @return null
  */
 public function getRedirectUrl($siteId = null, $requestUrl = null)
 {
     if (empty($siteId)) {
         $siteId = $this->siteService->getCurrentSite()->getSiteId();
     }
     if (empty($siteId)) {
         return null;
     }
     if (empty($requestUrl)) {
         $requestUrl = $this->getRequestUrl();
     }
     $redirect = $this->redirectRepo->getRedirect($requestUrl, $siteId);
     if (!empty($redirect)) {
         return $redirect->getRedirectUrl();
     }
     return null;
 }