Example #1
0
 /**
  * __invoke
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param callable|null     $next
  *
  * @return ResponseInterface
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     // @todo Set from request site
     $redirectUrl = $this->redirectService->getRedirectUrl();
     if (!empty($redirect)) {
         $response = $response->withHeader('Location', $redirectUrl);
         return $response->withStatus(302);
     }
     return $next($request, $response);
 }
Example #2
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)
 {
     if ($this->isConsoleRequest()) {
         return null;
     }
     // User defaults
     $redirectUrl = $this->redirectService->getRedirectUrl();
     if (empty($redirectUrl)) {
         return null;
     }
     header('Location: ' . $redirectUrl, 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;
             */
 }