Completed
Push — master ( 32ca2f...3d4ee7 )
by Andreas
16:33
created

midcom_response_relocate::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 6
rs 10
1
<?php
2
/**
3
 * @package midcom
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
11
/**
12
 * Wrapper for HTTP relocate responses
13
 *
14
 * @package midcom
15
 */
16
class midcom_response_relocate extends RedirectResponse
17
{
18 53
    public function setTargetUrl($url)
19
    {
20 53
        if (   substr($url, 0, 1) != "/"
21 53
            && !preg_match('|^https?://|', $url)) {
22 29
            $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
23 29
            if ($prefix == '') {
24
                $prefix = '/';
25
            }
26 29
            $url = $prefix . $url;
27 29
            debug_add("This is a relative URL from the local site, prepending anchor prefix: {$url}");
28
        }
29 53
        return parent::setTargetUrl($url);
30
    }
31
32
    public function send()
33
    {
34
        if (defined('OPENPSA2_UNITTEST_RUN')) {
35
            throw new openpsa_test_relocate($this->targetUrl, $this->getStatusCode());
36
        }
37
38
        midcom::get()->cache->content->no_cache();
39
        debug_add("Relocating to {$this->targetUrl}");
40
        return parent::send();
41
    }
42
}
43