Passed
Push — master ( 73f345...78312e )
by Radu
01:42
created

ResponseUrlTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reload() 0 4 1
A redirectUrl() 0 6 1
A redirect() 0 8 2
1
<?php
2
namespace WebServCo\Framework\Traits;
3
4
trait ResponseUrlTrait
5
{
6
    abstract protected function request();
7
    
8
    /**
9
     * Redirect to an application location (Request target).
10
     */
11
    final protected function redirect($location, $addSuffix = true)
12
    {
13
        $url = $this->request()->getAppUrl();
14
        $url .= $location;
15
        if ($addSuffix) {
16
            $url .= $this->request()->getSuffix();
17
        }
18
        return $this->redirectUrl($url);
19
    }
20
    
21
    /**
22
     * Redirect to the current URL
23
     */
24
    final protected function reload($removeParameters = [])
25
    {
26
        $url = $this->request()->getUrl($removeParameters);
27
        return $this->redirectUrl($url);
28
    }
29
    
30
    /**
31
     * Redirect to a full URL
32
     */
33
    final protected function redirectUrl($url)
34
    {
35
        return new \WebServCo\Framework\Libraries\HttpResponse(
36
            null,
37
            302,
38
            ['Location' => $url]
39
        );
40
    }
41
}
42