Completed
Push — master ( 27c34d...eab493 )
by Restu
03:04
created

Request::createFromGlobals()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.439
cc 6
eloc 13
nc 10
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
     * Return IP address client
62
     *
63
     * @return string
64
     */
65
    public function ip()
66
    {
67
        return $this->getClientIp();
68
    }
69
70
    /**
71
     * Return IP address client
72
     *
73
     * @return array
74
     */
75
    public function ipAll()
76
    {
77
        return $this->getClientIps();
78
    }
79
80
    /**
81
     * Creates a new request with values from PHP's super globals.
82
     *
83
     * @return Request A new request
84
     */
85
    public static function createFromSymfonyGlobal()
86
    {
87
        $baseRequest = BaseRequest::createFromGlobals();
88
89
        $query = $baseRequest->query->all();
90
        $request = $baseRequest->request->all();
91
        $attributes = array();
92
        $cookies = $baseRequest->cookies->all();
93
        $files = $baseRequest->files->all();
94
        $server = $baseRequest->server->all();
95
        $content = $baseRequest->content->all();
0 ignored issues
show
Bug introduced by
The method all cannot be called on $baseRequest->content (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
96
97
        return new static($query, $request, $attributes, $cookies, $files, $server, $content);
98
    }
99
}
100