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