These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | */ |
||
5 | |||
6 | namespace Mvc5\Request\Config; |
||
7 | |||
8 | use Mvc5\Arg; |
||
9 | use Mvc5\Http\Config\Request as HttpRequest; |
||
10 | use Mvc5\Http\Error; |
||
11 | |||
12 | trait Request |
||
13 | { |
||
14 | /** |
||
15 | * |
||
16 | */ |
||
17 | use HttpRequest; |
||
18 | |||
19 | /** |
||
20 | * @param $name |
||
21 | * @return mixed |
||
22 | */ |
||
23 | 4 | function arg($name) |
|
0 ignored issues
–
show
|
|||
24 | { |
||
25 | 4 | return $this->get(Arg::ARGS)[$name] ?? null; |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * @return array |
||
30 | */ |
||
31 | 3 | function args() |
|
0 ignored issues
–
show
|
|||
32 | { |
||
33 | 3 | return $this[Arg::ARGS] ?: []; |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return mixed |
||
38 | */ |
||
39 | 1 | function clientAddress() |
|
0 ignored issues
–
show
|
|||
40 | { |
||
41 | 1 | return $this[Arg::CLIENT_ADDRESS]; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return mixed |
||
46 | */ |
||
47 | 1 | function contentType() |
|
0 ignored issues
–
show
|
|||
48 | { |
||
49 | 1 | return $this[Arg::CONTENT_TYPE]; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return array|callable|null|object|string |
||
54 | */ |
||
55 | 20 | function controller() |
|
0 ignored issues
–
show
|
|||
56 | { |
||
57 | 20 | return $this[Arg::CONTROLLER]; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param $name |
||
62 | * @return array|\ArrayAccess |
||
63 | */ |
||
64 | 1 | function cookie($name) |
|
0 ignored issues
–
show
|
|||
65 | { |
||
66 | 1 | return $this->get(Arg::COOKIES)[$name] ?? null; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return array|\ArrayAccess |
||
71 | */ |
||
72 | 1 | function cookies() |
|
0 ignored issues
–
show
|
|||
73 | { |
||
74 | 1 | return $this[Arg::COOKIES] ?: []; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param $name |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 5 | function data($name = null) |
|
0 ignored issues
–
show
|
|||
82 | { |
||
83 | 5 | return null === $name ? ($this[Arg::DATA] ?: []) : ($this->get(Arg::DATA)[$name] ?? null); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return Error |
||
88 | */ |
||
89 | 3 | function error() |
|
0 ignored issues
–
show
|
|||
90 | { |
||
91 | 3 | return $this[Arg::ERROR]; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return array |
||
96 | */ |
||
97 | 2 | function files() |
|
0 ignored issues
–
show
|
|||
98 | { |
||
99 | 2 | return $this[Arg::FILES] ?: []; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param $name |
||
104 | * @return string |
||
105 | */ |
||
106 | 2 | function header($name) |
|
0 ignored issues
–
show
|
|||
107 | { |
||
108 | 2 | return $this->get(Arg::HEADERS)[$name] ?? null; |
|
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return string|string[] |
||
113 | */ |
||
114 | 6 | function host() |
|
0 ignored issues
–
show
|
|||
115 | { |
||
116 | 6 | return $this->get(Arg::URI)[Arg::HOST] ?? null; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return bool |
||
121 | */ |
||
122 | 1 | function isPost() |
|
0 ignored issues
–
show
|
|||
123 | { |
||
124 | 1 | return 'POST' === $this->method(); |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return bool |
||
129 | */ |
||
130 | 1 | function isSecure() |
|
0 ignored issues
–
show
|
|||
131 | { |
||
132 | 1 | return 'https' === $this->scheme(); |
|
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return bool |
||
137 | */ |
||
138 | 1 | function isXmlHttpRequest() |
|
0 ignored issues
–
show
|
|||
139 | { |
||
140 | 1 | return 'XMLHttpRequest' == $this->header('X-Requested-With'); |
|
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return string |
||
145 | */ |
||
146 | 16 | function name() |
|
0 ignored issues
–
show
|
|||
147 | { |
||
148 | 16 | return $this[Arg::NAME]; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * @param $name |
||
153 | * @return mixed |
||
154 | */ |
||
155 | 3 | function param($name) |
|
0 ignored issues
–
show
|
|||
156 | { |
||
157 | 3 | return $this->get(Arg::PARAMS)[$name] ?? null; |
|
158 | } |
||
159 | |||
160 | /** |
||
161 | * @return array |
||
162 | */ |
||
163 | 33 | function params() |
|
0 ignored issues
–
show
|
|||
164 | { |
||
165 | 33 | return $this[Arg::PARAMS] ?: []; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | */ |
||
171 | 23 | function path() |
|
0 ignored issues
–
show
|
|||
172 | { |
||
173 | 23 | return $this->get(Arg::URI)[Arg::PATH] ?? Arg::SEPARATOR; |
|
174 | } |
||
175 | |||
176 | /** |
||
177 | * @return int|null|string |
||
178 | */ |
||
179 | 4 | function port() |
|
0 ignored issues
–
show
|
|||
180 | { |
||
181 | 4 | return $this->get(Arg::URI)[Arg::PORT] ?? null; |
|
182 | } |
||
183 | |||
184 | /** |
||
185 | * @param $name |
||
186 | * @return array |
||
187 | */ |
||
188 | 1 | function post($name = null) |
|
0 ignored issues
–
show
|
|||
189 | { |
||
190 | 1 | return $this->data($name); |
|
191 | } |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | 1 | function query() |
|
0 ignored issues
–
show
|
|||
197 | { |
||
198 | 1 | return $this->get(Arg::URI)[Arg::QUERY] ?? null; |
|
199 | } |
||
200 | |||
201 | /** |
||
202 | * @return string|string[] |
||
203 | */ |
||
204 | 6 | function scheme() |
|
0 ignored issues
–
show
|
|||
205 | { |
||
206 | 6 | return $this->get(Arg::URI)[Arg::SCHEME] ?? null; |
|
207 | } |
||
208 | |||
209 | /** |
||
210 | * @param $name |
||
211 | * @return array|\ArrayAccess |
||
212 | */ |
||
213 | 2 | function server($name = null) |
|
0 ignored issues
–
show
|
|||
214 | { |
||
215 | 2 | return null === $name ? ($this[Arg::SERVER] ?: []) : ($this->get(Arg::SERVER)[$name] ?? null); |
|
216 | } |
||
217 | |||
218 | /** |
||
219 | * @param $name |
||
220 | * @return array|\ArrayAccess |
||
221 | */ |
||
222 | 2 | function session($name = null) |
|
0 ignored issues
–
show
|
|||
223 | { |
||
224 | 2 | return null === $name ? ($this[Arg::SESSION] ?: []) : ($this->get(Arg::SESSION)[$name] ?? null); |
|
225 | } |
||
226 | |||
227 | /** |
||
228 | * @return resource |
||
229 | */ |
||
230 | 1 | function stream() |
|
0 ignored issues
–
show
|
|||
231 | { |
||
232 | 1 | return $this[Arg::STREAM]; |
|
233 | } |
||
234 | |||
235 | /** |
||
236 | * @return mixed |
||
237 | */ |
||
238 | 1 | function user() |
|
0 ignored issues
–
show
|
|||
239 | { |
||
240 | 1 | return $this[Arg::USER]; |
|
241 | } |
||
242 | |||
243 | /** |
||
244 | * @return mixed |
||
245 | */ |
||
246 | 1 | function userAgent() |
|
0 ignored issues
–
show
|
|||
247 | { |
||
248 | 1 | return $this[Arg::USER_AGENT]; |
|
249 | } |
||
250 | |||
251 | /** |
||
252 | * @param $name |
||
253 | * @return mixed |
||
254 | */ |
||
255 | 2 | function variable($name) |
|
0 ignored issues
–
show
|
|||
256 | { |
||
257 | 2 | return $this->param($name) ?? $this->arg($name) ?? $this->data($name); |
|
258 | } |
||
259 | |||
260 | /** |
||
261 | * @return array |
||
262 | */ |
||
263 | 1 | function vars() |
|
0 ignored issues
–
show
|
|||
264 | { |
||
265 | 1 | return $this->params() + $this->args() + $this->data(); |
|
266 | } |
||
267 | } |
||
268 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.