Symfony\Component\HttpFoundation\Response::isRedirect PHP Method

isRedirect() public method

Is the response a redirect of some form?
public isRedirect ( string $location = null ) : boolean
$location string
return boolean
    public function isRedirect($location = null)
    {
        return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
    }

Usage Example

Example #1
0
 public function handle(Event $event, Response $response)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
         return $response;
     }
     if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
         $response->setContent(sprintf('<html><head></head><body><h1>This Request redirects to<br /><a href="%s">%s</a>.</h1></body></html>', $response->headers->get('location'), $response->headers->get('location')));
         $response->setStatusCode(200);
         $response->headers->delete('Location');
     }
     $request = $event->getParameter('request');
     if (!$response->headers->has('X-Debug-Token') || '3' === substr($response->getStatusCode(), 0, 1) || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || $request->isXmlHttpRequest()) {
         return $response;
     }
     $this->injectToolbar($request, $response);
     return $response;
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Response::isRedirect