-
Notifications
You must be signed in to change notification settings - Fork 1
/
Status301.php
61 lines (47 loc) · 1.6 KB
/
Status301.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php namespace Comodojo\Dispatcher\Response\Preprocessor;
use \Comodojo\Dispatcher\Response\Model as Response;
use \Exception;
/**
* Status: Moved Permanently
*
* @package Comodojo Dispatcher
* @author Marco Giovinazzi <marco.giovinazzi@comodojo.org>
* @license MIT
*
* LICENSE:
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
class Status301 extends Status200 {
/**
* {@inheritdoc}
*/
public function consolidate(Response $response) {
$location = $response->getLocation()->get();
if (empty($location)) {
throw new Exception("Invalid location, cannot redirect");
}
$response->getHeaders()->set("Location", $location);
$content = $response->getContent();
if (empty($content->get())) {
$content->set(sprintf('<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="1;url=%1$s" />
<title>Redirecting to %1$s</title>
</head>
<body>
Redirecting to <a href="%1$s">%1$s</a>.
</body>
</html>', htmlspecialchars($location, ENT_QUOTES, 'UTF-8')));
}
parent::consolidate();
}
}