Completed
Push — master ( 4c517c...5a2ca5 )
by Restu
12:42
created

Request::refererURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace JayaCode\Framework\Core\Http;
3
4
use Symfony\Component\HttpFoundation\Request as BaseRequest;
5
6
class Request extends BaseRequest
7
{
8
9
    /**
10
     * Get the current path info for the request.
11
     *
12
     * @return string
13
     */
14
    public function path()
15
    {
16
        $pattern = trim($this->getPathInfo(), '/');
17
        return $pattern == '' ? '/' : $pattern;
18
    }
19
20
    /**
21
     * Get the request method.
22
     *
23
     * @return string
24
     */
25
    public function method()
26
    {
27
        return $this->getMethod();
28
    }
29
30
    /**
31
     * Get the root URL
32
     *
33
     * @return string
34
     */
35
    public function rootURL()
36
    {
37
        return rtrim($this->getSchemeAndHttpHost().$this->getBaseUrl(), '/');
38
    }
39
40
    /**
41
     * Return true if server HTTP_REFERER isset
42
     *
43
     * @return bool
44
     */
45
    public function hasRefererURL()
46
    {
47
        return $this->server->has("HTTP_REFERER");
48
    }
49
50
    /**
51
     * Return server HTTP_REFERER
52
     *
53
     * @return string
54
     */
55
    public function refererURL()
56
    {
57
        return $this->server->get("HTTP_REFERER");
58
    }
59
60
    /**
61
     * Creates a new request with values from PHP's super globals.
62
     *
63
     * @return Request A new request
64
     */
65
    public static function createFromSymfonyGlobal()
66
    {
67
        $baseRequest = BaseRequest::createFromGlobals();
68
69
        $query = $baseRequest->query->all();
70
        $request = $baseRequest->request->all();
71
        $attributes = array();
72
        $cookies = $baseRequest->cookies->all();
73
        $files = $baseRequest->files->all();
74
        $server = $baseRequest->server->all();
75
        $content = $baseRequest->getContent();
76
77
        return new static($query, $request, $attributes, $cookies, $files, $server, $content);
78
    }
79
}
80