Completed
Push — 4.0 ( ad8a54...ed771a )
by Marco
06:33
created

Status301::consolidate()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 19
cp 0
rs 8.8571
cc 3
eloc 8
nc 3
nop 0
crap 12
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     GPL-3.0+
12
 *
13
 * LICENSE:
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27
 */
28
29
class Status301 extends Status200 {
30
31
    public function consolidate() {
32
33
        $location = $this->response()->location()->get();
34
35
        if ( empty($location) ) throw new Exception("Invalid location, cannot redirect");
36
37
        $this->response()->headers()->set("Location: ".$location);
38
39
        if ( empty($this->response->content()->get()) ) {
40
41
            $this->response->content()->set(sprintf('<!DOCTYPE html>
42
<html>
43
    <head>
44
        <meta charset="UTF-8" />
45
        <meta http-equiv="refresh" content="1;url=%1$s" />
46
        <title>Redirecting to %1$s</title>
47
    </head>
48
    <body>
49
        Redirecting to <a href="%1$s">%1$s</a>.
50
    </body>
51
</html>', htmlspecialchars($location, ENT_QUOTES, 'UTF-8')));
52
53
        }
54
55
        parent::consolidate();
56
57
    }
58
59
}
60