-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: RedirectResponse is defined in Response
- Loading branch information
Olivier Laviale
committed
Sep 14, 2014
1 parent
310dc4f
commit 3a01807
Showing
2 changed files
with
61 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ICanBoogie package. | ||
* | ||
* (c) Olivier Laviale <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ICanBoogie\HTTP; | ||
|
||
/** | ||
* A HTTP response doing a redirect. | ||
*/ | ||
class RedirectResponse extends Response | ||
{ | ||
/** | ||
* Initializes the `Location` header. | ||
* | ||
* @param string $url URL to redirect to. | ||
* @param int $status Status code (default to 302). | ||
* @param array $headers Additional headers. | ||
* | ||
* @throws \InvalidArgumentException if the provided status code is not a redirect. | ||
*/ | ||
public function __construct($url, $status=302, array $headers=[]) | ||
{ | ||
parent::__construct | ||
( | ||
function($response) { | ||
|
||
$location = $response->location; | ||
$title = \ICanBoogie\escape($location); | ||
|
||
echo <<<EOT | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<meta http-equiv="refresh" content="1;url={$location}" /> | ||
<title>Redirecting to {$title}</title> | ||
</head> | ||
<body> | ||
Redirecting to <a href="{$location}">{$title}</a>. | ||
</body> | ||
</html> | ||
EOT; | ||
}, | ||
|
||
$status, [ 'Location' => $url ] + $headers | ||
); | ||
|
||
if (!$this->is_redirect) | ||
{ | ||
throw new \InvalidArgumentException("The HTTP status code is not a redirect: {$status}."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters