Passed
Push — master ( fca16e...a09e23 )
by Alexander
04:10
created
src/components/Http/Loaders/Files.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -40,29 +40,29 @@
 block discarded – undo
40 40
     }
41 41
 
42 42
     /**
43
-	 * Replaces the current parameters.
44
-	 * 
45
-	 * @param  array  $parameters
46
-	 * 
47
-	 * @return void
48
-	 */
49
-	public function replace(array $files = []): void
50
-	{
51
-		$this->parameters = [];
43
+     * Replaces the current parameters.
44
+     * 
45
+     * @param  array  $parameters
46
+     * 
47
+     * @return void
48
+     */
49
+    public function replace(array $files = []): void
50
+    {
51
+        $this->parameters = [];
52 52
         $this->add($files);
53
-	}
53
+    }
54 54
 
55
-	/**
56
-	 * Adds parameters.
57
-	 * 
58
-	 * @param  array  $parameters
59
-	 * 
60
-	 * @return void
61
-	 */
62
-	public function add(array $files = []): void
63
-	{
55
+    /**
56
+     * Adds parameters.
57
+     * 
58
+     * @param  array  $parameters
59
+     * 
60
+     * @return void
61
+     */
62
+    public function add(array $files = []): void
63
+    {
64 64
         foreach ($files as $key => $file) {
65 65
             $this->set($key, $file);
66 66
         }
67
-	}
67
+    }
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Loaders/Headers.php 1 patch
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -35,266 +35,266 @@
 block discarded – undo
35 35
  */
36 36
 class Headers implements IteratorAggregate, Countable
37 37
 {
38
-	protected const STRING_UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
39
-	protected const STRING_LOWER = '-abcdefghijklmnopqrstuvwxyz';
38
+    protected const STRING_UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
39
+    protected const STRING_LOWER = '-abcdefghijklmnopqrstuvwxyz';
40 40
 
41
-	/**
42
-	 * An array of HTTP headers.
43
-	 * 
44
-	 * @var array $herders
45
-	 */
46
-	protected $headers = [];
41
+    /**
42
+     * An array of HTTP headers.
43
+     * 
44
+     * @var array $herders
45
+     */
46
+    protected $headers = [];
47 47
 	
48
-	/**
49
-	 * Specifies the directives for the caching mechanisms in both
50
-	 * the requests and the responses.
51
-	 * 
52
-	 * @var array $cacheControl
53
-	 */
54
-	protected $cacheControl = [];
48
+    /**
49
+     * Specifies the directives for the caching mechanisms in both
50
+     * the requests and the responses.
51
+     * 
52
+     * @var array $cacheControl
53
+     */
54
+    protected $cacheControl = [];
55 55
 	
56
-	/**
57
-	 * Constructor. The Headers class instance.
58
-	 * 
59
-	 * @param  array  $headers
60
-	 * 
61
-	 * @return void
62
-	 */
63
-	public function __construct(array $headers = [])
64
-	{
65
-		foreach ($headers as $key => $values) {
66
-			$this->set($key, $values);
67
-		}
68
-	}
56
+    /**
57
+     * Constructor. The Headers class instance.
58
+     * 
59
+     * @param  array  $headers
60
+     * 
61
+     * @return void
62
+     */
63
+    public function __construct(array $headers = [])
64
+    {
65
+        foreach ($headers as $key => $values) {
66
+            $this->set($key, $values);
67
+        }
68
+    }
69 69
 	
70
-	/**
71
-	 * Returns all the headers.
72
-	 * 
73
-	 * @param  string|null  $key  The name of the headers
74
-	 * 
75
-	 * @return array
76
-	 */
77
-	public function all(string $key = null): array
78
-	{
79
-		if (null !== $key) {
80
-			return $this->headers[strtr($key, self::STRING_UPPER, self::STRING_LOWER)] ?? [];
81
-		}
70
+    /**
71
+     * Returns all the headers.
72
+     * 
73
+     * @param  string|null  $key  The name of the headers
74
+     * 
75
+     * @return array
76
+     */
77
+    public function all(string $key = null): array
78
+    {
79
+        if (null !== $key) {
80
+            return $this->headers[strtr($key, self::STRING_UPPER, self::STRING_LOWER)] ?? [];
81
+        }
82 82
 
83
-		return $this->headers;
84
-	}
83
+        return $this->headers;
84
+    }
85 85
 	
86
-	/**
87
-	 * Returns the parameter keys.
88
-	 * 
89
-	 * @return array An array of parameter keys
90
-	 */
91
-	public function keys(): array
92
-	{
93
-		return array_keys($this->all());
94
-	}
86
+    /**
87
+     * Returns the parameter keys.
88
+     * 
89
+     * @return array An array of parameter keys
90
+     */
91
+    public function keys(): array
92
+    {
93
+        return array_keys($this->all());
94
+    }
95 95
 	
96
-	/**
97
-	 * Replaces the current HTTP headers by a new set.
98
-	 * 
99
-	 * @param  array  $headers
100
-	 * 
101
-	 * @return void
102
-	 */
103
-	public function replace(array $headers = []): void
104
-	{
105
-		$this->headers = [];
106
-		$this->add($headers);
107
-	}
96
+    /**
97
+     * Replaces the current HTTP headers by a new set.
98
+     * 
99
+     * @param  array  $headers
100
+     * 
101
+     * @return void
102
+     */
103
+    public function replace(array $headers = []): void
104
+    {
105
+        $this->headers = [];
106
+        $this->add($headers);
107
+    }
108 108
 	
109
-	/**
110
-	 * Adds multiple header to the queue.
111
-	 * 
112
-	 * @param  array  $headers  The header name
113
-	 * 
114
-	 * @return mixed
115
-	 */
116
-	public function add(array $headers = [])
117
-	{
118
-		foreach ($headers as $key => $values) {
119
-			$this->set($key, $values);
120
-		}
121
-	}
109
+    /**
110
+     * Adds multiple header to the queue.
111
+     * 
112
+     * @param  array  $headers  The header name
113
+     * 
114
+     * @return mixed
115
+     */
116
+    public function add(array $headers = [])
117
+    {
118
+        foreach ($headers as $key => $values) {
119
+            $this->set($key, $values);
120
+        }
121
+    }
122 122
 	
123
-	/**
124
-	 * Gets a header value by name.
125
-	 *
126
-	 * @param  string  $key  The header name, or null for all headers
127
-	 * @param  string|null  $default  The default value
128
-	 *
129
-	 * @return mixed
130
-	 */
131
-	public function get(string $key, string $default = null): ?string
132
-	{
133
-		$headers = $this->all($key);
123
+    /**
124
+     * Gets a header value by name.
125
+     *
126
+     * @param  string  $key  The header name, or null for all headers
127
+     * @param  string|null  $default  The default value
128
+     *
129
+     * @return mixed
130
+     */
131
+    public function get(string $key, string $default = null): ?string
132
+    {
133
+        $headers = $this->all($key);
134 134
 		
135
-		if ( ! $headers) {
136
-			return $default;
137
-		}
135
+        if ( ! $headers) {
136
+            return $default;
137
+        }
138 138
 		
139
-		if (null === $headers[0]) {
140
-			return null;
141
-		}
139
+        if (null === $headers[0]) {
140
+            return null;
141
+        }
142 142
 		
143
-		return (string) $headers[0];
144
-	}
143
+        return (string) $headers[0];
144
+    }
145 145
 
146
-	/**
147
-	 * Sets a header by name.
148
-	 * 
149
-	 * @param  string  $key  The header name
150
-	 * @param  string|string[]|null  $values  The value or an array of values
151
-	 * @param  bool  $replace  If you want to replace the value exists by the header, 
152
-	 * 					       it is not overwritten / overwritten when it is false
153
-	 *
154
-	 * @return void
155
-	 */
156
-	public function set(string $key, $values, bool $replace = true): void
157
-	{
158
-		$key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
146
+    /**
147
+     * Sets a header by name.
148
+     * 
149
+     * @param  string  $key  The header name
150
+     * @param  string|string[]|null  $values  The value or an array of values
151
+     * @param  bool  $replace  If you want to replace the value exists by the header, 
152
+     * 					       it is not overwritten / overwritten when it is false
153
+     *
154
+     * @return void
155
+     */
156
+    public function set(string $key, $values, bool $replace = true): void
157
+    {
158
+        $key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
159 159
 
160
-		if (is_array($values)) {
161
-			$values = array_values($values);
160
+        if (is_array($values)) {
161
+            $values = array_values($values);
162 162
 
163
-			if (true === $replace || ! isset($this->headers[$key])) {
164
-				$this->headers[$key] = $values;
165
-			} else {
166
-				$this->headers[$key] = array_merge($this->headers[$key], $values);
167
-			}
168
-		} else {
169
-			if (true === $replace || ! isset($this->headers[$key])) {
170
-				$this->headers[$key] = [$values];
171
-			} else {
172
-				$this->headers[$key][] = $values;
173
-			}
174
-		}
163
+            if (true === $replace || ! isset($this->headers[$key])) {
164
+                $this->headers[$key] = $values;
165
+            } else {
166
+                $this->headers[$key] = array_merge($this->headers[$key], $values);
167
+            }
168
+        } else {
169
+            if (true === $replace || ! isset($this->headers[$key])) {
170
+                $this->headers[$key] = [$values];
171
+            } else {
172
+                $this->headers[$key][] = $values;
173
+            }
174
+        }
175 175
 		
176
-		if ('cache-control' === $key) {
177
-			$this->cacheControl = $this->parseCacheControl(implode(', ', $this->headers[$key]));
178
-		}
179
-	}
176
+        if ('cache-control' === $key) {
177
+            $this->cacheControl = $this->parseCacheControl(implode(', ', $this->headers[$key]));
178
+        }
179
+    }
180 180
 
181
-	/**
182
-	 * Returns true if the HTTP header is defined.
183
-	 * 
184
-	 * @param  string  $key  The HTTP header
185
-	 * 
186
-	 * @return bool  true if the parameter exists, false otherwise
187
-	 */
188
-	public function has(string $key): bool
189
-	{
190
-		return array_key_exists(strtr($key, self::STRING_UPPER, self::STRING_LOWER), $this->all());
191
-	}
181
+    /**
182
+     * Returns true if the HTTP header is defined.
183
+     * 
184
+     * @param  string  $key  The HTTP header
185
+     * 
186
+     * @return bool  true if the parameter exists, false otherwise
187
+     */
188
+    public function has(string $key): bool
189
+    {
190
+        return array_key_exists(strtr($key, self::STRING_UPPER, self::STRING_LOWER), $this->all());
191
+    }
192 192
 
193
-	/**
194
-	 * Removes a header.
195
-	 * 
196
-	 * @param  string  $name  The header name
197
-	 * 
198
-	 * @return mixed
199
-	 */
200
-	public function remove(string $key)
201
-	{
202
-		$key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
193
+    /**
194
+     * Removes a header.
195
+     * 
196
+     * @param  string  $name  The header name
197
+     * 
198
+     * @return mixed
199
+     */
200
+    public function remove(string $key)
201
+    {
202
+        $key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
203 203
 
204
-		unset($this->headers[$key]);
204
+        unset($this->headers[$key]);
205 205
 
206
-		if ('cache-control' === $key) {
207
-			$this->cacheControl = [];
208
-		}
209
-	}
206
+        if ('cache-control' === $key) {
207
+            $this->cacheControl = [];
208
+        }
209
+    }
210 210
 	
211
-	/**
212
-	 * Returns the HTTP header value converted to a date.
213
-	 * 
214
-	 * @param  string  $key
215
-	 * @param  DateTime|null  $default
216
-	 * 
217
-	 * @throws \RuntimeException When the HTTP header is not parseable
218
-	 */
219
-	public function getDate(string $key, DateTime $default = null): ?DateTimeInterface
220
-	{
221
-		if (null === $value = $this->get($key)) {
222
-			return $default;
223
-		}
211
+    /**
212
+     * Returns the HTTP header value converted to a date.
213
+     * 
214
+     * @param  string  $key
215
+     * @param  DateTime|null  $default
216
+     * 
217
+     * @throws \RuntimeException When the HTTP header is not parseable
218
+     */
219
+    public function getDate(string $key, DateTime $default = null): ?DateTimeInterface
220
+    {
221
+        if (null === $value = $this->get($key)) {
222
+            return $default;
223
+        }
224 224
 		
225
-		if (false === $date = DateTime::createFromFormat(DATE_RFC2822, $value)) {
226
-			throw new RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
227
-		}
225
+        if (false === $date = DateTime::createFromFormat(DATE_RFC2822, $value)) {
226
+            throw new RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
227
+        }
228 228
 		
229
-		return $date;
230
-	}
229
+        return $date;
230
+    }
231 231
 	
232
-	/**
233
-	 * Returns an iterator for headers.
234
-	 * 
235
-	 * @return \ArrayIterator An \ArrayIterator instance
236
-	 */
237
-	public function getIterator(): Traversable
238
-	{
239
-		return new ArrayIterator($this->headers);
240
-	}
232
+    /**
233
+     * Returns an iterator for headers.
234
+     * 
235
+     * @return \ArrayIterator An \ArrayIterator instance
236
+     */
237
+    public function getIterator(): Traversable
238
+    {
239
+        return new ArrayIterator($this->headers);
240
+    }
241 241
 	
242
-	/**
243
-	 * Returns the number of headers.
244
-	 * 
245
-	 * @return int The number of headers
246
-	 */
247
-	public function count(): int
248
-	{
249
-		return count($this->headers);
250
-	}
242
+    /**
243
+     * Returns the number of headers.
244
+     * 
245
+     * @return int The number of headers
246
+     */
247
+    public function count(): int
248
+    {
249
+        return count($this->headers);
250
+    }
251 251
 	
252
-	/**
253
-	 * Parses a Cache-Control HTTP header.
254
-	 * 
255
-	 * @param string $header The value of the Cache-Control HTTP header
256
-	 * 
257
-	 * @return array An array representing the attribute values
258
-	 */
259
-	protected function parseCacheControl($header): array
260
-	{
261
-		$cacheControl = [];
252
+    /**
253
+     * Parses a Cache-Control HTTP header.
254
+     * 
255
+     * @param string $header The value of the Cache-Control HTTP header
256
+     * 
257
+     * @return array An array representing the attribute values
258
+     */
259
+    protected function parseCacheControl($header): array
260
+    {
261
+        $cacheControl = [];
262 262
 		
263
-		preg_match_all('~([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?~', $header, $matches, PREG_SET_ORDER);
263
+        preg_match_all('~([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?~', $header, $matches, PREG_SET_ORDER);
264 264
 		
265
-		foreach ($matches as $match) {
266
-			$cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
267
-		}
265
+        foreach ($matches as $match) {
266
+            $cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
267
+        }
268 268
 		
269
-		return $cacheControl;
270
-	}
269
+        return $cacheControl;
270
+    }
271 271
 	
272
-	/**
273
-	 * Magic method.
274
-	 * 
275
-	 * Returns the headers as a string.
276
-	 * 
277
-	 * @return string The headers
278
-	 */
279
-	public function __toString(): string
280
-	{
281
-		if ( ! $headers = $this->all()) {
282
-			return '';
283
-		}
272
+    /**
273
+     * Magic method.
274
+     * 
275
+     * Returns the headers as a string.
276
+     * 
277
+     * @return string The headers
278
+     */
279
+    public function __toString(): string
280
+    {
281
+        if ( ! $headers = $this->all()) {
282
+            return '';
283
+        }
284 284
 		
285
-		ksort($headers);
285
+        ksort($headers);
286 286
 		
287
-		$max     = max(array_map('strlen', array_keys($headers))) + 1;
288
-		$content = '';
287
+        $max     = max(array_map('strlen', array_keys($headers))) + 1;
288
+        $content = '';
289 289
 		
290
-		foreach ($headers as $name => $values) {
291
-			$name = ucwords($name, '-');
290
+        foreach ($headers as $name => $values) {
291
+            $name = ucwords($name, '-');
292 292
 			
293
-			foreach ($values as $value) {
294
-				$content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
295
-			}
296
-		}
293
+            foreach ($values as $value) {
294
+                $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
295
+            }
296
+        }
297 297
 
298
-		return $content;
299
-	}
298
+        return $content;
299
+    }
300 300
 }
301 301
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/URI.php 1 patch
Indentation   +493 added lines, -493 removed lines patch added patch discarded remove patch
@@ -31,499 +31,499 @@
 block discarded – undo
31 31
  */
32 32
 class URI
33 33
 {
34
-	/**
35
-	 * Returns default schemes/ports.
36
-	 * 
37
-	 * @var array $defaultPorts
38
-	 */
39
-	protected $defaultPorts = [
40
-		'http'  => 80,
41
-		'https' => 443,
42
-		'ftp'   => 21,
43
-		'sftp'  => 22
44
-	];
45
-
46
-	/**
47
-	 * The name of any fragment.
48
-	 * 
49
-	 * @var string $fragment
50
-	 */
51
-	protected $fragment = '';
52
-
53
-	/**
54
-	 * The URI Host.
55
-	 * 
56
-	 * @var string $host
57
-	 */
58
-	protected $host;
34
+    /**
35
+     * Returns default schemes/ports.
36
+     * 
37
+     * @var array $defaultPorts
38
+     */
39
+    protected $defaultPorts = [
40
+        'http'  => 80,
41
+        'https' => 443,
42
+        'ftp'   => 21,
43
+        'sftp'  => 22
44
+    ];
45
+
46
+    /**
47
+     * The name of any fragment.
48
+     * 
49
+     * @var string $fragment
50
+     */
51
+    protected $fragment = '';
52
+
53
+    /**
54
+     * The URI Host.
55
+     * 
56
+     * @var string $host
57
+     */
58
+    protected $host;
59 59
 	
60
-	/**
61
-	 * The URI User Password.
62
-	 * 
63
-	 * @var string $password
64
-	 */
65
-	protected $password;
66
-
67
-	/**
68
-	 * The URI path.
69
-	 * 
70
-	 * @var string $path
71
-	 */
72
-	protected $path;
73
-
74
-	/**
75
-	 * The URI Port.
76
-	 * 
77
-	 * @var int $port
78
-	 */
79
-	protected $port;
80
-
81
-	/**
82
-	 * The query string.
83
-	 * 
84
-	 * @var string $query
85
-	 */
86
-	protected $query;
87
-
88
-	/**
89
-	 * The URI Scheme.
90
-	 * 
91
-	 * @var string $scheme
92
-	 */
93
-	protected $scheme = 'http';
94
-
95
-	/**
96
-	 * Whether passwords should be shown in userInfo/authority calls.
97
-	 * 
98
-	 * @var boolean $showPassword
99
-	 */
100
-	protected $showPassword = false;
60
+    /**
61
+     * The URI User Password.
62
+     * 
63
+     * @var string $password
64
+     */
65
+    protected $password;
66
+
67
+    /**
68
+     * The URI path.
69
+     * 
70
+     * @var string $path
71
+     */
72
+    protected $path;
73
+
74
+    /**
75
+     * The URI Port.
76
+     * 
77
+     * @var int $port
78
+     */
79
+    protected $port;
80
+
81
+    /**
82
+     * The query string.
83
+     * 
84
+     * @var string $query
85
+     */
86
+    protected $query;
87
+
88
+    /**
89
+     * The URI Scheme.
90
+     * 
91
+     * @var string $scheme
92
+     */
93
+    protected $scheme = 'http';
94
+
95
+    /**
96
+     * Whether passwords should be shown in userInfo/authority calls.
97
+     * 
98
+     * @var boolean $showPassword
99
+     */
100
+    protected $showPassword = false;
101 101
 	
102
-	/**
103
-	 * The URI User Info.
104
-	 * 
105
-	 * @var string $user
106
-	 */
107
-	protected $user;
108
-
109
-	/**
110
-	 * Constructor. The URI class instance.
111
-	 * 
112
-	 * @param  string|null  $uri  
113
-	 * 
114
-	 * @return void
115
-	 * 
116
-	 * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
117
-	 */
118
-	public function __construct(string $uri = null)
119
-	{
120
-		if ( ! is_null($uri)) {
121
-			$this->setUri($uri);
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * Sets and overwrites any current URI information.
127
-	 * 
128
-	 * @param  string|null  $uri  
129
-	 * 
130
-	 * @return static
131
-	 * 
132
-	 * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
133
-	 */
134
-	public function setUri(string $uri = null): static
135
-	{
136
-		if ( ! is_null($uri)) {
137
-			$parts = parse_url($uri);
138
-
139
-			if ($parts === false) {
140
-				throw HttpURIException::UnableToParseURI($uri);
141
-			}
142
-
143
-			$this->applyParts($parts);
144
-		}
145
-
146
-		return $this;
147
-	}
148
-
149
-	/**
150
-	 * Returns the full URI string.
151
-	 *
152
-	 * @return string  The URI string
153
-	 */
154
-	public function get(): string
155
-	{
156
-		return '/'.ltrim($this->path, '/');
157
-	}
158
-
159
-	/**
160
-	 * Sets of URI string.
161
-	 * 
162
-	 * @param  string  $uri
163
-	 * 
164
-	 * @return static
165
-	 */
166
-	public function set(string $uri): static
167
-	{
168
-		$this->path = $uri;
169
-
170
-		return $this;
171
-	}
172
-
173
-	/**
174
-	 * Retrieve the path component of the URI. The path can either be empty or absolute 
175
-	 * (starting with a slash) or rootless (not starting with a slash).
176
-	 * 
177
-	 * @return string
178
-	 */
179
-	public function getPath(): string
180
-	{
181
-		return (is_null($this->path) ? '' : $this->path);
182
-	}
183
-
184
-	/**
185
-	 * Sets the path portion of the URI.
186
-	 * 
187
-	 * @param  string  $uri
188
-	 *
189
-	 * @return array
190
-	 */
191
-	public function setPath(string $uri): array
192
-	{
193
-		$this->path = $this->filterPath($uri);
194
-
195
-		$tempPath = trim($this->path, '/');
196
-
197
-		return $this->filterSegments($tempPath);
198
-	} 
199
-
200
-	/**
201
-	 * Encodes any dangerous characters.
202
-	 * 
203
-	 * @param  string  $uri
204
-	 * 
205
-	 * @return string
206
-	 */
207
-	protected function filterPath(string $uri): string
208
-	{
209
-		return urldecode($uri);
210
-	}
211
-
212
-	/**
213
-	 * Filter the segments of path.
214
-	 * 
215
-	 * @param  string  $uri
216
-	 * 
217
-	 * @return string[]
218
-	 */
219
-	protected function filterSegments(string $uri): array
220
-	{
221
-		return ($uri == '') ? [] : explode('/', $uri);
222
-	}
223
-
224
-	/**
225
-	 * Get the specified URI segment, return default if it doesn't exist.
226
-	 * Segment index is 1 based, not 0 based.
227
-	 *
228
-	 * @param  int  $index  The 1-based segment index
229
-	 * @param  mixed  $default  The default value
230
-	 *
231
-	 * @return mixed
232
-	 */
233
-	public function getSegment(int $index, $default = null): mixed
234
-	{
235
-		return Arr::get($this->getSegments(), $index - 1, $default);
236
-	}
237
-
238
-	/**
239
-	 * Returns the segments of the path as an array.
240
-	 *
241
-	 * @return array  The URI segments
242
-	 */
243
-	public function getSegments(): array
244
-	{
245
-		$segments = $this->setPath(Request::decodedPath());
246
-
247
-		return array_values(array_filter($segments, fn ($value) => $value != ''));
248
-	}
249
-
250
-	/**
251
-	 * Returns the total number of segment.
252
-	 *
253
-	 * @return int  
254
-	 */
255
-	public function getTotalSegments(): int
256
-	{
257
-		return count($this->getSegments());
258
-	}
259
-
260
-	/**
261
-	 * Retrieve the scheme component of the URI.
262
-	 * 
263
-	 * @return string
264
-	 */
265
-	public function getScheme(): string
266
-	{
267
-		return $this->scheme;
268
-	}
269
-
270
-	/**
271
-	 * Sets the scheme for this URI.
272
-	 * 
273
-	 * @param  string  $str
274
-	 * 
275
-	 * @return string
276
-	 */
277
-	public function setScheme(string $str): string
278
-	{
279
-		$str = preg_replace('~:(//)?$~', '', strtolower($str));
280
-
281
-		$this->scheme = $str;
282
-
283
-		return $this->scheme;
284
-	}
285
-
286
-	/**
287
-	 * Retrieve the user component of the URI.
288
-	 * 
289
-	 * @return string|null
290
-	 */
291
-	public function getUserInfo()
292
-	{
293
-		$user = $this->user;
294
-		$pass = $this->password;
295
-
296
-		if ($this->showPassword === true && ! empty($pass)) {
297
-			$user .= ":$pass";
298
-		}
299
-
300
-		return $user;
301
-	}
302
-
303
-	/**
304
-	 * Sets the user portion of the URI.
305
-	 * 
306
-	 * @param  string  $user
307
-	 * 
308
-	 * @return string|null
309
-	 */
310
-	public function setUser($user): string
311
-	{
312
-		$this->user = trim($user);
313
-
314
-		return $this->user;
315
-	}
316
-
317
-	/**
318
-	 * Sets the password portion of the URI.
319
-	 * 
320
-	 * @param  string  $password
321
-	 * 
322
-	 * @return string|null
323
-	 */
324
-	public function setPassword($password): string
325
-	{
326
-		$this->password = trim($password);
327
-
328
-		return $this->password;
329
-	}
330
-
331
-	/**
332
-	 * Temporarily sets the URI to show a password in userInfo.
333
-	 * 
334
-	 * @param  boolean  $option  
335
-	 * 
336
-	 * @return static
337
-	 */
338
-	public function showPassword(bool $option = true): static
339
-	{
340
-		$this->showPassword = $option;
341
-
342
-		return $this;
343
-	}
344
-
345
-	/**
346
-	 * Retrieve the authority component of the URI.
347
-	 * 
348
-	 * @param  boolean  $ignore  
349
-	 * 
350
-	 * @return string
351
-	 */
352
-	public function getAuthority(bool $ignore = false): string
353
-	{
354
-		if (empty($this->host)) {
355
-			return '';
356
-		}
357
-
358
-		$authority = $this->host;
359
-
360
-		if ( ! empty($this->getUserInfo())) {
361
-			$authority = $this->getUserInfo().'@'.$authority;
362
-		}
363
-
364
-		if ( ! empty($this->port) && ! $ignore) {
365
-			if ($this->port !== $this->defaultPorts[$this->scheme]) {
366
-				$authority .= ":$this->port";
367
-			}
368
-		}
369
-
370
-		$this->showPassword = false;
371
-
372
-		return $authority;
373
-	}
374
-
375
-	/**
376
-	 * Parses the given string an saves the appropriate authority pieces.
377
-	 * 
378
-	 * @param  string  $str
379
-	 * 
380
-	 * @return static
381
-	 */
382
-	public function setAuthority(string $str): static
383
-	{
384
-		$parts = parse_url($str);
385
-
386
-		if (empty($parts['host']) && ! empty($parts['path'])) {
387
-			$parts['host'] = $parts['path'];
388
-			unset($parts['path']);
389
-		}
390
-
391
-		$this->applyParts($parts);
392
-
393
-		return $this;
394
-	}
395
-
396
-	/**
397
-	 * Retrieve the host component of the URI.
398
-	 * 
399
-	 * @return string
400
-	 */
401
-	public function getHost(): string
402
-	{
403
-		return $this->host;
404
-	}
405
-
406
-	/**
407
-	 * Sets the host name to use.
408
-	 * 
409
-	 * @param  string  $str
410
-	 * 
411
-	 * @return string
412
-	 */
413
-	public function setHost(string $str): string
414
-	{
415
-		$this->host = trim($str);
416
-
417
-		return $this->host;
418
-	}
419
-
420
-	/**
421
-	 * Retrieve the port component of the URI.
422
-	 * 
423
-	 * @return int|null
424
-	 */
425
-	public function getPort()
426
-	{
427
-		return $this->port;
428
-	}
429
-
430
-	/**
431
-	 * Sets the port portion of the URI.
432
-	 * 
433
-	 * @param  int|null  $port  
434
-	 * 
435
-	 * @return string
436
-	 */
437
-	public function setPort(int $port = null): string
438
-	{
439
-		if (is_null($port)) {
440
-			return $this;
441
-		}
442
-
443
-		if ($port <= 0 || $port > 65355) {
444
-			throw HttpURIException::invalidPort($port);
445
-		}
446
-
447
-		$this->port = $port;
448
-
449
-		return $this->port;
450
-	}
451
-
452
-	/**
453
-	 * Retrieve a URI fragment.
454
-	 * 
455
-	 * @return string
456
-	 */
457
-	public function getFragment(): string
458
-	{
459
-		return is_null($this->fragment) ? '' : $this->fragment;
460
-	}
461
-
462
-	/**
463
-	 * Sets the fragment portion of the URI.
464
-	 * 
465
-	 * @param  string  $str
466
-	 * 
467
-	 * @return string
468
-	 */
469
-	public function setFragment(string $str): string
470
-	{
471
-		$this->fragment = trim($str, '# ');
472
-
473
-		return $this->fragment;
474
-	}
475
-
476
-	/**
477
-	 * Saves our parts from a parse_url call.
478
-	 * 
479
-	 * @param  array  $parts
480
-	 * 
481
-	 * @return mixed
482
-	 */
483
-	public function applyParts(array $paths)
484
-	{
485
-		if (isset($parts['scheme'])) {
486
-			$this->SetScheme(rtrim($parts['scheme'], ':/'));
487
-		} else {
488
-			$this->setScheme('http');
489
-		}
490
-
491
-		if ( ! empty($parts['host'])) {
492
-			$this->host = $parts['host'];
493
-		}
494
-
495
-		if (isset($parts['port'])) {
496
-			if ( ! is_null($parts['port'])) {
497
-				$this->port = $parts['port'];
498
-			}
499
-		}
500
-
501
-		if ( ! empty($parts['user'])) {
502
-			$this->user = $parts['user'];
503
-		}
504
-
505
-		if ( ! empty($parts['pass'])) {
506
-			$this->password = $parts['pass'];
507
-		}
508
-
509
-		if ( ! empty($parts['path'])) {
510
-			$this->path = $this->filterPath($parts['path']);
511
-		}
512
-
513
-		if ( ! empty($parts['fragment'])) {
514
-			$this->fragment = $parts['fragment'];
515
-		}
516
-	}
517
-
518
-	/**
519
-	 * Magic method.
520
-	 * 
521
-	 * Returns the URI string.
522
-	 *
523
-	 * @return string
524
-	 */
525
-	public function __toString(): string
526
-	{
527
-		return (string) $this->getPath();
528
-	}
102
+    /**
103
+     * The URI User Info.
104
+     * 
105
+     * @var string $user
106
+     */
107
+    protected $user;
108
+
109
+    /**
110
+     * Constructor. The URI class instance.
111
+     * 
112
+     * @param  string|null  $uri  
113
+     * 
114
+     * @return void
115
+     * 
116
+     * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
117
+     */
118
+    public function __construct(string $uri = null)
119
+    {
120
+        if ( ! is_null($uri)) {
121
+            $this->setUri($uri);
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Sets and overwrites any current URI information.
127
+     * 
128
+     * @param  string|null  $uri  
129
+     * 
130
+     * @return static
131
+     * 
132
+     * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
133
+     */
134
+    public function setUri(string $uri = null): static
135
+    {
136
+        if ( ! is_null($uri)) {
137
+            $parts = parse_url($uri);
138
+
139
+            if ($parts === false) {
140
+                throw HttpURIException::UnableToParseURI($uri);
141
+            }
142
+
143
+            $this->applyParts($parts);
144
+        }
145
+
146
+        return $this;
147
+    }
148
+
149
+    /**
150
+     * Returns the full URI string.
151
+     *
152
+     * @return string  The URI string
153
+     */
154
+    public function get(): string
155
+    {
156
+        return '/'.ltrim($this->path, '/');
157
+    }
158
+
159
+    /**
160
+     * Sets of URI string.
161
+     * 
162
+     * @param  string  $uri
163
+     * 
164
+     * @return static
165
+     */
166
+    public function set(string $uri): static
167
+    {
168
+        $this->path = $uri;
169
+
170
+        return $this;
171
+    }
172
+
173
+    /**
174
+     * Retrieve the path component of the URI. The path can either be empty or absolute 
175
+     * (starting with a slash) or rootless (not starting with a slash).
176
+     * 
177
+     * @return string
178
+     */
179
+    public function getPath(): string
180
+    {
181
+        return (is_null($this->path) ? '' : $this->path);
182
+    }
183
+
184
+    /**
185
+     * Sets the path portion of the URI.
186
+     * 
187
+     * @param  string  $uri
188
+     *
189
+     * @return array
190
+     */
191
+    public function setPath(string $uri): array
192
+    {
193
+        $this->path = $this->filterPath($uri);
194
+
195
+        $tempPath = trim($this->path, '/');
196
+
197
+        return $this->filterSegments($tempPath);
198
+    } 
199
+
200
+    /**
201
+     * Encodes any dangerous characters.
202
+     * 
203
+     * @param  string  $uri
204
+     * 
205
+     * @return string
206
+     */
207
+    protected function filterPath(string $uri): string
208
+    {
209
+        return urldecode($uri);
210
+    }
211
+
212
+    /**
213
+     * Filter the segments of path.
214
+     * 
215
+     * @param  string  $uri
216
+     * 
217
+     * @return string[]
218
+     */
219
+    protected function filterSegments(string $uri): array
220
+    {
221
+        return ($uri == '') ? [] : explode('/', $uri);
222
+    }
223
+
224
+    /**
225
+     * Get the specified URI segment, return default if it doesn't exist.
226
+     * Segment index is 1 based, not 0 based.
227
+     *
228
+     * @param  int  $index  The 1-based segment index
229
+     * @param  mixed  $default  The default value
230
+     *
231
+     * @return mixed
232
+     */
233
+    public function getSegment(int $index, $default = null): mixed
234
+    {
235
+        return Arr::get($this->getSegments(), $index - 1, $default);
236
+    }
237
+
238
+    /**
239
+     * Returns the segments of the path as an array.
240
+     *
241
+     * @return array  The URI segments
242
+     */
243
+    public function getSegments(): array
244
+    {
245
+        $segments = $this->setPath(Request::decodedPath());
246
+
247
+        return array_values(array_filter($segments, fn ($value) => $value != ''));
248
+    }
249
+
250
+    /**
251
+     * Returns the total number of segment.
252
+     *
253
+     * @return int  
254
+     */
255
+    public function getTotalSegments(): int
256
+    {
257
+        return count($this->getSegments());
258
+    }
259
+
260
+    /**
261
+     * Retrieve the scheme component of the URI.
262
+     * 
263
+     * @return string
264
+     */
265
+    public function getScheme(): string
266
+    {
267
+        return $this->scheme;
268
+    }
269
+
270
+    /**
271
+     * Sets the scheme for this URI.
272
+     * 
273
+     * @param  string  $str
274
+     * 
275
+     * @return string
276
+     */
277
+    public function setScheme(string $str): string
278
+    {
279
+        $str = preg_replace('~:(//)?$~', '', strtolower($str));
280
+
281
+        $this->scheme = $str;
282
+
283
+        return $this->scheme;
284
+    }
285
+
286
+    /**
287
+     * Retrieve the user component of the URI.
288
+     * 
289
+     * @return string|null
290
+     */
291
+    public function getUserInfo()
292
+    {
293
+        $user = $this->user;
294
+        $pass = $this->password;
295
+
296
+        if ($this->showPassword === true && ! empty($pass)) {
297
+            $user .= ":$pass";
298
+        }
299
+
300
+        return $user;
301
+    }
302
+
303
+    /**
304
+     * Sets the user portion of the URI.
305
+     * 
306
+     * @param  string  $user
307
+     * 
308
+     * @return string|null
309
+     */
310
+    public function setUser($user): string
311
+    {
312
+        $this->user = trim($user);
313
+
314
+        return $this->user;
315
+    }
316
+
317
+    /**
318
+     * Sets the password portion of the URI.
319
+     * 
320
+     * @param  string  $password
321
+     * 
322
+     * @return string|null
323
+     */
324
+    public function setPassword($password): string
325
+    {
326
+        $this->password = trim($password);
327
+
328
+        return $this->password;
329
+    }
330
+
331
+    /**
332
+     * Temporarily sets the URI to show a password in userInfo.
333
+     * 
334
+     * @param  boolean  $option  
335
+     * 
336
+     * @return static
337
+     */
338
+    public function showPassword(bool $option = true): static
339
+    {
340
+        $this->showPassword = $option;
341
+
342
+        return $this;
343
+    }
344
+
345
+    /**
346
+     * Retrieve the authority component of the URI.
347
+     * 
348
+     * @param  boolean  $ignore  
349
+     * 
350
+     * @return string
351
+     */
352
+    public function getAuthority(bool $ignore = false): string
353
+    {
354
+        if (empty($this->host)) {
355
+            return '';
356
+        }
357
+
358
+        $authority = $this->host;
359
+
360
+        if ( ! empty($this->getUserInfo())) {
361
+            $authority = $this->getUserInfo().'@'.$authority;
362
+        }
363
+
364
+        if ( ! empty($this->port) && ! $ignore) {
365
+            if ($this->port !== $this->defaultPorts[$this->scheme]) {
366
+                $authority .= ":$this->port";
367
+            }
368
+        }
369
+
370
+        $this->showPassword = false;
371
+
372
+        return $authority;
373
+    }
374
+
375
+    /**
376
+     * Parses the given string an saves the appropriate authority pieces.
377
+     * 
378
+     * @param  string  $str
379
+     * 
380
+     * @return static
381
+     */
382
+    public function setAuthority(string $str): static
383
+    {
384
+        $parts = parse_url($str);
385
+
386
+        if (empty($parts['host']) && ! empty($parts['path'])) {
387
+            $parts['host'] = $parts['path'];
388
+            unset($parts['path']);
389
+        }
390
+
391
+        $this->applyParts($parts);
392
+
393
+        return $this;
394
+    }
395
+
396
+    /**
397
+     * Retrieve the host component of the URI.
398
+     * 
399
+     * @return string
400
+     */
401
+    public function getHost(): string
402
+    {
403
+        return $this->host;
404
+    }
405
+
406
+    /**
407
+     * Sets the host name to use.
408
+     * 
409
+     * @param  string  $str
410
+     * 
411
+     * @return string
412
+     */
413
+    public function setHost(string $str): string
414
+    {
415
+        $this->host = trim($str);
416
+
417
+        return $this->host;
418
+    }
419
+
420
+    /**
421
+     * Retrieve the port component of the URI.
422
+     * 
423
+     * @return int|null
424
+     */
425
+    public function getPort()
426
+    {
427
+        return $this->port;
428
+    }
429
+
430
+    /**
431
+     * Sets the port portion of the URI.
432
+     * 
433
+     * @param  int|null  $port  
434
+     * 
435
+     * @return string
436
+     */
437
+    public function setPort(int $port = null): string
438
+    {
439
+        if (is_null($port)) {
440
+            return $this;
441
+        }
442
+
443
+        if ($port <= 0 || $port > 65355) {
444
+            throw HttpURIException::invalidPort($port);
445
+        }
446
+
447
+        $this->port = $port;
448
+
449
+        return $this->port;
450
+    }
451
+
452
+    /**
453
+     * Retrieve a URI fragment.
454
+     * 
455
+     * @return string
456
+     */
457
+    public function getFragment(): string
458
+    {
459
+        return is_null($this->fragment) ? '' : $this->fragment;
460
+    }
461
+
462
+    /**
463
+     * Sets the fragment portion of the URI.
464
+     * 
465
+     * @param  string  $str
466
+     * 
467
+     * @return string
468
+     */
469
+    public function setFragment(string $str): string
470
+    {
471
+        $this->fragment = trim($str, '# ');
472
+
473
+        return $this->fragment;
474
+    }
475
+
476
+    /**
477
+     * Saves our parts from a parse_url call.
478
+     * 
479
+     * @param  array  $parts
480
+     * 
481
+     * @return mixed
482
+     */
483
+    public function applyParts(array $paths)
484
+    {
485
+        if (isset($parts['scheme'])) {
486
+            $this->SetScheme(rtrim($parts['scheme'], ':/'));
487
+        } else {
488
+            $this->setScheme('http');
489
+        }
490
+
491
+        if ( ! empty($parts['host'])) {
492
+            $this->host = $parts['host'];
493
+        }
494
+
495
+        if (isset($parts['port'])) {
496
+            if ( ! is_null($parts['port'])) {
497
+                $this->port = $parts['port'];
498
+            }
499
+        }
500
+
501
+        if ( ! empty($parts['user'])) {
502
+            $this->user = $parts['user'];
503
+        }
504
+
505
+        if ( ! empty($parts['pass'])) {
506
+            $this->password = $parts['pass'];
507
+        }
508
+
509
+        if ( ! empty($parts['path'])) {
510
+            $this->path = $this->filterPath($parts['path']);
511
+        }
512
+
513
+        if ( ! empty($parts['fragment'])) {
514
+            $this->fragment = $parts['fragment'];
515
+        }
516
+    }
517
+
518
+    /**
519
+     * Magic method.
520
+     * 
521
+     * Returns the URI string.
522
+     *
523
+     * @return string
524
+     */
525
+    public function __toString(): string
526
+    {
527
+        return (string) $this->getPath();
528
+    }
529 529
 }
530 530
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Request.php 2 patches
Indentation   +1020 added lines, -1020 removed lines patch added patch discarded remove patch
@@ -48,560 +48,560 @@  discard block
 block discarded – undo
48 48
  */
49 49
 class Request
50 50
 {
51
-	use HttpRequest,
52
-	    HttpResources,
53
-	    CanBePrecognitive,	    
54
-	    InteractsWithInput,
55
-	    InteractsWithContentTypes;
56
-
57
-	/**
58
-	 * Get the acceptable of content types.
59
-	 * 
60
-	 * @var string[] $acceptableContenTypes
61
-	 */
62
-	protected $acceptableContentTypes;
63
-
64
-	/**
65
-	 * Get the custom parameters.
66
-	 * 
67
-	 * @var \Syscodes\Components\Http\Loaders\Parameters $attributes
68
-	 */
69
-	public $attributes;
70
-
71
-	/**
72
-	 * The base URL.
73
-	 * 
74
-	 * @var string $baseUrl
75
-	 */
76
-	protected $baseUrl;
77
-
78
-	/**
79
-	 * Get the client ip.
80
-	 * 
81
-	 * @var mixed $clientIp
82
-	 */
83
-	protected $clientIp;
84
-
85
-	/**
86
-	 * Gets cookies ($_COOKIE).
87
-	 * 
88
-	 * @var \Syscodes\Components\Http\Loaders\Inputs $cookies
89
-	 */
90
-	public $cookies;
91
-
92
-	/**
93
-	 * Gets the string with format JSON.
94
-	 * 
95
-	 * @var string|resource|object|null $content
96
-	 */
97
-	protected $content;
98
-
99
-	/**
100
-	 * The default Locale this request.
101
-	 * 
102
-	 * @var string $defaultLocale
103
-	 */
104
-	protected $defaultLocale = 'en';
51
+    use HttpRequest,
52
+        HttpResources,
53
+        CanBePrecognitive,	    
54
+        InteractsWithInput,
55
+        InteractsWithContentTypes;
56
+
57
+    /**
58
+     * Get the acceptable of content types.
59
+     * 
60
+     * @var string[] $acceptableContenTypes
61
+     */
62
+    protected $acceptableContentTypes;
63
+
64
+    /**
65
+     * Get the custom parameters.
66
+     * 
67
+     * @var \Syscodes\Components\Http\Loaders\Parameters $attributes
68
+     */
69
+    public $attributes;
70
+
71
+    /**
72
+     * The base URL.
73
+     * 
74
+     * @var string $baseUrl
75
+     */
76
+    protected $baseUrl;
77
+
78
+    /**
79
+     * Get the client ip.
80
+     * 
81
+     * @var mixed $clientIp
82
+     */
83
+    protected $clientIp;
84
+
85
+    /**
86
+     * Gets cookies ($_COOKIE).
87
+     * 
88
+     * @var \Syscodes\Components\Http\Loaders\Inputs $cookies
89
+     */
90
+    public $cookies;
91
+
92
+    /**
93
+     * Gets the string with format JSON.
94
+     * 
95
+     * @var string|resource|object|null $content
96
+     */
97
+    protected $content;
98
+
99
+    /**
100
+     * The default Locale this request.
101
+     * 
102
+     * @var string $defaultLocale
103
+     */
104
+    protected $defaultLocale = 'en';
105 105
 	
106
-	/**
107
-	 * Gets files request ($_FILES).
108
-	 * 
109
-	 * @var \Syscodes\Components\Http\Loaders\Files $files
110
-	 */
111
-	public $files;
106
+    /**
107
+     * Gets files request ($_FILES).
108
+     * 
109
+     * @var \Syscodes\Components\Http\Loaders\Files $files
110
+     */
111
+    public $files;
112 112
 	
113
-	/**
114
-	 * Get the headers request ($_SERVER).
115
-	 * 
116
-	 * @var \Syscodes\Components\Http\Loaders\Headers $headers
117
-	 */
118
-	public $headers;
119
-
120
-	/**
121
-	 * The decoded JSON content for the request.
122
-	 * 
123
-	 * @var \Syscodes\Components\Http\Loaders\Parameters|null $json
124
-	 */
125
-	protected $json;
126
-
127
-	/**
128
-	 * The current language of the application.
129
-	 * 
130
-	 * @var string $languages
131
-	 */
132
-	protected $languages;
113
+    /**
114
+     * Get the headers request ($_SERVER).
115
+     * 
116
+     * @var \Syscodes\Components\Http\Loaders\Headers $headers
117
+     */
118
+    public $headers;
119
+
120
+    /**
121
+     * The decoded JSON content for the request.
122
+     * 
123
+     * @var \Syscodes\Components\Http\Loaders\Parameters|null $json
124
+     */
125
+    protected $json;
126
+
127
+    /**
128
+     * The current language of the application.
129
+     * 
130
+     * @var string $languages
131
+     */
132
+    protected $languages;
133 133
 	
134
-	/**
135
-	 * Get the locale.
136
-	 * 
137
-	 * @var string $locale
138
-	 */
139
-	protected $locale;
134
+    /**
135
+     * Get the locale.
136
+     * 
137
+     * @var string $locale
138
+     */
139
+    protected $locale;
140 140
 	
141
-	/** 
142
-	 * The method name.
143
-	 * 
144
-	 * @var string $method
145
-	 */
146
-	protected $method;
147
-
148
-	/**
149
-	 * The path info of URL.
150
-	 * 
151
-	 * @var string $pathInfo
152
-	 */
153
-	protected $pathInfo;
154
-
155
-	/**
156
-	 * Query string parameters ($_GET).
157
-	 * 
158
-	 * @var \Syscodes\Components\Http\Loaders\Parameters $query
159
-	 */
160
-	public $query;
161
-
162
-	/**
163
-	 * Request body parameters ($_POST).
164
-	 * 
165
-	 * @var \Syscodes\Components\Http\Loaders\Parameters $request
166
-	 */
167
-	public $request;
168
-
169
-	/**
170
-	 * Get request URI.
171
-	 * 
172
-	 * @var string $requestToUri
173
-	 */
174
-	protected $requestToUri;
175
-
176
-	/**
177
-	 * Get the route resolver callback.
178
-	 * 
179
-	 * @var \Closure $routeResolver
180
-	 */
181
-	protected $routeResolver;
182
-
183
-	/**
184
-	 * The Session implementation.
185
-	 * 
186
-	 * @var \Syscodes\Components\Contracts\Session\Session $session
187
-	 */
188
-	protected $session;
189
-
190
-	/**
191
-	 * The detected uri and server variables ($_SERVER).
192
-	 * 
193
-	 * @var \Syscodes\Components\Http\Loaders\Server $server
194
-	 */
195
-	public $server;
196
-
197
-	/** 
198
-	 * List of routes uri.
199
-	 *
200
-	 * @var \Syscodes\Components\Http\URI $uri 
201
-	 */
202
-	public $uri;
203
-
204
-	/**
205
-	 * Stores the valid locale codes.
206
-	 * 
207
-	 * @var array $validLocales
208
-	 */
209
-	protected $validLocales = [];
210
-
211
-	/**
212
-	 * Constructor: Create new the Request class.
213
-	 * 
214
-	 * @param  array  $query
215
-	 * @param  array  $request
216
-	 * @param  array  $attributes
217
-	 * @param  array  $cookies
218
-	 * @param  array  $files
219
-	 * @param  array  $server
220
-	 * @param  string|resource|null $content  
221
-	 * 
222
-	 * @return void
223
-	 */
224
-	public function __construct(
225
-		array $query = [],
226
-		array $request = [],
227
-		array $attributes = [],
228
-		array $cookies = [],
229
-		array $files = [],
230
-		array $server = [],
231
-		$content = null
232
-	) {
233
-		$this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
141
+    /** 
142
+     * The method name.
143
+     * 
144
+     * @var string $method
145
+     */
146
+    protected $method;
147
+
148
+    /**
149
+     * The path info of URL.
150
+     * 
151
+     * @var string $pathInfo
152
+     */
153
+    protected $pathInfo;
154
+
155
+    /**
156
+     * Query string parameters ($_GET).
157
+     * 
158
+     * @var \Syscodes\Components\Http\Loaders\Parameters $query
159
+     */
160
+    public $query;
161
+
162
+    /**
163
+     * Request body parameters ($_POST).
164
+     * 
165
+     * @var \Syscodes\Components\Http\Loaders\Parameters $request
166
+     */
167
+    public $request;
168
+
169
+    /**
170
+     * Get request URI.
171
+     * 
172
+     * @var string $requestToUri
173
+     */
174
+    protected $requestToUri;
175
+
176
+    /**
177
+     * Get the route resolver callback.
178
+     * 
179
+     * @var \Closure $routeResolver
180
+     */
181
+    protected $routeResolver;
182
+
183
+    /**
184
+     * The Session implementation.
185
+     * 
186
+     * @var \Syscodes\Components\Contracts\Session\Session $session
187
+     */
188
+    protected $session;
189
+
190
+    /**
191
+     * The detected uri and server variables ($_SERVER).
192
+     * 
193
+     * @var \Syscodes\Components\Http\Loaders\Server $server
194
+     */
195
+    public $server;
196
+
197
+    /** 
198
+     * List of routes uri.
199
+     *
200
+     * @var \Syscodes\Components\Http\URI $uri 
201
+     */
202
+    public $uri;
203
+
204
+    /**
205
+     * Stores the valid locale codes.
206
+     * 
207
+     * @var array $validLocales
208
+     */
209
+    protected $validLocales = [];
210
+
211
+    /**
212
+     * Constructor: Create new the Request class.
213
+     * 
214
+     * @param  array  $query
215
+     * @param  array  $request
216
+     * @param  array  $attributes
217
+     * @param  array  $cookies
218
+     * @param  array  $files
219
+     * @param  array  $server
220
+     * @param  string|resource|null $content  
221
+     * 
222
+     * @return void
223
+     */
224
+    public function __construct(
225
+        array $query = [],
226
+        array $request = [],
227
+        array $attributes = [],
228
+        array $cookies = [],
229
+        array $files = [],
230
+        array $server = [],
231
+        $content = null
232
+    ) {
233
+        $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
234 234
 		
235
-		$this->detectLocale();
236
-	}
237
-
238
-	/**
239
-	 * Sets the parameters for this request.
240
-	 * 
241
-	 * @param  array  $query
242
-	 * @param  array  $request
243
-	 * @param  array  $attributes
244
-	 * @param  array  $cookies
245
-	 * @param  array  $files
246
-	 * @param  array  $server
247
-	 * 
248
-	 * @return void
249
-	 */
250
-	public function initialize(
251
-		array $query = [], 
252
-		array $request = [],
253
-		array $attributes = [],
254
-		array $cookies = [], 
255
-		array $files = [], 
256
-		array $server = [], 
257
-		$content = null
258
-	): void {
259
-		$this->query = new Inputs($query);
260
-		$this->request = new Inputs($request);
261
-		$this->attributes = new Parameters($attributes);
262
-		$this->cookies = new Inputs($cookies);
263
-		$this->files = new Files($files);
264
-		$this->server = new Server($server);
265
-		$this->headers = new Headers($this->server->all());
266
-
267
-		// Variables initialized
268
-		$this->uri = new URI;
269
-		$this->method = null;
270
-		$this->baseUrl = null;
271
-		$this->content = $content;
272
-		$this->pathInfo = null;
273
-		$this->languages = null;
274
-		$this->acceptableContentTypes = null;
275
-		$this->validLocales = config('app.supportedLocales');
276
-		$this->clientIp = new RequestClientIP($this->server->all());
277
-	}
278
-
279
-	/**
280
-	 * Clones a request and overrides some of its parameters.
281
-	 * 
282
-	 * @param  array|null  $query
283
-	 * @param  array|null  $request
284
-	 * @param  array|null  $attributes
285
-	 * @param  array|null  $cookies
286
-	 * @param  array|null  $files
287
-	 * @param  array|null  $server
288
-	 * 
289
-	 * @return static
290
-	 */
291
-	public function duplicate(
292
-		array $query = null, 
293
-		array $request = null,
294
-		array $attributes = null,
295
-		array $cookies = null,
296
-		array $files = null,
297
-		array $server = null
298
-	): static {
299
-		$duplicate = clone $this;
300
-
301
-		if (null !== $query) {
302
-			$duplicate->query = new Inputs($query);
303
-		}
304
-
305
-		if (null !== $request) {
306
-			$duplicate->request = new Inputs($request);
307
-		}
308
-
309
-		if (null !== $attributes) {
310
-			$duplicate->attributes = new Parameters($attributes);
311
-		}
312
-
313
-		if (null !== $cookies) {
314
-			$duplicate->cookies = new Inputs($cookies);
315
-		}
316
-
317
-		if (null !== $files) {
318
-			$duplicate->files = new Files($files);
319
-		}
320
-
321
-		if (null !== $server) {
322
-			$duplicate->server  = new Server($server);
323
-			$duplicate->headers = new Headers($duplicate->server->all());
324
-		}
325
-
326
-		$duplicate->uri = new URI;
327
-		$duplicate->locale = null;
328
-		$duplicate->method = null;
329
-		$duplicate->baseUrl = null;
330
-		$duplicate->pathInfo = null;
331
-		$duplicate->validLocales = config('app.supportedLocales');
332
-		$duplicate->clientIp = new RequestClientIP($duplicate->server->all());
333
-
334
-		return $duplicate;		
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
-		return $this->uri->getSegment($index, $default);
348
-	}
349
-
350
-	/**
351
-	 * Returns all segments in an array. For total of segments
352
-	 * used the function PHP count().
353
-	 *
354
-	 * @return array|null
355
-	 */
356
-	public function segments()
357
-	{
358
-		return $this->uri->getSegments();
359
-	}
360
-
361
-	/**
362
-	 * Returns the total number of segment.
363
-	 *
364
-	 * @return int|null  
365
-	 */
366
-	public function totalSegments()
367
-	{
368
-		return $this->uri->getTotalSegments();
369
-	}
370
-
371
-	/**
372
-	 * Handles setting up the locale, auto-detecting of language.
373
-	 * 
374
-	 * @return void
375
-	 */
376
-	public function detectLocale(): void
377
-	{
378
-		$this->languages = $this->defaultLocale = config('app.locale');
379
-
380
-		$this->setLocale($this->validLocales[0]);
381
-	}
382
-
383
-	/**
384
-	 * Returns the default locale as set.
385
-	 * 
386
-	 * @return string
387
-	 */
388
-	public function getDefaultLocale(): string
389
-	{
390
-		return $this->defaultLocale;
391
-	}
392
-
393
-	/**
394
-	 * Gets the current locale, with a fallback to the default.
395
-	 * 
396
-	 * @return string 
397
-	 */
398
-	public function getLocale(): string
399
-	{
400
-		return $this->languages ?: $this->defaultLocale;
401
-	}
402
-
403
-	/**
404
-	 * Sets the locale string for this request.
405
-	 * 
406
-	 * @param  string  $locale
407
-	 * 
408
-	 * @return self
409
-	 */
410
-	public function setLocale(string $locale): self
411
-	{
412
-		if ( ! in_array($locale, $this->validLocales, true)) {
413
-			$locale = $this->defaultLocale;
414
-		}
235
+        $this->detectLocale();
236
+    }
237
+
238
+    /**
239
+     * Sets the parameters for this request.
240
+     * 
241
+     * @param  array  $query
242
+     * @param  array  $request
243
+     * @param  array  $attributes
244
+     * @param  array  $cookies
245
+     * @param  array  $files
246
+     * @param  array  $server
247
+     * 
248
+     * @return void
249
+     */
250
+    public function initialize(
251
+        array $query = [], 
252
+        array $request = [],
253
+        array $attributes = [],
254
+        array $cookies = [], 
255
+        array $files = [], 
256
+        array $server = [], 
257
+        $content = null
258
+    ): void {
259
+        $this->query = new Inputs($query);
260
+        $this->request = new Inputs($request);
261
+        $this->attributes = new Parameters($attributes);
262
+        $this->cookies = new Inputs($cookies);
263
+        $this->files = new Files($files);
264
+        $this->server = new Server($server);
265
+        $this->headers = new Headers($this->server->all());
266
+
267
+        // Variables initialized
268
+        $this->uri = new URI;
269
+        $this->method = null;
270
+        $this->baseUrl = null;
271
+        $this->content = $content;
272
+        $this->pathInfo = null;
273
+        $this->languages = null;
274
+        $this->acceptableContentTypes = null;
275
+        $this->validLocales = config('app.supportedLocales');
276
+        $this->clientIp = new RequestClientIP($this->server->all());
277
+    }
278
+
279
+    /**
280
+     * Clones a request and overrides some of its parameters.
281
+     * 
282
+     * @param  array|null  $query
283
+     * @param  array|null  $request
284
+     * @param  array|null  $attributes
285
+     * @param  array|null  $cookies
286
+     * @param  array|null  $files
287
+     * @param  array|null  $server
288
+     * 
289
+     * @return static
290
+     */
291
+    public function duplicate(
292
+        array $query = null, 
293
+        array $request = null,
294
+        array $attributes = null,
295
+        array $cookies = null,
296
+        array $files = null,
297
+        array $server = null
298
+    ): static {
299
+        $duplicate = clone $this;
300
+
301
+        if (null !== $query) {
302
+            $duplicate->query = new Inputs($query);
303
+        }
304
+
305
+        if (null !== $request) {
306
+            $duplicate->request = new Inputs($request);
307
+        }
308
+
309
+        if (null !== $attributes) {
310
+            $duplicate->attributes = new Parameters($attributes);
311
+        }
312
+
313
+        if (null !== $cookies) {
314
+            $duplicate->cookies = new Inputs($cookies);
315
+        }
316
+
317
+        if (null !== $files) {
318
+            $duplicate->files = new Files($files);
319
+        }
320
+
321
+        if (null !== $server) {
322
+            $duplicate->server  = new Server($server);
323
+            $duplicate->headers = new Headers($duplicate->server->all());
324
+        }
325
+
326
+        $duplicate->uri = new URI;
327
+        $duplicate->locale = null;
328
+        $duplicate->method = null;
329
+        $duplicate->baseUrl = null;
330
+        $duplicate->pathInfo = null;
331
+        $duplicate->validLocales = config('app.supportedLocales');
332
+        $duplicate->clientIp = new RequestClientIP($duplicate->server->all());
333
+
334
+        return $duplicate;		
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
+        return $this->uri->getSegment($index, $default);
348
+    }
349
+
350
+    /**
351
+     * Returns all segments in an array. For total of segments
352
+     * used the function PHP count().
353
+     *
354
+     * @return array|null
355
+     */
356
+    public function segments()
357
+    {
358
+        return $this->uri->getSegments();
359
+    }
360
+
361
+    /**
362
+     * Returns the total number of segment.
363
+     *
364
+     * @return int|null  
365
+     */
366
+    public function totalSegments()
367
+    {
368
+        return $this->uri->getTotalSegments();
369
+    }
370
+
371
+    /**
372
+     * Handles setting up the locale, auto-detecting of language.
373
+     * 
374
+     * @return void
375
+     */
376
+    public function detectLocale(): void
377
+    {
378
+        $this->languages = $this->defaultLocale = config('app.locale');
379
+
380
+        $this->setLocale($this->validLocales[0]);
381
+    }
382
+
383
+    /**
384
+     * Returns the default locale as set.
385
+     * 
386
+     * @return string
387
+     */
388
+    public function getDefaultLocale(): string
389
+    {
390
+        return $this->defaultLocale;
391
+    }
392
+
393
+    /**
394
+     * Gets the current locale, with a fallback to the default.
395
+     * 
396
+     * @return string 
397
+     */
398
+    public function getLocale(): string
399
+    {
400
+        return $this->languages ?: $this->defaultLocale;
401
+    }
402
+
403
+    /**
404
+     * Sets the locale string for this request.
405
+     * 
406
+     * @param  string  $locale
407
+     * 
408
+     * @return self
409
+     */
410
+    public function setLocale(string $locale): self
411
+    {
412
+        if ( ! in_array($locale, $this->validLocales, true)) {
413
+            $locale = $this->defaultLocale;
414
+        }
415 415
 		
416
-		$this->languages = $locale;
416
+        $this->languages = $locale;
417 417
 
418
-		Locale::setDefault($locale);
418
+        Locale::setDefault($locale);
419 419
 			
420
-		return $this;
421
-	}
422
-
423
-	/**
424
-	 * Returns the full request string.
425
-	 * 
426
-	 * @param  string  $key
427
-	 * @param  mixed  $default
428
-	 *
429
-	 * @return mixed 
430
-	 */
431
-	public function get(string $key, $default = null) 
432
-	{
433
-		if ($this !== $result = $this->attributes->get($key, $this)) {
434
-			return $result;
435
-		}
436
-
437
-		if ($this->query->has($key)) {
438
-			return $this->query->all()[$key];
439
-		}
420
+        return $this;
421
+    }
422
+
423
+    /**
424
+     * Returns the full request string.
425
+     * 
426
+     * @param  string  $key
427
+     * @param  mixed  $default
428
+     *
429
+     * @return mixed 
430
+     */
431
+    public function get(string $key, $default = null) 
432
+    {
433
+        if ($this !== $result = $this->attributes->get($key, $this)) {
434
+            return $result;
435
+        }
436
+
437
+        if ($this->query->has($key)) {
438
+            return $this->query->all()[$key];
439
+        }
440 440
 		
441
-		if ($this->request->has($key)) {
442
-			return $this->request->all()[$key];
443
-		}
441
+        if ($this->request->has($key)) {
442
+            return $this->request->all()[$key];
443
+        }
444 444
 		
445
-		return $default;
446
-	}
447
-
448
-	/**
449
-	 * Gets the Session.
450
-	 * 
451
-	 * @return \Syscodes\Components\Http\Session\SessionInterface
452
-	 * 
453
-	 * @throws \Syscodes\Components\Http\Exceptions\SessionNotFoundException
454
-	 */
455
-	public function getSession()
456
-	{
457
-		$this->hasSession()
458
-		            ? new SessionDecorator($this->session())
459
-					: throw new SessionNotFoundException;
460
-	}
461
-
462
-	/**
463
-	 * Whether the request contains a Session object.
464
-	 * 
465
-	 * @return bool
466
-	 */
467
-	public function hasSession(): bool
468
-	{
469
-		return ! is_null($this->session);
470
-	}
471
-
472
-	/**
473
-	 * Get the session associated with the request.
474
-	 * 
475
-	 * @return \Syscodes\Components\Contracts\Session\Session
476
-	 * 
477
-	 * @throws RuntimeException
478
-	 */
479
-	public function session()
480
-	{
481
-		if ( ! $this->hasSession()) {
482
-			throw new RuntimeException('Session store not set on request');
483
-		}
445
+        return $default;
446
+    }
447
+
448
+    /**
449
+     * Gets the Session.
450
+     * 
451
+     * @return \Syscodes\Components\Http\Session\SessionInterface
452
+     * 
453
+     * @throws \Syscodes\Components\Http\Exceptions\SessionNotFoundException
454
+     */
455
+    public function getSession()
456
+    {
457
+        $this->hasSession()
458
+                    ? new SessionDecorator($this->session())
459
+                    : throw new SessionNotFoundException;
460
+    }
461
+
462
+    /**
463
+     * Whether the request contains a Session object.
464
+     * 
465
+     * @return bool
466
+     */
467
+    public function hasSession(): bool
468
+    {
469
+        return ! is_null($this->session);
470
+    }
471
+
472
+    /**
473
+     * Get the session associated with the request.
474
+     * 
475
+     * @return \Syscodes\Components\Contracts\Session\Session
476
+     * 
477
+     * @throws RuntimeException
478
+     */
479
+    public function session()
480
+    {
481
+        if ( ! $this->hasSession()) {
482
+            throw new RuntimeException('Session store not set on request');
483
+        }
484 484
 		
485
-		return $this->session;
486
-	}
485
+        return $this->session;
486
+    }
487 487
 	
488
-	/**
489
-	 * Set the session instance on the request.
490
-	 * 
491
-	 * @param  \Syscodes\Components\Contracts\Session\Session  $session
492
-	 * 
493
-	 * @return void
494
-	 */
495
-	public function setSession($session): void
496
-	{
497
-		$this->session = $session;
498
-	}
499
-
500
-	/**
501
-	 * Get the JSON payload for the request.
502
-	 * 
503
-	 * @param  string|null  $key  
504
-	 * @param  mixed  $default  
505
-	 * 
506
-	 * @return \Syscodes\Components\Http\Utilities\Parameters|mixed
507
-	 */
508
-	public function json($key = null, $default = null)
509
-	{
510
-		if ( ! isset($this->json)) {
511
-			$this->json = new Parameters((array) json_decode($this->getContent(), true));
512
-		}
513
-
514
-		if (is_null($key)) {
515
-			return $this->json;
516
-		}
517
-
518
-		return Arr::get($this->json->all(), $key, $default);
519
-	}
520
-
521
-	/**
522
-	 * Set the JSON payload for the request.
523
-	 * 
524
-	 * @param  \Syscodes\Components\Http\Utilities\Parameters  $json
525
-	 * 
526
-	 * @return static
527
-	 */
528
-	public function setJson($json): static
529
-	{
530
-		$this->json = $json;
531
-
532
-		return $this;
533
-	}
488
+    /**
489
+     * Set the session instance on the request.
490
+     * 
491
+     * @param  \Syscodes\Components\Contracts\Session\Session  $session
492
+     * 
493
+     * @return void
494
+     */
495
+    public function setSession($session): void
496
+    {
497
+        $this->session = $session;
498
+    }
499
+
500
+    /**
501
+     * Get the JSON payload for the request.
502
+     * 
503
+     * @param  string|null  $key  
504
+     * @param  mixed  $default  
505
+     * 
506
+     * @return \Syscodes\Components\Http\Utilities\Parameters|mixed
507
+     */
508
+    public function json($key = null, $default = null)
509
+    {
510
+        if ( ! isset($this->json)) {
511
+            $this->json = new Parameters((array) json_decode($this->getContent(), true));
512
+        }
513
+
514
+        if (is_null($key)) {
515
+            return $this->json;
516
+        }
517
+
518
+        return Arr::get($this->json->all(), $key, $default);
519
+    }
520
+
521
+    /**
522
+     * Set the JSON payload for the request.
523
+     * 
524
+     * @param  \Syscodes\Components\Http\Utilities\Parameters  $json
525
+     * 
526
+     * @return static
527
+     */
528
+    public function setJson($json): static
529
+    {
530
+        $this->json = $json;
531
+
532
+        return $this;
533
+    }
534 534
 	
535
-	/**
536
-	 * Gets a list of content types acceptable by the client browser in preferable order.
537
-	 * 
538
-	 * @return string[]
539
-	 */
540
-	public function getAcceptableContentTypes(): array
541
-	{
542
-		if (null !== $this->acceptableContentTypes) {
543
-			return $this->acceptableContentTypes;
544
-		}
535
+    /**
536
+     * Gets a list of content types acceptable by the client browser in preferable order.
537
+     * 
538
+     * @return string[]
539
+     */
540
+    public function getAcceptableContentTypes(): array
541
+    {
542
+        if (null !== $this->acceptableContentTypes) {
543
+            return $this->acceptableContentTypes;
544
+        }
545 545
 		
546
-		return $this->acceptableContentTypes = array_map('strval', [$this->headers->get('Accept')]);
547
-	}
548
-
549
-	/**
550
-	 * Returns whether this is an AJAX request or not.
551
-	 * Alias of isXmlHttpRequest().
552
-	 *
553
-	 * @return bool
554
-	 */
555
-	public function ajax(): bool
556
-	{
557
-		return $this->isXmlHttpRequest();
558
-	}
559
-
560
-	/**
561
-	 * Returns whether this is an AJAX request or not.
562
-	 *
563
-	 * @return bool
564
-	 */
565
-	public function isXmlHttpRequest(): bool
566
-	{
567
-		return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && 
568
-				strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest';
569
-	}
546
+        return $this->acceptableContentTypes = array_map('strval', [$this->headers->get('Accept')]);
547
+    }
548
+
549
+    /**
550
+     * Returns whether this is an AJAX request or not.
551
+     * Alias of isXmlHttpRequest().
552
+     *
553
+     * @return bool
554
+     */
555
+    public function ajax(): bool
556
+    {
557
+        return $this->isXmlHttpRequest();
558
+    }
559
+
560
+    /**
561
+     * Returns whether this is an AJAX request or not.
562
+     *
563
+     * @return bool
564
+     */
565
+    public function isXmlHttpRequest(): bool
566
+    {
567
+        return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && 
568
+                strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest';
569
+    }
570 570
 	
571
-	/**
572
-	 * Determine if the request is the result of a PJAX call.
573
-	 * 
574
-	 * @return bool
575
-	 */
576
-	public function pjax(): bool
577
-	{
578
-		return $this->headers->get('X-PJAX') == true;
579
-	}
571
+    /**
572
+     * Determine if the request is the result of a PJAX call.
573
+     * 
574
+     * @return bool
575
+     */
576
+    public function pjax(): bool
577
+    {
578
+        return $this->headers->get('X-PJAX') == true;
579
+    }
580 580
 	
581
-	/**
582
-	 * Determine if the request is the result of a prefetch call.
583
-	 * 
584
-	 * @return bool
585
-	 */
586
-	public function prefetch(): bool
587
-	{
588
-		return strcasecmp($this->server->get('HTTP_X_MOZ') ?? '', 'prefetch') === 0 ||
589
-		       strcasecmp($this->headers->get('Purpose') ?? '', 'prefetch') === 0;
590
-	}
591
-
592
-	/**
593
-	 * Checks if the method request is of specified type.
594
-	 * 
595
-	 * @param  string  $method
596
-	 * 
597
-	 * @return bool
598
-	 */
599
-	public function isMethod(string $method): bool
600
-	{
601
-		return $this->getMethod() === strtoupper($method);
602
-	}
603
-
604
-	/**
581
+    /**
582
+     * Determine if the request is the result of a prefetch call.
583
+     * 
584
+     * @return bool
585
+     */
586
+    public function prefetch(): bool
587
+    {
588
+        return strcasecmp($this->server->get('HTTP_X_MOZ') ?? '', 'prefetch') === 0 ||
589
+               strcasecmp($this->headers->get('Purpose') ?? '', 'prefetch') === 0;
590
+    }
591
+
592
+    /**
593
+     * Checks if the method request is of specified type.
594
+     * 
595
+     * @param  string  $method
596
+     * 
597
+     * @return bool
598
+     */
599
+    public function isMethod(string $method): bool
600
+    {
601
+        return $this->getMethod() === strtoupper($method);
602
+    }
603
+
604
+    /**
605 605
      * Alias of the request method.
606 606
      * 
607 607
      * @return string
@@ -611,509 +611,509 @@  discard block
 block discarded – undo
611 611
         return $this->getMethod();
612 612
     }
613 613
 
614
-	/**
615
-	 * Returns the input method used (GET, POST, DELETE, etc.).
616
-	 *
617
-	 * @return string
618
-	 * 
619
-	 * @throws \LogicException  
620
-	 */
621
-	public function getmethod(): string
622
-	{
623
-		if (null !== $this->method) {
624
-			return $this->method;
625
-		}
614
+    /**
615
+     * Returns the input method used (GET, POST, DELETE, etc.).
616
+     *
617
+     * @return string
618
+     * 
619
+     * @throws \LogicException  
620
+     */
621
+    public function getmethod(): string
622
+    {
623
+        if (null !== $this->method) {
624
+            return $this->method;
625
+        }
626 626
 		
627
-		$this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
627
+        $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
628 628
 		
629
-		if ('POST' !== $this->method) {
630
-			return $this->method;
631
-		}
629
+        if ('POST' !== $this->method) {
630
+            return $this->method;
631
+        }
632 632
 		
633
-		$method = $this->headers->get('X-HTTP-METHOD-OVERRIDE');
633
+        $method = $this->headers->get('X-HTTP-METHOD-OVERRIDE');
634 634
 		
635
-		if ( ! $method && self::$httpMethodParameterOverride) {
636
-			$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
637
-		}
635
+        if ( ! $method && self::$httpMethodParameterOverride) {
636
+            $method = $this->request->get('_method', $this->query->get('_method', 'POST'));
637
+        }
638 638
 		
639
-		if ( ! is_string($method)) {
640
-			return $this->method;
641
-		}
639
+        if ( ! is_string($method)) {
640
+            return $this->method;
641
+        }
642 642
 		
643
-		$method = strtoupper($method);
643
+        $method = strtoupper($method);
644 644
 		
645
-		if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) {
646
-			return $this->method = $method;
647
-		}
645
+        if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) {
646
+            return $this->method = $method;
647
+        }
648 648
 		
649
-		if ( ! preg_match('/^[A-Z]++$/D', $method)) {
650
-			throw new LogicException(sprintf('Invalid method override "%s".', $method));
651
-		}
649
+        if ( ! preg_match('/^[A-Z]++$/D', $method)) {
650
+            throw new LogicException(sprintf('Invalid method override "%s".', $method));
651
+        }
652 652
 		
653
-		return $this->method = $method;
654
-	}
655
-
656
-	/**
657
-	 * Sets the request method.
658
-	 *
659
-	 * @param  string  $method  
660
-	 *
661
-	 * @return void
662
-	 */
663
-	public function setMethod(string $method): void
664
-	{
665
-		$this->method = null;
666
-
667
-		$this->server->set('REQUEST_METHOD', $method);
668
-	}
669
-
670
-	/**
671
-	 * Get the input source for the request.
672
-	 * 
673
-	 * @return \Syscodes\Components\Http\Utilities\Parameters
674
-	 */
675
-	public function getInputSource()
676
-	{
677
-		if ($this->isJson()) {
678
-			return $this->json();
679
-		}
680
-
681
-		return in_array($this->getMethod(), ['GET', 'HEAD']) ? $this->query : $this->request;
682
-	}
653
+        return $this->method = $method;
654
+    }
655
+
656
+    /**
657
+     * Sets the request method.
658
+     *
659
+     * @param  string  $method  
660
+     *
661
+     * @return void
662
+     */
663
+    public function setMethod(string $method): void
664
+    {
665
+        $this->method = null;
666
+
667
+        $this->server->set('REQUEST_METHOD', $method);
668
+    }
669
+
670
+    /**
671
+     * Get the input source for the request.
672
+     * 
673
+     * @return \Syscodes\Components\Http\Utilities\Parameters
674
+     */
675
+    public function getInputSource()
676
+    {
677
+        if ($this->isJson()) {
678
+            return $this->json();
679
+        }
680
+
681
+        return in_array($this->getMethod(), ['GET', 'HEAD']) ? $this->query : $this->request;
682
+    }
683 683
 	
684
-	/**
685
-	 * Determine if the current request URI matches a pattern.
686
-	 * 
687
-	 * @param  mixed  ...$patterns
688
-	 * 
689
-	 * @return bool
690
-	 */
691
-	public function is(...$patterns): bool
692
-	{
693
-		$path = $this->decodedPath();
684
+    /**
685
+     * Determine if the current request URI matches a pattern.
686
+     * 
687
+     * @param  mixed  ...$patterns
688
+     * 
689
+     * @return bool
690
+     */
691
+    public function is(...$patterns): bool
692
+    {
693
+        $path = $this->decodedPath();
694 694
 		
695
-		foreach ($patterns as $pattern) {
696
-			if (Str::is($pattern, $path)) {
697
-				return true;
698
-			}
699
-		}
700
-
701
-		return false;
702
-	}
703
-
704
-	/**
705
-	 * Determine if the route name matches a given pattern.
706
-	 * 
707
-	 * @param  mixed  ...$patterns
708
-	 * 
709
-	 * @return bool
710
-	 */
711
-	public function routeIs(...$patterns): bool
712
-	{
713
-		return $this->route() && $this->route()->is(...$patterns);
714
-	}
715
-
716
-	/**
717
-	 * Get the route handling the request.
718
-	 * 
719
-	 * @param  string|null  $param  
720
-	 * @param  mixed  $default  
721
-	 * 
722
-	 * @return \Syscodes\Components\Routing\Route|object|string|null
723
-	 */
724
-	public function route($param = null, $default = null)
725
-	{
726
-		$route = call_user_func($this->getRouteResolver());
727
-
728
-		if (is_null($route) || is_null($param)) {
729
-			return $route;
730
-		}
731
-
732
-		return $route->parameter($param, $default);
733
-	}
734
-
735
-	/**
736
-	 * Get the current decoded path info for the request.
737
-	 * 
738
-	 * @return string
739
-	 */
740
-	public function decodedPath(): string
741
-	{
742
-		return rawurldecode($this->path());
743
-	}
744
-
745
-	/**
746
-	 * Get the current path info for the request.
747
-	 * 
748
-	 * @return string
749
-	 */
750
-	public function path(): string
751
-	{
752
-		$path = trim($this->getPathInfo(), '/');
753
-
754
-		return $path == '' ? '/' : $path;
755
-	}
756
-
757
-	/**
758
-	 * Get the full URL for the request.
759
-	 * 
760
-	 * @return string
761
-	 */
762
-	public function fullUrl(): string
763
-	{
764
-		$query = $this->getQueryString();
695
+        foreach ($patterns as $pattern) {
696
+            if (Str::is($pattern, $path)) {
697
+                return true;
698
+            }
699
+        }
700
+
701
+        return false;
702
+    }
703
+
704
+    /**
705
+     * Determine if the route name matches a given pattern.
706
+     * 
707
+     * @param  mixed  ...$patterns
708
+     * 
709
+     * @return bool
710
+     */
711
+    public function routeIs(...$patterns): bool
712
+    {
713
+        return $this->route() && $this->route()->is(...$patterns);
714
+    }
715
+
716
+    /**
717
+     * Get the route handling the request.
718
+     * 
719
+     * @param  string|null  $param  
720
+     * @param  mixed  $default  
721
+     * 
722
+     * @return \Syscodes\Components\Routing\Route|object|string|null
723
+     */
724
+    public function route($param = null, $default = null)
725
+    {
726
+        $route = call_user_func($this->getRouteResolver());
727
+
728
+        if (is_null($route) || is_null($param)) {
729
+            return $route;
730
+        }
731
+
732
+        return $route->parameter($param, $default);
733
+    }
734
+
735
+    /**
736
+     * Get the current decoded path info for the request.
737
+     * 
738
+     * @return string
739
+     */
740
+    public function decodedPath(): string
741
+    {
742
+        return rawurldecode($this->path());
743
+    }
744
+
745
+    /**
746
+     * Get the current path info for the request.
747
+     * 
748
+     * @return string
749
+     */
750
+    public function path(): string
751
+    {
752
+        $path = trim($this->getPathInfo(), '/');
753
+
754
+        return $path == '' ? '/' : $path;
755
+    }
756
+
757
+    /**
758
+     * Get the full URL for the request.
759
+     * 
760
+     * @return string
761
+     */
762
+    public function fullUrl(): string
763
+    {
764
+        $query = $this->getQueryString();
765 765
 		
766
-		$question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?';
766
+        $question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?';
767 767
 		
768
-		return $query ? $this->url().$question.$query : $this->url();
769
-	}
768
+        return $query ? $this->url().$question.$query : $this->url();
769
+    }
770 770
 	
771
-	/**
772
-	 * Generates the normalized query string for the Request.
773
-	 * 
774
-	 * @return string
775
-	 */
776
-	public function getQueryString(): ?string
777
-	{
778
-		$queryString = RequestUtils::normalizedQueryString($this->server->get('QUERY_STRING'));
771
+    /**
772
+     * Generates the normalized query string for the Request.
773
+     * 
774
+     * @return string
775
+     */
776
+    public function getQueryString(): ?string
777
+    {
778
+        $queryString = RequestUtils::normalizedQueryString($this->server->get('QUERY_STRING'));
779 779
 		
780
-		return '' === $queryString ? null : $queryString;
781
-	}
782
-
783
-	/**
784
-	 * Retunrs the request body content.
785
-	 * 
786
-	 * @return string
787
-	 */
788
-	public function getContent(): string
789
-	{
790
-		if (null === $this->content || false === $this->content) {
791
-			$this->content = file_get_contents('php://input');
792
-		}
793
-
794
-		return $this->content;
795
-	}
796
-
797
-	/**
798
-	 * Returns the path being requested relative to the executed script. 
799
-	 * 
800
-	 * @return string
801
-	 */
802
-	public function getPathInfo(): string
803
-	{
804
-		if (null === $this->pathInfo) {
805
-			$this->pathInfo = $this->parsePathInfo();
806
-		}
807
-
808
-		return $this->pathInfo;
809
-	}
810
-
811
-	/**
812
-	 * Returns the root URL from which this request is executed.
813
-	 * 
814
-	 * @return string
815
-	 */
816
-	public function getBaseUrl(): string
817
-	{
818
-		if (null === $this->baseUrl) {
819
-			$this->baseUrl = $this->parseBaseUrl();
820
-		}
821
-
822
-		return $this->baseUrl;
823
-	}
824
-
825
-	/**
826
-	 * Returns the requested URI.
827
-	 * 
828
-	 * @return string
829
-	 */
830
-	public function getRequestUri(): string
831
-	{
832
-		if (null === $this->requestToUri) {
833
-			$this->requestToUri = $this->parseRequestUri();
834
-		}
835
-
836
-		return $this->requestToUri;
837
-	}
780
+        return '' === $queryString ? null : $queryString;
781
+    }
782
+
783
+    /**
784
+     * Retunrs the request body content.
785
+     * 
786
+     * @return string
787
+     */
788
+    public function getContent(): string
789
+    {
790
+        if (null === $this->content || false === $this->content) {
791
+            $this->content = file_get_contents('php://input');
792
+        }
793
+
794
+        return $this->content;
795
+    }
796
+
797
+    /**
798
+     * Returns the path being requested relative to the executed script. 
799
+     * 
800
+     * @return string
801
+     */
802
+    public function getPathInfo(): string
803
+    {
804
+        if (null === $this->pathInfo) {
805
+            $this->pathInfo = $this->parsePathInfo();
806
+        }
807
+
808
+        return $this->pathInfo;
809
+    }
810
+
811
+    /**
812
+     * Returns the root URL from which this request is executed.
813
+     * 
814
+     * @return string
815
+     */
816
+    public function getBaseUrl(): string
817
+    {
818
+        if (null === $this->baseUrl) {
819
+            $this->baseUrl = $this->parseBaseUrl();
820
+        }
821
+
822
+        return $this->baseUrl;
823
+    }
824
+
825
+    /**
826
+     * Returns the requested URI.
827
+     * 
828
+     * @return string
829
+     */
830
+    public function getRequestUri(): string
831
+    {
832
+        if (null === $this->requestToUri) {
833
+            $this->requestToUri = $this->parseRequestUri();
834
+        }
835
+
836
+        return $this->requestToUri;
837
+    }
838 838
 	
839
-	/**
840
-	 * Generates a normalized URI (URL) for the Request.
841
-	 * 
842
-	 * @return string
843
-	 */
844
-	public function getUri(): string
845
-	{
846
-		if (null !== $query = $this->getQueryString()) {
847
-			$query = '?'.$query;
848
-		}
839
+    /**
840
+     * Generates a normalized URI (URL) for the Request.
841
+     * 
842
+     * @return string
843
+     */
844
+    public function getUri(): string
845
+    {
846
+        if (null !== $query = $this->getQueryString()) {
847
+            $query = '?'.$query;
848
+        }
849 849
 	
850
-		return $this->getSchemeWithHttpHost().$this->getBaseUrl().$this->getPathInfo().$query;
851
-	}
850
+        return $this->getSchemeWithHttpHost().$this->getBaseUrl().$this->getPathInfo().$query;
851
+    }
852 852
 	
853
-	/**
854
-	 * Gets the request's scheme.
855
-	 * 
856
-	 * @return string
857
-	 */
858
-	public function getScheme(): string
859
-	{
860
-		return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http');
861
-	}
862
-
863
-	/**
864
-	 * Returns the host name.
865
-	 * 
866
-	 * @return string
867
-	 */
868
-	public function getHost(): string
869
-	{
870
-		if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) {
871
-			$host = $forwardedHost[0];
872
-		} elseif ( ! $host = $this->headers->get('HOST')) {
873
-			if ( ! $host = $this->server->get('SERVER_NAME')) {
874
-				$host = $this->server->get('REMOTE_ADDR', '');
875
-			}
876
-		}
877
-
878
-		$host = strtolower(preg_replace('/:\d+$/', '', trim(($host))));
853
+    /**
854
+     * Gets the request's scheme.
855
+     * 
856
+     * @return string
857
+     */
858
+    public function getScheme(): string
859
+    {
860
+        return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http');
861
+    }
862
+
863
+    /**
864
+     * Returns the host name.
865
+     * 
866
+     * @return string
867
+     */
868
+    public function getHost(): string
869
+    {
870
+        if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) {
871
+            $host = $forwardedHost[0];
872
+        } elseif ( ! $host = $this->headers->get('HOST')) {
873
+            if ( ! $host = $this->server->get('SERVER_NAME')) {
874
+                $host = $this->server->get('REMOTE_ADDR', '');
875
+            }
876
+        }
877
+
878
+        $host = strtolower(preg_replace('/:\d+$/', '', trim(($host))));
879 879
 		
880
-		return $this->uri->setHost($host);
881
-	}
882
-
883
-	/**
884
-	 * Returns the port on which the request is made.
885
-	 * 
886
-	 * @return int
887
-	 */
888
-	public function getPort(): int
889
-	{
890
-		if ( ! $this->server->get('HTTP_HOST')) {
891
-			return $this->server->get('SERVER_PORT');
892
-		}
880
+        return $this->uri->setHost($host);
881
+    }
882
+
883
+    /**
884
+     * Returns the port on which the request is made.
885
+     * 
886
+     * @return int
887
+     */
888
+    public function getPort(): int
889
+    {
890
+        if ( ! $this->server->get('HTTP_HOST')) {
891
+            return $this->server->get('SERVER_PORT');
892
+        }
893 893
 		
894
-		return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80);
895
-	}
896
-
897
-	/**
898
-	 * Get the user.
899
-	 * 
900
-	 * @return string|null
901
-	 */
902
-	public function getUser(): ?string
903
-	{
904
-		$user = $this->uri->setUser(
905
-			$this->headers->get('PHP_AUTH_USER')
906
-		);
907
-
908
-		return $user;
909
-	}
910
-
911
-	/**
912
-	 * Get the password.
913
-	 * 
914
-	 * @return string|null
915
-	 */
916
-	public function getPassword(): ?string
917
-	{
918
-		$password = $this->uri->setPassword(
919
-			$this->headers->get('PHP_AUTH_PW')
920
-		);
921
-
922
-		return $password;
923
-	}
924
-
925
-	/**
926
-	 * Gets the user info.
927
-	 * 
928
-	 * @return string|null
929
-	 */
930
-	public function getUserInfo(): ?string
931
-	{
932
-		return $this->uri->getUserInfo();
933
-	}
934
-
935
-	/**
936
-	 * Returns the HTTP host being requested.
937
-	 * 
938
-	 * @return string
939
-	 */
940
-	public function getHttpHost(): string
941
-	{
942
-		$scheme = $this->getScheme();
943
-		$port   = $this->getPort();
944
-
945
-		if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port))	{
946
-			return $this->getHost();
947
-		}
948
-
949
-		return $this->getHost().':'.$port;
950
-	}
951
-
952
-	/**
953
-	 * Gets the scheme and HTTP host.
954
-	 * 
955
-	 * @return string
956
-	 */
957
-	public function getSchemeWithHttpHost(): string
958
-	{
959
-		return $this->getScheme().'://'.$this->getHttpHost();
960
-	}
961
-
962
-	/**
963
-	 * Get the root URL for the application.
964
-	 * 
965
-	 * @return string
966
-	 */
967
-	public function root(): string
968
-	{
969
-		return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/');
970
-	}
971
-
972
-	/**
973
-	 * Get the URL for the request.
974
-	 * 
975
-	 * @return string
976
-	 */
977
-	public function url(): string
978
-	{
979
-		// Changed $this->path() for $this->getUri()
980
-		return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');
981
-	}
982
-
983
-	/**
984
-	 * Returns the referer.
985
-	 * 
986
-	 * @param  string  $default
987
-	 * 
988
-	 * @return string
989
-	 */
990
-	public function referer(string $default = ''): string
991
-	{
992
-		return $this->server->get('HTTP_REFERER', $default);
993
-	}
894
+        return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80);
895
+    }
896
+
897
+    /**
898
+     * Get the user.
899
+     * 
900
+     * @return string|null
901
+     */
902
+    public function getUser(): ?string
903
+    {
904
+        $user = $this->uri->setUser(
905
+            $this->headers->get('PHP_AUTH_USER')
906
+        );
907
+
908
+        return $user;
909
+    }
910
+
911
+    /**
912
+     * Get the password.
913
+     * 
914
+     * @return string|null
915
+     */
916
+    public function getPassword(): ?string
917
+    {
918
+        $password = $this->uri->setPassword(
919
+            $this->headers->get('PHP_AUTH_PW')
920
+        );
921
+
922
+        return $password;
923
+    }
924
+
925
+    /**
926
+     * Gets the user info.
927
+     * 
928
+     * @return string|null
929
+     */
930
+    public function getUserInfo(): ?string
931
+    {
932
+        return $this->uri->getUserInfo();
933
+    }
934
+
935
+    /**
936
+     * Returns the HTTP host being requested.
937
+     * 
938
+     * @return string
939
+     */
940
+    public function getHttpHost(): string
941
+    {
942
+        $scheme = $this->getScheme();
943
+        $port   = $this->getPort();
944
+
945
+        if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port))	{
946
+            return $this->getHost();
947
+        }
948
+
949
+        return $this->getHost().':'.$port;
950
+    }
951
+
952
+    /**
953
+     * Gets the scheme and HTTP host.
954
+     * 
955
+     * @return string
956
+     */
957
+    public function getSchemeWithHttpHost(): string
958
+    {
959
+        return $this->getScheme().'://'.$this->getHttpHost();
960
+    }
961
+
962
+    /**
963
+     * Get the root URL for the application.
964
+     * 
965
+     * @return string
966
+     */
967
+    public function root(): string
968
+    {
969
+        return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/');
970
+    }
971
+
972
+    /**
973
+     * Get the URL for the request.
974
+     * 
975
+     * @return string
976
+     */
977
+    public function url(): string
978
+    {
979
+        // Changed $this->path() for $this->getUri()
980
+        return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');
981
+    }
982
+
983
+    /**
984
+     * Returns the referer.
985
+     * 
986
+     * @param  string  $default
987
+     * 
988
+     * @return string
989
+     */
990
+    public function referer(string $default = ''): string
991
+    {
992
+        return $this->server->get('HTTP_REFERER', $default);
993
+    }
994 994
 	
995
-	/**
996
-	 * Attempts to detect if the current connection is secure through 
997
-	 * over HTTPS protocol.
998
-	 * 
999
-	 * @return bool
1000
-	 */
1001
-	public function secure(): bool
1002
-	{
1003
-		if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') {
1004
-			return true;
1005
-		} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') {
1006
-			return true;
1007
-		} elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') {
1008
-			return true;
1009
-		}
1010
-
1011
-		return false;
1012
-	}
1013
-
1014
-	/**
1015
-	 * Returns the user agent.
1016
-	 *
1017
-	 * @param  string|null  $default
1018
-	 *
1019
-	 * @return string
1020
-	 */
1021
-	public function userAgent(string $default = null): string
1022
-	{
1023
-		return $this->server->get('HTTP_USER_AGENT', $default);
1024
-	}
995
+    /**
996
+     * Attempts to detect if the current connection is secure through 
997
+     * over HTTPS protocol.
998
+     * 
999
+     * @return bool
1000
+     */
1001
+    public function secure(): bool
1002
+    {
1003
+        if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') {
1004
+            return true;
1005
+        } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') {
1006
+            return true;
1007
+        } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') {
1008
+            return true;
1009
+        }
1010
+
1011
+        return false;
1012
+    }
1013
+
1014
+    /**
1015
+     * Returns the user agent.
1016
+     *
1017
+     * @param  string|null  $default
1018
+     *
1019
+     * @return string
1020
+     */
1021
+    public function userAgent(string $default = null): string
1022
+    {
1023
+        return $this->server->get('HTTP_USER_AGENT', $default);
1024
+    }
1025 1025
 	
1026
-	/**
1027
-	 * Get the client IP address.
1028
-	 * 
1029
-	 * @return string|null
1030
-	 */
1031
-	public function ip(): ?string
1032
-	{
1033
-		return $this->clientIp->getClientIp();
1034
-	}
1035
-
1036
-	/**
1037
-	 * Get the route resolver callback.
1038
-	 * 
1039
-	 * @return \Closure
1040
-	 */
1041
-	public function getRouteResolver(): Closure
1042
-	{
1043
-		return $this->routeResolver ?: function () {
1044
-			//
1045
-		};
1046
-	}
1047
-
1048
-	/**
1049
-	 * Set the route resolver callback.
1050
-	 * 
1051
-	 * @param  \Closure  $callback
1052
-	 * 
1053
-	 * @return static
1054
-	 */
1055
-	public function setRouteResolver(Closure $callback): static
1056
-	{
1057
-		$this->routeResolver = $callback;
1058
-
1059
-		return $this;
1060
-	}
1061
-
1062
-	/**
1063
-	 * Magic method.
1064
-	 * 
1065
-	 * Get an element from the request.
1066
-	 * 
1067
-	 * @return string[]
1068
-	 */
1069
-	public function __get($key)
1070
-	{
1071
-		return Arr::get($this->all(), $key, fn () => $this->route($key));
1072
-	}
1073
-
1074
-	/**
1075
-	 * Magic method.
1076
-	 * 
1077
-	 * Returns the Request as an HTTP string.
1078
-	 * 
1079
-	 * @return string
1080
-	 */
1081
-	public function __toString(): string
1082
-	{
1083
-		$content = $this->getContent();
1084
-
1085
-		$cookieHeader = '';
1086
-		$cookies      = [];
1087
-
1088
-		foreach ($this->cookies as $key => $value) {
1089
-			$cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value";
1090
-		}
1091
-
1092
-		if ($cookies) {
1093
-			$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
1094
-		}
1026
+    /**
1027
+     * Get the client IP address.
1028
+     * 
1029
+     * @return string|null
1030
+     */
1031
+    public function ip(): ?string
1032
+    {
1033
+        return $this->clientIp->getClientIp();
1034
+    }
1035
+
1036
+    /**
1037
+     * Get the route resolver callback.
1038
+     * 
1039
+     * @return \Closure
1040
+     */
1041
+    public function getRouteResolver(): Closure
1042
+    {
1043
+        return $this->routeResolver ?: function () {
1044
+            //
1045
+        };
1046
+    }
1047
+
1048
+    /**
1049
+     * Set the route resolver callback.
1050
+     * 
1051
+     * @param  \Closure  $callback
1052
+     * 
1053
+     * @return static
1054
+     */
1055
+    public function setRouteResolver(Closure $callback): static
1056
+    {
1057
+        $this->routeResolver = $callback;
1058
+
1059
+        return $this;
1060
+    }
1061
+
1062
+    /**
1063
+     * Magic method.
1064
+     * 
1065
+     * Get an element from the request.
1066
+     * 
1067
+     * @return string[]
1068
+     */
1069
+    public function __get($key)
1070
+    {
1071
+        return Arr::get($this->all(), $key, fn () => $this->route($key));
1072
+    }
1073
+
1074
+    /**
1075
+     * Magic method.
1076
+     * 
1077
+     * Returns the Request as an HTTP string.
1078
+     * 
1079
+     * @return string
1080
+     */
1081
+    public function __toString(): string
1082
+    {
1083
+        $content = $this->getContent();
1084
+
1085
+        $cookieHeader = '';
1086
+        $cookies      = [];
1087
+
1088
+        foreach ($this->cookies as $key => $value) {
1089
+            $cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value";
1090
+        }
1091
+
1092
+        if ($cookies) {
1093
+            $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
1094
+        }
1095 1095
 		
1096
-		return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
1097
-			$this->headers.
1098
-			$cookieHeader."\r\n".
1099
-			$content;
1100
-	}
1101
-
1102
-	/**
1103
-	 * Magic method.
1104
-	 * 
1105
-	 * Clones the current request.
1106
-	 * 
1107
-	 * @return void
1108
-	 */
1109
-	public function __clone()
1110
-	{
1111
-		$this->query      = clone $this->query;
1112
-		$this->request    = clone $this->request;
1113
-		$this->attributes = clone $this->attributes;
1114
-		$this->cookies    = clone $this->cookies;
1115
-		$this->files      = clone $this->files;
1116
-		$this->server     = clone $this->server;
1117
-		$this->headers    = clone $this->headers;
1118
-	}
1096
+        return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
1097
+            $this->headers.
1098
+            $cookieHeader."\r\n".
1099
+            $content;
1100
+    }
1101
+
1102
+    /**
1103
+     * Magic method.
1104
+     * 
1105
+     * Clones the current request.
1106
+     * 
1107
+     * @return void
1108
+     */
1109
+    public function __clone()
1110
+    {
1111
+        $this->query      = clone $this->query;
1112
+        $this->request    = clone $this->request;
1113
+        $this->attributes = clone $this->attributes;
1114
+        $this->cookies    = clone $this->cookies;
1115
+        $this->files      = clone $this->files;
1116
+        $this->server     = clone $this->server;
1117
+        $this->headers    = clone $this->headers;
1118
+    }
1119 1119
 }
1120 1120
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 		$scheme = $this->getScheme();
943 943
 		$port   = $this->getPort();
944 944
 
945
-		if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port))	{
945
+		if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) {
946 946
 			return $this->getHost();
947 947
 		}
948 948
 
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
 	 */
1041 1041
 	public function getRouteResolver(): Closure
1042 1042
 	{
1043
-		return $this->routeResolver ?: function () {
1043
+		return $this->routeResolver ?: function() {
1044 1044
 			//
1045 1045
 		};
1046 1046
 	}
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
 		$cookies      = [];
1087 1087
 
1088 1088
 		foreach ($this->cookies as $key => $value) {
1089
-			$cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value";
1089
+			$cookies[] = is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value";
1090 1090
 		}
1091 1091
 
1092 1092
 		if ($cookies) {
Please login to merge, or discard this patch.
src/components/Http/ResponseHeaders.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -30,210 +30,210 @@
 block discarded – undo
30 30
  */
31 31
 class ResponseHeaders extends Headers
32 32
 {
33
-	const COOKIE_FLAT = 'flat';
34
-	const COOKIE_ARRAY = 'array';
33
+    const COOKIE_FLAT = 'flat';
34
+    const COOKIE_ARRAY = 'array';
35 35
 	
36
-	/**
37
-	 * The list of cookies.
38
-	 * 
39
-	 * @var array $cookies
40
-	 */
41
-	protected $cookies = [];
36
+    /**
37
+     * The list of cookies.
38
+     * 
39
+     * @var array $cookies
40
+     */
41
+    protected $cookies = [];
42 42
 
43 43
     /**
44 44
      * The header names.
45
-	 * 
46
-	 * @var array $headerNames 
45
+     * 
46
+     * @var array $headerNames 
47
+     */
48
+    protected $headerNames = [];
49
+
50
+    /**
51
+     * Constructor. Create a new ResponseHeaders class instance.
52
+     * 
53
+     * @param  array  $headers
54
+     * 
55
+     * @return void 
47 56
      */
48
-	protected $headerNames = [];
49
-
50
-	/**
51
-	 * Constructor. Create a new ResponseHeaders class instance.
52
-	 * 
53
-	 * @param  array  $headers
54
-	 * 
55
-	 * @return void 
56
-	 */
57
-	public function __construct(array $headers = [])
58
-	{
59
-		parent::__construct($headers);
57
+    public function __construct(array $headers = [])
58
+    {
59
+        parent::__construct($headers);
60 60
 		
61
-		if ( ! isset($this->headers['cache-control'])) {
62
-			$this->set('Cache-Control', '');
63
-		}
64
-
65
-		if ( ! isset($this->headers['date'])) {
66
-			$this->initDate();
67
-		}
68
-	}
69
-
70
-	/**
71
-	 * Returns the headers, without cookies.
72
-	 * 
73
-	 * @return mixed
74
-	 */
75
-	public function allPreserveCaseWithoutCookies()
76
-	{
77
-		$headers = $this->allPreserveCase();
61
+        if ( ! isset($this->headers['cache-control'])) {
62
+            $this->set('Cache-Control', '');
63
+        }
64
+
65
+        if ( ! isset($this->headers['date'])) {
66
+            $this->initDate();
67
+        }
68
+    }
69
+
70
+    /**
71
+     * Returns the headers, without cookies.
72
+     * 
73
+     * @return mixed
74
+     */
75
+    public function allPreserveCaseWithoutCookies()
76
+    {
77
+        $headers = $this->allPreserveCase();
78 78
 		
79
-		if (isset($this->headerNames['set-cookie'])) {
80
-			unset($headers[$this->headerNames['set-cookie']]);
81
-		}
79
+        if (isset($this->headerNames['set-cookie'])) {
80
+            unset($headers[$this->headerNames['set-cookie']]);
81
+        }
82 82
 		
83
-		return $headers;
84
-	}
83
+        return $headers;
84
+    }
85 85
 
86 86
     /**
87
-	 * Returns the headers, with original capitalizations.
88
-	 * 
89
-	 * @return array An array of headers
90
-	 */
91
-	public function allPreserveCase(): array
92
-	{
93
-		$headers = [];
87
+     * Returns the headers, with original capitalizations.
88
+     * 
89
+     * @return array An array of headers
90
+     */
91
+    public function allPreserveCase(): array
92
+    {
93
+        $headers = [];
94 94
 		
95
-		foreach ($this->all() as $name => $value) {
96
-			$headers[$this->headerNames[$name] ?? $name] = $value;
97
-		}
95
+        foreach ($this->all() as $name => $value) {
96
+            $headers[$this->headerNames[$name] ?? $name] = $value;
97
+        }
98 98
 		
99
-		return $headers;
100
-	}
99
+        return $headers;
100
+    }
101 101
 	
102
-	/**
103
-	 * Returns all the headers.
104
-	 * 
105
-	 * @param  string|null  $key  The name of the headers
106
-	 * 
107
-	 * @return array
108
-	 */
109
-	public function all(string $key = null): array
110
-	{
111
-		$headers = parent::all();
102
+    /**
103
+     * Returns all the headers.
104
+     * 
105
+     * @param  string|null  $key  The name of the headers
106
+     * 
107
+     * @return array
108
+     */
109
+    public function all(string $key = null): array
110
+    {
111
+        $headers = parent::all();
112 112
 		
113
-		if (null !== $key) {
114
-			$key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
113
+        if (null !== $key) {
114
+            $key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
115 115
 			
116
-			return 'set-cookie' !== $key ? $headers[$key] ?? [] : array_map('strval', $this->getCookies());
117
-		}
116
+            return 'set-cookie' !== $key ? $headers[$key] ?? [] : array_map('strval', $this->getCookies());
117
+        }
118 118
 		
119
-		foreach ($this->getCookies() as $cookie) {
120
-			$headers['set-cookie'][] = (string) $cookie;
121
-		}
119
+        foreach ($this->getCookies() as $cookie) {
120
+            $headers['set-cookie'][] = (string) $cookie;
121
+        }
122 122
 		
123
-		return $headers;
124
-	}
125
-
126
-	/**
127
-	 * Replaces the current HTTP headers by a new set.
128
-	 * 
129
-	 * @param  array  $headers
130
-	 * 
131
-	 * @return void
132
-	 */
133
-	public function replace(array $headers = []): void
134
-	{
135
-		$this->headerNames = [];
136
-
137
-		parent::replace($headers);
138
-
139
-		if ( ! isset($this->headers['cache-control'])) {
140
-			$this->set('Cache-Control', '');
141
-		}
123
+        return $headers;
124
+    }
125
+
126
+    /**
127
+     * Replaces the current HTTP headers by a new set.
128
+     * 
129
+     * @param  array  $headers
130
+     * 
131
+     * @return void
132
+     */
133
+    public function replace(array $headers = []): void
134
+    {
135
+        $this->headerNames = [];
136
+
137
+        parent::replace($headers);
138
+
139
+        if ( ! isset($this->headers['cache-control'])) {
140
+            $this->set('Cache-Control', '');
141
+        }
142 142
 		
143
-		if ( ! isset($this->headers['date'])) {
144
-			$this->initDate();
145
-		}
146
-	}
147
-
148
-	/**
149
-	 * Sets a header by name.
150
-	 * 
151
-	 * @param  string  $key  The header name
152
-	 * @param  string|string[]|null  $values  The value or an array of values
153
-	 * @param  bool  $replace  If you want to replace the value exists by the header, 
154
-	 * 					       it is not overwritten / overwritten when it is false
155
-	 *
156
-	 * @return void
157
-	 */
158
-	public function set(string $key, $values, bool $replace = true): void
159
-	{
160
-		$unique = strtr($key, self::STRING_UPPER, self::STRING_LOWER); 
143
+        if ( ! isset($this->headers['date'])) {
144
+            $this->initDate();
145
+        }
146
+    }
147
+
148
+    /**
149
+     * Sets a header by name.
150
+     * 
151
+     * @param  string  $key  The header name
152
+     * @param  string|string[]|null  $values  The value or an array of values
153
+     * @param  bool  $replace  If you want to replace the value exists by the header, 
154
+     * 					       it is not overwritten / overwritten when it is false
155
+     *
156
+     * @return void
157
+     */
158
+    public function set(string $key, $values, bool $replace = true): void
159
+    {
160
+        $unique = strtr($key, self::STRING_UPPER, self::STRING_LOWER); 
161 161
 		
162
-		if ('set-cookie' === $unique) {
163
-			if ($replace) {
164
-				$this->cookies = [];
165
-			}
162
+        if ('set-cookie' === $unique) {
163
+            if ($replace) {
164
+                $this->cookies = [];
165
+            }
166 166
 			
167
-			foreach ((array) $values as $cookie) {
168
-				$this->setCookie($cookie);
169
-			}
167
+            foreach ((array) $values as $cookie) {
168
+                $this->setCookie($cookie);
169
+            }
170 170
 			
171
-			$this->headerNames[$unique] = $key;
171
+            $this->headerNames[$unique] = $key;
172 172
 
173
-			return;
174
-		}
173
+            return;
174
+        }
175 175
 		
176
-		$this->headerNames[$unique] = $key;
176
+        $this->headerNames[$unique] = $key;
177 177
 		
178
-		parent::set($key, $values, $replace);
179
-	}
178
+        parent::set($key, $values, $replace);
179
+    }
180 180
 	
181
-	/**
182
-	 * Gets an array with all cookies.
183
-	 * 
184
-	 * @param  string  $format
185
-	 * 
186
-	 * @return Cookie[]
187
-	 * 
188
-	 * @throws \InvalidArgumentException
189
-	 */
190
-	public function getCookies(string $format = self::COOKIE_FLAT): array
191
-	{
192
-		if ( ! in_array($format, [self::COOKIE_FLAT, self::COOKIE_ARRAY])) {
193
-			throw new InvalidArgumentException(
194
-				sprintf('Format "%s" invalid (%s)', $format, implode(', ', [self::COOKIE_FLAT, self::COOKIE_ARRAY])
195
-			));
196
-		}
181
+    /**
182
+     * Gets an array with all cookies.
183
+     * 
184
+     * @param  string  $format
185
+     * 
186
+     * @return Cookie[]
187
+     * 
188
+     * @throws \InvalidArgumentException
189
+     */
190
+    public function getCookies(string $format = self::COOKIE_FLAT): array
191
+    {
192
+        if ( ! in_array($format, [self::COOKIE_FLAT, self::COOKIE_ARRAY])) {
193
+            throw new InvalidArgumentException(
194
+                sprintf('Format "%s" invalid (%s)', $format, implode(', ', [self::COOKIE_FLAT, self::COOKIE_ARRAY])
195
+            ));
196
+        }
197 197
 		
198
-		if (self::COOKIE_ARRAY === $format) {
199
-			return $this->cookies;
200
-		}
198
+        if (self::COOKIE_ARRAY === $format) {
199
+            return $this->cookies;
200
+        }
201 201
 		
202
-		$stringCookies = [];
203
-
204
-		foreach ($this->cookies as $path) {
205
-			foreach ($path as $cookies) {
206
-				foreach ($cookies as $cookie) {
207
-					$stringCookies[] = $cookie;
208
-				}
209
-			}
210
-		}
202
+        $stringCookies = [];
203
+
204
+        foreach ($this->cookies as $path) {
205
+            foreach ($path as $cookies) {
206
+                foreach ($cookies as $cookie) {
207
+                    $stringCookies[] = $cookie;
208
+                }
209
+            }
210
+        }
211 211
 		
212
-		return $stringCookies;
212
+        return $stringCookies;
213 213
     }
214 214
 
215
-	/**
216
-	 * Sets the cookie.
217
-	 * 
218
-	 * @param  \Syscodes\Components\Http\Cookie  $cookie
219
-	 * 
220
-	 * @return static
221
-	 */
222
-	public function setCookie(Cookie $cookie): static
223
-	{
224
-		$this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
225
-		$this->headerNames['set-cookie'] = 'Set-Cookie';
226
-
227
-		return $this;
228
-	}
229
-
230
-	/**
231
-	 * Initialize the date.
232
-	 * 
233
-	 * @return void
234
-	 */
235
-	private function initDate(): void
236
-	{
237
-		$this->set('Date', gmdate('D, d M Y H:i:s').' GMT');
238
-	}
215
+    /**
216
+     * Sets the cookie.
217
+     * 
218
+     * @param  \Syscodes\Components\Http\Cookie  $cookie
219
+     * 
220
+     * @return static
221
+     */
222
+    public function setCookie(Cookie $cookie): static
223
+    {
224
+        $this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
225
+        $this->headerNames['set-cookie'] = 'Set-Cookie';
226
+
227
+        return $this;
228
+    }
229
+
230
+    /**
231
+     * Initialize the date.
232
+     * 
233
+     * @return void
234
+     */
235
+    private function initDate(): void
236
+    {
237
+        $this->set('Date', gmdate('D, d M Y H:i:s').' GMT');
238
+    }
239 239
 }
240 240
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Resources/HttpResources.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -29,211 +29,211 @@
 block discarded – undo
29 29
  */
30 30
 trait HttpResources
31 31
 {
32
-	/**
33
-	 * Filters a value from the start of a string in this case the passed URI string.
34
-	 *
35
-	 * @return string
36
-	 */
37
-	protected function parseRequestUri(): string
38
-	{
39
-		$requestUri = '';
40
-		
41
-		if ('1' == $this->server->get('IIS_WasUrlRewritten') && '' != $this->server->get('UNENCODED_URL')) {
42
-			// IIS7 with URL Rewrite: make sure we get the unencoded URL (double slash problem)
43
-			$requestUri = $this->server->get('UNENCODED_URL');
44
-			$this->server->remove('UNENCODED_URL');
45
-			$this->server->remove('IIS_WasUrlRewritten');
46
-		} elseif ($this->server->has('REQUEST_URI')) {
47
-			$requestUri = $this->server->get('REQUEST_URI');
32
+    /**
33
+     * Filters a value from the start of a string in this case the passed URI string.
34
+     *
35
+     * @return string
36
+     */
37
+    protected function parseRequestUri(): string
38
+    {
39
+        $requestUri = '';
40
+		
41
+        if ('1' == $this->server->get('IIS_WasUrlRewritten') && '' != $this->server->get('UNENCODED_URL')) {
42
+            // IIS7 with URL Rewrite: make sure we get the unencoded URL (double slash problem)
43
+            $requestUri = $this->server->get('UNENCODED_URL');
44
+            $this->server->remove('UNENCODED_URL');
45
+            $this->server->remove('IIS_WasUrlRewritten');
46
+        } elseif ($this->server->has('REQUEST_URI')) {
47
+            $requestUri = $this->server->get('REQUEST_URI');
48 48
 			
49
-			if ('' !== $requestUri && '/' === $requestUri[0]) {
50
-				// To only use path and query remove the fragment.
51
-				if (false !== $pos = strpos($requestUri, '#')) {
52
-					$requestUri = substr($requestUri, 0, $pos);
53
-				}
54
-			} else {
55
-				// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
56
-				// only use URL path.
57
-				$uriComponents = parse_url($requestUri);
49
+            if ('' !== $requestUri && '/' === $requestUri[0]) {
50
+                // To only use path and query remove the fragment.
51
+                if (false !== $pos = strpos($requestUri, '#')) {
52
+                    $requestUri = substr($requestUri, 0, $pos);
53
+                }
54
+            } else {
55
+                // HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
56
+                // only use URL path.
57
+                $uriComponents = parse_url($requestUri);
58 58
 				
59
-				if (isset($uriComponents['path'])) {
60
-					$requestUri = $uriComponents['path'];
61
-				}
59
+                if (isset($uriComponents['path'])) {
60
+                    $requestUri = $uriComponents['path'];
61
+                }
62 62
 				
63
-				if (isset($uriComponents['query'])) {
64
-					$requestUri .= '?'.$uriComponents['query'];
65
-				}
66
-			}
67
-		} elseif ($this->server->has('ORIG_PATH_INFO')) {
68
-			// IIS 5.0, PHP as CGI
69
-			$requestUri = $this->server->get('ORIG_PATH_INFO');
63
+                if (isset($uriComponents['query'])) {
64
+                    $requestUri .= '?'.$uriComponents['query'];
65
+                }
66
+            }
67
+        } elseif ($this->server->has('ORIG_PATH_INFO')) {
68
+            // IIS 5.0, PHP as CGI
69
+            $requestUri = $this->server->get('ORIG_PATH_INFO');
70 70
 			
71
-			if ('' != $this->server->get('QUERY_STRING')) {
72
-				$requestUri .= '?'.$this->server->get('QUERY_STRING');
73
-			}
71
+            if ('' != $this->server->get('QUERY_STRING')) {
72
+                $requestUri .= '?'.$this->server->get('QUERY_STRING');
73
+            }
74 74
 			
75
-			$this->server->remove('ORIG_PATH_INFO');
76
-		}
75
+            $this->server->remove('ORIG_PATH_INFO');
76
+        }
77 77
 		
78
-		// normalize the request URI to ease creating sub-requests from this request
79
-		$this->server->set('REQUEST_URI', $requestUri);
78
+        // normalize the request URI to ease creating sub-requests from this request
79
+        $this->server->set('REQUEST_URI', $requestUri);
80 80
 		
81
-		return $this->filterDecode($requestUri);
82
-	}
81
+        return $this->filterDecode($requestUri);
82
+    }
83 83
 
84
-	/**
85
-	 * Will parse QUERY_STRING and automatically detect the URI from it.
86
-	 * 
87
-	 * @return string
88
-	 */
89
-	protected function parseQueryString(): string
90
-	{
91
-		$uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');
84
+    /**
85
+     * Will parse QUERY_STRING and automatically detect the URI from it.
86
+     * 
87
+     * @return string
88
+     */
89
+    protected function parseQueryString(): string
90
+    {
91
+        $uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');
92 92
 
93
-		if (trim($uri, '/') === '') {
94
-			return '';
95
-		} elseif (0 === strncmp($uri, '/', 1)) {
96
-			$uri    				 = explode('?', $uri, 2);
97
-			$_SERVER['QUERY_STRING'] = $uri[1] ?? '';
98
-			$uri    				 = $uri[0] ?? '';
99
-		}
93
+        if (trim($uri, '/') === '') {
94
+            return '';
95
+        } elseif (0 === strncmp($uri, '/', 1)) {
96
+            $uri    				 = explode('?', $uri, 2);
97
+            $_SERVER['QUERY_STRING'] = $uri[1] ?? '';
98
+            $uri    				 = $uri[0] ?? '';
99
+        }
100 100
 
101
-		parse_str($_SERVER['QUERY_STRING'], $_GET);
101
+        parse_str($_SERVER['QUERY_STRING'], $_GET);
102 102
 
103
-		return $this->filterDecode($uri);
104
-	}
103
+        return $this->filterDecode($uri);
104
+    }
105 105
 	
106
-	/**
107
-	 * Parse the base URL.
108
-	 * 
109
-	 * @return string
110
-	 */
111
-	public function parseBaseUrl(): string
112
-	{
113
-		$filename = basename($this->server('SCRIPT_FILENAME'));
114
-		
115
-		if ($filename === basename($this->server('SCRIPT_NAME'))) {
116
-			$baseUrl = $this->server('SCRIPT_NAME');
117
-		} elseif ($filename === basename($this->server('PHP_SELF'))) {
118
-			$baseUrl = $this->server('PHP_SELF');
119
-		} elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME'))) {
120
-			$baseUrl = $this->server('ORIG_SCRIPT_NAME');
121
-		} else {
122
-			$path    = $this->server('PHP_SELF', '');
123
-			$file    = $this->server('SCRIPT_NAME', '');
124
-			$segs    = explode('/', trim($file, '/'));
125
-			$segs    = array_reverse($segs);
126
-			$index   = 0;
127
-			$last    = count($segs);
128
-			$baseUrl = '';
106
+    /**
107
+     * Parse the base URL.
108
+     * 
109
+     * @return string
110
+     */
111
+    public function parseBaseUrl(): string
112
+    {
113
+        $filename = basename($this->server('SCRIPT_FILENAME'));
114
+		
115
+        if ($filename === basename($this->server('SCRIPT_NAME'))) {
116
+            $baseUrl = $this->server('SCRIPT_NAME');
117
+        } elseif ($filename === basename($this->server('PHP_SELF'))) {
118
+            $baseUrl = $this->server('PHP_SELF');
119
+        } elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME'))) {
120
+            $baseUrl = $this->server('ORIG_SCRIPT_NAME');
121
+        } else {
122
+            $path    = $this->server('PHP_SELF', '');
123
+            $file    = $this->server('SCRIPT_NAME', '');
124
+            $segs    = explode('/', trim($file, '/'));
125
+            $segs    = array_reverse($segs);
126
+            $index   = 0;
127
+            $last    = count($segs);
128
+            $baseUrl = '';
129 129
 			
130
-			do 	{
131
-				$seg     = $segs[$index];
132
-				$baseUrl = '/'.$seg.$baseUrl;
133
-				++$index;
134
-			} while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
135
-		}
136
-		
137
-		// Does the baseUrl have anything in common with the request_uri?
138
-		$requestUri = $this->getRequestUri();
139
-		
140
-		if ('' !== $requestUri && '/' !== $requestUri[0]) {
141
-			$requestUri = '/'.$requestUri;
142
-		}
143
-		
144
-		if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, $baseUrl)) {
145
-			// Full $baseUrl matches
146
-			return $this->filterDecode($uri);
147
-		}
148
-		
149
-		if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, rtrim(dirname($baseUrl), '/'.DIRECTORY_SEPARATOR))) {
150
-			// Directory portion of $baseUrl matches
151
-			return $this->filterDecode($uri);
152
-		}
130
+            do 	{
131
+                $seg     = $segs[$index];
132
+                $baseUrl = '/'.$seg.$baseUrl;
133
+                ++$index;
134
+            } while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
135
+        }
136
+		
137
+        // Does the baseUrl have anything in common with the request_uri?
138
+        $requestUri = $this->getRequestUri();
139
+		
140
+        if ('' !== $requestUri && '/' !== $requestUri[0]) {
141
+            $requestUri = '/'.$requestUri;
142
+        }
143
+		
144
+        if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, $baseUrl)) {
145
+            // Full $baseUrl matches
146
+            return $this->filterDecode($uri);
147
+        }
148
+		
149
+        if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, rtrim(dirname($baseUrl), '/'.DIRECTORY_SEPARATOR))) {
150
+            // Directory portion of $baseUrl matches
151
+            return $this->filterDecode($uri);
152
+        }
153 153
 
154
-		$baseUrl = dirname($baseUrl ?? '');
154
+        $baseUrl = dirname($baseUrl ?? '');
155 155
 		
156
-		// If using mod_rewrite or ISAPI_Rewrite strip the script filename
157
-		// out of baseUrl. $pos !== 0 makes sure it is not matching a value
158
-		// from PATH_INFO or QUERY_STRING
159
-		if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && 0 !== $pos) {
160
-			$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
161
-		}
156
+        // If using mod_rewrite or ISAPI_Rewrite strip the script filename
157
+        // out of baseUrl. $pos !== 0 makes sure it is not matching a value
158
+        // from PATH_INFO or QUERY_STRING
159
+        if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && 0 !== $pos) {
160
+            $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
161
+        }
162 162
 		
163
-		return $this->filterDecode($baseUrl);
164
-	}
163
+        return $this->filterDecode($baseUrl);
164
+    }
165 165
 	
166
-	/**
167
-	 * Returns the prefix as encoded in the string when the string starts with
168
-	 * the given prefix, null otherwise.
169
-	 *
170
-	 * return string|null
171
-	 */
172
-	private function getUrlencoded(string $string, string $prefix): ?string
173
-	{
174
-		if ( ! Str::startsWith(rawurldecode($string), $prefix)) {
175
-			return null;
176
-		}
177
-		
178
-		$length = strlen($prefix);
179
-		
180
-		if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $length), $string, $match)) {
181
-			return $match[0];
182
-		}
183
-		
184
-		return null;
185
-	}
166
+    /**
167
+     * Returns the prefix as encoded in the string when the string starts with
168
+     * the given prefix, null otherwise.
169
+     *
170
+     * return string|null
171
+     */
172
+    private function getUrlencoded(string $string, string $prefix): ?string
173
+    {
174
+        if ( ! Str::startsWith(rawurldecode($string), $prefix)) {
175
+            return null;
176
+        }
177
+		
178
+        $length = strlen($prefix);
179
+		
180
+        if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $length), $string, $match)) {
181
+            return $match[0];
182
+        }
183
+		
184
+        return null;
185
+    }
186 186
 
187 187
 
188
-	/**
189
-	 * Parse the path info.
190
-	 * 
191
-	 * @return string
192
-	 */
193
-	public function parsePathInfo(): string
194
-	{
195
-		if (null === ($requestUri = $this->getRequestUri())) {
196
-			return '/';
197
-		}
198
-		
199
-		// Remove the query string from REQUEST_URI
200
-		if (false !== $pos = strpos($requestUri, '?')) {
201
-			$requestUri = substr($requestUri, 0, $pos);
202
-		}
203
-		
204
-		if ('' !== $requestUri && '/' !== $requestUri[0]) {
205
-			$requestUri = '/'.$requestUri;
206
-		}
207
-		
208
-		if (null === ($baseUrl = $this->getBaseUrl())) {
209
-			return $requestUri;
210
-		}
211
-		
212
-		$pathInfo = substr($requestUri, \strlen($baseUrl));
213
-		
214
-		if (false === $pathInfo || '' === $pathInfo) {
215
-			// If substr() returns false then PATH_INFO is set to an empty string
216
-			return '/';
217
-		}
218
-		
219
-		return $this->filterDecode($pathInfo);
220
-	}
188
+    /**
189
+     * Parse the path info.
190
+     * 
191
+     * @return string
192
+     */
193
+    public function parsePathInfo(): string
194
+    {
195
+        if (null === ($requestUri = $this->getRequestUri())) {
196
+            return '/';
197
+        }
198
+		
199
+        // Remove the query string from REQUEST_URI
200
+        if (false !== $pos = strpos($requestUri, '?')) {
201
+            $requestUri = substr($requestUri, 0, $pos);
202
+        }
203
+		
204
+        if ('' !== $requestUri && '/' !== $requestUri[0]) {
205
+            $requestUri = '/'.$requestUri;
206
+        }
207
+		
208
+        if (null === ($baseUrl = $this->getBaseUrl())) {
209
+            return $requestUri;
210
+        }
211
+		
212
+        $pathInfo = substr($requestUri, \strlen($baseUrl));
213
+		
214
+        if (false === $pathInfo || '' === $pathInfo) {
215
+            // If substr() returns false then PATH_INFO is set to an empty string
216
+            return '/';
217
+        }
218
+		
219
+        return $this->filterDecode($pathInfo);
220
+    }
221 221
 
222
-	/**
223
-	 * Filters the uri string remove any malicious characters and inappropriate slashes.
224
-	 *
225
-	 * @param  string  $uri
226
-	 *
227
-	 * @return string
228
-	 */
229
-	protected function filterDecode($uri): string
230
-	{
231
-		// Remove all characters except letters,
232
-		// digits and $-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=.
233
-		$uri = filter_var(rawurldecode($uri), FILTER_SANITIZE_URL);
234
-		$uri = mb_strtolower(trim($uri), 'UTF-8');
235
-		
236
-		// Return argument if not empty or return a single slash
237
-		return trim($uri);
238
-	}
222
+    /**
223
+     * Filters the uri string remove any malicious characters and inappropriate slashes.
224
+     *
225
+     * @param  string  $uri
226
+     *
227
+     * @return string
228
+     */
229
+    protected function filterDecode($uri): string
230
+    {
231
+        // Remove all characters except letters,
232
+        // digits and $-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=.
233
+        $uri = filter_var(rawurldecode($uri), FILTER_SANITIZE_URL);
234
+        $uri = mb_strtolower(trim($uri), 'UTF-8');
235
+		
236
+        // Return argument if not empty or return a single slash
237
+        return trim($uri);
238
+    }
239 239
 }
240 240
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@
 block discarded – undo
127 127
 			$last    = count($segs);
128 128
 			$baseUrl = '';
129 129
 			
130
-			do 	{
130
+			do {
131 131
 				$seg     = $segs[$index];
132 132
 				$baseUrl = '/'.$seg.$baseUrl;
133 133
 				++$index;
Please login to merge, or discard this patch.
src/components/Http/Resources/HttpRequest.php 2 patches
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -31,33 +31,33 @@  discard block
 block discarded – undo
31 31
  */
32 32
 trait HttpRequest
33 33
 {
34
-	/**
35
-	 * Holds the global active request instance.
36
-	 *
37
-	 * @var bool $requestURI
38
-	 */
39
-	protected static $requestURI;
40
-
41
-	/**
42
-	 * Get the http method parameter.
43
-	 * 
44
-	 * @var bool $httpMethodParameterOverride
45
-	 */
46
-	protected static $httpMethodParameterOverride = false;
34
+    /**
35
+     * Holds the global active request instance.
36
+     *
37
+     * @var bool $requestURI
38
+     */
39
+    protected static $requestURI;
40
+
41
+    /**
42
+     * Get the http method parameter.
43
+     * 
44
+     * @var bool $httpMethodParameterOverride
45
+     */
46
+    protected static $httpMethodParameterOverride = false;
47 47
 
48 48
     /**
49
-	 * Create a new Syscodes HTTP request from server variables.
50
-	 * 
51
-	 * @return static
52
-	 */
53
-	public static function capture(): static
54
-	{
55
-		static::enabledHttpMethodParameterOverride();
49
+     * Create a new Syscodes HTTP request from server variables.
50
+     * 
51
+     * @return static
52
+     */
53
+    public static function capture(): static
54
+    {
55
+        static::enabledHttpMethodParameterOverride();
56 56
 		
57
-		return static::createFromRequest(static::createFromRequestGlobals());
58
-	}
57
+        return static::createFromRequest(static::createFromRequestGlobals());
58
+    }
59 59
 
60
-	/**
60
+    /**
61 61
      * Enables support for the _method request parameter to determine the intended HTTP method.
62 62
      * 
63 63
      * @return void
@@ -67,101 +67,101 @@  discard block
 block discarded – undo
67 67
         self::$httpMethodParameterOverride = true;
68 68
     }
69 69
 	
70
-	/**
71
-	 * Checks whether support for the _method request parameter is enabled.
72
-	 * 
73
-	 * @return bool
74
-	 */
75
-	public static function getHttpMethodParameterOverride(): bool
76
-	{
77
-		return self::$httpMethodParameterOverride;
78
-	}
79
-
80
-	/**
81
-	 * Creates an Syscodes request from of the Request class instance.
82
-	 * 
83
-	 * @param  \Syscodes\Components\Http\Request  $request
84
-	 * 
85
-	 * @return static
86
-	 */
87
-	public static function createFromRequest($request): static
88
-	{
89
-		$newRequest = (new static)->duplicate(
90
-			$request->query->all(), $request->request->all(), $request->attributes->all(),
91
-			$request->cookies->all(), $request->files->all(), $request->server->all()
92
-		);
70
+    /**
71
+     * Checks whether support for the _method request parameter is enabled.
72
+     * 
73
+     * @return bool
74
+     */
75
+    public static function getHttpMethodParameterOverride(): bool
76
+    {
77
+        return self::$httpMethodParameterOverride;
78
+    }
79
+
80
+    /**
81
+     * Creates an Syscodes request from of the Request class instance.
82
+     * 
83
+     * @param  \Syscodes\Components\Http\Request  $request
84
+     * 
85
+     * @return static
86
+     */
87
+    public static function createFromRequest($request): static
88
+    {
89
+        $newRequest = (new static)->duplicate(
90
+            $request->query->all(), $request->request->all(), $request->attributes->all(),
91
+            $request->cookies->all(), $request->files->all(), $request->server->all()
92
+        );
93 93
 		
94
-		$newRequest->headers->replace($request->headers->all());
94
+        $newRequest->headers->replace($request->headers->all());
95 95
 		
96
-		$newRequest->content = $request->content;
96
+        $newRequest->content = $request->content;
97 97
 		
98
-		if ($newRequest->isJson()) {
99
-			$newRequest->request = $newRequest->json();
100
-		}
98
+        if ($newRequest->isJson()) {
99
+            $newRequest->request = $newRequest->json();
100
+        }
101 101
 		
102
-		return $newRequest;
103
-	}
104
-
105
-	/**
106
-	 * Creates a new request with value from PHP's super global.
107
-	 * 
108
-	 * @return static
109
-	 */
110
-	public static function createFromRequestGlobals(): static
111
-	{
112
-		$request = static::createFromRequestFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
113
-
114
-		if (Str::startsWith($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded')
115
-		    && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])) {
116
-			parse_str($request->getContent(), $data);
117
-			$request->request = new Inputs($data);
118
-		}
119
-
120
-		return $request;
121
-	}
122
-
123
-	/**
124
-	 * Creates a new request from a factory.
125
-	 * 
126
-	 * @param  array  $query
127
-	 * @param  array  $request
128
-	 * @param  array  $attributes
129
-	 * @param  array  $cookies
130
-	 * @param  array  $files
131
-	 * @param  array  $server
132
-	 * 
133
-	 * @return static
134
-	 */
135
-	private static function createFromRequestFactory(
136
-		array $query = [], 
137
-		array $request = [],
138
-		array $attributes = [] ,
139
-		array $cookies = [], 
140
-		array $files = [], 
141
-		array $server = []
142
-	): static {
143
-		if (self::$requestURI) {
144
-			$request = (self::$requestURI)($query, $request, [], $cookies, $files, $server);
145
-
146
-			if ( ! $request instanceof self) {
147
-				throw new LogicException('The Request active must return an instance of Syscodes\Components\Http\Request');
148
-			}
149
-
150
-			return $request;
151
-		}
152
-
153
-		return new static($query, $request, $attributes, $cookies, $files, $server);
154
-	}
155
-
156
-	/**
157
-	 * Returns the factory request currently being used.
158
-	 *
159
-	 * @param  \Syscodes\Components\Http\Request|callable|null  $request  
160
-	 *
161
-	 * @return void
162
-	 */
163
-	public static function setFactory(?callable $request): void
164
-	{
165
-		self::$requestURI = $request;
166
-	}
102
+        return $newRequest;
103
+    }
104
+
105
+    /**
106
+     * Creates a new request with value from PHP's super global.
107
+     * 
108
+     * @return static
109
+     */
110
+    public static function createFromRequestGlobals(): static
111
+    {
112
+        $request = static::createFromRequestFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
113
+
114
+        if (Str::startsWith($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded')
115
+            && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])) {
116
+            parse_str($request->getContent(), $data);
117
+            $request->request = new Inputs($data);
118
+        }
119
+
120
+        return $request;
121
+    }
122
+
123
+    /**
124
+     * Creates a new request from a factory.
125
+     * 
126
+     * @param  array  $query
127
+     * @param  array  $request
128
+     * @param  array  $attributes
129
+     * @param  array  $cookies
130
+     * @param  array  $files
131
+     * @param  array  $server
132
+     * 
133
+     * @return static
134
+     */
135
+    private static function createFromRequestFactory(
136
+        array $query = [], 
137
+        array $request = [],
138
+        array $attributes = [] ,
139
+        array $cookies = [], 
140
+        array $files = [], 
141
+        array $server = []
142
+    ): static {
143
+        if (self::$requestURI) {
144
+            $request = (self::$requestURI)($query, $request, [], $cookies, $files, $server);
145
+
146
+            if ( ! $request instanceof self) {
147
+                throw new LogicException('The Request active must return an instance of Syscodes\Components\Http\Request');
148
+            }
149
+
150
+            return $request;
151
+        }
152
+
153
+        return new static($query, $request, $attributes, $cookies, $files, $server);
154
+    }
155
+
156
+    /**
157
+     * Returns the factory request currently being used.
158
+     *
159
+     * @param  \Syscodes\Components\Http\Request|callable|null  $request  
160
+     *
161
+     * @return void
162
+     */
163
+    public static function setFactory(?callable $request): void
164
+    {
165
+        self::$requestURI = $request;
166
+    }
167 167
 }
168 168
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@
 block discarded – undo
135 135
 	private static function createFromRequestFactory(
136 136
 		array $query = [], 
137 137
 		array $request = [],
138
-		array $attributes = [] ,
138
+		array $attributes = [],
139 139
 		array $cookies = [], 
140 140
 		array $files = [], 
141 141
 		array $server = []
Please login to merge, or discard this patch.
src/components/Http/Resources/HttpResponse.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
      * 
50 50
      * @var \Syscodes\Components\Http\ResponseHeaders $headers
51 51
      */
52
-	public $headers;
52
+    public $headers;
53 53
 
54 54
     /**
55 55
      * The HTTP protocol version.
Please login to merge, or discard this patch.
src/components/Http/Resources/HttpStatusCode.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -30,209 +30,209 @@
 block discarded – undo
30 30
  */
31 31
 trait HttpStatusCode
32 32
 {
33
-	/**
34
-	 * The HTTP status code.
35
-	 *
36
-	 * @var int $statusCode
37
-	 */
38
-	protected $statusCode = 200;
39
-
40
-	/**
41
-	 * An array of status codes and messages.
42
-	 *
43
-	 * @var array $statusCodeTexts
44
-	 */
45
-	public static $statusCodeTexts = [
46
-		// 1xx: Informational
47
-		100 => 'Continue',
48
-		101 => 'Switching Protocols',
49
-		102 => 'Processing',
50
-
51
-		// 2xx: Success
52
-		200 => 'OK',
53
-		201 => 'Created',
54
-		202 => 'Accepted',
55
-		203 => 'Non-Authoritative Information',
56
-		204 => 'No Content',
57
-		205 => 'Reset Content',
58
-		206 => 'Partial Content',
59
-		207 => 'Multi-Status',
60
-		208 => 'Already Reported',
61
-		226 => 'IM Used',
62
-
63
-		// 3xx: Redirection
64
-		300 => 'Multiple Choices',
65
-		301 => 'Moved Permanently',
66
-		302 => 'Found',
67
-		303 => 'See Other',
68
-		304 => 'Not Modified',
69
-		305 => 'Use Proxy',
70
-		307 => 'Temporary Redirect',
71
-		308 => 'Permanent Redirect',
72
-
73
-		// 4xx: Client error
74
-		400 => 'Bad Request',
75
-		401 => 'Unauthorized',
76
-		402 => 'Payment Required',
77
-		403 => 'Forbidden',
78
-		404 => 'Not Found',
79
-		405 => 'Method Not Allowed',
80
-		406 => 'Not Acceptable',
81
-		407 => 'Proxy Authentication Required',
82
-		408 => 'Request Timeout',
83
-		409 => 'Conflict',
84
-		410 => 'Gone',
85
-		411 => 'Length Required',
86
-		412 => 'Precondition Failed',
87
-		413 => 'Request Entity Too Large',
88
-		414 => 'Request-URI Too Long',
89
-		415 => 'Unsupported Media Type',
90
-		416 => 'Requested Range Not Satisfiable',
91
-		417 => 'Expectation Failed',
92
-		418 => 'I\'m a Teapot',
93
-		// 419 (Authentication Timeout) is a non-standard status code with unknown origin
94
-		421 => 'Misdirected Request',
95
-		422 => 'Unprocessable Entity',
96
-		423 => 'Locked',
97
-		424 => 'Failed Dependency',
98
-		426 => 'Upgrade Required',
99
-		428 => 'Precondition Required',
100
-		429 => 'Too Many Requests',
101
-		431 => 'Request Header Fields Too Large',
102
-		451 => 'Unavailable For Legal Reasons',
103
-
104
-		// 5xx: Server error
105
-		500 => 'Internal Server Error',
106
-		501 => 'Not Implemented',
107
-		502 => 'Bad Gateway',
108
-		503 => 'Service Unavailable',
109
-		504 => 'Gateway Timeout',
110
-		505 => 'HTTP Version Not Supported',
111
-		506 => 'Variant Also Negotiates',
112
-		507 => 'Insufficient Storage',
113
-		508 => 'Loop Detected',
114
-		509 => 'Bandwidth Limit Exceeded',
115
-		510 => 'Not Extended',
116
-		511 => 'Network Authentication Required'
117
-	];
118
-
119
-	/**
120
-	 * Gets string of status code.
121
-	 * 
122
-	 * @var string $statusText
123
-	 */
124
-	protected $statusText;
125
-
126
-	/**
127
-	 * Gets the response status code.
128
-	 *
129
-	 * The status code is a 3-digit code to specify server response results to the browser.
130
-	 *
131
-	 * @return int
132
-	 *
133
-	 * @throws \BadMethodCallException
134
-	 */
135
-	public function getStatusCode(): int
136
-	{
137
-		if (empty($this->statusCode)) {
138
-			throw new BadMethodCallException('HTTP Response is missing a status code');
139
-		}
140
-
141
-		return $this->statusCode;
142
-	}
143
-
144
-	/**
145
-	* Sets the response status code.
146
-	*
147
-	* @param  int  $code  The status code
148
-	* @param  string|null  $text  The status text
149
-	*
150
-	* @return static
151
-	*
152
-	* @throws \InvalidArgumentException
153
-	*/
154
-	public function setStatusCode(int $code, $text = null): static
155
-	{
156
-		$this->statusCode = $code; 
157
-
158
-		// Valid range?
159
-		if ($this->isInvalid()) {
160
-			throw new InvalidArgumentException(__('response.statusCodeNotValid', ['code' => $code]));			
161
-		}
162
-
163
-		// Check if you have an accepted status code if not shows to a message of unknown status
164
-		if (null === $text) {
165
-			$this->statusText = self::$statusCodeTexts[$code] ?? __('response.UnknownStatus');
166
-
167
-			return $this;
168
-		}
169
-
170
-		if (false === $text) {
171
-			$this->statusText = '';
172
-
173
-			return $this;
174
-		}
175
-
176
-		$this->statusText = $text;
177
-
178
-		return $this;
179
-	}
180
-
181
-	/**
182
-	 * Is response invalid?
183
-	 * 
184
-	 * @final
185
-	 * 
186
-	 * @return bool
187
-	 */
188
-	public function isInvalid(): bool
189
-	{
190
-		return $this->statusCode < 100 || $this->statusCode >= 600;
191
-	}
192
-
193
-	/**
194
-	 * Is response informative?
195
-	 * 
196
-	 * @final
197
-	 * 
198
-	 * @return bool
199
-	 */
200
-	public function isInformational(): bool
201
-	{
202
-		return $this->statusCode >= 100 && $this->statusCode < 200;
203
-	}
33
+    /**
34
+     * The HTTP status code.
35
+     *
36
+     * @var int $statusCode
37
+     */
38
+    protected $statusCode = 200;
39
+
40
+    /**
41
+     * An array of status codes and messages.
42
+     *
43
+     * @var array $statusCodeTexts
44
+     */
45
+    public static $statusCodeTexts = [
46
+        // 1xx: Informational
47
+        100 => 'Continue',
48
+        101 => 'Switching Protocols',
49
+        102 => 'Processing',
50
+
51
+        // 2xx: Success
52
+        200 => 'OK',
53
+        201 => 'Created',
54
+        202 => 'Accepted',
55
+        203 => 'Non-Authoritative Information',
56
+        204 => 'No Content',
57
+        205 => 'Reset Content',
58
+        206 => 'Partial Content',
59
+        207 => 'Multi-Status',
60
+        208 => 'Already Reported',
61
+        226 => 'IM Used',
62
+
63
+        // 3xx: Redirection
64
+        300 => 'Multiple Choices',
65
+        301 => 'Moved Permanently',
66
+        302 => 'Found',
67
+        303 => 'See Other',
68
+        304 => 'Not Modified',
69
+        305 => 'Use Proxy',
70
+        307 => 'Temporary Redirect',
71
+        308 => 'Permanent Redirect',
72
+
73
+        // 4xx: Client error
74
+        400 => 'Bad Request',
75
+        401 => 'Unauthorized',
76
+        402 => 'Payment Required',
77
+        403 => 'Forbidden',
78
+        404 => 'Not Found',
79
+        405 => 'Method Not Allowed',
80
+        406 => 'Not Acceptable',
81
+        407 => 'Proxy Authentication Required',
82
+        408 => 'Request Timeout',
83
+        409 => 'Conflict',
84
+        410 => 'Gone',
85
+        411 => 'Length Required',
86
+        412 => 'Precondition Failed',
87
+        413 => 'Request Entity Too Large',
88
+        414 => 'Request-URI Too Long',
89
+        415 => 'Unsupported Media Type',
90
+        416 => 'Requested Range Not Satisfiable',
91
+        417 => 'Expectation Failed',
92
+        418 => 'I\'m a Teapot',
93
+        // 419 (Authentication Timeout) is a non-standard status code with unknown origin
94
+        421 => 'Misdirected Request',
95
+        422 => 'Unprocessable Entity',
96
+        423 => 'Locked',
97
+        424 => 'Failed Dependency',
98
+        426 => 'Upgrade Required',
99
+        428 => 'Precondition Required',
100
+        429 => 'Too Many Requests',
101
+        431 => 'Request Header Fields Too Large',
102
+        451 => 'Unavailable For Legal Reasons',
103
+
104
+        // 5xx: Server error
105
+        500 => 'Internal Server Error',
106
+        501 => 'Not Implemented',
107
+        502 => 'Bad Gateway',
108
+        503 => 'Service Unavailable',
109
+        504 => 'Gateway Timeout',
110
+        505 => 'HTTP Version Not Supported',
111
+        506 => 'Variant Also Negotiates',
112
+        507 => 'Insufficient Storage',
113
+        508 => 'Loop Detected',
114
+        509 => 'Bandwidth Limit Exceeded',
115
+        510 => 'Not Extended',
116
+        511 => 'Network Authentication Required'
117
+    ];
118
+
119
+    /**
120
+     * Gets string of status code.
121
+     * 
122
+     * @var string $statusText
123
+     */
124
+    protected $statusText;
125
+
126
+    /**
127
+     * Gets the response status code.
128
+     *
129
+     * The status code is a 3-digit code to specify server response results to the browser.
130
+     *
131
+     * @return int
132
+     *
133
+     * @throws \BadMethodCallException
134
+     */
135
+    public function getStatusCode(): int
136
+    {
137
+        if (empty($this->statusCode)) {
138
+            throw new BadMethodCallException('HTTP Response is missing a status code');
139
+        }
140
+
141
+        return $this->statusCode;
142
+    }
143
+
144
+    /**
145
+     * Sets the response status code.
146
+     *
147
+     * @param  int  $code  The status code
148
+     * @param  string|null  $text  The status text
149
+     *
150
+     * @return static
151
+     *
152
+     * @throws \InvalidArgumentException
153
+     */
154
+    public function setStatusCode(int $code, $text = null): static
155
+    {
156
+        $this->statusCode = $code; 
157
+
158
+        // Valid range?
159
+        if ($this->isInvalid()) {
160
+            throw new InvalidArgumentException(__('response.statusCodeNotValid', ['code' => $code]));			
161
+        }
162
+
163
+        // Check if you have an accepted status code if not shows to a message of unknown status
164
+        if (null === $text) {
165
+            $this->statusText = self::$statusCodeTexts[$code] ?? __('response.UnknownStatus');
166
+
167
+            return $this;
168
+        }
169
+
170
+        if (false === $text) {
171
+            $this->statusText = '';
172
+
173
+            return $this;
174
+        }
175
+
176
+        $this->statusText = $text;
177
+
178
+        return $this;
179
+    }
180
+
181
+    /**
182
+     * Is response invalid?
183
+     * 
184
+     * @final
185
+     * 
186
+     * @return bool
187
+     */
188
+    public function isInvalid(): bool
189
+    {
190
+        return $this->statusCode < 100 || $this->statusCode >= 600;
191
+    }
192
+
193
+    /**
194
+     * Is response informative?
195
+     * 
196
+     * @final
197
+     * 
198
+     * @return bool
199
+     */
200
+    public function isInformational(): bool
201
+    {
202
+        return $this->statusCode >= 100 && $this->statusCode < 200;
203
+    }
204 204
 	
205
-	/**
206
-	 * Is the response a redirect?
207
-	 * 
208
-	 * @final
209
-	 * 
210
-	 * @return void
211
-	 */
212
-	public function isRedirection(): bool
213
-	{
214
-		return $this->statusCode >= 300 && $this->statusCode < 400;
215
-	}
205
+    /**
206
+     * Is the response a redirect?
207
+     * 
208
+     * @final
209
+     * 
210
+     * @return void
211
+     */
212
+    public function isRedirection(): bool
213
+    {
214
+        return $this->statusCode >= 300 && $this->statusCode < 400;
215
+    }
216 216
 	
217
-	/**
218
-	 * Is the response empty?
219
-	 * 
220
-	 * @final
221
-	 * 
222
-	 * @return bool
223
-	 */
224
-	public function isEmpty(): bool
225
-	{
226
-		return in_array($this->statusCode, [204, 304]);
227
-	}
217
+    /**
218
+     * Is the response empty?
219
+     * 
220
+     * @final
221
+     * 
222
+     * @return bool
223
+     */
224
+    public function isEmpty(): bool
225
+    {
226
+        return in_array($this->statusCode, [204, 304]);
227
+    }
228 228
 	
229
-	/**
230
-	 * Is the response a redirect of some form?
231
-	 * 
232
-	 * @return bool
233
-	 */
234
-	public function isRedirect(): bool
235
-	{
236
-		return in_array($this->statusCode, [301, 302, 303, 307, 308]);
237
-	}
229
+    /**
230
+     * Is the response a redirect of some form?
231
+     * 
232
+     * @return bool
233
+     */
234
+    public function isRedirect(): bool
235
+    {
236
+        return in_array($this->statusCode, [301, 302, 303, 307, 308]);
237
+    }
238 238
 }
239 239
\ No newline at end of file
Please login to merge, or discard this patch.