ICanBoogie/HTTP v2.4.0
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Exception
    • HTTP
      • Dispatcher
      • Headers
      • Request

Classes

  • ICanBoogie\Exception\RescueEvent
  • ICanBoogie\HTTP\CallableDispatcher
  • ICanBoogie\HTTP\Dispatcher
  • ICanBoogie\HTTP\Dispatcher\BeforeDispatchEvent
  • ICanBoogie\HTTP\Dispatcher\DispatchEvent
  • ICanBoogie\HTTP\File
  • ICanBoogie\HTTP\FileInfo
  • ICanBoogie\HTTP\FileList
  • ICanBoogie\HTTP\Headers
  • ICanBoogie\HTTP\Headers\CacheControl
  • ICanBoogie\HTTP\Headers\ContentDisposition
  • ICanBoogie\HTTP\Headers\ContentType
  • ICanBoogie\HTTP\Headers\Date
  • ICanBoogie\HTTP\Headers\Header
  • ICanBoogie\HTTP\Headers\HeaderParameter
  • ICanBoogie\HTTP\Helpers
  • ICanBoogie\HTTP\RedirectResponse
  • ICanBoogie\HTTP\Request
  • ICanBoogie\HTTP\Request\Context
  • ICanBoogie\HTTP\Response
  • ICanBoogie\HTTP\Status
  • ICanBoogie\HTTP\WeightedDispatcher

Interfaces

  • ICanBoogie\HTTP\DispatcherInterface
  • ICanBoogie\HTTP\Exception

Exceptions

  • ICanBoogie\HTTP\DispatcherNotDefined
  • ICanBoogie\HTTP\ForceRedirect
  • ICanBoogie\HTTP\MethodNotSupported
  • ICanBoogie\HTTP\NotFound
  • ICanBoogie\HTTP\ServiceUnavailable
  • ICanBoogie\HTTP\StatusCodeNotValid
 1 <?php
 2 
 3 /*
 4  * This file is part of the ICanBoogie package.
 5  *
 6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
 7  *
 8  * For the full copyright and license information, please view the LICENSE
 9  * file that was distributed with this source code.
10  */
11 
12 namespace ICanBoogie\HTTP;
13 
14 /**
15  * A HTTP response doing a redirect.
16  */
17 class RedirectResponse extends Response
18 {
19     /**
20      * Initializes the `Location` header.
21      *
22      * @param string $url URL to redirect to.
23      * @param int $status Status code (default to 302).
24      * @param array $headers Additional headers.
25      *
26      * @throws \InvalidArgumentException if the provided status code is not a redirect.
27      */
28     public function __construct($url, $status = 302, array $headers = [])
29     {
30         parent::__construct
31         (
32             function(Response $response) {
33 
34                 $location = $response->location;
35                 $title = \ICanBoogie\escape($location);
36 
37                 echo <<<EOT
38 <!DOCTYPE html>
39 <html>
40 <head>
41     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
42     <meta http-equiv="refresh" content="1;url={$location}" />
43 
44     <title>Redirecting to {$title}</title>
45 </head>
46 <body>
47     Redirecting to <a href="{$location}">{$title}</a>.
48 </body>
49 </html>
50 EOT
51 ; // @codeCoverageIgnore
52             },
53 
54             $status, [ 'Location' => $url ] + $headers
55         );
56 
57         if (!$this->status->is_redirect)
58         {
59             throw new StatusCodeNotValid($this->status->code, "The HTTP status code is not a redirect: {$status}.");
60         }
61     }
62 }
63 
ICanBoogie/HTTP v2.4.0 API documentation generated by ApiGen