@@ -39,903 +39,903 @@ |
||
39 | 39 | */ |
40 | 40 | class Request |
41 | 41 | { |
42 | - /** |
|
43 | - * Holds the global active request instance. |
|
44 | - * |
|
45 | - * @var bool $requestURI |
|
46 | - */ |
|
47 | - protected static $requestURI; |
|
48 | - |
|
49 | - /** |
|
50 | - * The base URL. |
|
51 | - * |
|
52 | - * @var string $baseUrl |
|
53 | - */ |
|
54 | - protected $baseUrl; |
|
55 | - |
|
56 | - /** |
|
57 | - * Gets cookies ($_COOKIE). |
|
58 | - * |
|
59 | - * @var string $cookies |
|
60 | - */ |
|
61 | - public $cookies; |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets the string with format JSON. |
|
65 | - * |
|
66 | - * @var string|resource|null $content |
|
67 | - */ |
|
68 | - protected $content; |
|
69 | - |
|
70 | - /** |
|
71 | - * The default Locale this request. |
|
72 | - * |
|
73 | - * @var string $defaultLocale |
|
74 | - */ |
|
75 | - protected $defaultLocale = 'en'; |
|
42 | + /** |
|
43 | + * Holds the global active request instance. |
|
44 | + * |
|
45 | + * @var bool $requestURI |
|
46 | + */ |
|
47 | + protected static $requestURI; |
|
48 | + |
|
49 | + /** |
|
50 | + * The base URL. |
|
51 | + * |
|
52 | + * @var string $baseUrl |
|
53 | + */ |
|
54 | + protected $baseUrl; |
|
55 | + |
|
56 | + /** |
|
57 | + * Gets cookies ($_COOKIE). |
|
58 | + * |
|
59 | + * @var string $cookies |
|
60 | + */ |
|
61 | + public $cookies; |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets the string with format JSON. |
|
65 | + * |
|
66 | + * @var string|resource|null $content |
|
67 | + */ |
|
68 | + protected $content; |
|
69 | + |
|
70 | + /** |
|
71 | + * The default Locale this request. |
|
72 | + * |
|
73 | + * @var string $defaultLocale |
|
74 | + */ |
|
75 | + protected $defaultLocale = 'en'; |
|
76 | 76 | |
77 | - /** |
|
78 | - * Gets files request ($_FILES). |
|
79 | - * |
|
80 | - * @var string $files |
|
81 | - */ |
|
82 | - public $files; |
|
83 | - |
|
84 | - /** |
|
85 | - * The detected uri and server variables. |
|
86 | - * |
|
87 | - * @var string $http |
|
88 | - */ |
|
89 | - protected $http; |
|
90 | - |
|
91 | - /** |
|
92 | - * The decoded JSON content for the request. |
|
93 | - * |
|
94 | - * @var \Syscodes\Http\Contributors\Parameters|null $json |
|
95 | - */ |
|
96 | - protected $json; |
|
97 | - |
|
98 | - /** |
|
99 | - * The current language of the application. |
|
100 | - * |
|
101 | - * @var string $languages |
|
102 | - */ |
|
103 | - protected $languages; |
|
77 | + /** |
|
78 | + * Gets files request ($_FILES). |
|
79 | + * |
|
80 | + * @var string $files |
|
81 | + */ |
|
82 | + public $files; |
|
83 | + |
|
84 | + /** |
|
85 | + * The detected uri and server variables. |
|
86 | + * |
|
87 | + * @var string $http |
|
88 | + */ |
|
89 | + protected $http; |
|
90 | + |
|
91 | + /** |
|
92 | + * The decoded JSON content for the request. |
|
93 | + * |
|
94 | + * @var \Syscodes\Http\Contributors\Parameters|null $json |
|
95 | + */ |
|
96 | + protected $json; |
|
97 | + |
|
98 | + /** |
|
99 | + * The current language of the application. |
|
100 | + * |
|
101 | + * @var string $languages |
|
102 | + */ |
|
103 | + protected $languages; |
|
104 | 104 | |
105 | - /** |
|
106 | - * The method name. |
|
107 | - * |
|
108 | - * @var string $method |
|
109 | - */ |
|
110 | - protected $method; |
|
111 | - |
|
112 | - /** |
|
113 | - * The path info of URL. |
|
114 | - * |
|
115 | - * @var string $pathInfo |
|
116 | - */ |
|
117 | - protected $pathInfo; |
|
118 | - |
|
119 | - /** |
|
120 | - * Request body parameters ($_POST). |
|
121 | - * |
|
122 | - * @var \Syscodes\Http\Contributors\Parameters $request |
|
123 | - */ |
|
124 | - public $request; |
|
125 | - |
|
126 | - /** |
|
127 | - * Get request URI. |
|
128 | - * |
|
129 | - * @var string $requestToURI |
|
130 | - */ |
|
131 | - protected $requestToURI; |
|
132 | - |
|
133 | - /** |
|
134 | - * The detected uri and server variables ($_FILES). |
|
135 | - * |
|
136 | - * @var array $server |
|
137 | - */ |
|
138 | - public $server = []; |
|
139 | - |
|
140 | - /** |
|
141 | - * List of routes uri. |
|
142 | - * |
|
143 | - * @var string|array $uri |
|
144 | - */ |
|
145 | - public $uri; |
|
146 | - |
|
147 | - /** |
|
148 | - * Stores the valid locale codes. |
|
149 | - * |
|
150 | - * @var array $validLocales |
|
151 | - */ |
|
152 | - protected $validLocales = []; |
|
153 | - |
|
154 | - /** |
|
155 | - * Constructor: Create new the Request class. |
|
156 | - * |
|
157 | - * @param array $request |
|
158 | - * @param array $cookies |
|
159 | - * @param array $files |
|
160 | - * @param array $server |
|
161 | - * @param string|resource|null $content (null by default) |
|
162 | - * |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
166 | - { |
|
167 | - static::$requestURI = $this; |
|
105 | + /** |
|
106 | + * The method name. |
|
107 | + * |
|
108 | + * @var string $method |
|
109 | + */ |
|
110 | + protected $method; |
|
111 | + |
|
112 | + /** |
|
113 | + * The path info of URL. |
|
114 | + * |
|
115 | + * @var string $pathInfo |
|
116 | + */ |
|
117 | + protected $pathInfo; |
|
118 | + |
|
119 | + /** |
|
120 | + * Request body parameters ($_POST). |
|
121 | + * |
|
122 | + * @var \Syscodes\Http\Contributors\Parameters $request |
|
123 | + */ |
|
124 | + public $request; |
|
125 | + |
|
126 | + /** |
|
127 | + * Get request URI. |
|
128 | + * |
|
129 | + * @var string $requestToURI |
|
130 | + */ |
|
131 | + protected $requestToURI; |
|
132 | + |
|
133 | + /** |
|
134 | + * The detected uri and server variables ($_FILES). |
|
135 | + * |
|
136 | + * @var array $server |
|
137 | + */ |
|
138 | + public $server = []; |
|
139 | + |
|
140 | + /** |
|
141 | + * List of routes uri. |
|
142 | + * |
|
143 | + * @var string|array $uri |
|
144 | + */ |
|
145 | + public $uri; |
|
146 | + |
|
147 | + /** |
|
148 | + * Stores the valid locale codes. |
|
149 | + * |
|
150 | + * @var array $validLocales |
|
151 | + */ |
|
152 | + protected $validLocales = []; |
|
153 | + |
|
154 | + /** |
|
155 | + * Constructor: Create new the Request class. |
|
156 | + * |
|
157 | + * @param array $request |
|
158 | + * @param array $cookies |
|
159 | + * @param array $files |
|
160 | + * @param array $server |
|
161 | + * @param string|resource|null $content (null by default) |
|
162 | + * |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
166 | + { |
|
167 | + static::$requestURI = $this; |
|
168 | 168 | |
169 | - $this->initialize($request, $cookies, $files, $server, $content); |
|
170 | - |
|
171 | - $this->detectURI(config('app.uriProtocol'), config('app.baseUrl')); |
|
172 | - |
|
173 | - $this->detectLocale(); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Sets the parameters for this request. |
|
178 | - * |
|
179 | - * @param array $request |
|
180 | - * @param array $cookies |
|
181 | - * @param array $files |
|
182 | - * @param array $server |
|
183 | - * |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
187 | - { |
|
188 | - $this->request = new Parameters($request); |
|
189 | - $this->cookies = new Inputs($cookies); |
|
190 | - $this->files = new Files($files); |
|
191 | - $this->server = new Server($server); |
|
192 | - $this->headers = new Headers($this->server->all()); |
|
193 | - |
|
194 | - $this->uri = new URI; |
|
195 | - $this->http = new Http; |
|
196 | - $this->method = null; |
|
197 | - $this->baseUrl = null; |
|
198 | - $this->content = $content; |
|
199 | - $this->pathInfo = null; |
|
200 | - $this->languages = null; |
|
201 | - $this->validLocales = config('app.supportedLocales'); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Create a new Syscodes HTTP request from server variables. |
|
206 | - * |
|
207 | - * @return static |
|
208 | - */ |
|
209 | - public static function capture() |
|
210 | - { |
|
211 | - return static::createFromRequest(static::createFromRequestGlobals()); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Creates an Syscodes request from of the Request class instance. |
|
216 | - * |
|
217 | - * @param \Syscodes\Http\Request $request |
|
218 | - * |
|
219 | - * @return static |
|
220 | - */ |
|
221 | - public static function createFromRequest($request) |
|
222 | - { |
|
223 | - $newRequest = (new static)->duplicate( |
|
224 | - $request->request->all(), $request->cookies->all(), |
|
225 | - $request->files->all(), $request->server->all() |
|
226 | - ); |
|
227 | - |
|
228 | - $newRequest->content = $request->content; |
|
229 | - |
|
230 | - return $newRequest; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Creates a new request with value from PHP's super global. |
|
235 | - * |
|
236 | - * @return static |
|
237 | - */ |
|
238 | - public static function createFromRequestGlobals() |
|
239 | - { |
|
240 | - $request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER); |
|
241 | - |
|
242 | - return $request; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Creates a new request from a factory. |
|
247 | - * |
|
248 | - * @param array $request |
|
249 | - * @param array $cookies |
|
250 | - * @param array $files |
|
251 | - * @param array $server |
|
252 | - * |
|
253 | - * @return static |
|
254 | - */ |
|
255 | - protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
256 | - { |
|
257 | - if (self::$requestURI) |
|
258 | - { |
|
259 | - $request = (self::$requestURI)($request, $cookies, $files, $server); |
|
260 | - |
|
261 | - if ( ! $request instanceof self) |
|
262 | - { |
|
263 | - throw new LogicException('The Request active must return an instance of Syscodes\Http\Request'); |
|
264 | - } |
|
265 | - |
|
266 | - return $request; |
|
267 | - } |
|
268 | - |
|
269 | - return new static($request, $cookies, $files, $server); |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Clones a request and overrides some of its parameters. |
|
274 | - * |
|
275 | - * @param array $request |
|
276 | - * @param array $cookies |
|
277 | - * @param array $files |
|
278 | - * @param array $server |
|
279 | - * |
|
280 | - * @return static |
|
281 | - */ |
|
282 | - public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
283 | - { |
|
284 | - $duplicate = clone $this; |
|
285 | - |
|
286 | - if (null !== $request) |
|
287 | - { |
|
288 | - $duplicate->request = new Parameters($request); |
|
289 | - } |
|
290 | - |
|
291 | - if (null !== $cookies) |
|
292 | - { |
|
293 | - $duplicate->cookies = new Inputs($cookies); |
|
294 | - } |
|
295 | - |
|
296 | - if (null !== $files) |
|
297 | - { |
|
298 | - $duplicate->files = new Files($files); |
|
299 | - } |
|
300 | - |
|
301 | - if (null !== $server) |
|
302 | - { |
|
303 | - $duplicate->server = new Server($server); |
|
304 | - $duplicate->headers = new Headers($duplicate->server->all()); |
|
305 | - } |
|
306 | - |
|
307 | - $duplicate->uri = new URI; |
|
308 | - $duplicate->http = new Http; |
|
309 | - $duplicate->locale = null; |
|
310 | - $duplicate->method = null; |
|
311 | - $duplicate->baseUrl = null; |
|
312 | - $duplicate->pathInfo = null; |
|
313 | - $duplicate->validLocales = config('app.supportedLocales'); |
|
314 | - |
|
315 | - return $duplicate; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns the active request currently being used. |
|
320 | - * |
|
321 | - * @param \Syscodes\Http\Request|bool|null $request Overwrite current request |
|
322 | - * before returning, false prevents |
|
323 | - * overwrite |
|
324 | - * |
|
325 | - * @return \Syscodes\Http\Request |
|
326 | - */ |
|
327 | - public static function active($request = false) |
|
328 | - { |
|
329 | - if ($request !== false) |
|
330 | - { |
|
331 | - static::$requestURI = $request; |
|
332 | - } |
|
333 | - |
|
334 | - return static::$requestURI; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Returns the desired segment, or $default if it does not exist. |
|
339 | - * |
|
340 | - * @param int $index The segment number (1-based index) |
|
341 | - * @param mixed $default Default value to return |
|
342 | - * |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - public function segment($index, $default = null) |
|
346 | - { |
|
347 | - if ($request = static::active()) |
|
348 | - { |
|
349 | - return $request->uri->getSegment($index, $default); |
|
350 | - } |
|
351 | - |
|
352 | - return null; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns all segments in an array. For total of segments |
|
357 | - * used the function PHP count(). |
|
358 | - * |
|
359 | - * @return array |
|
360 | - */ |
|
361 | - public function segments() |
|
362 | - { |
|
363 | - if ($request = static::active()) |
|
364 | - { |
|
365 | - return $request->uri->getSegments(); |
|
366 | - } |
|
367 | - |
|
368 | - return null; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Returns the total number of segment. |
|
373 | - * |
|
374 | - * @return int|null |
|
375 | - */ |
|
376 | - public function totalSegments() |
|
377 | - { |
|
378 | - if ($request = static::active()) |
|
379 | - { |
|
380 | - return $request->uri->getTotalSegments(); |
|
381 | - } |
|
382 | - |
|
383 | - return null; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Detects and returns the current URI based on a number of different server variables. |
|
388 | - * |
|
389 | - * @param string $protocol |
|
390 | - * @param string $baseUrl |
|
391 | - * |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - protected function detectURI(string $protocol, string $baseUrl) |
|
395 | - { |
|
396 | - $this->uri->setPath($this->http->detectPath($protocol)); |
|
397 | - |
|
398 | - $baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl; |
|
399 | - |
|
400 | - if ( ! empty($baseUrl)) |
|
401 | - { |
|
402 | - $this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME)); |
|
403 | - $this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST)); |
|
404 | - $this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT)); |
|
405 | - } |
|
406 | - else |
|
407 | - { |
|
408 | - if ( ! $this->http->isCli()) |
|
409 | - { |
|
410 | - exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.'); |
|
411 | - } |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Handles setting up the locale, auto-detecting of language. |
|
417 | - * |
|
418 | - * @return void |
|
419 | - */ |
|
420 | - public function detectLocale() |
|
421 | - { |
|
422 | - $this->languages = $this->defaultLocale = config('app.locale'); |
|
423 | - |
|
424 | - $this->setLocale($this->validLocales); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Returns the default locale as set. |
|
429 | - * |
|
430 | - * @return string |
|
431 | - */ |
|
432 | - public function getDefaultLocale() |
|
433 | - { |
|
434 | - return $this->defaultLocale; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Gets the current locale, with a fallback to the default. |
|
439 | - * |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - public function getLocale() |
|
443 | - { |
|
444 | - return $this->languages ?: $this->defaultLocale; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Sets the locale string for this request. |
|
449 | - * |
|
450 | - * @param string $locale |
|
451 | - * |
|
452 | - * @return \Syscodes\Http\Request |
|
453 | - */ |
|
454 | - public function setLocale($locale) |
|
455 | - { |
|
456 | - if ( ! in_array($locale, $this->validLocales)) |
|
457 | - { |
|
458 | - $locale = $this->defaultLocale; |
|
459 | - } |
|
169 | + $this->initialize($request, $cookies, $files, $server, $content); |
|
170 | + |
|
171 | + $this->detectURI(config('app.uriProtocol'), config('app.baseUrl')); |
|
172 | + |
|
173 | + $this->detectLocale(); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Sets the parameters for this request. |
|
178 | + * |
|
179 | + * @param array $request |
|
180 | + * @param array $cookies |
|
181 | + * @param array $files |
|
182 | + * @param array $server |
|
183 | + * |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
187 | + { |
|
188 | + $this->request = new Parameters($request); |
|
189 | + $this->cookies = new Inputs($cookies); |
|
190 | + $this->files = new Files($files); |
|
191 | + $this->server = new Server($server); |
|
192 | + $this->headers = new Headers($this->server->all()); |
|
193 | + |
|
194 | + $this->uri = new URI; |
|
195 | + $this->http = new Http; |
|
196 | + $this->method = null; |
|
197 | + $this->baseUrl = null; |
|
198 | + $this->content = $content; |
|
199 | + $this->pathInfo = null; |
|
200 | + $this->languages = null; |
|
201 | + $this->validLocales = config('app.supportedLocales'); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Create a new Syscodes HTTP request from server variables. |
|
206 | + * |
|
207 | + * @return static |
|
208 | + */ |
|
209 | + public static function capture() |
|
210 | + { |
|
211 | + return static::createFromRequest(static::createFromRequestGlobals()); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Creates an Syscodes request from of the Request class instance. |
|
216 | + * |
|
217 | + * @param \Syscodes\Http\Request $request |
|
218 | + * |
|
219 | + * @return static |
|
220 | + */ |
|
221 | + public static function createFromRequest($request) |
|
222 | + { |
|
223 | + $newRequest = (new static)->duplicate( |
|
224 | + $request->request->all(), $request->cookies->all(), |
|
225 | + $request->files->all(), $request->server->all() |
|
226 | + ); |
|
227 | + |
|
228 | + $newRequest->content = $request->content; |
|
229 | + |
|
230 | + return $newRequest; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Creates a new request with value from PHP's super global. |
|
235 | + * |
|
236 | + * @return static |
|
237 | + */ |
|
238 | + public static function createFromRequestGlobals() |
|
239 | + { |
|
240 | + $request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER); |
|
241 | + |
|
242 | + return $request; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Creates a new request from a factory. |
|
247 | + * |
|
248 | + * @param array $request |
|
249 | + * @param array $cookies |
|
250 | + * @param array $files |
|
251 | + * @param array $server |
|
252 | + * |
|
253 | + * @return static |
|
254 | + */ |
|
255 | + protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
256 | + { |
|
257 | + if (self::$requestURI) |
|
258 | + { |
|
259 | + $request = (self::$requestURI)($request, $cookies, $files, $server); |
|
260 | + |
|
261 | + if ( ! $request instanceof self) |
|
262 | + { |
|
263 | + throw new LogicException('The Request active must return an instance of Syscodes\Http\Request'); |
|
264 | + } |
|
265 | + |
|
266 | + return $request; |
|
267 | + } |
|
268 | + |
|
269 | + return new static($request, $cookies, $files, $server); |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Clones a request and overrides some of its parameters. |
|
274 | + * |
|
275 | + * @param array $request |
|
276 | + * @param array $cookies |
|
277 | + * @param array $files |
|
278 | + * @param array $server |
|
279 | + * |
|
280 | + * @return static |
|
281 | + */ |
|
282 | + public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
283 | + { |
|
284 | + $duplicate = clone $this; |
|
285 | + |
|
286 | + if (null !== $request) |
|
287 | + { |
|
288 | + $duplicate->request = new Parameters($request); |
|
289 | + } |
|
290 | + |
|
291 | + if (null !== $cookies) |
|
292 | + { |
|
293 | + $duplicate->cookies = new Inputs($cookies); |
|
294 | + } |
|
295 | + |
|
296 | + if (null !== $files) |
|
297 | + { |
|
298 | + $duplicate->files = new Files($files); |
|
299 | + } |
|
300 | + |
|
301 | + if (null !== $server) |
|
302 | + { |
|
303 | + $duplicate->server = new Server($server); |
|
304 | + $duplicate->headers = new Headers($duplicate->server->all()); |
|
305 | + } |
|
306 | + |
|
307 | + $duplicate->uri = new URI; |
|
308 | + $duplicate->http = new Http; |
|
309 | + $duplicate->locale = null; |
|
310 | + $duplicate->method = null; |
|
311 | + $duplicate->baseUrl = null; |
|
312 | + $duplicate->pathInfo = null; |
|
313 | + $duplicate->validLocales = config('app.supportedLocales'); |
|
314 | + |
|
315 | + return $duplicate; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns the active request currently being used. |
|
320 | + * |
|
321 | + * @param \Syscodes\Http\Request|bool|null $request Overwrite current request |
|
322 | + * before returning, false prevents |
|
323 | + * overwrite |
|
324 | + * |
|
325 | + * @return \Syscodes\Http\Request |
|
326 | + */ |
|
327 | + public static function active($request = false) |
|
328 | + { |
|
329 | + if ($request !== false) |
|
330 | + { |
|
331 | + static::$requestURI = $request; |
|
332 | + } |
|
333 | + |
|
334 | + return static::$requestURI; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Returns the desired segment, or $default if it does not exist. |
|
339 | + * |
|
340 | + * @param int $index The segment number (1-based index) |
|
341 | + * @param mixed $default Default value to return |
|
342 | + * |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + public function segment($index, $default = null) |
|
346 | + { |
|
347 | + if ($request = static::active()) |
|
348 | + { |
|
349 | + return $request->uri->getSegment($index, $default); |
|
350 | + } |
|
351 | + |
|
352 | + return null; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns all segments in an array. For total of segments |
|
357 | + * used the function PHP count(). |
|
358 | + * |
|
359 | + * @return array |
|
360 | + */ |
|
361 | + public function segments() |
|
362 | + { |
|
363 | + if ($request = static::active()) |
|
364 | + { |
|
365 | + return $request->uri->getSegments(); |
|
366 | + } |
|
367 | + |
|
368 | + return null; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Returns the total number of segment. |
|
373 | + * |
|
374 | + * @return int|null |
|
375 | + */ |
|
376 | + public function totalSegments() |
|
377 | + { |
|
378 | + if ($request = static::active()) |
|
379 | + { |
|
380 | + return $request->uri->getTotalSegments(); |
|
381 | + } |
|
382 | + |
|
383 | + return null; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Detects and returns the current URI based on a number of different server variables. |
|
388 | + * |
|
389 | + * @param string $protocol |
|
390 | + * @param string $baseUrl |
|
391 | + * |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + protected function detectURI(string $protocol, string $baseUrl) |
|
395 | + { |
|
396 | + $this->uri->setPath($this->http->detectPath($protocol)); |
|
397 | + |
|
398 | + $baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl; |
|
399 | + |
|
400 | + if ( ! empty($baseUrl)) |
|
401 | + { |
|
402 | + $this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME)); |
|
403 | + $this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST)); |
|
404 | + $this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT)); |
|
405 | + } |
|
406 | + else |
|
407 | + { |
|
408 | + if ( ! $this->http->isCli()) |
|
409 | + { |
|
410 | + exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.'); |
|
411 | + } |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Handles setting up the locale, auto-detecting of language. |
|
417 | + * |
|
418 | + * @return void |
|
419 | + */ |
|
420 | + public function detectLocale() |
|
421 | + { |
|
422 | + $this->languages = $this->defaultLocale = config('app.locale'); |
|
423 | + |
|
424 | + $this->setLocale($this->validLocales); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Returns the default locale as set. |
|
429 | + * |
|
430 | + * @return string |
|
431 | + */ |
|
432 | + public function getDefaultLocale() |
|
433 | + { |
|
434 | + return $this->defaultLocale; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Gets the current locale, with a fallback to the default. |
|
439 | + * |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + public function getLocale() |
|
443 | + { |
|
444 | + return $this->languages ?: $this->defaultLocale; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Sets the locale string for this request. |
|
449 | + * |
|
450 | + * @param string $locale |
|
451 | + * |
|
452 | + * @return \Syscodes\Http\Request |
|
453 | + */ |
|
454 | + public function setLocale($locale) |
|
455 | + { |
|
456 | + if ( ! in_array($locale, $this->validLocales)) |
|
457 | + { |
|
458 | + $locale = $this->defaultLocale; |
|
459 | + } |
|
460 | 460 | |
461 | - $this->languages = $locale; |
|
462 | - |
|
463 | - try |
|
464 | - { |
|
465 | - if (class_exists('Locale', false)) |
|
466 | - { |
|
467 | - Locale::setDefault($locale); |
|
468 | - } |
|
469 | - } |
|
470 | - catch (Exception $exception) {} |
|
471 | - |
|
472 | - return $this; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Returns the full request string. |
|
477 | - * |
|
478 | - * @return string|null The Request string |
|
479 | - */ |
|
480 | - public function get() |
|
481 | - { |
|
482 | - if ($request = static::active()) |
|
483 | - { |
|
484 | - return $request->uri->get(); |
|
485 | - } |
|
486 | - |
|
487 | - return null; |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Get the JSON payload for the request. |
|
492 | - * |
|
493 | - * @param string|null $key (null by default) |
|
494 | - * @param mixed $default (null by default) |
|
495 | - * |
|
496 | - * @return \Syscodes\Http\Contributors\Parameters|mixed |
|
497 | - */ |
|
498 | - public function json($key = null, $default = null) |
|
499 | - { |
|
500 | - if ( ! isset($this->json)) { |
|
501 | - $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
502 | - } |
|
503 | - |
|
504 | - if (is_null($key)) { |
|
505 | - return $this->json; |
|
506 | - } |
|
507 | - |
|
508 | - return Arr::get($this->json->all(), $key, $default); |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Set the JSON payload for the request |
|
513 | - * |
|
514 | - * @param \Syscodes\Http\Contributors\Parameters $json |
|
515 | - * |
|
516 | - * @return $this |
|
517 | - */ |
|
518 | - public function setJson($json) |
|
519 | - { |
|
520 | - $this->json = $json; |
|
521 | - |
|
522 | - return $this; |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * Returns whether this is an AJAX request or not. |
|
527 | - * |
|
528 | - * @return bool |
|
529 | - */ |
|
530 | - public function isXmlHttpRequest() |
|
531 | - { |
|
532 | - return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
533 | - strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
534 | - } |
|
535 | - |
|
536 | - /** |
|
537 | - * Returns the input method used (GET, POST, DELETE, etc.). |
|
538 | - * |
|
539 | - * @return string |
|
540 | - * |
|
541 | - * @throws \LogicException |
|
542 | - */ |
|
543 | - public function getmethod() |
|
544 | - { |
|
545 | - if (null !== $this->method) |
|
546 | - { |
|
547 | - return $this->method; |
|
548 | - } |
|
461 | + $this->languages = $locale; |
|
462 | + |
|
463 | + try |
|
464 | + { |
|
465 | + if (class_exists('Locale', false)) |
|
466 | + { |
|
467 | + Locale::setDefault($locale); |
|
468 | + } |
|
469 | + } |
|
470 | + catch (Exception $exception) {} |
|
471 | + |
|
472 | + return $this; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Returns the full request string. |
|
477 | + * |
|
478 | + * @return string|null The Request string |
|
479 | + */ |
|
480 | + public function get() |
|
481 | + { |
|
482 | + if ($request = static::active()) |
|
483 | + { |
|
484 | + return $request->uri->get(); |
|
485 | + } |
|
486 | + |
|
487 | + return null; |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Get the JSON payload for the request. |
|
492 | + * |
|
493 | + * @param string|null $key (null by default) |
|
494 | + * @param mixed $default (null by default) |
|
495 | + * |
|
496 | + * @return \Syscodes\Http\Contributors\Parameters|mixed |
|
497 | + */ |
|
498 | + public function json($key = null, $default = null) |
|
499 | + { |
|
500 | + if ( ! isset($this->json)) { |
|
501 | + $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
502 | + } |
|
503 | + |
|
504 | + if (is_null($key)) { |
|
505 | + return $this->json; |
|
506 | + } |
|
507 | + |
|
508 | + return Arr::get($this->json->all(), $key, $default); |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Set the JSON payload for the request |
|
513 | + * |
|
514 | + * @param \Syscodes\Http\Contributors\Parameters $json |
|
515 | + * |
|
516 | + * @return $this |
|
517 | + */ |
|
518 | + public function setJson($json) |
|
519 | + { |
|
520 | + $this->json = $json; |
|
521 | + |
|
522 | + return $this; |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * Returns whether this is an AJAX request or not. |
|
527 | + * |
|
528 | + * @return bool |
|
529 | + */ |
|
530 | + public function isXmlHttpRequest() |
|
531 | + { |
|
532 | + return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
533 | + strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | + * Returns the input method used (GET, POST, DELETE, etc.). |
|
538 | + * |
|
539 | + * @return string |
|
540 | + * |
|
541 | + * @throws \LogicException |
|
542 | + */ |
|
543 | + public function getmethod() |
|
544 | + { |
|
545 | + if (null !== $this->method) |
|
546 | + { |
|
547 | + return $this->method; |
|
548 | + } |
|
549 | 549 | |
550 | - $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
550 | + $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
551 | 551 | |
552 | - if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) |
|
553 | - { |
|
554 | - return $this->method = $method; |
|
555 | - } |
|
552 | + if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) |
|
553 | + { |
|
554 | + return $this->method = $method; |
|
555 | + } |
|
556 | 556 | |
557 | - if ( ! preg_match('~^[A-Z]++$#~D', $method)) |
|
558 | - { |
|
559 | - throw new logicException(sprintf('Invalid method override "%s"', $method)); |
|
560 | - } |
|
561 | - |
|
562 | - return $this->method = $method; |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Sets the request method. |
|
567 | - * |
|
568 | - * @param string $method |
|
569 | - * |
|
570 | - * @return string |
|
571 | - */ |
|
572 | - public function setMethod(string $method) |
|
573 | - { |
|
574 | - $this->method = null; |
|
575 | - |
|
576 | - $this->server->set('REQUEST_METHOD', $method); |
|
577 | - } |
|
557 | + if ( ! preg_match('~^[A-Z]++$#~D', $method)) |
|
558 | + { |
|
559 | + throw new logicException(sprintf('Invalid method override "%s"', $method)); |
|
560 | + } |
|
561 | + |
|
562 | + return $this->method = $method; |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Sets the request method. |
|
567 | + * |
|
568 | + * @param string $method |
|
569 | + * |
|
570 | + * @return string |
|
571 | + */ |
|
572 | + public function setMethod(string $method) |
|
573 | + { |
|
574 | + $this->method = null; |
|
575 | + |
|
576 | + $this->server->set('REQUEST_METHOD', $method); |
|
577 | + } |
|
578 | 578 | |
579 | - /** |
|
580 | - * Determine if the current request URI matches a pattern. |
|
581 | - * |
|
582 | - * @param mixed ...$patterns |
|
583 | - * |
|
584 | - * @return bool |
|
585 | - */ |
|
586 | - public function is(...$patterns) |
|
587 | - { |
|
588 | - $path = $this->decodedPath(); |
|
579 | + /** |
|
580 | + * Determine if the current request URI matches a pattern. |
|
581 | + * |
|
582 | + * @param mixed ...$patterns |
|
583 | + * |
|
584 | + * @return bool |
|
585 | + */ |
|
586 | + public function is(...$patterns) |
|
587 | + { |
|
588 | + $path = $this->decodedPath(); |
|
589 | 589 | |
590 | - foreach ($patterns as $pattern) |
|
591 | - { |
|
592 | - if (Str::is($pattern, $path)) |
|
593 | - { |
|
594 | - return true; |
|
595 | - } |
|
596 | - } |
|
597 | - |
|
598 | - return false; |
|
599 | - } |
|
600 | - |
|
601 | - /** |
|
602 | - * Determine if the route name matches a given pattern. |
|
603 | - * |
|
604 | - * @param mixed ...$patterns |
|
605 | - * |
|
606 | - * @return bool |
|
607 | - */ |
|
608 | - public function routeIs(...$patterns) |
|
609 | - { |
|
610 | - return $this->route() && $this->route()->is(...$patterns); |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Get the route handling the request. |
|
615 | - * |
|
616 | - * @param string|null $param (null by default) |
|
617 | - * @param mixed $default (null by default) |
|
618 | - * |
|
619 | - * @return \Syscodes\Routing\Route|object|string|null |
|
620 | - */ |
|
621 | - public function route($param = null, $default = null) |
|
622 | - { |
|
623 | - $route = $this->getRoute(); |
|
624 | - |
|
625 | - if (is_null($route) || is_null($param)) |
|
626 | - { |
|
627 | - return $route; |
|
628 | - } |
|
629 | - |
|
630 | - return $route->parameter($param, $default); |
|
631 | - } |
|
632 | - |
|
633 | - /** |
|
634 | - * Get the current decoded path info for the request. |
|
635 | - * |
|
636 | - * @return string |
|
637 | - */ |
|
638 | - public function decodedPath() |
|
639 | - { |
|
640 | - return rawurldecode($this->path()); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Get the current path info for the request. |
|
645 | - * |
|
646 | - * @return string |
|
647 | - */ |
|
648 | - public function path() |
|
649 | - { |
|
650 | - $path = trim($this->getPathInfo(), '/'); |
|
651 | - |
|
652 | - return $path == '' ? '/' : $path; |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Retunrs the request body content. |
|
657 | - * |
|
658 | - * @return string |
|
659 | - */ |
|
660 | - public function getContent() |
|
661 | - { |
|
662 | - if (null === $this->content || false === $this->content) |
|
663 | - { |
|
664 | - $this->content = file_get_contents('php://input'); |
|
665 | - } |
|
666 | - |
|
667 | - return $this->content; |
|
668 | - } |
|
669 | - |
|
670 | - /** |
|
671 | - * Returns the path being requested relative to the executed script. |
|
672 | - * |
|
673 | - * @return string |
|
674 | - */ |
|
675 | - public function getPathInfo() |
|
676 | - { |
|
677 | - if (null === $this->pathInfo) |
|
678 | - { |
|
679 | - $this->pathInfo = $this->http->parsePathInfo(); |
|
680 | - } |
|
681 | - |
|
682 | - return $this->pathInfo; |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * Returns the root URL from which this request is executed. |
|
687 | - * |
|
688 | - * @return string |
|
689 | - */ |
|
690 | - public function getBaseUrl() |
|
691 | - { |
|
692 | - if (null === $this->baseUrl) |
|
693 | - { |
|
694 | - $this->baseUrl = $this->http->parseBaseUrl(); |
|
695 | - } |
|
696 | - |
|
697 | - return $this->baseUrl; |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Returns the requested URI. |
|
702 | - * |
|
703 | - * @return string |
|
704 | - */ |
|
705 | - public function getRequestUri() |
|
706 | - { |
|
707 | - if (null === $this->requestToUri) |
|
708 | - { |
|
709 | - $this->requestToUri = $this->http->parseRequestUri(); |
|
710 | - } |
|
711 | - |
|
712 | - return $this->requestToUri; |
|
713 | - } |
|
590 | + foreach ($patterns as $pattern) |
|
591 | + { |
|
592 | + if (Str::is($pattern, $path)) |
|
593 | + { |
|
594 | + return true; |
|
595 | + } |
|
596 | + } |
|
597 | + |
|
598 | + return false; |
|
599 | + } |
|
600 | + |
|
601 | + /** |
|
602 | + * Determine if the route name matches a given pattern. |
|
603 | + * |
|
604 | + * @param mixed ...$patterns |
|
605 | + * |
|
606 | + * @return bool |
|
607 | + */ |
|
608 | + public function routeIs(...$patterns) |
|
609 | + { |
|
610 | + return $this->route() && $this->route()->is(...$patterns); |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Get the route handling the request. |
|
615 | + * |
|
616 | + * @param string|null $param (null by default) |
|
617 | + * @param mixed $default (null by default) |
|
618 | + * |
|
619 | + * @return \Syscodes\Routing\Route|object|string|null |
|
620 | + */ |
|
621 | + public function route($param = null, $default = null) |
|
622 | + { |
|
623 | + $route = $this->getRoute(); |
|
624 | + |
|
625 | + if (is_null($route) || is_null($param)) |
|
626 | + { |
|
627 | + return $route; |
|
628 | + } |
|
629 | + |
|
630 | + return $route->parameter($param, $default); |
|
631 | + } |
|
632 | + |
|
633 | + /** |
|
634 | + * Get the current decoded path info for the request. |
|
635 | + * |
|
636 | + * @return string |
|
637 | + */ |
|
638 | + public function decodedPath() |
|
639 | + { |
|
640 | + return rawurldecode($this->path()); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Get the current path info for the request. |
|
645 | + * |
|
646 | + * @return string |
|
647 | + */ |
|
648 | + public function path() |
|
649 | + { |
|
650 | + $path = trim($this->getPathInfo(), '/'); |
|
651 | + |
|
652 | + return $path == '' ? '/' : $path; |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * Retunrs the request body content. |
|
657 | + * |
|
658 | + * @return string |
|
659 | + */ |
|
660 | + public function getContent() |
|
661 | + { |
|
662 | + if (null === $this->content || false === $this->content) |
|
663 | + { |
|
664 | + $this->content = file_get_contents('php://input'); |
|
665 | + } |
|
666 | + |
|
667 | + return $this->content; |
|
668 | + } |
|
669 | + |
|
670 | + /** |
|
671 | + * Returns the path being requested relative to the executed script. |
|
672 | + * |
|
673 | + * @return string |
|
674 | + */ |
|
675 | + public function getPathInfo() |
|
676 | + { |
|
677 | + if (null === $this->pathInfo) |
|
678 | + { |
|
679 | + $this->pathInfo = $this->http->parsePathInfo(); |
|
680 | + } |
|
681 | + |
|
682 | + return $this->pathInfo; |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Returns the root URL from which this request is executed. |
|
687 | + * |
|
688 | + * @return string |
|
689 | + */ |
|
690 | + public function getBaseUrl() |
|
691 | + { |
|
692 | + if (null === $this->baseUrl) |
|
693 | + { |
|
694 | + $this->baseUrl = $this->http->parseBaseUrl(); |
|
695 | + } |
|
696 | + |
|
697 | + return $this->baseUrl; |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Returns the requested URI. |
|
702 | + * |
|
703 | + * @return string |
|
704 | + */ |
|
705 | + public function getRequestUri() |
|
706 | + { |
|
707 | + if (null === $this->requestToUri) |
|
708 | + { |
|
709 | + $this->requestToUri = $this->http->parseRequestUri(); |
|
710 | + } |
|
711 | + |
|
712 | + return $this->requestToUri; |
|
713 | + } |
|
714 | 714 | |
715 | - /** |
|
716 | - * Gets the request's scheme. |
|
717 | - * |
|
718 | - * @return string |
|
719 | - */ |
|
720 | - public function getScheme() |
|
721 | - { |
|
722 | - return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * Returns the host name. |
|
727 | - * |
|
728 | - * @return void |
|
729 | - */ |
|
730 | - public function getHost() |
|
731 | - { |
|
732 | - if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
733 | - $host = $forawardedHost[0]; |
|
734 | - } |
|
735 | - elseif ( ! $host = $this->headers->get('HOST')) { |
|
736 | - if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
737 | - $host = $this->server->get('REMOTE_ADDR', ''); |
|
738 | - } |
|
739 | - } |
|
740 | - |
|
741 | - $host = $_SERVER['SERVER_NAME']; |
|
742 | - |
|
743 | - $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
715 | + /** |
|
716 | + * Gets the request's scheme. |
|
717 | + * |
|
718 | + * @return string |
|
719 | + */ |
|
720 | + public function getScheme() |
|
721 | + { |
|
722 | + return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
723 | + } |
|
724 | + |
|
725 | + /** |
|
726 | + * Returns the host name. |
|
727 | + * |
|
728 | + * @return void |
|
729 | + */ |
|
730 | + public function getHost() |
|
731 | + { |
|
732 | + if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
733 | + $host = $forawardedHost[0]; |
|
734 | + } |
|
735 | + elseif ( ! $host = $this->headers->get('HOST')) { |
|
736 | + if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
737 | + $host = $this->server->get('REMOTE_ADDR', ''); |
|
738 | + } |
|
739 | + } |
|
740 | + |
|
741 | + $host = $_SERVER['SERVER_NAME']; |
|
742 | + |
|
743 | + $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
744 | 744 | |
745 | - return $host; |
|
746 | - } |
|
747 | - |
|
748 | - /** |
|
749 | - * Returns the port on which the request is made. |
|
750 | - * |
|
751 | - * @return int |
|
752 | - */ |
|
753 | - public function getPort() |
|
754 | - { |
|
755 | - if ( ! $this->server->get('HTTP_HOST')) |
|
756 | - { |
|
757 | - return $this->server->get('SERVER_PORT'); |
|
758 | - } |
|
745 | + return $host; |
|
746 | + } |
|
747 | + |
|
748 | + /** |
|
749 | + * Returns the port on which the request is made. |
|
750 | + * |
|
751 | + * @return int |
|
752 | + */ |
|
753 | + public function getPort() |
|
754 | + { |
|
755 | + if ( ! $this->server->get('HTTP_HOST')) |
|
756 | + { |
|
757 | + return $this->server->get('SERVER_PORT'); |
|
758 | + } |
|
759 | 759 | |
760 | - return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
761 | - } |
|
762 | - |
|
763 | - /** |
|
764 | - * Returns the HTTP host being requested. |
|
765 | - * |
|
766 | - * @return string |
|
767 | - */ |
|
768 | - public function getHttpHost() |
|
769 | - { |
|
770 | - $scheme = $this->getScheme(); |
|
771 | - $port = $this->getPort(); |
|
772 | - |
|
773 | - if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) |
|
774 | - { |
|
775 | - return $this->getHost(); |
|
776 | - } |
|
777 | - |
|
778 | - return $this->getHost().':'.$port; |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * Gets the scheme and HTTP host. |
|
783 | - * |
|
784 | - * @return string |
|
785 | - */ |
|
786 | - public function getSchemeWithHttpHost() |
|
787 | - { |
|
788 | - return $this->getScheme().'://'.$this->getHttpHost(); |
|
789 | - } |
|
790 | - |
|
791 | - /** |
|
792 | - * Get the root URL for the application. |
|
793 | - * |
|
794 | - * @return string |
|
795 | - */ |
|
796 | - public function root() |
|
797 | - { |
|
798 | - return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
799 | - } |
|
800 | - |
|
801 | - /** |
|
802 | - * Get the URL for the request. |
|
803 | - * |
|
804 | - * @return string |
|
805 | - */ |
|
806 | - public function url() |
|
807 | - { |
|
808 | - return trim(preg_replace('/\?.*/', '', $this->get()), '/'); |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * Returns the referer. |
|
813 | - * |
|
814 | - * @param string $default |
|
815 | - * |
|
816 | - * @return string |
|
817 | - */ |
|
818 | - public function referer(string $default = '') |
|
819 | - { |
|
820 | - return $this->server->get('HTTP_REFERER', $default); |
|
821 | - } |
|
760 | + return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Returns the HTTP host being requested. |
|
765 | + * |
|
766 | + * @return string |
|
767 | + */ |
|
768 | + public function getHttpHost() |
|
769 | + { |
|
770 | + $scheme = $this->getScheme(); |
|
771 | + $port = $this->getPort(); |
|
772 | + |
|
773 | + if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) |
|
774 | + { |
|
775 | + return $this->getHost(); |
|
776 | + } |
|
777 | + |
|
778 | + return $this->getHost().':'.$port; |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * Gets the scheme and HTTP host. |
|
783 | + * |
|
784 | + * @return string |
|
785 | + */ |
|
786 | + public function getSchemeWithHttpHost() |
|
787 | + { |
|
788 | + return $this->getScheme().'://'.$this->getHttpHost(); |
|
789 | + } |
|
790 | + |
|
791 | + /** |
|
792 | + * Get the root URL for the application. |
|
793 | + * |
|
794 | + * @return string |
|
795 | + */ |
|
796 | + public function root() |
|
797 | + { |
|
798 | + return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
799 | + } |
|
800 | + |
|
801 | + /** |
|
802 | + * Get the URL for the request. |
|
803 | + * |
|
804 | + * @return string |
|
805 | + */ |
|
806 | + public function url() |
|
807 | + { |
|
808 | + return trim(preg_replace('/\?.*/', '', $this->get()), '/'); |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * Returns the referer. |
|
813 | + * |
|
814 | + * @param string $default |
|
815 | + * |
|
816 | + * @return string |
|
817 | + */ |
|
818 | + public function referer(string $default = '') |
|
819 | + { |
|
820 | + return $this->server->get('HTTP_REFERER', $default); |
|
821 | + } |
|
822 | 822 | |
823 | - /** |
|
824 | - * Attempts to detect if the current connection is secure through |
|
825 | - * over HTTPS protocol. |
|
826 | - * |
|
827 | - * @return bool |
|
828 | - */ |
|
829 | - public function secure() |
|
830 | - { |
|
831 | - if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') |
|
832 | - { |
|
833 | - return true; |
|
834 | - } |
|
835 | - elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') |
|
836 | - { |
|
837 | - return true; |
|
838 | - } |
|
839 | - elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') |
|
840 | - { |
|
841 | - return true; |
|
842 | - } |
|
843 | - |
|
844 | - return false; |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Returns the user agent. |
|
849 | - * |
|
850 | - * @param string|null $default |
|
851 | - * |
|
852 | - * @return string |
|
853 | - */ |
|
854 | - public function userAgent(string $default = null) |
|
855 | - { |
|
856 | - return $this->server->get('HTTP_USER_AGENT', $default); |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * Get the route resolver. |
|
861 | - * |
|
862 | - * @return \Syscodes\Routing\Router |
|
863 | - */ |
|
864 | - public function getRoute() |
|
865 | - { |
|
866 | - return app('router'); |
|
867 | - } |
|
868 | - |
|
869 | - /** |
|
870 | - * Get an element from the request. |
|
871 | - * |
|
872 | - * @return string[] |
|
873 | - */ |
|
874 | - public function __get($key) |
|
875 | - { |
|
876 | - $all = $this->server->all(); |
|
877 | - |
|
878 | - if (array_key_exists($key, $all)) |
|
879 | - { |
|
880 | - return $all[$key]; |
|
881 | - } |
|
882 | - else |
|
883 | - { |
|
884 | - return $key; |
|
885 | - } |
|
886 | - } |
|
887 | - |
|
888 | - /** |
|
889 | - * Returns the Request as an HTTP string. |
|
890 | - * |
|
891 | - * @return string |
|
892 | - */ |
|
893 | - public function __toString() |
|
894 | - { |
|
895 | - try |
|
896 | - { |
|
897 | - $content = $this->getContent(); |
|
898 | - } |
|
899 | - catch (LogicException $e) |
|
900 | - { |
|
901 | - if (PHP_VERSION_ID > 70400) |
|
902 | - { |
|
903 | - throw $e; |
|
904 | - } |
|
905 | - |
|
906 | - return trigger_error($e, E_USER_ERROR); |
|
907 | - } |
|
908 | - |
|
909 | - $cookieHeader = ''; |
|
910 | - $cookies = []; |
|
911 | - |
|
912 | - foreach ($this->cookies as $key => $value) |
|
913 | - { |
|
914 | - $cookies[]= "{$key} = {$value}"; |
|
915 | - } |
|
916 | - |
|
917 | - if ( ! empty($cookies)) |
|
918 | - { |
|
919 | - $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
920 | - } |
|
823 | + /** |
|
824 | + * Attempts to detect if the current connection is secure through |
|
825 | + * over HTTPS protocol. |
|
826 | + * |
|
827 | + * @return bool |
|
828 | + */ |
|
829 | + public function secure() |
|
830 | + { |
|
831 | + if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') |
|
832 | + { |
|
833 | + return true; |
|
834 | + } |
|
835 | + elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') |
|
836 | + { |
|
837 | + return true; |
|
838 | + } |
|
839 | + elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') |
|
840 | + { |
|
841 | + return true; |
|
842 | + } |
|
843 | + |
|
844 | + return false; |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * Returns the user agent. |
|
849 | + * |
|
850 | + * @param string|null $default |
|
851 | + * |
|
852 | + * @return string |
|
853 | + */ |
|
854 | + public function userAgent(string $default = null) |
|
855 | + { |
|
856 | + return $this->server->get('HTTP_USER_AGENT', $default); |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * Get the route resolver. |
|
861 | + * |
|
862 | + * @return \Syscodes\Routing\Router |
|
863 | + */ |
|
864 | + public function getRoute() |
|
865 | + { |
|
866 | + return app('router'); |
|
867 | + } |
|
868 | + |
|
869 | + /** |
|
870 | + * Get an element from the request. |
|
871 | + * |
|
872 | + * @return string[] |
|
873 | + */ |
|
874 | + public function __get($key) |
|
875 | + { |
|
876 | + $all = $this->server->all(); |
|
877 | + |
|
878 | + if (array_key_exists($key, $all)) |
|
879 | + { |
|
880 | + return $all[$key]; |
|
881 | + } |
|
882 | + else |
|
883 | + { |
|
884 | + return $key; |
|
885 | + } |
|
886 | + } |
|
887 | + |
|
888 | + /** |
|
889 | + * Returns the Request as an HTTP string. |
|
890 | + * |
|
891 | + * @return string |
|
892 | + */ |
|
893 | + public function __toString() |
|
894 | + { |
|
895 | + try |
|
896 | + { |
|
897 | + $content = $this->getContent(); |
|
898 | + } |
|
899 | + catch (LogicException $e) |
|
900 | + { |
|
901 | + if (PHP_VERSION_ID > 70400) |
|
902 | + { |
|
903 | + throw $e; |
|
904 | + } |
|
905 | + |
|
906 | + return trigger_error($e, E_USER_ERROR); |
|
907 | + } |
|
908 | + |
|
909 | + $cookieHeader = ''; |
|
910 | + $cookies = []; |
|
911 | + |
|
912 | + foreach ($this->cookies as $key => $value) |
|
913 | + { |
|
914 | + $cookies[]= "{$key} = {$value}"; |
|
915 | + } |
|
916 | + |
|
917 | + if ( ! empty($cookies)) |
|
918 | + { |
|
919 | + $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
920 | + } |
|
921 | 921 | |
922 | - return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
923 | - $this->headers. |
|
924 | - $cookieHeader."\r\n". |
|
925 | - $content; |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * Clones the current request. |
|
930 | - * |
|
931 | - * @return void |
|
932 | - */ |
|
933 | - public function __clone() |
|
934 | - { |
|
935 | - $this->request = clone $this->request; |
|
936 | - $this->cookies = clone $this->cookies; |
|
937 | - $this->files = clone $this->files; |
|
938 | - $this->server = clone $this->server; |
|
939 | - $this->headers = clone $this->headers; |
|
940 | - } |
|
922 | + return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
923 | + $this->headers. |
|
924 | + $cookieHeader."\r\n". |
|
925 | + $content; |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * Clones the current request. |
|
930 | + * |
|
931 | + * @return void |
|
932 | + */ |
|
933 | + public function __clone() |
|
934 | + { |
|
935 | + $this->request = clone $this->request; |
|
936 | + $this->cookies = clone $this->cookies; |
|
937 | + $this->files = clone $this->files; |
|
938 | + $this->server = clone $this->server; |
|
939 | + $this->headers = clone $this->headers; |
|
940 | + } |
|
941 | 941 | } |
942 | 942 | \ No newline at end of file |
@@ -402,8 +402,7 @@ discard block |
||
402 | 402 | $this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME)); |
403 | 403 | $this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST)); |
404 | 404 | $this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT)); |
405 | - } |
|
406 | - else |
|
405 | + } else |
|
407 | 406 | { |
408 | 407 | if ( ! $this->http->isCli()) |
409 | 408 | { |
@@ -466,8 +465,7 @@ discard block |
||
466 | 465 | { |
467 | 466 | Locale::setDefault($locale); |
468 | 467 | } |
469 | - } |
|
470 | - catch (Exception $exception) {} |
|
468 | + } catch (Exception $exception) {} |
|
471 | 469 | |
472 | 470 | return $this; |
473 | 471 | } |
@@ -731,8 +729,7 @@ discard block |
||
731 | 729 | { |
732 | 730 | if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
733 | 731 | $host = $forawardedHost[0]; |
734 | - } |
|
735 | - elseif ( ! $host = $this->headers->get('HOST')) { |
|
732 | + } elseif ( ! $host = $this->headers->get('HOST')) { |
|
736 | 733 | if ( ! $host = $this->server->get('SERVER_NAME')) { |
737 | 734 | $host = $this->server->get('REMOTE_ADDR', ''); |
738 | 735 | } |
@@ -831,12 +828,10 @@ discard block |
||
831 | 828 | if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') |
832 | 829 | { |
833 | 830 | return true; |
834 | - } |
|
835 | - elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') |
|
831 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') |
|
836 | 832 | { |
837 | 833 | return true; |
838 | - } |
|
839 | - elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') |
|
834 | + } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') |
|
840 | 835 | { |
841 | 836 | return true; |
842 | 837 | } |
@@ -878,8 +873,7 @@ discard block |
||
878 | 873 | if (array_key_exists($key, $all)) |
879 | 874 | { |
880 | 875 | return $all[$key]; |
881 | - } |
|
882 | - else |
|
876 | + } else |
|
883 | 877 | { |
884 | 878 | return $key; |
885 | 879 | } |
@@ -895,8 +889,7 @@ discard block |
||
895 | 889 | try |
896 | 890 | { |
897 | 891 | $content = $this->getContent(); |
898 | - } |
|
899 | - catch (LogicException $e) |
|
892 | + } catch (LogicException $e) |
|
900 | 893 | { |
901 | 894 | if (PHP_VERSION_ID > 70400) |
902 | 895 | { |
@@ -33,158 +33,158 @@ |
||
33 | 33 | */ |
34 | 34 | class Parameters implements IteratorAggregate, Countable |
35 | 35 | { |
36 | - /** |
|
37 | - * Array parameters from the Server global. |
|
38 | - * |
|
39 | - * @var array $parameters |
|
40 | - */ |
|
41 | - protected $parameters = []; |
|
36 | + /** |
|
37 | + * Array parameters from the Server global. |
|
38 | + * |
|
39 | + * @var array $parameters |
|
40 | + */ |
|
41 | + protected $parameters = []; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Parameter Object Constructor. |
|
45 | - * |
|
46 | - * @param array $parameters |
|
47 | - * |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function __construct(array $parameters = []) |
|
51 | - { |
|
52 | - $this->parameters = $parameters; |
|
53 | - } |
|
43 | + /** |
|
44 | + * Parameter Object Constructor. |
|
45 | + * |
|
46 | + * @param array $parameters |
|
47 | + * |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function __construct(array $parameters = []) |
|
51 | + { |
|
52 | + $this->parameters = $parameters; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the parameters. |
|
57 | - * |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function all() |
|
61 | - { |
|
62 | - return $this->parameters; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Returns the parameters. |
|
57 | + * |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function all() |
|
61 | + { |
|
62 | + return $this->parameters; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns the parameter keys. |
|
67 | - * |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function keys() |
|
71 | - { |
|
72 | - return array_keys($this->parameters); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Returns the parameter keys. |
|
67 | + * |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function keys() |
|
71 | + { |
|
72 | + return array_keys($this->parameters); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Replaces the current parameters. |
|
77 | - * |
|
78 | - * @param array $parameters |
|
79 | - * |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function replace(array $parameters = []) |
|
83 | - { |
|
84 | - $this->parameters = $parameters; |
|
85 | - } |
|
75 | + /** |
|
76 | + * Replaces the current parameters. |
|
77 | + * |
|
78 | + * @param array $parameters |
|
79 | + * |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function replace(array $parameters = []) |
|
83 | + { |
|
84 | + $this->parameters = $parameters; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Adds parameters. |
|
89 | - * |
|
90 | - * @param array $parameters |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function add(array $parameters = []) |
|
95 | - { |
|
96 | - $this->parameters = array_replace($this->parameters, $parameters); |
|
97 | - } |
|
87 | + /** |
|
88 | + * Adds parameters. |
|
89 | + * |
|
90 | + * @param array $parameters |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function add(array $parameters = []) |
|
95 | + { |
|
96 | + $this->parameters = array_replace($this->parameters, $parameters); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get a parameter array item. |
|
101 | - * |
|
102 | - * @param string $key |
|
103 | - * @param string|null $default (null by default) |
|
104 | - * |
|
105 | - * @return mixed |
|
106 | - */ |
|
107 | - public function get($key, $default = null) |
|
108 | - { |
|
109 | - if ($this->has($key)) |
|
110 | - { |
|
111 | - return $this->parameters[$key]; |
|
112 | - } |
|
99 | + /** |
|
100 | + * Get a parameter array item. |
|
101 | + * |
|
102 | + * @param string $key |
|
103 | + * @param string|null $default (null by default) |
|
104 | + * |
|
105 | + * @return mixed |
|
106 | + */ |
|
107 | + public function get($key, $default = null) |
|
108 | + { |
|
109 | + if ($this->has($key)) |
|
110 | + { |
|
111 | + return $this->parameters[$key]; |
|
112 | + } |
|
113 | 113 | |
114 | - return $default; |
|
115 | - } |
|
114 | + return $default; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Check if a parameter array item exists. |
|
119 | - * |
|
120 | - * @param string $key |
|
121 | - * |
|
122 | - * @return mixed |
|
123 | - */ |
|
124 | - public function has($key) |
|
125 | - { |
|
126 | - return Arr::exists($this->parameters, $key); |
|
127 | - } |
|
117 | + /** |
|
118 | + * Check if a parameter array item exists. |
|
119 | + * |
|
120 | + * @param string $key |
|
121 | + * |
|
122 | + * @return mixed |
|
123 | + */ |
|
124 | + public function has($key) |
|
125 | + { |
|
126 | + return Arr::exists($this->parameters, $key); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Set a parameter array item. |
|
131 | - * |
|
132 | - * @param string $key |
|
133 | - * @param string $value |
|
134 | - * |
|
135 | - * @return mixed |
|
136 | - */ |
|
137 | - public function set($key, $value) |
|
138 | - { |
|
139 | - $this->parameters[$key] = $value; |
|
140 | - } |
|
129 | + /** |
|
130 | + * Set a parameter array item. |
|
131 | + * |
|
132 | + * @param string $key |
|
133 | + * @param string $value |
|
134 | + * |
|
135 | + * @return mixed |
|
136 | + */ |
|
137 | + public function set($key, $value) |
|
138 | + { |
|
139 | + $this->parameters[$key] = $value; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Remove a parameter array item. |
|
144 | - * |
|
145 | - * @param string $key |
|
146 | - * |
|
147 | - * @return void |
|
148 | - */ |
|
149 | - public function remove($key) |
|
150 | - { |
|
151 | - if ($this->has($key)) |
|
152 | - { |
|
153 | - unset($this->parameters[$key]); |
|
154 | - } |
|
155 | - } |
|
142 | + /** |
|
143 | + * Remove a parameter array item. |
|
144 | + * |
|
145 | + * @param string $key |
|
146 | + * |
|
147 | + * @return void |
|
148 | + */ |
|
149 | + public function remove($key) |
|
150 | + { |
|
151 | + if ($this->has($key)) |
|
152 | + { |
|
153 | + unset($this->parameters[$key]); |
|
154 | + } |
|
155 | + } |
|
156 | 156 | |
157 | - /* |
|
157 | + /* |
|
158 | 158 | |----------------------------------------------------------------- |
159 | 159 | | IteratorAggregate Method |
160 | 160 | |----------------------------------------------------------------- |
161 | 161 | */ |
162 | 162 | |
163 | - /** |
|
164 | - * Retrieve an external iterator. |
|
165 | - * |
|
166 | - * @see \IteratorAggregate::getIterator |
|
167 | - * |
|
168 | - * @return new \ArrayIterator |
|
169 | - */ |
|
170 | - public function getIterator() |
|
171 | - { |
|
172 | - return new ArrayIterator($this->parameters); |
|
173 | - } |
|
163 | + /** |
|
164 | + * Retrieve an external iterator. |
|
165 | + * |
|
166 | + * @see \IteratorAggregate::getIterator |
|
167 | + * |
|
168 | + * @return new \ArrayIterator |
|
169 | + */ |
|
170 | + public function getIterator() |
|
171 | + { |
|
172 | + return new ArrayIterator($this->parameters); |
|
173 | + } |
|
174 | 174 | |
175 | - /* |
|
175 | + /* |
|
176 | 176 | |----------------------------------------------------------------- |
177 | 177 | | Countable Method |
178 | 178 | |----------------------------------------------------------------- |
179 | 179 | */ |
180 | 180 | |
181 | - /** |
|
182 | - * Returns the number of parameters. |
|
183 | - * |
|
184 | - * @return int The number of parameters |
|
185 | - */ |
|
186 | - public function count() |
|
187 | - { |
|
188 | - return count($this->parameters); |
|
189 | - } |
|
181 | + /** |
|
182 | + * Returns the number of parameters. |
|
183 | + * |
|
184 | + * @return int The number of parameters |
|
185 | + */ |
|
186 | + public function count() |
|
187 | + { |
|
188 | + return count($this->parameters); |
|
189 | + } |
|
190 | 190 | } |
191 | 191 | \ No newline at end of file |