base::uri()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 12
rs 10
1
<?php
2
/**
3
 * ==================================
4
 * Responsible PHP API
5
 * ==================================
6
 *
7
 * @link Git https://github.com/vince-scarpa/responsibleAPI.git
8
 *
9
 * @api Responible API
10
 * @package responsible\core\route
11
 *
12
 * @author Vince scarpa <[email protected]>
13
 *
14
 */
15
namespace responsible\core\route;
16
17
class base
18
{
19
    /**
20
     * [base_url]
21
     * @return string
22
     */
23
    public function url()
24
    {
25
        $protocol = $this->protocol();
26
27
        $base_url = $protocol . '://' . $_SERVER['HTTP_HOST'];
28
29
        return $base_url;
30
    }
31
32
    /**
33
     * [base_uri]
34
     * @return string
35
     */
36
    public function uri()
37
    {
38
        $basepath = $this->basepath();
39
40
        $uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
41
42
        if (strstr($uri, '?')) {
43
            $uri = substr($uri, 0, strpos($uri, '?'));
44
        }
45
        $uri = '/' . trim($uri, '/');
46
47
        return $uri;
48
    }
49
50
    /**
51
     * [basepath]
52
     * @return string
53
     */
54
    public function basepath()
55
    {
56
        $scriptName = ltrim($_SERVER['SCRIPT_NAME']);
0 ignored issues
show
Unused Code introduced by
The assignment to $scriptName is dead and can be removed.
Loading history...
57
        $uri = array_values(array_filter(explode('/', $_SERVER['SCRIPT_NAME'])));
58
        return '/'.implode('/', array_slice($uri, 0, 1)).'/';
59
    }
60
61
    /**
62
     * [protocol]
63
     * @return string
64
     */
65
    public function protocol()
66
    {
67
        $https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
68
        return ($https) ? 'https' : 'http';
69
    }
70
}
71