Passed
Push — 0.7.0 ( a89e02...6d61aa )
by Alexander
03:28
created
src/components/Contracts/Config/Configure.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -30,54 +30,54 @@
 block discarded – undo
30 30
  */
31 31
 interface Configure
32 32
 {
33
-	/**
34
-	 * Determine if the given configuration value exists.
35
-	 * 
36
-	 * @param  string  $key
37
-	 * 
38
-	 * @return bool
39
-	 */
40
-	public function has(string $key);
33
+    /**
34
+     * Determine if the given configuration value exists.
35
+     * 
36
+     * @param  string  $key
37
+     * 
38
+     * @return bool
39
+     */
40
+    public function has(string $key);
41 41
 
42
-	/**
43
-	 * Deletes a (dot notated) config item.
44
-	 * 
45
-	 * @param  string  $key  A (dot notated) config key
46
-	 * 
47
-	 * @return array|bool
48
-	 * 
49
-	 * @uses   \Syscodes\Support\Arr
50
-	 */	
51
-	public function erase(string $key);
42
+    /**
43
+     * Deletes a (dot notated) config item.
44
+     * 
45
+     * @param  string  $key  A (dot notated) config key
46
+     * 
47
+     * @return array|bool
48
+     * 
49
+     * @uses   \Syscodes\Support\Arr
50
+     */	
51
+    public function erase(string $key);
52 52
 
53
-	/**
54
-	 * Returns a (dot notated) config setting.
55
-	 *
56
-	 * @param  string  $key  The dot-notated key or array of keys
57
-	 * @param  mixed  $default  The default value
58
-	 *
59
-	 * @return mixed
60
-	 *
61
-	 * @uses    \Syscodes\Support\Arr
62
-	 */
63
-	public function get(string $key, $default = null);
53
+    /**
54
+     * Returns a (dot notated) config setting.
55
+     *
56
+     * @param  string  $key  The dot-notated key or array of keys
57
+     * @param  mixed  $default  The default value
58
+     *
59
+     * @return mixed
60
+     *
61
+     * @uses    \Syscodes\Support\Arr
62
+     */
63
+    public function get(string $key, $default = null);
64 64
 	
65
-	/**
66
-	 * Sets a value in the config array.
67
-	 *
68
-	 * @param  string  $key  The dot-notated key or array of keys
69
-	 * @param  mixed  $value  The default value
70
-	 *
71
-	 * @return mixed
72
-	 *
73
-	 * @uses  \Syscodes\Support\Arr
74
-	 */
75
-	public function set(string $key, $value);
65
+    /**
66
+     * Sets a value in the config array.
67
+     *
68
+     * @param  string  $key  The dot-notated key or array of keys
69
+     * @param  mixed  $value  The default value
70
+     *
71
+     * @return mixed
72
+     *
73
+     * @uses  \Syscodes\Support\Arr
74
+     */
75
+    public function set(string $key, $value);
76 76
 
77
-	/**
78
-	 * Get all of the configuration items for the application.
79
-	 * 
80
-	 * @return array
81
-	 */
82
-	public function all();
77
+    /**
78
+     * Get all of the configuration items for the application.
79
+     * 
80
+     * @return array
81
+     */
82
+    public function all();
83 83
 }
84 84
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Contracts/Container/Container.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function extend($id, Closure $closure);
68 68
 
69
-     /**
70
-     * Marks a callable as being a factory service.
71
-     * 
72
-     * @param  string  $id
73
-     * 
74
-     * @return \Closure
75
-     */
69
+        /**
70
+         * Marks a callable as being a factory service.
71
+         * 
72
+         * @param  string  $id
73
+         * 
74
+         * @return \Closure
75
+         */
76 76
     public function factory($id);
77 77
 
78 78
     /**
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getBindings();
84 84
 
85
-     /**
86
-     * Register an existing instance as singleton in the container.
87
-     *
88
-     * @param  string  $id
89
-     * @param  mixed  $instance
90
-     * 
91
-     * @return mixed
92
-     */
85
+        /**
86
+         * Register an existing instance as singleton in the container.
87
+         *
88
+         * @param  string  $id
89
+         * @param  mixed  $instance
90
+         * 
91
+         * @return mixed
92
+         */
93 93
     public function instance($id, $instance);
94 94
 
95 95
     /**
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function set($id, string $value);
123 123
 
124
-     /**
125
-     * Register a singleton binding in the container.
126
-     * 
127
-     * @param  string  $id
128
-     * @param  \Closure|string|null  $value
129
-     * 
130
-     * @return void
131
-     */
124
+        /**
125
+         * Register a singleton binding in the container.
126
+         * 
127
+         * @param  string  $id
128
+         * @param  \Closure|string|null  $value
129
+         * 
130
+         * @return void
131
+         */
132 132
     public function singleton($id, $value = null);
133 133
 }
134 134
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Response.php 3 patches
Indentation   +303 added lines, -303 removed lines patch added patch discarded remove patch
@@ -40,314 +40,314 @@
 block discarded – undo
40 40
  */
41 41
 class Response extends Status 
42 42
 {
43
-	use ResponseTrait;
44
-
45
-	/**
46
-	 * Sets up the response with a content and a status code.
47
-	 *
48
-	 * @param  mixed  $content  The response content 
49
-	 * @param  int  $status  The response status  (200 by default)
50
-	 * @param  array  $headers  Array of HTTP headers for this response
51
-	 *
52
-	 * @return string
53
-	 */
54
-	public function __construct($content = '', int $status = 200, array $headers = [])
55
-	{
56
-		$this->setContent($content);
57
-		$this->setStatusCode($status);
43
+    use ResponseTrait;
44
+
45
+    /**
46
+     * Sets up the response with a content and a status code.
47
+     *
48
+     * @param  mixed  $content  The response content 
49
+     * @param  int  $status  The response status  (200 by default)
50
+     * @param  array  $headers  Array of HTTP headers for this response
51
+     *
52
+     * @return string
53
+     */
54
+    public function __construct($content = '', int $status = 200, array $headers = [])
55
+    {
56
+        $this->setContent($content);
57
+        $this->setStatusCode($status);
58 58
 		
59
-		$this->server  = new Server($_SERVER);
60
-		$this->headers = new Headers($headers);
61
-	}
62
-
63
-	/**
64
-	 * Creates an instance of the same response class for rendering contents to the content, 
65
-	 * status code and headers.
66
-	 *
67
-	 * @param  mixed  $content  The response content  
68
-	 * @param  int  $status  The HTTP response status for this response  (200 by default)
69
-	 * @param  array  $headers  Array of HTTP headers for this response
70
-	 *
71
-	 * @return static
72
-	 */
73
-	public static function render($content = '', $status = 200, $headers = [])
74
-	{
75
-		return new static($content, $status, $headers);
76
-	}
77
-
78
-	/**
79
-	 * Gets the current response content.
80
-	 * 
81
-	 * @return string
82
-	 */
83
-	public function getContent()
84
-	{
85
-		return $this->content;
86
-	}
87
-
88
-	/**
89
-	 * Gets the response status code.
90
-	 *
91
-	 * The status code is a 3-digit code to specify server response results to the browser.
92
-	 *
93
-	 * @return int
94
-	 *
95
-	 * @throws \BadMethodCallException
96
-	 */
97
-	public function getStatusCode()
98
-	{
99
-		if (empty($this->status))
100
-		{
101
-			throw new BadMethodCallException('HTTP Response is missing a status code.');
102
-		}
103
-
104
-		return $this->status;
105
-	}
106
-
107
-	/**
108
-	 * Sends the headers if they haven't already been sent. 
109
-	 * Returns whether they were sent or not.
110
-	 *
111
-	 * @return bool
112
-	 *
113
-	 * @uses   \Syscodes\Http\Http
114
-	 */
115
-	public function sendHeaders()
116
-	{
117
-		// Have the headers already been sent?
118
-		if (headers_sent())
119
-		{
120
-			return $this;
121
-		}
122
-
123
-		// Headers
124
-		foreach ($this->headers->allPreserveCase() as $name => $values) 
125
-		{
126
-			$replace = 0 === strcasecmp($name, 'Content-Type');
127
-
128
-			foreach ($values as $value)
129
-			{
130
-				header($name.': '. $value, $replace, $this->status);
131
-			}
132
-		}
133
-
134
-		// Status
135
-		if ( ! empty($_SERVER['FCGI_SERVER_VERSION']))
136
-		{
137
-			// Send the protocol/status line first, FCGI servers need different status header
138
-			header(sprintf('Status: %s %s', $this->status, $this->statusText));
139
-		}
140
-		else
141
-		{
142
-			$this->protocol = (string) $this->server->get('SERVER_PROTOCOL') ?: 'HTTP/1.1';
143
-			header(sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText), true, $this->status);
144
-		}
145
-
146
-		return $this;
147
-	}
148
-
149
-	/**
150
-	 * Sends content for the current web response.
151
-	 * 
152
-	 * @return $this
153
-	 */
154
-	public function sendContent()
155
-	{
156
-		echo $this->content;
157
-
158
-		return $this;
159
-	}
160
-
161
-	/**
162
-	 * Sends the response to the output buffer. Optionally, headers will be sent. 
163
-	 *
164
-	 * @param  bool  $sendHeader  Whether or not to send the defined HTTP headers
165
-	 *
166
-	 * @return $this
167
-	 */
168
-	public function send($sendHeader = false)
169
-	{
170
-		if ($sendHeader)
171
-		{
172
-			$this->sendHeaders();
173
-		}
174
-
175
-		if (null !== $this->content) 
176
-		{
177
-			$this->sendContent();
178
-		}
179
-
180
-		return $this;
181
-	}
182
-
183
-	/**
184
-	 * Sends the content of the message to the browser.
185
-	 *
186
-	 * @param  mixed  $content  The response content
187
-	 *
188
-	 * @return $this
189
-	 */
190
-	public function setContent($content)
191
-	{
192
-		if ($content !== null && ! is_string($content) && ! is_numeric($content) && ! is_callable([$content, '__toString'])) 
193
-		{
194
-			throw new UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
195
-		}
196
-
197
-		if ($content instanceof JsonSerializable || is_array($content))
198
-		{
199
-			$this->header('Content-Type', 'application/json');
200
-
201
-			$content = json_encode($content);
202
-		}
203
-		elseif ($content instanceof Renderable)
204
-		{
205
-			$content = $content->render();
206
-		}
59
+        $this->server  = new Server($_SERVER);
60
+        $this->headers = new Headers($headers);
61
+    }
62
+
63
+    /**
64
+     * Creates an instance of the same response class for rendering contents to the content, 
65
+     * status code and headers.
66
+     *
67
+     * @param  mixed  $content  The response content  
68
+     * @param  int  $status  The HTTP response status for this response  (200 by default)
69
+     * @param  array  $headers  Array of HTTP headers for this response
70
+     *
71
+     * @return static
72
+     */
73
+    public static function render($content = '', $status = 200, $headers = [])
74
+    {
75
+        return new static($content, $status, $headers);
76
+    }
77
+
78
+    /**
79
+     * Gets the current response content.
80
+     * 
81
+     * @return string
82
+     */
83
+    public function getContent()
84
+    {
85
+        return $this->content;
86
+    }
87
+
88
+    /**
89
+     * Gets the response status code.
90
+     *
91
+     * The status code is a 3-digit code to specify server response results to the browser.
92
+     *
93
+     * @return int
94
+     *
95
+     * @throws \BadMethodCallException
96
+     */
97
+    public function getStatusCode()
98
+    {
99
+        if (empty($this->status))
100
+        {
101
+            throw new BadMethodCallException('HTTP Response is missing a status code.');
102
+        }
103
+
104
+        return $this->status;
105
+    }
106
+
107
+    /**
108
+     * Sends the headers if they haven't already been sent. 
109
+     * Returns whether they were sent or not.
110
+     *
111
+     * @return bool
112
+     *
113
+     * @uses   \Syscodes\Http\Http
114
+     */
115
+    public function sendHeaders()
116
+    {
117
+        // Have the headers already been sent?
118
+        if (headers_sent())
119
+        {
120
+            return $this;
121
+        }
122
+
123
+        // Headers
124
+        foreach ($this->headers->allPreserveCase() as $name => $values) 
125
+        {
126
+            $replace = 0 === strcasecmp($name, 'Content-Type');
127
+
128
+            foreach ($values as $value)
129
+            {
130
+                header($name.': '. $value, $replace, $this->status);
131
+            }
132
+        }
133
+
134
+        // Status
135
+        if ( ! empty($_SERVER['FCGI_SERVER_VERSION']))
136
+        {
137
+            // Send the protocol/status line first, FCGI servers need different status header
138
+            header(sprintf('Status: %s %s', $this->status, $this->statusText));
139
+        }
140
+        else
141
+        {
142
+            $this->protocol = (string) $this->server->get('SERVER_PROTOCOL') ?: 'HTTP/1.1';
143
+            header(sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText), true, $this->status);
144
+        }
145
+
146
+        return $this;
147
+    }
148
+
149
+    /**
150
+     * Sends content for the current web response.
151
+     * 
152
+     * @return $this
153
+     */
154
+    public function sendContent()
155
+    {
156
+        echo $this->content;
157
+
158
+        return $this;
159
+    }
160
+
161
+    /**
162
+     * Sends the response to the output buffer. Optionally, headers will be sent. 
163
+     *
164
+     * @param  bool  $sendHeader  Whether or not to send the defined HTTP headers
165
+     *
166
+     * @return $this
167
+     */
168
+    public function send($sendHeader = false)
169
+    {
170
+        if ($sendHeader)
171
+        {
172
+            $this->sendHeaders();
173
+        }
174
+
175
+        if (null !== $this->content) 
176
+        {
177
+            $this->sendContent();
178
+        }
179
+
180
+        return $this;
181
+    }
182
+
183
+    /**
184
+     * Sends the content of the message to the browser.
185
+     *
186
+     * @param  mixed  $content  The response content
187
+     *
188
+     * @return $this
189
+     */
190
+    public function setContent($content)
191
+    {
192
+        if ($content !== null && ! is_string($content) && ! is_numeric($content) && ! is_callable([$content, '__toString'])) 
193
+        {
194
+            throw new UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', gettype($content)));
195
+        }
196
+
197
+        if ($content instanceof JsonSerializable || is_array($content))
198
+        {
199
+            $this->header('Content-Type', 'application/json');
200
+
201
+            $content = json_encode($content);
202
+        }
203
+        elseif ($content instanceof Renderable)
204
+        {
205
+            $content = $content->render();
206
+        }
207 207
 		
208
-		$this->content = $content ?? '';
209
-
210
-		return $this;
211
-	}
212
-
213
-	/**
214
-	 * Prepares the Response before it is sent to the client.
215
-	 * 
216
-	 * @param  \Syscodes\Http\Request  $request
217
-	 * 
218
-	 * @return $this
219
-	 */
220
-	public function prepare($request)
221
-	{
222
-		$headers = $this->headers;
223
-
224
-		if ($this->isInformational() || $this->isEmpty()) 
225
-		{
226
-			$this->setContent(null);
227
-			$headers->remove('Content-Type');
228
-			$headers->remove('Content-Length');
229
-		}
230
-
231
-		return $this;
232
-	}
233
-
234
-	/**
235
-	* Sets the response status code.
236
-	*
237
-	* @param  int  $code  The status code
238
-	* @param  string|null  $text  The status text
239
-	*
240
-	* @return $this
241
-	*
242
-	* @throws \InvalidArgumentException
243
-	*/
244
-	public function setStatusCode(int $code, $text = null)
245
-	{
246
-		$this->status = $code; 
247
-
248
-		// Valid range?
249
-		if ($this->isInvalid())
250
-		{
251
-			throw new InvalidArgumentException(__('response.statusCodeNotValid', ['code' => $code]));			
252
-		}
253
-
254
-		// Check if you have an accepted status code if not shows to a message of unknown status
255
-		if (null === $text)
256
-		{
257
-			$this->statusText = isset($this->statusCodes[$code]) ? $this->statusCodes[$code] : __('response.UnknownStatus');
258
-
259
-			return $this;
260
-		}
261
-
262
-		if (false === $text)
263
-		{
264
-			$this->statusText = '';
265
-
266
-			return $this;
267
-		}
268
-
269
-		$this->statusText = $text;
270
-
271
-		return $this;
272
-	}
273
-
274
-	/**
275
-	 * Is response invalid?
276
-	 * 
277
-	 * @final
278
-	 * 
279
-	 * @return void
280
-	 */
281
-	public function isInvalid(): bool
282
-	{
283
-		return $this->status < 100 || $this->status >= 600;
284
-	}
285
-
286
-	/**
287
-	 * Is response informative?
288
-	 * 
289
-	 * @final
290
-	 * 
291
-	 * @return void
292
-	 */
293
-	public function isInformational()
294
-	{
295
-		return $this->status >= 100 && $this->status < 200;
296
-	}
208
+        $this->content = $content ?? '';
209
+
210
+        return $this;
211
+    }
212
+
213
+    /**
214
+     * Prepares the Response before it is sent to the client.
215
+     * 
216
+     * @param  \Syscodes\Http\Request  $request
217
+     * 
218
+     * @return $this
219
+     */
220
+    public function prepare($request)
221
+    {
222
+        $headers = $this->headers;
223
+
224
+        if ($this->isInformational() || $this->isEmpty()) 
225
+        {
226
+            $this->setContent(null);
227
+            $headers->remove('Content-Type');
228
+            $headers->remove('Content-Length');
229
+        }
230
+
231
+        return $this;
232
+    }
233
+
234
+    /**
235
+     * Sets the response status code.
236
+     *
237
+     * @param  int  $code  The status code
238
+     * @param  string|null  $text  The status text
239
+     *
240
+     * @return $this
241
+     *
242
+     * @throws \InvalidArgumentException
243
+     */
244
+    public function setStatusCode(int $code, $text = null)
245
+    {
246
+        $this->status = $code; 
247
+
248
+        // Valid range?
249
+        if ($this->isInvalid())
250
+        {
251
+            throw new InvalidArgumentException(__('response.statusCodeNotValid', ['code' => $code]));			
252
+        }
253
+
254
+        // Check if you have an accepted status code if not shows to a message of unknown status
255
+        if (null === $text)
256
+        {
257
+            $this->statusText = isset($this->statusCodes[$code]) ? $this->statusCodes[$code] : __('response.UnknownStatus');
258
+
259
+            return $this;
260
+        }
261
+
262
+        if (false === $text)
263
+        {
264
+            $this->statusText = '';
265
+
266
+            return $this;
267
+        }
268
+
269
+        $this->statusText = $text;
270
+
271
+        return $this;
272
+    }
273
+
274
+    /**
275
+     * Is response invalid?
276
+     * 
277
+     * @final
278
+     * 
279
+     * @return void
280
+     */
281
+    public function isInvalid(): bool
282
+    {
283
+        return $this->status < 100 || $this->status >= 600;
284
+    }
285
+
286
+    /**
287
+     * Is response informative?
288
+     * 
289
+     * @final
290
+     * 
291
+     * @return void
292
+     */
293
+    public function isInformational()
294
+    {
295
+        return $this->status >= 100 && $this->status < 200;
296
+    }
297 297
 	
298
-	/**
299
-	 * Is the response a redirect?
300
-	 * 
301
-	 * @final
302
-	 * 
303
-	 * @return void
304
-	 */
305
-	public function isRedirection()
306
-	{
307
-		return $this->status >= 300 && $this->status < 400;
308
-	}
298
+    /**
299
+     * Is the response a redirect?
300
+     * 
301
+     * @final
302
+     * 
303
+     * @return void
304
+     */
305
+    public function isRedirection()
306
+    {
307
+        return $this->status >= 300 && $this->status < 400;
308
+    }
309 309
 	
310
-	/**
311
-	 * Is the response empty?
312
-	 * 
313
-	 * @final
314
-	 * 
315
-	 * @return void
316
-	 */
317
-	public function isEmpty()
318
-	{
319
-		return in_array($this->status, [204, 304]);
320
-	}
310
+    /**
311
+     * Is the response empty?
312
+     * 
313
+     * @final
314
+     * 
315
+     * @return void
316
+     */
317
+    public function isEmpty()
318
+    {
319
+        return in_array($this->status, [204, 304]);
320
+    }
321 321
 	
322
-	/**
323
-	 * Is the response a redirect of some form?
324
-	 * 
325
-	 * @return bool
326
-	 */
327
-	public function isRedirect()
328
-	{
329
-		return in_array($this->status, [301, 302, 303, 307, 308]);
330
-	}
322
+    /**
323
+     * Is the response a redirect of some form?
324
+     * 
325
+     * @return bool
326
+     */
327
+    public function isRedirect()
328
+    {
329
+        return in_array($this->status, [301, 302, 303, 307, 308]);
330
+    }
331 331
 	
332
-	/**
333
-	 * Returns the Response as an HTTP string.
334
-	 * 
335
-	 * @return string
336
-	 */
337
-	public function __toString()
338
-	{
339
-		return sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText)."\r\n".
340
-			$this->headers."\r\n".
341
-			$this->getContent();
342
-	}
332
+    /**
333
+     * Returns the Response as an HTTP string.
334
+     * 
335
+     * @return string
336
+     */
337
+    public function __toString()
338
+    {
339
+        return sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText)."\r\n".
340
+            $this->headers."\r\n".
341
+            $this->getContent();
342
+    }
343 343
 	
344
-	/**
345
-	 * Clone the current Response instance.
346
-	 * 
347
-	 * @return void
348
-	 */
349
-	public function __clone()
350
-	{
351
-		$this->headers = clone $this->headers;
352
-	}
344
+    /**
345
+     * Clone the current Response instance.
346
+     * 
347
+     * @return void
348
+     */
349
+    public function __clone()
350
+    {
351
+        $this->headers = clone $this->headers;
352
+    }
353 353
 }
354 354
\ 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
 
128 128
 			foreach ($values as $value)
129 129
 			{
130
-				header($name.': '. $value, $replace, $this->status);
130
+				header($name.': '.$value, $replace, $this->status);
131 131
 			}
132 132
 		}
133 133
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -136,8 +136,7 @@  discard block
 block discarded – undo
136 136
 		{
137 137
 			// Send the protocol/status line first, FCGI servers need different status header
138 138
 			header(sprintf('Status: %s %s', $this->status, $this->statusText));
139
-		}
140
-		else
139
+		} else
141 140
 		{
142 141
 			$this->protocol = (string) $this->server->get('SERVER_PROTOCOL') ?: 'HTTP/1.1';
143 142
 			header(sprintf('%s %s %s', $this->protocol, $this->status, $this->statusText), true, $this->status);
@@ -199,8 +198,7 @@  discard block
 block discarded – undo
199 198
 			$this->header('Content-Type', 'application/json');
200 199
 
201 200
 			$content = json_encode($content);
202
-		}
203
-		elseif ($content instanceof Renderable)
201
+		} elseif ($content instanceof Renderable)
204 202
 		{
205 203
 			$content = $content->render();
206 204
 		}
Please login to merge, or discard this patch.
src/components/Http/JsonResponse.php 1 patch
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -142,16 +142,13 @@
 block discarded – undo
142 142
         if ($data instanceof Jsonable)
143 143
         {
144 144
             $this->data = $data->toJson($this->jsonEncodingOptions);
145
-        }
146
-        elseif ($data instanceof JsonSerializable)
145
+        } elseif ($data instanceof JsonSerializable)
147 146
         {
148 147
             $this->data = json_encode($data->jsonSerialize(), $this->jsonEncodingOptions);
149
-        }
150
-        elseif ($data instanceof Arrayable)
148
+        } elseif ($data instanceof Arrayable)
151 149
         {
152 150
             $this->data = json_encode($data->toArray(), $this->jsonEncodingOptions);
153
-        }
154
-        else
151
+        } else
155 152
         {
156 153
             $this->data = json_encode($data, $this->jsonEncodingOptions);
157 154
         }
Please login to merge, or discard this patch.
src/components/Http/Request.php 3 patches
Indentation   +849 added lines, -849 removed lines patch added patch discarded remove patch
@@ -40,866 +40,866 @@
 block discarded – undo
40 40
  */
41 41
 class Request
42 42
 {
43
-	/**
44
-	 * Holds the global active request instance.
45
-	 *
46
-	 * @var bool $requestURI
47
-	 */
48
-	protected static $requestURI;
49
-
50
-	/**
51
-	 * The base URL.
52
-	 * 
53
-	 * @var string $baseUrl
54
-	 */
55
-	protected $baseUrl;
56
-
57
-	/**
58
-	 * Gets cookies ($_COOKIE).
59
-	 * 
60
-	 * @var string $cookies
61
-	 */
62
-	public $cookies;
63
-
64
-	/**
65
-	 * Gets the string with format JSON.
66
-	 * 
67
-	 * @var string|resource|null $content
68
-	 */
69
-	protected $content;
70
-
71
-	/**
72
-	 * The default Locale this request.
73
-	 * 
74
-	 * @var string $defaultLocale
75
-	 */
76
-	protected $defaultLocale = 'en';
43
+    /**
44
+     * Holds the global active request instance.
45
+     *
46
+     * @var bool $requestURI
47
+     */
48
+    protected static $requestURI;
49
+
50
+    /**
51
+     * The base URL.
52
+     * 
53
+     * @var string $baseUrl
54
+     */
55
+    protected $baseUrl;
56
+
57
+    /**
58
+     * Gets cookies ($_COOKIE).
59
+     * 
60
+     * @var string $cookies
61
+     */
62
+    public $cookies;
63
+
64
+    /**
65
+     * Gets the string with format JSON.
66
+     * 
67
+     * @var string|resource|null $content
68
+     */
69
+    protected $content;
70
+
71
+    /**
72
+     * The default Locale this request.
73
+     * 
74
+     * @var string $defaultLocale
75
+     */
76
+    protected $defaultLocale = 'en';
77 77
 	
78
-	/**
79
-	 * Gets files request ($_FILES).
80
-	 * 
81
-	 * @var string $files
82
-	 */
83
-	public $files;
84
-
85
-	/**
86
-	 * The detected uri and server variables.
87
-	 * 
88
-	 * @var string $http
89
-	 */
90
-	protected $http;
91
-
92
-	/**
93
-	 * The current language of the application.
94
-	 * 
95
-	 * @var string $languages
96
-	 */
97
-	protected $languages;
78
+    /**
79
+     * Gets files request ($_FILES).
80
+     * 
81
+     * @var string $files
82
+     */
83
+    public $files;
84
+
85
+    /**
86
+     * The detected uri and server variables.
87
+     * 
88
+     * @var string $http
89
+     */
90
+    protected $http;
91
+
92
+    /**
93
+     * The current language of the application.
94
+     * 
95
+     * @var string $languages
96
+     */
97
+    protected $languages;
98 98
 	
99
-	/** 
100
-	 * The method name.
101
-	 * 
102
-	 * @var string $method
103
-	 */
104
-	protected $method;
105
-
106
-	/**
107
-	 * The path info of URL.
108
-	 * 
109
-	 * @var string $pathInfo
110
-	 */
111
-	protected $pathInfo;
112
-
113
-	/**
114
-	 * Request body parameters ($_POST).
115
-	 * 
116
-	 * @var \Syscodes\Http\Contributors\Parameters $request
117
-	 */
118
-	public $request;
119
-
120
-	/**
121
-	 * Get request URI.
122
-	 * 
123
-	 * @var string $requestToURI
124
-	 */
125
-	protected $requestToURI;
126
-
127
-	/**
128
-	 * The detected uri and server variables ($_FILES).
129
-	 * 
130
-	 * @var array $server
131
-	 */
132
-	public $server = [];
133
-
134
-	/** 
135
-	 * List of routes uri.
136
-	 *
137
-	 * @var string|array $uri 
138
-	 */
139
-	public $uri;
140
-
141
-	/**
142
-	 * Stores the valid locale codes.
143
-	 * 
144
-	 * @var array $validLocales
145
-	 */
146
-	protected $validLocales = [];
147
-
148
-	/**
149
-	 * Constructor: Create new the Request class.
150
-	 * 
151
-	 * @param  array  $request
152
-	 * @param  array  $cookies
153
-	 * @param  array  $files
154
-	 * @param  array  $server
155
-	 * @param  string|resource|null $content  (null by default)
156
-	 * 
157
-	 * @return void
158
-	 */
159
-	public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
160
-	{
161
-		static::$requestURI = $this;
99
+    /** 
100
+     * The method name.
101
+     * 
102
+     * @var string $method
103
+     */
104
+    protected $method;
105
+
106
+    /**
107
+     * The path info of URL.
108
+     * 
109
+     * @var string $pathInfo
110
+     */
111
+    protected $pathInfo;
112
+
113
+    /**
114
+     * Request body parameters ($_POST).
115
+     * 
116
+     * @var \Syscodes\Http\Contributors\Parameters $request
117
+     */
118
+    public $request;
119
+
120
+    /**
121
+     * Get request URI.
122
+     * 
123
+     * @var string $requestToURI
124
+     */
125
+    protected $requestToURI;
126
+
127
+    /**
128
+     * The detected uri and server variables ($_FILES).
129
+     * 
130
+     * @var array $server
131
+     */
132
+    public $server = [];
133
+
134
+    /** 
135
+     * List of routes uri.
136
+     *
137
+     * @var string|array $uri 
138
+     */
139
+    public $uri;
140
+
141
+    /**
142
+     * Stores the valid locale codes.
143
+     * 
144
+     * @var array $validLocales
145
+     */
146
+    protected $validLocales = [];
147
+
148
+    /**
149
+     * Constructor: Create new the Request class.
150
+     * 
151
+     * @param  array  $request
152
+     * @param  array  $cookies
153
+     * @param  array  $files
154
+     * @param  array  $server
155
+     * @param  string|resource|null $content  (null by default)
156
+     * 
157
+     * @return void
158
+     */
159
+    public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
160
+    {
161
+        static::$requestURI = $this;
162 162
 		
163
-		$this->initialize($request, $cookies, $files, $server, $content);
164
-
165
-		$this->detectURI(config('app.uriProtocol'), config('app.baseUrl'));
166
-
167
-		$this->detectLocale();
168
-	}
169
-
170
-	/**
171
-	 * Sets the parameters for this request.
172
-	 * 
173
-	 * @param  array  $request
174
-	 * @param  array  $cookies
175
-	 * @param  array  $files
176
-	 * @param  array  $server
177
-	 * 
178
-	 * @return void
179
-	 */
180
-	public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
181
-	{
182
-		$this->request      = new Parameters($request);
183
-		$this->cookies      = new Inputs($cookies);
184
-		$this->files        = new Files($files);
185
-		$this->server       = new Server($server);
186
-		$this->headers      = new Headers($this->server->all());
187
-
188
-		$this->uri          = new URI;
189
-		$this->http         = new Http;
190
-		$this->method       = null;
191
-		$this->baseUrl      = null;
192
-		$this->content      = $content;
193
-		$this->pathInfo     = null;
194
-		$this->languages    = null;
195
-		$this->validLocales = config('app.supportedLocales');
196
-	}
197
-
198
-	/**
199
-	 * Create a new Syscodes HTTP request from server variables.
200
-	 * 
201
-	 * @return static
202
-	 */
203
-	public static function capture()
204
-	{
205
-		return static::createFromRequest(static::createFromRequestGlobals());
206
-	}
207
-
208
-	/**
209
-	 * Creates an Syscodes request from of the Request class instance.
210
-	 * 
211
-	 * @param  \Syscodes\Http\Request  $request
212
-	 * 
213
-	 * @return static
214
-	 */
215
-	public static function createFromRequest($request)
216
-	{
217
-		$newRequest = (new static)->duplicate($request->request->all(), $request->cookies->all(), 
218
-											  $request->files->all(), $request->server->all());
219
-
220
-		return $newRequest;
221
-	}
222
-
223
-	/**
224
-	 * Creates a new request with value from PHP's super global.
225
-	 * 
226
-	 * @return static
227
-	 */
228
-	public static function createFromRequestGlobals()
229
-	{
230
-		$request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER);
231
-
232
-		return $request;
233
-	}
234
-
235
-	/**
236
-	 * Creates a new request from a factory.
237
-	 * 
238
-	 * @param  array  $request
239
-	 * @param  array  $cookies
240
-	 * @param  array  $files
241
-	 * @param  array  $server
242
-	 * 
243
-	 * @return static
244
-	 */
245
-	protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = [])
246
-	{
247
-		if (self::$requestURI)
248
-		{
249
-			$request = (self::$requestURI)($request, $cookies, $files, $server);
250
-
251
-			if ( ! $request instanceof self)
252
-			{
253
-				throw new LogicException('The Request active must return an instance of Syscodes\Http\Request');
254
-			}
255
-
256
-			return $request;
257
-		}
258
-
259
-		return new static($request, $cookies, $files, $server);
260
-	}
261
-
262
-	/**
263
-	 * Clones a request and overrides some of its parameters.
264
-	 * 
265
-	 * @param  array  $request
266
-	 * @param  array  $cookies
267
-	 * @param  array  $files
268
-	 * @param  array  $server
269
-	 * 
270
-	 * @return static
271
-	 */
272
-	public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = [])
273
-	{
274
-		$duplicate = clone $this;
275
-
276
-		if (null !== $request)
277
-		{
278
-			$duplicate->request = new Parameters($request);
279
-		}
280
-
281
-		if (null !== $cookies)
282
-		{
283
-			$duplicate->cookies = new Inputs($cookies);
284
-		}
285
-
286
-		if (null !== $files)
287
-		{
288
-			$duplicate->files = new Files($files);
289
-		}
290
-
291
-		if (null !== $server)
292
-		{
293
-			$duplicate->server  = new Server($server);
294
-			$duplicate->headers = new Headers($duplicate->server->all());
295
-		}
296
-
297
-		$duplicate->uri          = new URI;
298
-		$duplicate->http         = new Http;
299
-		$duplicate->locale       = null;
300
-		$duplicate->method       = null;
301
-		$duplicate->baseUrl      = null;
302
-		$duplicate->pathInfo     = null;
303
-		$duplicate->validLocales = config('app.supportedLocales');
304
-
305
-		return $duplicate;		
306
-	}
307
-
308
-	/**
309
-	 * Returns the active request currently being used.
310
-	 *
311
-	 * @param  \Syscodes\Http\Request|bool|null  $request  Overwrite current request 
312
-	 *                                                     before returning, false prevents 
313
-	 *                                                     overwrite
314
-	 *
315
-	 * @return \Syscodes\Http\Request
316
-	 */
317
-	public static function active($request = false)
318
-	{
319
-		if ($request !== false)
320
-		{
321
-			static::$requestURI = $request;
322
-		}
323
-
324
-		return static::$requestURI;
325
-	}
326
-
327
-	/**
328
-	 * Returns the desired segment, or $default if it does not exist.
329
-	 *
330
-	 * @param  int  $index  The segment number (1-based index)
331
-	 * @param  mixed  $default  Default value to return
332
-	 *
333
-	 * @return  string
334
-	 */
335
-	public function segment($index, $default = null)
336
-	{
337
-		if ($request = static::active())
338
-		{
339
-			return $request->uri->getSegment($index, $default);
340
-		}
341
-
342
-		return null;
343
-	}
344
-
345
-	/**
346
-	 * Returns all segments in an array. For total of segments
347
-	 * used the function PHP count().
348
-	 *
349
-	 * @return array
350
-	 */
351
-	public function segments()
352
-	{
353
-		if ($request = static::active())
354
-		{
355
-			return $request->uri->getSegments();
356
-		}
357
-
358
-		return null;
359
-	}
360
-
361
-	/**
362
-	 * Returns the total number of segment.
363
-	 *
364
-	 * @return int|null  
365
-	 */
366
-	public function totalSegments()
367
-	{
368
-		if ($request = static::active())
369
-		{
370
-			return $request->uri->getTotalSegments();
371
-		}
372
-
373
-		return null;
374
-	}
375
-
376
-	/**
377
-	 * Detects and returns the current URI based on a number of different server variables.
378
-	 * 
379
-	 * @param  string  $protocol
380
-	 * @param  string  $baseUrl
381
-	 * 
382
-	 * @return string
383
-	 */
384
-	protected function detectURI(string $protocol, string $baseUrl)
385
-	{
386
-		$this->uri->setPath($this->http->detectPath($protocol));
387
-
388
-		$baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl;
389
-
390
-		if ( ! empty($baseUrl))
391
-		{
392
-			$this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME));
393
-			$this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST));
394
-			$this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT));
395
-		}
396
-		else 
397
-		{
398
-			if ( ! $this->http->isCli())
399
-			{
400
-				exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.');
401
-			}
402
-		}
403
-	}
404
-
405
-	/**
406
-	 * Handles setting up the locale, auto-detecting of language.
407
-	 * 
408
-	 * @return void
409
-	 */
410
-	public function detectLocale()
411
-	{
412
-		$this->languages = $this->defaultLocale = config('app.locale');
413
-
414
-		$this->setLocale($this->validLocales);
415
-	}
416
-
417
-	/**
418
-	 * Returns the default locale as set.
419
-	 * 
420
-	 * @return string
421
-	 */
422
-	public function getDefaultLocale()
423
-	{
424
-		return $this->defaultLocale;
425
-	}
426
-
427
-	/**
428
-	 * Gets the current locale, with a fallback to the default.
429
-	 * 
430
-	 * @return string 
431
-	 */
432
-	public function getLocale()
433
-	{
434
-		return $this->languages ?: $this->defaultLocale;
435
-	}
436
-
437
-	/**
438
-	 * Sets the locale string for this request.
439
-	 * 
440
-	 * @param  string  $locale
441
-	 * 
442
-	 * @return \Syscodes\Http\Request
443
-	 */
444
-	public function setLocale($locale)
445
-	{
446
-		if ( ! in_array($locale, $this->validLocales))
447
-		{
448
-			$locale = $this->defaultLocale;
449
-		}
163
+        $this->initialize($request, $cookies, $files, $server, $content);
164
+
165
+        $this->detectURI(config('app.uriProtocol'), config('app.baseUrl'));
166
+
167
+        $this->detectLocale();
168
+    }
169
+
170
+    /**
171
+     * Sets the parameters for this request.
172
+     * 
173
+     * @param  array  $request
174
+     * @param  array  $cookies
175
+     * @param  array  $files
176
+     * @param  array  $server
177
+     * 
178
+     * @return void
179
+     */
180
+    public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null)
181
+    {
182
+        $this->request      = new Parameters($request);
183
+        $this->cookies      = new Inputs($cookies);
184
+        $this->files        = new Files($files);
185
+        $this->server       = new Server($server);
186
+        $this->headers      = new Headers($this->server->all());
187
+
188
+        $this->uri          = new URI;
189
+        $this->http         = new Http;
190
+        $this->method       = null;
191
+        $this->baseUrl      = null;
192
+        $this->content      = $content;
193
+        $this->pathInfo     = null;
194
+        $this->languages    = null;
195
+        $this->validLocales = config('app.supportedLocales');
196
+    }
197
+
198
+    /**
199
+     * Create a new Syscodes HTTP request from server variables.
200
+     * 
201
+     * @return static
202
+     */
203
+    public static function capture()
204
+    {
205
+        return static::createFromRequest(static::createFromRequestGlobals());
206
+    }
207
+
208
+    /**
209
+     * Creates an Syscodes request from of the Request class instance.
210
+     * 
211
+     * @param  \Syscodes\Http\Request  $request
212
+     * 
213
+     * @return static
214
+     */
215
+    public static function createFromRequest($request)
216
+    {
217
+        $newRequest = (new static)->duplicate($request->request->all(), $request->cookies->all(), 
218
+                                                $request->files->all(), $request->server->all());
219
+
220
+        return $newRequest;
221
+    }
222
+
223
+    /**
224
+     * Creates a new request with value from PHP's super global.
225
+     * 
226
+     * @return static
227
+     */
228
+    public static function createFromRequestGlobals()
229
+    {
230
+        $request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER);
231
+
232
+        return $request;
233
+    }
234
+
235
+    /**
236
+     * Creates a new request from a factory.
237
+     * 
238
+     * @param  array  $request
239
+     * @param  array  $cookies
240
+     * @param  array  $files
241
+     * @param  array  $server
242
+     * 
243
+     * @return static
244
+     */
245
+    protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = [])
246
+    {
247
+        if (self::$requestURI)
248
+        {
249
+            $request = (self::$requestURI)($request, $cookies, $files, $server);
250
+
251
+            if ( ! $request instanceof self)
252
+            {
253
+                throw new LogicException('The Request active must return an instance of Syscodes\Http\Request');
254
+            }
255
+
256
+            return $request;
257
+        }
258
+
259
+        return new static($request, $cookies, $files, $server);
260
+    }
261
+
262
+    /**
263
+     * Clones a request and overrides some of its parameters.
264
+     * 
265
+     * @param  array  $request
266
+     * @param  array  $cookies
267
+     * @param  array  $files
268
+     * @param  array  $server
269
+     * 
270
+     * @return static
271
+     */
272
+    public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = [])
273
+    {
274
+        $duplicate = clone $this;
275
+
276
+        if (null !== $request)
277
+        {
278
+            $duplicate->request = new Parameters($request);
279
+        }
280
+
281
+        if (null !== $cookies)
282
+        {
283
+            $duplicate->cookies = new Inputs($cookies);
284
+        }
285
+
286
+        if (null !== $files)
287
+        {
288
+            $duplicate->files = new Files($files);
289
+        }
290
+
291
+        if (null !== $server)
292
+        {
293
+            $duplicate->server  = new Server($server);
294
+            $duplicate->headers = new Headers($duplicate->server->all());
295
+        }
296
+
297
+        $duplicate->uri          = new URI;
298
+        $duplicate->http         = new Http;
299
+        $duplicate->locale       = null;
300
+        $duplicate->method       = null;
301
+        $duplicate->baseUrl      = null;
302
+        $duplicate->pathInfo     = null;
303
+        $duplicate->validLocales = config('app.supportedLocales');
304
+
305
+        return $duplicate;		
306
+    }
307
+
308
+    /**
309
+     * Returns the active request currently being used.
310
+     *
311
+     * @param  \Syscodes\Http\Request|bool|null  $request  Overwrite current request 
312
+     *                                                     before returning, false prevents 
313
+     *                                                     overwrite
314
+     *
315
+     * @return \Syscodes\Http\Request
316
+     */
317
+    public static function active($request = false)
318
+    {
319
+        if ($request !== false)
320
+        {
321
+            static::$requestURI = $request;
322
+        }
323
+
324
+        return static::$requestURI;
325
+    }
326
+
327
+    /**
328
+     * Returns the desired segment, or $default if it does not exist.
329
+     *
330
+     * @param  int  $index  The segment number (1-based index)
331
+     * @param  mixed  $default  Default value to return
332
+     *
333
+     * @return  string
334
+     */
335
+    public function segment($index, $default = null)
336
+    {
337
+        if ($request = static::active())
338
+        {
339
+            return $request->uri->getSegment($index, $default);
340
+        }
341
+
342
+        return null;
343
+    }
344
+
345
+    /**
346
+     * Returns all segments in an array. For total of segments
347
+     * used the function PHP count().
348
+     *
349
+     * @return array
350
+     */
351
+    public function segments()
352
+    {
353
+        if ($request = static::active())
354
+        {
355
+            return $request->uri->getSegments();
356
+        }
357
+
358
+        return null;
359
+    }
360
+
361
+    /**
362
+     * Returns the total number of segment.
363
+     *
364
+     * @return int|null  
365
+     */
366
+    public function totalSegments()
367
+    {
368
+        if ($request = static::active())
369
+        {
370
+            return $request->uri->getTotalSegments();
371
+        }
372
+
373
+        return null;
374
+    }
375
+
376
+    /**
377
+     * Detects and returns the current URI based on a number of different server variables.
378
+     * 
379
+     * @param  string  $protocol
380
+     * @param  string  $baseUrl
381
+     * 
382
+     * @return string
383
+     */
384
+    protected function detectURI(string $protocol, string $baseUrl)
385
+    {
386
+        $this->uri->setPath($this->http->detectPath($protocol));
387
+
388
+        $baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl;
389
+
390
+        if ( ! empty($baseUrl))
391
+        {
392
+            $this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME));
393
+            $this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST));
394
+            $this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT));
395
+        }
396
+        else 
397
+        {
398
+            if ( ! $this->http->isCli())
399
+            {
400
+                exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.');
401
+            }
402
+        }
403
+    }
404
+
405
+    /**
406
+     * Handles setting up the locale, auto-detecting of language.
407
+     * 
408
+     * @return void
409
+     */
410
+    public function detectLocale()
411
+    {
412
+        $this->languages = $this->defaultLocale = config('app.locale');
413
+
414
+        $this->setLocale($this->validLocales);
415
+    }
416
+
417
+    /**
418
+     * Returns the default locale as set.
419
+     * 
420
+     * @return string
421
+     */
422
+    public function getDefaultLocale()
423
+    {
424
+        return $this->defaultLocale;
425
+    }
426
+
427
+    /**
428
+     * Gets the current locale, with a fallback to the default.
429
+     * 
430
+     * @return string 
431
+     */
432
+    public function getLocale()
433
+    {
434
+        return $this->languages ?: $this->defaultLocale;
435
+    }
436
+
437
+    /**
438
+     * Sets the locale string for this request.
439
+     * 
440
+     * @param  string  $locale
441
+     * 
442
+     * @return \Syscodes\Http\Request
443
+     */
444
+    public function setLocale($locale)
445
+    {
446
+        if ( ! in_array($locale, $this->validLocales))
447
+        {
448
+            $locale = $this->defaultLocale;
449
+        }
450 450
 		
451
-		$this->languages = $locale;
452
-
453
-		try
454
-		{
455
-		    if (class_exists('Locale', false))
456
-			{
457
-				Locale::setDefault($locale);
458
-			}
459
-		}
460
-		catch (Exception $exception) {}
461
-
462
-		return $this;
463
-	}
464
-
465
-	/**
466
-	 * Returns the full request string.
467
-	 *
468
-	 * @return string|null  The Request string
469
-	 */
470
-	public function get() 
471
-	{
472
-		if ($request = static::active())
473
-		{
474
-			return $request->uri->get();
475
-		}
476
-
477
-		return null;
478
-	}
479
-
480
-	/**
481
-	 * A convenience method that grabs the raw input stream and decodes
482
-	 * the JSON into an array.
483
-	 * 
484
-	 * @param  bool  $assoc  (false by default)
485
-	 * @param  int  $depth  (512 by default)
486
-	 * @param  int  $options  (0 by default)
487
-	 * 
488
-	 * @return mixed
489
-	 */
490
-	public function getJSON(bool $assoc = false, int $depth = 512, int $options = 0)
491
-	{
492
-		return json_decode($this->content, $assoc, $depth, $options);
493
-	}
494
-
495
-	/**
496
-	 * Returns whether this is an AJAX request or not.
497
-	 *
498
-	 * @return bool
499
-	 */
500
-	public function isXmlHttpRequest()
501
-	{
502
-		return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && 
503
-				strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest';
504
-	}
505
-
506
-	/**
507
-	 * Returns the input method used (GET, POST, DELETE, etc.).
508
-	 *
509
-	 * @return string
510
-	 * 
511
-	 * @throws \LogicException  
512
-	 */
513
-	public function getmethod()
514
-	{
515
-		if (null !== $this->method)
516
-		{
517
-			return $this->method;
518
-		}
451
+        $this->languages = $locale;
452
+
453
+        try
454
+        {
455
+            if (class_exists('Locale', false))
456
+            {
457
+                Locale::setDefault($locale);
458
+            }
459
+        }
460
+        catch (Exception $exception) {}
461
+
462
+        return $this;
463
+    }
464
+
465
+    /**
466
+     * Returns the full request string.
467
+     *
468
+     * @return string|null  The Request string
469
+     */
470
+    public function get() 
471
+    {
472
+        if ($request = static::active())
473
+        {
474
+            return $request->uri->get();
475
+        }
476
+
477
+        return null;
478
+    }
479
+
480
+    /**
481
+     * A convenience method that grabs the raw input stream and decodes
482
+     * the JSON into an array.
483
+     * 
484
+     * @param  bool  $assoc  (false by default)
485
+     * @param  int  $depth  (512 by default)
486
+     * @param  int  $options  (0 by default)
487
+     * 
488
+     * @return mixed
489
+     */
490
+    public function getJSON(bool $assoc = false, int $depth = 512, int $options = 0)
491
+    {
492
+        return json_decode($this->content, $assoc, $depth, $options);
493
+    }
494
+
495
+    /**
496
+     * Returns whether this is an AJAX request or not.
497
+     *
498
+     * @return bool
499
+     */
500
+    public function isXmlHttpRequest()
501
+    {
502
+        return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && 
503
+                strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest';
504
+    }
505
+
506
+    /**
507
+     * Returns the input method used (GET, POST, DELETE, etc.).
508
+     *
509
+     * @return string
510
+     * 
511
+     * @throws \LogicException  
512
+     */
513
+    public function getmethod()
514
+    {
515
+        if (null !== $this->method)
516
+        {
517
+            return $this->method;
518
+        }
519 519
 		
520
-		$method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
520
+        $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
521 521
 		
522
-		if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true))
523
-		{
524
-			return $this->method = $method;
525
-		}
522
+        if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true))
523
+        {
524
+            return $this->method = $method;
525
+        }
526 526
 		
527
-		if ( ! preg_match('~^[A-Z]++$#~D', $method))
528
-		{
529
-			throw new logicException(sprintf('Invalid method override "%s"', $method));
530
-		}
531
-
532
-		return $this->method = $method;
533
-	}
534
-
535
-	/**
536
-	 * Sets the request method.
537
-	 *
538
-	 * @param  string  $method  
539
-	 *
540
-	 * @return string
541
-	 */
542
-	public function setMethod(string $method) 
543
-	{
544
-		$this->method = null;
545
-		$this->server->set('REQUEST_METHOD', $method);
546
-	}
527
+        if ( ! preg_match('~^[A-Z]++$#~D', $method))
528
+        {
529
+            throw new logicException(sprintf('Invalid method override "%s"', $method));
530
+        }
531
+
532
+        return $this->method = $method;
533
+    }
534
+
535
+    /**
536
+     * Sets the request method.
537
+     *
538
+     * @param  string  $method  
539
+     *
540
+     * @return string
541
+     */
542
+    public function setMethod(string $method) 
543
+    {
544
+        $this->method = null;
545
+        $this->server->set('REQUEST_METHOD', $method);
546
+    }
547 547
 	
548
-	/**
549
-	 * Determine if the current request URI matches a pattern.
550
-	 * 
551
-	 * @param  mixed  ...$patterns
552
-	 * 
553
-	 * @return bool
554
-	 */
555
-	public function is(...$patterns)
556
-	{
557
-		$path = $this->decodedPath();
548
+    /**
549
+     * Determine if the current request URI matches a pattern.
550
+     * 
551
+     * @param  mixed  ...$patterns
552
+     * 
553
+     * @return bool
554
+     */
555
+    public function is(...$patterns)
556
+    {
557
+        $path = $this->decodedPath();
558 558
 		
559
-		foreach ($patterns as $pattern)
560
-		{
561
-			if (Str::is($pattern, $path))
562
-			{
563
-				return true;
564
-			}
565
-		}
566
-
567
-		return false;
568
-	}
569
-
570
-	/**
571
-	 * Determine if the route name matches a given pattern.
572
-	 * 
573
-	 * @param  mixed  ...$patterns
574
-	 * 
575
-	 * @return bool
576
-	 */
577
-	public function routeIs(...$patterns)
578
-	{
579
-		return $this->route() && $this->route()->is(...$patterns);
580
-	}
581
-
582
-	/**
583
-	 * Get the route handling the request.
584
-	 * 
585
-	 * @param  string|null  $param  (null by default)
586
-	 * @param  mixed  $default  (null by default)
587
-	 * 
588
-	 * @return \Syscodes\Routing\Route|object|string|null
589
-	 */
590
-	public function route($param = null, $default = null)
591
-	{
592
-		$route = $this->getRoute();
593
-
594
-		if (is_null($route) || is_null($param))
595
-		{
596
-			return $route;
597
-		}
598
-
599
-		return $route->parameter($param, $default);
600
-	}
601
-
602
-	/**
603
-	 * Get the current decoded path info for the request.
604
-	 * 
605
-	 * @return string
606
-	 */
607
-	public function decodedPath()
608
-	{
609
-		return rawurldecode($this->path());
610
-	}
611
-
612
-	/**
613
-	 * Get the current path info for the request.
614
-	 * 
615
-	 * @return string
616
-	 */
617
-	public function path()
618
-	{
619
-		$path = trim($this->getPathInfo(), '/');
620
-
621
-		return $path == '' ? '/' : $path;
622
-	}
623
-
624
-	/**
625
-	 * Retunrs the request body content.
626
-	 * 
627
-	 * @return string
628
-	 */
629
-	public function getContent()
630
-	{
631
-		if (null === $this->content || false === $this->content)
632
-		{
633
-			$this->content = file_get_contents('php://input');
634
-		}
635
-
636
-		return $this->content;
637
-	}
638
-
639
-	/**
640
-	 * Returns the path being requested relative to the executed script. 
641
-	 * 
642
-	 * @return string
643
-	 */
644
-	public function getPathInfo()
645
-	{
646
-		if (null === $this->pathInfo)
647
-		{
648
-			$this->pathInfo = $this->http->parsePathInfo();
649
-		}
650
-
651
-		return $this->pathInfo;
652
-	}
653
-
654
-	/**
655
-	 * Returns the root URL from which this request is executed.
656
-	 * 
657
-	 * @return string
658
-	 */
659
-	public function getBaseUrl()
660
-	{
661
-		if (null === $this->baseUrl)
662
-		{
663
-			$this->baseUrl = $this->http->parseBaseUrl();
664
-		}
665
-
666
-		return $this->baseUrl;
667
-	}
668
-
669
-	/**
670
-	 * Returns the requested URI.
671
-	 * 
672
-	 * @return string
673
-	 */
674
-	public function getRequestUri()
675
-	{
676
-		if (null === $this->requestToUri)
677
-		{
678
-			$this->requestToUri = $this->http->parseRequestUri();
679
-		}
680
-
681
-		return $this->requestToUri;
682
-	}
559
+        foreach ($patterns as $pattern)
560
+        {
561
+            if (Str::is($pattern, $path))
562
+            {
563
+                return true;
564
+            }
565
+        }
566
+
567
+        return false;
568
+    }
569
+
570
+    /**
571
+     * Determine if the route name matches a given pattern.
572
+     * 
573
+     * @param  mixed  ...$patterns
574
+     * 
575
+     * @return bool
576
+     */
577
+    public function routeIs(...$patterns)
578
+    {
579
+        return $this->route() && $this->route()->is(...$patterns);
580
+    }
581
+
582
+    /**
583
+     * Get the route handling the request.
584
+     * 
585
+     * @param  string|null  $param  (null by default)
586
+     * @param  mixed  $default  (null by default)
587
+     * 
588
+     * @return \Syscodes\Routing\Route|object|string|null
589
+     */
590
+    public function route($param = null, $default = null)
591
+    {
592
+        $route = $this->getRoute();
593
+
594
+        if (is_null($route) || is_null($param))
595
+        {
596
+            return $route;
597
+        }
598
+
599
+        return $route->parameter($param, $default);
600
+    }
601
+
602
+    /**
603
+     * Get the current decoded path info for the request.
604
+     * 
605
+     * @return string
606
+     */
607
+    public function decodedPath()
608
+    {
609
+        return rawurldecode($this->path());
610
+    }
611
+
612
+    /**
613
+     * Get the current path info for the request.
614
+     * 
615
+     * @return string
616
+     */
617
+    public function path()
618
+    {
619
+        $path = trim($this->getPathInfo(), '/');
620
+
621
+        return $path == '' ? '/' : $path;
622
+    }
623
+
624
+    /**
625
+     * Retunrs the request body content.
626
+     * 
627
+     * @return string
628
+     */
629
+    public function getContent()
630
+    {
631
+        if (null === $this->content || false === $this->content)
632
+        {
633
+            $this->content = file_get_contents('php://input');
634
+        }
635
+
636
+        return $this->content;
637
+    }
638
+
639
+    /**
640
+     * Returns the path being requested relative to the executed script. 
641
+     * 
642
+     * @return string
643
+     */
644
+    public function getPathInfo()
645
+    {
646
+        if (null === $this->pathInfo)
647
+        {
648
+            $this->pathInfo = $this->http->parsePathInfo();
649
+        }
650
+
651
+        return $this->pathInfo;
652
+    }
653
+
654
+    /**
655
+     * Returns the root URL from which this request is executed.
656
+     * 
657
+     * @return string
658
+     */
659
+    public function getBaseUrl()
660
+    {
661
+        if (null === $this->baseUrl)
662
+        {
663
+            $this->baseUrl = $this->http->parseBaseUrl();
664
+        }
665
+
666
+        return $this->baseUrl;
667
+    }
668
+
669
+    /**
670
+     * Returns the requested URI.
671
+     * 
672
+     * @return string
673
+     */
674
+    public function getRequestUri()
675
+    {
676
+        if (null === $this->requestToUri)
677
+        {
678
+            $this->requestToUri = $this->http->parseRequestUri();
679
+        }
680
+
681
+        return $this->requestToUri;
682
+    }
683 683
 	
684
-	/**
685
-	 * Gets the request's scheme.
686
-	 * 
687
-	 * @return string
688
-	 */
689
-	public function getScheme()
690
-	{
691
-		return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http');
692
-	}
693
-
694
-	/**
695
-	 * Returns the host name.
696
-	 * 
697
-	 * @return void
698
-	 */
699
-	public function getHost()
700
-	{
701
-		if ( ! $host = $this->server->get('SERVER_NAME'))
702
-		{
703
-			$host = $this->server->get('SERVER_ADDR', '');
704
-		}
705
-
706
-		$host = strtolower(preg_replace('/:\d+$/', '', $this->uri->setHost($host)));
707
-
708
-		return $host;
709
-	}
710
-
711
-	/**
712
-	 * Returns the port on which the request is made.
713
-	 * 
714
-	 * @return int
715
-	 */
716
-	public function getPort()
717
-	{
718
-		if ( ! $this->server->get('HTTP_HOST')) 
719
-		{
720
-			return $this->server->get('SERVER_PORT');
721
-		}
684
+    /**
685
+     * Gets the request's scheme.
686
+     * 
687
+     * @return string
688
+     */
689
+    public function getScheme()
690
+    {
691
+        return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http');
692
+    }
693
+
694
+    /**
695
+     * Returns the host name.
696
+     * 
697
+     * @return void
698
+     */
699
+    public function getHost()
700
+    {
701
+        if ( ! $host = $this->server->get('SERVER_NAME'))
702
+        {
703
+            $host = $this->server->get('SERVER_ADDR', '');
704
+        }
705
+
706
+        $host = strtolower(preg_replace('/:\d+$/', '', $this->uri->setHost($host)));
707
+
708
+        return $host;
709
+    }
710
+
711
+    /**
712
+     * Returns the port on which the request is made.
713
+     * 
714
+     * @return int
715
+     */
716
+    public function getPort()
717
+    {
718
+        if ( ! $this->server->get('HTTP_HOST')) 
719
+        {
720
+            return $this->server->get('SERVER_PORT');
721
+        }
722 722
 		
723
-		return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80);
724
-	}
725
-
726
-	/**
727
-	 * Returns the HTTP host being requested.
728
-	 * 
729
-	 * @return string
730
-	 */
731
-	public function getHttpHost()
732
-	{
733
-		$scheme = $this->getScheme();
734
-		$host   = $this->getHost();
735
-		$port   = $this->getPort();
736
-
737
-		if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port))		
738
-		{
739
-			return $host;
740
-		}
741
-
742
-		return $host.':'.$port;
743
-	}
744
-
745
-	/**
746
-	 * Gets the scheme and HTTP host.
747
-	 * 
748
-	 * @return string
749
-	 */
750
-	public function getSchemeWithHttpHost()
751
-	{
752
-		return $this->getScheme().'://'.$this->getHttpHost();
753
-	}
754
-
755
-	/**
756
-	 * Get the root URL for the application.
757
-	 * 
758
-	 * @return string
759
-	 */
760
-	public function root()
761
-	{
762
-		return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/');
763
-	}
764
-
765
-	/**
766
-	 * Get the URL for the request.
767
-	 * 
768
-	 * @return string
769
-	 */
770
-	public function url()
771
-	{
772
-		return trim(preg_replace('/\?.*/', '', $this->get()), '/');
773
-	}
774
-
775
-	/**
776
-	 * Returns the referer.
777
-	 * 
778
-	 * @param  string  $default
779
-	 * 
780
-	 * @return string
781
-	 */
782
-	public function referer(string $default = '')
783
-	{
784
-		return $this->server->get('HTTP_REFERER', $default);
785
-	}
723
+        return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80);
724
+    }
725
+
726
+    /**
727
+     * Returns the HTTP host being requested.
728
+     * 
729
+     * @return string
730
+     */
731
+    public function getHttpHost()
732
+    {
733
+        $scheme = $this->getScheme();
734
+        $host   = $this->getHost();
735
+        $port   = $this->getPort();
736
+
737
+        if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port))		
738
+        {
739
+            return $host;
740
+        }
741
+
742
+        return $host.':'.$port;
743
+    }
744
+
745
+    /**
746
+     * Gets the scheme and HTTP host.
747
+     * 
748
+     * @return string
749
+     */
750
+    public function getSchemeWithHttpHost()
751
+    {
752
+        return $this->getScheme().'://'.$this->getHttpHost();
753
+    }
754
+
755
+    /**
756
+     * Get the root URL for the application.
757
+     * 
758
+     * @return string
759
+     */
760
+    public function root()
761
+    {
762
+        return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/');
763
+    }
764
+
765
+    /**
766
+     * Get the URL for the request.
767
+     * 
768
+     * @return string
769
+     */
770
+    public function url()
771
+    {
772
+        return trim(preg_replace('/\?.*/', '', $this->get()), '/');
773
+    }
774
+
775
+    /**
776
+     * Returns the referer.
777
+     * 
778
+     * @param  string  $default
779
+     * 
780
+     * @return string
781
+     */
782
+    public function referer(string $default = '')
783
+    {
784
+        return $this->server->get('HTTP_REFERER', $default);
785
+    }
786 786
 	
787
-	/**
788
-	 * Attempts to detect if the current connection is secure through 
789
-	 * over HTTPS protocol.
790
-	 * 
791
-	 * @return bool
792
-	 */
793
-	public function secure()
794
-	{
795
-		if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off')
796
-		{
797
-			return true;
798
-		}
799
-		elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https')
800
-		{
801
-			return true;
802
-		}
803
-		elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off')
804
-		{
805
-			return true;
806
-		}
807
-
808
-		return false;
809
-	}
810
-
811
-	/**
812
-	 * Returns the user agent.
813
-	 *
814
-	 * @param  string|null  $default
815
-	 *
816
-	 * @return string
817
-	 */
818
-	public function userAgent(string $default = null)
819
-	{
820
-		return $this->server->get('HTTP_USER_AGENT', $default);
821
-	}
822
-
823
-	/**
824
-	 * Get the route resolver.
825
-	 * 
826
-	 * @return \Syscodes\Routing\Router
827
-	 */
828
-	public function getRoute()
829
-	{
830
-		return app('router');
831
-	}
832
-
833
-	/**
834
-	 * Get an element from the request.
835
-	 * 
836
-	 * @return string[]
837
-	 */
838
-	public function __get($key)
839
-	{
840
-		$all = $this->server->all();
841
-
842
-		if (array_key_exists($key, $all))
843
-		{
844
-			return $all[$key];
845
-		}
846
-		else
847
-		{
848
-			return $key;
849
-		}
850
-	}
851
-
852
-	/**
853
-	 * Returns the Request as an HTTP string.
854
-	 * 
855
-	 * @return string
856
-	 */
857
-	public function __toString()
858
-	{
859
-		try
860
-		{
861
-			$content = $this->getContent();
862
-		}
863
-		catch (LogicException $e)
864
-		{
865
-			if (PHP_VERSION_ID > 70400)
866
-			{
867
-				throw $e;
868
-			}
869
-
870
-			return trigger_error($e, E_USER_ERROR);
871
-		}
872
-
873
-		$cookieHeader = '';
874
-		$cookies      = [];
875
-
876
-		foreach ($this->cookies as $key => $value)
877
-		{
878
-			$cookies[]= "{$key} = {$value}";
879
-		}
880
-
881
-		if ( ! empty($cookies))
882
-		{
883
-			$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
884
-		}
787
+    /**
788
+     * Attempts to detect if the current connection is secure through 
789
+     * over HTTPS protocol.
790
+     * 
791
+     * @return bool
792
+     */
793
+    public function secure()
794
+    {
795
+        if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off')
796
+        {
797
+            return true;
798
+        }
799
+        elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https')
800
+        {
801
+            return true;
802
+        }
803
+        elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off')
804
+        {
805
+            return true;
806
+        }
807
+
808
+        return false;
809
+    }
810
+
811
+    /**
812
+     * Returns the user agent.
813
+     *
814
+     * @param  string|null  $default
815
+     *
816
+     * @return string
817
+     */
818
+    public function userAgent(string $default = null)
819
+    {
820
+        return $this->server->get('HTTP_USER_AGENT', $default);
821
+    }
822
+
823
+    /**
824
+     * Get the route resolver.
825
+     * 
826
+     * @return \Syscodes\Routing\Router
827
+     */
828
+    public function getRoute()
829
+    {
830
+        return app('router');
831
+    }
832
+
833
+    /**
834
+     * Get an element from the request.
835
+     * 
836
+     * @return string[]
837
+     */
838
+    public function __get($key)
839
+    {
840
+        $all = $this->server->all();
841
+
842
+        if (array_key_exists($key, $all))
843
+        {
844
+            return $all[$key];
845
+        }
846
+        else
847
+        {
848
+            return $key;
849
+        }
850
+    }
851
+
852
+    /**
853
+     * Returns the Request as an HTTP string.
854
+     * 
855
+     * @return string
856
+     */
857
+    public function __toString()
858
+    {
859
+        try
860
+        {
861
+            $content = $this->getContent();
862
+        }
863
+        catch (LogicException $e)
864
+        {
865
+            if (PHP_VERSION_ID > 70400)
866
+            {
867
+                throw $e;
868
+            }
869
+
870
+            return trigger_error($e, E_USER_ERROR);
871
+        }
872
+
873
+        $cookieHeader = '';
874
+        $cookies      = [];
875
+
876
+        foreach ($this->cookies as $key => $value)
877
+        {
878
+            $cookies[]= "{$key} = {$value}";
879
+        }
880
+
881
+        if ( ! empty($cookies))
882
+        {
883
+            $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
884
+        }
885 885
 		
886
-		return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
887
-			$this->headers.
888
-			$cookieHeader."\r\n".
889
-			$content;
890
-	}
891
-
892
-	/**
893
-	 * Clones the current request.
894
-	 * 
895
-	 * @return void
896
-	 */
897
-	public function __clone()
898
-	{
899
-		$this->request = clone $this->request;
900
-		$this->cookies = clone $this->cookies;
901
-		$this->files   = clone $this->files;
902
-		$this->server  = clone $this->server;
903
-		$this->headers = clone $this->headers;
904
-	}
886
+        return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
887
+            $this->headers.
888
+            $cookieHeader."\r\n".
889
+            $content;
890
+    }
891
+
892
+    /**
893
+     * Clones the current request.
894
+     * 
895
+     * @return void
896
+     */
897
+    public function __clone()
898
+    {
899
+        $this->request = clone $this->request;
900
+        $this->cookies = clone $this->cookies;
901
+        $this->files   = clone $this->files;
902
+        $this->server  = clone $this->server;
903
+        $this->headers = clone $this->headers;
904
+    }
905 905
 }
906 906
\ 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
@@ -875,7 +875,7 @@
 block discarded – undo
875 875
 
876 876
 		foreach ($this->cookies as $key => $value)
877 877
 		{
878
-			$cookies[]= "{$key} = {$value}";
878
+			$cookies[] = "{$key} = {$value}";
879 879
 		}
880 880
 
881 881
 		if ( ! empty($cookies))
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -392,8 +392,7 @@  discard block
 block discarded – undo
392 392
 			$this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME));
393 393
 			$this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST));
394 394
 			$this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT));
395
-		}
396
-		else 
395
+		} else 
397 396
 		{
398 397
 			if ( ! $this->http->isCli())
399 398
 			{
@@ -456,8 +455,7 @@  discard block
 block discarded – undo
456 455
 			{
457 456
 				Locale::setDefault($locale);
458 457
 			}
459
-		}
460
-		catch (Exception $exception) {}
458
+		} catch (Exception $exception) {}
461 459
 
462 460
 		return $this;
463 461
 	}
@@ -795,12 +793,10 @@  discard block
 block discarded – undo
795 793
 		if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off')
796 794
 		{
797 795
 			return true;
798
-		}
799
-		elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https')
796
+		} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https')
800 797
 		{
801 798
 			return true;
802
-		}
803
-		elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off')
799
+		} elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off')
804 800
 		{
805 801
 			return true;
806 802
 		}
@@ -842,8 +838,7 @@  discard block
 block discarded – undo
842 838
 		if (array_key_exists($key, $all))
843 839
 		{
844 840
 			return $all[$key];
845
-		}
846
-		else
841
+		} else
847 842
 		{
848 843
 			return $key;
849 844
 		}
@@ -859,8 +854,7 @@  discard block
 block discarded – undo
859 854
 		try
860 855
 		{
861 856
 			$content = $this->getContent();
862
-		}
863
-		catch (LogicException $e)
857
+		} catch (LogicException $e)
864 858
 		{
865 859
 			if (PHP_VERSION_ID > 70400)
866 860
 			{
Please login to merge, or discard this patch.
src/components/Http/RedirectResponse.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -102,13 +102,13 @@
 block discarded – undo
102 102
     }
103 103
 
104 104
     /**
105
-    * Redirects to another url. Sets the redirect header, sends the headers and exits.
106
-    * Can redirect via a Location header.
107
-    *
108
-    * @param  string  $url  The url
109
-    *
110
-    * @return $this
111
-    */
105
+     * Redirects to another url. Sets the redirect header, sends the headers and exits.
106
+     * Can redirect via a Location header.
107
+     *
108
+     * @param  string  $url  The url
109
+     *
110
+     * @return $this
111
+     */
112 112
     public function setTargetUrl($url)
113 113
     {
114 114
         if ('' === ($url ?? ''))
Please login to merge, or discard this patch.
src/components/Http/Exceptions/PostTooLargeHttpException.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -34,35 +34,35 @@
 block discarded – undo
34 34
  */
35 35
 class PostTooLargeHttpException extends HttpException
36 36
 {
37
-	/**
38
-	 * Get the HTTP status code.
39
-	 * 
40
-	 * @var int $code
41
-	 */
42
-	protected $code = 413;
37
+    /**
38
+     * Get the HTTP status code.
39
+     * 
40
+     * @var int $code
41
+     */
42
+    protected $code = 413;
43 43
 
44
-	/**
45
-	 * Initialize constructor. 
46
-	 * 
47
-	 * @param  string|null  $message  (null by default) 
48
-	 * @param  \Throwable|null  $previous  (null by default)
49
-	 * @param  int  $code  (0 by default)
50
-	 * @param  array  $headers
51
-	 * 
52
-	 * @return void
53
-	 */
54
-	public function __construct(
55
-		string $message = null, 
56
-		Throwable $previous = null, 
57
-		int $code = 0, 
58
-		array $headers = []
59
-	) {
44
+    /**
45
+     * Initialize constructor. 
46
+     * 
47
+     * @param  string|null  $message  (null by default) 
48
+     * @param  \Throwable|null  $previous  (null by default)
49
+     * @param  int  $code  (0 by default)
50
+     * @param  array  $headers
51
+     * 
52
+     * @return void
53
+     */
54
+    public function __construct(
55
+        string $message = null, 
56
+        Throwable $previous = null, 
57
+        int $code = 0, 
58
+        array $headers = []
59
+    ) {
60 60
         parent::__construct(
61
-			$this->code, 
62
-			$message, 
63
-			$previous, 
64
-			$headers, 
65
-			$code
66
-		);
67
-	}
61
+            $this->code, 
62
+            $message, 
63
+            $previous, 
64
+            $headers, 
65
+            $code
66
+        );
67
+    }
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/URI.php 3 patches
Indentation   +513 added lines, -513 removed lines patch added patch discarded remove patch
@@ -35,519 +35,519 @@
 block discarded – undo
35 35
  */
36 36
 class URI
37 37
 {
38
-	/**
39
-	 * Returns default schemes/ports.
40
-	 * 
41
-	 * @var array $defaultPorts
42
-	 */
43
-	protected $defaultPorts = [
44
-		'http'  => 80,
45
-		'https' => 443,
46
-		'ftp'   => 21,
47
-		'sftp'  => 22
48
-	];
49
-
50
-	/**
51
-	 * The name of any fragment.
52
-	 * 
53
-	 * @var string $fragment
54
-	 */
55
-	protected $fragment = '';
56
-
57
-	/**
58
-	 * The URI Host.
59
-	 * 
60
-	 * @var string $host
61
-	 */
62
-	protected $host;
38
+    /**
39
+     * Returns default schemes/ports.
40
+     * 
41
+     * @var array $defaultPorts
42
+     */
43
+    protected $defaultPorts = [
44
+        'http'  => 80,
45
+        'https' => 443,
46
+        'ftp'   => 21,
47
+        'sftp'  => 22
48
+    ];
49
+
50
+    /**
51
+     * The name of any fragment.
52
+     * 
53
+     * @var string $fragment
54
+     */
55
+    protected $fragment = '';
56
+
57
+    /**
58
+     * The URI Host.
59
+     * 
60
+     * @var string $host
61
+     */
62
+    protected $host;
63 63
 	
64
-	/**
65
-	 * The URI User Password.
66
-	 * 
67
-	 * @var string $password
68
-	 */
69
-	protected $password;
70
-
71
-	/**
72
-	 * The URI path.
73
-	 * 
74
-	 * @var string $path
75
-	 */
76
-	protected $path;
77
-
78
-	/**
79
-	 * The URI Port.
80
-	 * 
81
-	 * @var int $port
82
-	 */
83
-	protected $port;
84
-
85
-	/**
86
-	 * The query string.
87
-	 * 
88
-	 * @var string $query
89
-	 */
90
-	protected $query;
91
-
92
-	/**
93
-	 * The URI Scheme.
94
-	 * 
95
-	 * @var string $scheme
96
-	 */
97
-	protected $scheme = 'http';
98
-
99
-	/**
100
-	 * The URI segments.
101
-	 *
102
-	 * @var array $segments
103
-	 */
104
-	protected $segments = [];
105
-
106
-	/**
107
-	 * Whether passwords should be shown in userInfo/authority calls.
108
-	 * 
109
-	 * @var boolean $showPassword
110
-	 */
111
-	protected $showPassword = false;
64
+    /**
65
+     * The URI User Password.
66
+     * 
67
+     * @var string $password
68
+     */
69
+    protected $password;
70
+
71
+    /**
72
+     * The URI path.
73
+     * 
74
+     * @var string $path
75
+     */
76
+    protected $path;
77
+
78
+    /**
79
+     * The URI Port.
80
+     * 
81
+     * @var int $port
82
+     */
83
+    protected $port;
84
+
85
+    /**
86
+     * The query string.
87
+     * 
88
+     * @var string $query
89
+     */
90
+    protected $query;
91
+
92
+    /**
93
+     * The URI Scheme.
94
+     * 
95
+     * @var string $scheme
96
+     */
97
+    protected $scheme = 'http';
98
+
99
+    /**
100
+     * The URI segments.
101
+     *
102
+     * @var array $segments
103
+     */
104
+    protected $segments = [];
105
+
106
+    /**
107
+     * Whether passwords should be shown in userInfo/authority calls.
108
+     * 
109
+     * @var boolean $showPassword
110
+     */
111
+    protected $showPassword = false;
112 112
 	
113
-	/**
114
-	 * The URI User Info.
115
-	 * 
116
-	 * @var string $user
117
-	 */
118
-	protected $user;
119
-
120
-	/**
121
-	 * Constructor. The URI class instance.
122
-	 * 
123
-	 * @param  string|null  $uri  (null by default)
124
-	 * 
125
-	 * @return void
126
-	 * 
127
-	 * @throws \Syscodes\Http\Exceptions\HttpURIException
128
-	 */
129
-	public function __construct(string $uri = null)
130
-	{
131
-		if ( ! is_null($uri))
132
-		{
133
-			$this->setUri($uri);
134
-		}
135
-	}
136
-
137
-	/**
138
-	 * Sets and overwrites any current URI information.
139
-	 * 
140
-	 * @param  string|null  $uri  (null by default)
141
-	 * 
142
-	 * @return mixed
143
-	 * 
144
-	 * @throws \Syscodes\Http\Exceptions\HttpURIException
145
-	 */
146
-	public function setUri(string $uri = null)
147
-	{
148
-		if ( ! is_null($uri))
149
-		{
150
-			$parts = parse_url($uri);
151
-
152
-			if ($parts === false)
153
-			{
154
-				throw HttpURIException::UnableToParseURI($uri);
155
-			}
156
-
157
-			$this->applyParts($parts);
158
-		}
159
-
160
-		return $this;
161
-	}
162
-
163
-	/**
164
-	 * Returns the full URI string.
165
-	 *
166
-	 * @return string  The URI string
167
-	 */
168
-	public function get()
169
-	{
170
-		return '/'.ltrim($this->path, '/');
171
-	}
172
-
173
-	/**
174
-	 * Sets of URI string.
175
-	 * 
176
-	 * @param  string  $uri
177
-	 * 
178
-	 * @return $this
179
-	 */
180
-	public function set($uri)
181
-	{
182
-		$this->path = $uri;
183
-
184
-		return $this;
185
-	}
186
-
187
-	/**
188
-	 * Retrieve the path component of the URI. The path can either be empty or absolute 
189
-	 * (starting with a slash) or rootless (not starting with a slash).
190
-	 * 
191
-	 * @return string
192
-	 */
193
-	public function getPath()
194
-	{
195
-		return (is_null($this->path) ? '' : $this->path);
196
-	}
197
-
198
-	/**
199
-	 * Sets the path portion of the URI.
200
-	 * 
201
-	 * @param  string  $path
202
-	 *
203
-	 * @return void
204
-	 */
205
-	public function setPath(string $path) 
206
-	{
207
-		$this->path = $this->filterPath($path);
208
-
209
-		$this->filterSegments($this->path);
210
-
211
-		return $this;
212
-	} 
213
-
214
-	/**
215
-	 * Encodes any dangerous characters.
216
-	 * 
217
-	 * @param  string|null  $path
218
-	 * 
219
-	 * @return string
220
-	 */
221
-	protected function filterPath(string $path = null)
222
-	{
223
-		$path = urldecode($path);
224
-
225
-		return $path;
226
-	}
227
-
228
-	/**
229
-	 * Filter the segments of path.
230
-	 * 
231
-	 * @param  string  $uri
232
-	 * 
233
-	 * @return string[]
234
-	 */
235
-	protected function filterSegments($uri)
236
-	{
237
-		$this->segments = (empty($uri) ? [] : explode('/', $uri));
238
-	}
239
-
240
-	/**
241
-	 * Get the specified URI segment, return default if it doesn't exist.
242
-	 * Segment index is 1 based, not 0 based.
243
-	 *
244
-	 * @param  int  $index  The 1-based segment index
245
-	 * @param  mixed  $default  The default value
246
-	 *
247
-	 * @return mixed
248
-	 */
249
-	public function getSegment(int $index, $default = null)
250
-	{
251
-		return Arr::get($this->getSegments(), $index - 1, $default);
252
-	}
253
-
254
-	/**
255
-	 * Returns the segments of the path as an array.
256
-	 *
257
-	 * @return array  The URI segments
258
-	 */
259
-	public function getSegments()
260
-	{
261
-		return array_values(array_filter($this->segments, function ($value) {
262
-			return $value != '';
263
-		}));
264
-	}
265
-
266
-	/**
267
-	 * Returns the total number of segment.
268
-	 *
269
-	 * @return int  
270
-	 */
271
-	public function getTotalSegments()
272
-	{
273
-		return count($this->getSegments());
274
-	}
275
-
276
-	/**
277
-	 * Retrieve the scheme component of the URI.
278
-	 * 
279
-	 * @return string
280
-	 */
281
-	public function getScheme()
282
-	{
283
-		return $this->scheme;
284
-	}
285
-
286
-	/**
287
-	 * Sets the scheme for this URI.
288
-	 * 
289
-	 * @param  string  $str
290
-	 * 
291
-	 * @return $this
292
-	 */
293
-	public function setScheme(string $str)
294
-	{
295
-		$str = preg_replace('~:(//)?$~', '', strtolower($str));
296
-
297
-		$this->scheme = $str;
298
-
299
-		return $this->scheme;
300
-	}
301
-
302
-	/**
303
-	 * Retrieve the user component of the URI.
304
-	 * 
305
-	 * @return string|null
306
-	 */
307
-	public function getUserInfo()
308
-	{
309
-		$user = $this->user;
310
-
311
-		if ($this->showPassword === true && ! empty($this->password))
312
-		{
313
-			$user .= ":$this->password";
314
-		}
315
-
316
-		return $user;
317
-	}
318
-
319
-	/**
320
-	 * Sets the userInfo/Authority portion of the URI.
321
-	 * 
322
-	 * @param  string  $user
323
-	 * @param  string  $pass
324
-	 * 
325
-	 * @return $this
326
-	 */
327
-	public function setUserInfo(string $user, string $pass)
328
-	{
329
-		$this->user     = trim($user);
330
-		$this->password = trim($pass);
331
-
332
-		return $this;
333
-	}
334
-
335
-	/**
336
-	 * Temporarily sets the URI to show a password in userInfo.
337
-	 * 
338
-	 * @param  boolean  $option  (true by default)
339
-	 * 
340
-	 * @return $this
341
-	 */
342
-	public function showPassword(bool $option = true)
343
-	{
344
-		$this->password = $option;
345
-
346
-		return $this->password;
347
-	}
348
-
349
-	/**
350
-	 * Retrieve the authority component of the URI.
351
-	 * 
352
-	 * @param  boolean  $ignore  (false by default)
353
-	 * 
354
-	 * @return string
355
-	 */
356
-	public function getAuthority(bool $ignore = false)
357
-	{
358
-		if (empty($this->host))
359
-		{
360
-			return '';
361
-		}
362
-
363
-		$authority = $this->host;
364
-
365
-		if ( ! empty($this->getUserInfo()))
366
-		{
367
-			$authority = $this->getUserInfo().'@'.$authority;
368
-		}
369
-
370
-		if ( ! empty($this->port) && ! $ignore)
371
-		{
372
-			if ($this->port !== $this->defaultPorts[$this->scheme])
373
-			{
374
-				$authority .= ":$this->port";
375
-			}
376
-		}
377
-
378
-		$this->showPassword = false;
379
-
380
-		return $authority;
381
-	}
382
-
383
-	/**
384
-	 * Parses the given string an saves the appropriate authority pieces.
385
-	 * 
386
-	 * @param  string  $str
387
-	 * 
388
-	 * @return $this
389
-	 */
390
-	public function setAuthority(string $str)
391
-	{
392
-		$parts = parse_url($str);
393
-
394
-		if (empty($parts['host']) && ! empty($parts['path']))
395
-		{
396
-			$parts['host'] = $parts['path'];
397
-			unset($parts['path']);
398
-		}
399
-
400
-		$this->applyParts($parts);
401
-
402
-		return $this;
403
-	}
404
-
405
-	/**
406
-	 * Retrieve the host component of the URI.
407
-	 * 
408
-	 * @return string
409
-	 */
410
-	public function getHost()
411
-	{
412
-		return $this->host;
413
-	}
414
-
415
-	/**
416
-	 * Sets the host name to use.
417
-	 * 
418
-	 * @param  string  $str
419
-	 * 
420
-	 * @return $this
421
-	 */
422
-	public function setHost(string $str)
423
-	{
424
-		$this->host = trim($str);
425
-
426
-		return $this->host;
427
-	}
428
-
429
-	/**
430
-	 * Retrieve the port component of the URI.
431
-	 * 
432
-	 * @return int|null
433
-	 */
434
-	public function getPort()
435
-	{
436
-		return $this->port;
437
-	}
438
-
439
-	/**
440
-	 * Sets the port portion of the URI.
441
-	 * 
442
-	 * @param  int|null  $port  (null by default)
443
-	 * 
444
-	 * @return string
445
-	 */
446
-	public function setPort(int $port = null)
447
-	{
448
-		if (is_null($port))
449
-		{
450
-			return $this;
451
-		}
452
-
453
-		if ($port <= 0 || $port > 65355)
454
-		{
455
-			throw HttpURIException::invalidPort($port);
456
-		}
457
-
458
-		$this->port = $port;
459
-
460
-		return $this->port;
461
-	}
462
-
463
-	/**
464
-	 * Retrieve a URI fragment.
465
-	 * 
466
-	 * @return string
467
-	 */
468
-	public function getFragment()
469
-	{
470
-		return is_null($this->fragment) ? '' : $this->fragment;
471
-	}
472
-
473
-	/**
474
-	 * Sets the fragment portion of the URI.
475
-	 * 
476
-	 * @param  string  $str
477
-	 * 
478
-	 * @return $this
479
-	 */
480
-	public function setFragment(string $str)
481
-	{
482
-		$this->fragment = trim($str, '# ');
483
-
484
-		return $this->fragment;
485
-	}
486
-
487
-	/**
488
-	 * Saves our parts from a parse_url call.
489
-	 * 
490
-	 * @param  array  $parts
491
-	 * 
492
-	 * @return mixed
493
-	 */
494
-	public function applyParts(array $paths)
495
-	{
496
-		if (isset($parts['scheme']))
497
-		{
498
-			$this->SetScheme(rtrim($parts['scheme'], ':/'));
499
-		}
500
-		else
501
-		{
502
-			$this->setScheme('http');
503
-		}
504
-
505
-		if ( ! empty($parts['host']))
506
-		{
507
-			$this->host = $parts['host'];
508
-		}
509
-
510
-		if (isset($parts['port']))
511
-		{
512
-			if ( ! is_null($parts['port']))
513
-			{
514
-				$this->port = $parts['port'];
515
-			}
516
-		}
517
-
518
-		if ( ! empty($parts['user']))
519
-		{
520
-			$this->user = $parts['user'];
521
-		}
522
-
523
-		if ( ! empty($parts['pass']))
524
-		{
525
-			$this->password = $parts['pass'];
526
-		}
527
-
528
-		if ( ! empty($parts['path']))
529
-		{
530
-			$this->path = $this->filterPath($parts['path']);
531
-		}
532
-
533
-		if ( ! empty($parts['fragment']))
534
-		{
535
-			$this->fragment = $parts['fragment'];
536
-		}
537
-
538
-		if ( ! empty($parts['path']))
539
-		{
540
-			$this->segments = explode('/', $parts['path'], '/');
541
-		}
542
-	}
543
-
544
-	/**
545
-	 * Returns the URI string.
546
-	 *
547
-	 * @return string
548
-	 */
549
-	public function __toString()
550
-	{
551
-		return (string) $this->getPath();
552
-	}
113
+    /**
114
+     * The URI User Info.
115
+     * 
116
+     * @var string $user
117
+     */
118
+    protected $user;
119
+
120
+    /**
121
+     * Constructor. The URI class instance.
122
+     * 
123
+     * @param  string|null  $uri  (null by default)
124
+     * 
125
+     * @return void
126
+     * 
127
+     * @throws \Syscodes\Http\Exceptions\HttpURIException
128
+     */
129
+    public function __construct(string $uri = null)
130
+    {
131
+        if ( ! is_null($uri))
132
+        {
133
+            $this->setUri($uri);
134
+        }
135
+    }
136
+
137
+    /**
138
+     * Sets and overwrites any current URI information.
139
+     * 
140
+     * @param  string|null  $uri  (null by default)
141
+     * 
142
+     * @return mixed
143
+     * 
144
+     * @throws \Syscodes\Http\Exceptions\HttpURIException
145
+     */
146
+    public function setUri(string $uri = null)
147
+    {
148
+        if ( ! is_null($uri))
149
+        {
150
+            $parts = parse_url($uri);
151
+
152
+            if ($parts === false)
153
+            {
154
+                throw HttpURIException::UnableToParseURI($uri);
155
+            }
156
+
157
+            $this->applyParts($parts);
158
+        }
159
+
160
+        return $this;
161
+    }
162
+
163
+    /**
164
+     * Returns the full URI string.
165
+     *
166
+     * @return string  The URI string
167
+     */
168
+    public function get()
169
+    {
170
+        return '/'.ltrim($this->path, '/');
171
+    }
172
+
173
+    /**
174
+     * Sets of URI string.
175
+     * 
176
+     * @param  string  $uri
177
+     * 
178
+     * @return $this
179
+     */
180
+    public function set($uri)
181
+    {
182
+        $this->path = $uri;
183
+
184
+        return $this;
185
+    }
186
+
187
+    /**
188
+     * Retrieve the path component of the URI. The path can either be empty or absolute 
189
+     * (starting with a slash) or rootless (not starting with a slash).
190
+     * 
191
+     * @return string
192
+     */
193
+    public function getPath()
194
+    {
195
+        return (is_null($this->path) ? '' : $this->path);
196
+    }
197
+
198
+    /**
199
+     * Sets the path portion of the URI.
200
+     * 
201
+     * @param  string  $path
202
+     *
203
+     * @return void
204
+     */
205
+    public function setPath(string $path) 
206
+    {
207
+        $this->path = $this->filterPath($path);
208
+
209
+        $this->filterSegments($this->path);
210
+
211
+        return $this;
212
+    } 
213
+
214
+    /**
215
+     * Encodes any dangerous characters.
216
+     * 
217
+     * @param  string|null  $path
218
+     * 
219
+     * @return string
220
+     */
221
+    protected function filterPath(string $path = null)
222
+    {
223
+        $path = urldecode($path);
224
+
225
+        return $path;
226
+    }
227
+
228
+    /**
229
+     * Filter the segments of path.
230
+     * 
231
+     * @param  string  $uri
232
+     * 
233
+     * @return string[]
234
+     */
235
+    protected function filterSegments($uri)
236
+    {
237
+        $this->segments = (empty($uri) ? [] : explode('/', $uri));
238
+    }
239
+
240
+    /**
241
+     * Get the specified URI segment, return default if it doesn't exist.
242
+     * Segment index is 1 based, not 0 based.
243
+     *
244
+     * @param  int  $index  The 1-based segment index
245
+     * @param  mixed  $default  The default value
246
+     *
247
+     * @return mixed
248
+     */
249
+    public function getSegment(int $index, $default = null)
250
+    {
251
+        return Arr::get($this->getSegments(), $index - 1, $default);
252
+    }
253
+
254
+    /**
255
+     * Returns the segments of the path as an array.
256
+     *
257
+     * @return array  The URI segments
258
+     */
259
+    public function getSegments()
260
+    {
261
+        return array_values(array_filter($this->segments, function ($value) {
262
+            return $value != '';
263
+        }));
264
+    }
265
+
266
+    /**
267
+     * Returns the total number of segment.
268
+     *
269
+     * @return int  
270
+     */
271
+    public function getTotalSegments()
272
+    {
273
+        return count($this->getSegments());
274
+    }
275
+
276
+    /**
277
+     * Retrieve the scheme component of the URI.
278
+     * 
279
+     * @return string
280
+     */
281
+    public function getScheme()
282
+    {
283
+        return $this->scheme;
284
+    }
285
+
286
+    /**
287
+     * Sets the scheme for this URI.
288
+     * 
289
+     * @param  string  $str
290
+     * 
291
+     * @return $this
292
+     */
293
+    public function setScheme(string $str)
294
+    {
295
+        $str = preg_replace('~:(//)?$~', '', strtolower($str));
296
+
297
+        $this->scheme = $str;
298
+
299
+        return $this->scheme;
300
+    }
301
+
302
+    /**
303
+     * Retrieve the user component of the URI.
304
+     * 
305
+     * @return string|null
306
+     */
307
+    public function getUserInfo()
308
+    {
309
+        $user = $this->user;
310
+
311
+        if ($this->showPassword === true && ! empty($this->password))
312
+        {
313
+            $user .= ":$this->password";
314
+        }
315
+
316
+        return $user;
317
+    }
318
+
319
+    /**
320
+     * Sets the userInfo/Authority portion of the URI.
321
+     * 
322
+     * @param  string  $user
323
+     * @param  string  $pass
324
+     * 
325
+     * @return $this
326
+     */
327
+    public function setUserInfo(string $user, string $pass)
328
+    {
329
+        $this->user     = trim($user);
330
+        $this->password = trim($pass);
331
+
332
+        return $this;
333
+    }
334
+
335
+    /**
336
+     * Temporarily sets the URI to show a password in userInfo.
337
+     * 
338
+     * @param  boolean  $option  (true by default)
339
+     * 
340
+     * @return $this
341
+     */
342
+    public function showPassword(bool $option = true)
343
+    {
344
+        $this->password = $option;
345
+
346
+        return $this->password;
347
+    }
348
+
349
+    /**
350
+     * Retrieve the authority component of the URI.
351
+     * 
352
+     * @param  boolean  $ignore  (false by default)
353
+     * 
354
+     * @return string
355
+     */
356
+    public function getAuthority(bool $ignore = false)
357
+    {
358
+        if (empty($this->host))
359
+        {
360
+            return '';
361
+        }
362
+
363
+        $authority = $this->host;
364
+
365
+        if ( ! empty($this->getUserInfo()))
366
+        {
367
+            $authority = $this->getUserInfo().'@'.$authority;
368
+        }
369
+
370
+        if ( ! empty($this->port) && ! $ignore)
371
+        {
372
+            if ($this->port !== $this->defaultPorts[$this->scheme])
373
+            {
374
+                $authority .= ":$this->port";
375
+            }
376
+        }
377
+
378
+        $this->showPassword = false;
379
+
380
+        return $authority;
381
+    }
382
+
383
+    /**
384
+     * Parses the given string an saves the appropriate authority pieces.
385
+     * 
386
+     * @param  string  $str
387
+     * 
388
+     * @return $this
389
+     */
390
+    public function setAuthority(string $str)
391
+    {
392
+        $parts = parse_url($str);
393
+
394
+        if (empty($parts['host']) && ! empty($parts['path']))
395
+        {
396
+            $parts['host'] = $parts['path'];
397
+            unset($parts['path']);
398
+        }
399
+
400
+        $this->applyParts($parts);
401
+
402
+        return $this;
403
+    }
404
+
405
+    /**
406
+     * Retrieve the host component of the URI.
407
+     * 
408
+     * @return string
409
+     */
410
+    public function getHost()
411
+    {
412
+        return $this->host;
413
+    }
414
+
415
+    /**
416
+     * Sets the host name to use.
417
+     * 
418
+     * @param  string  $str
419
+     * 
420
+     * @return $this
421
+     */
422
+    public function setHost(string $str)
423
+    {
424
+        $this->host = trim($str);
425
+
426
+        return $this->host;
427
+    }
428
+
429
+    /**
430
+     * Retrieve the port component of the URI.
431
+     * 
432
+     * @return int|null
433
+     */
434
+    public function getPort()
435
+    {
436
+        return $this->port;
437
+    }
438
+
439
+    /**
440
+     * Sets the port portion of the URI.
441
+     * 
442
+     * @param  int|null  $port  (null by default)
443
+     * 
444
+     * @return string
445
+     */
446
+    public function setPort(int $port = null)
447
+    {
448
+        if (is_null($port))
449
+        {
450
+            return $this;
451
+        }
452
+
453
+        if ($port <= 0 || $port > 65355)
454
+        {
455
+            throw HttpURIException::invalidPort($port);
456
+        }
457
+
458
+        $this->port = $port;
459
+
460
+        return $this->port;
461
+    }
462
+
463
+    /**
464
+     * Retrieve a URI fragment.
465
+     * 
466
+     * @return string
467
+     */
468
+    public function getFragment()
469
+    {
470
+        return is_null($this->fragment) ? '' : $this->fragment;
471
+    }
472
+
473
+    /**
474
+     * Sets the fragment portion of the URI.
475
+     * 
476
+     * @param  string  $str
477
+     * 
478
+     * @return $this
479
+     */
480
+    public function setFragment(string $str)
481
+    {
482
+        $this->fragment = trim($str, '# ');
483
+
484
+        return $this->fragment;
485
+    }
486
+
487
+    /**
488
+     * Saves our parts from a parse_url call.
489
+     * 
490
+     * @param  array  $parts
491
+     * 
492
+     * @return mixed
493
+     */
494
+    public function applyParts(array $paths)
495
+    {
496
+        if (isset($parts['scheme']))
497
+        {
498
+            $this->SetScheme(rtrim($parts['scheme'], ':/'));
499
+        }
500
+        else
501
+        {
502
+            $this->setScheme('http');
503
+        }
504
+
505
+        if ( ! empty($parts['host']))
506
+        {
507
+            $this->host = $parts['host'];
508
+        }
509
+
510
+        if (isset($parts['port']))
511
+        {
512
+            if ( ! is_null($parts['port']))
513
+            {
514
+                $this->port = $parts['port'];
515
+            }
516
+        }
517
+
518
+        if ( ! empty($parts['user']))
519
+        {
520
+            $this->user = $parts['user'];
521
+        }
522
+
523
+        if ( ! empty($parts['pass']))
524
+        {
525
+            $this->password = $parts['pass'];
526
+        }
527
+
528
+        if ( ! empty($parts['path']))
529
+        {
530
+            $this->path = $this->filterPath($parts['path']);
531
+        }
532
+
533
+        if ( ! empty($parts['fragment']))
534
+        {
535
+            $this->fragment = $parts['fragment'];
536
+        }
537
+
538
+        if ( ! empty($parts['path']))
539
+        {
540
+            $this->segments = explode('/', $parts['path'], '/');
541
+        }
542
+    }
543
+
544
+    /**
545
+     * Returns the URI string.
546
+     *
547
+     * @return string
548
+     */
549
+    public function __toString()
550
+    {
551
+        return (string) $this->getPath();
552
+    }
553 553
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -258,7 +258,7 @@
 block discarded – undo
258 258
 	 */
259 259
 	public function getSegments()
260 260
 	{
261
-		return array_values(array_filter($this->segments, function ($value) {
261
+		return array_values(array_filter($this->segments, function($value) {
262 262
 			return $value != '';
263 263
 		}));
264 264
 	}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -496,8 +496,7 @@
 block discarded – undo
496 496
 		if (isset($parts['scheme']))
497 497
 		{
498 498
 			$this->SetScheme(rtrim($parts['scheme'], ':/'));
499
-		}
500
-		else
499
+		} else
501 500
 		{
502 501
 			$this->setScheme('http');
503 502
 		}
Please login to merge, or discard this patch.
src/components/Http/Http.php 3 patches
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -32,307 +32,307 @@
 block discarded – undo
32 32
  */
33 33
 class Http
34 34
 {
35
-	/**
36
-	 * Determines if this request was made from the command line (CLI).
37
-	 * 
38
-	 * @return bool
39
-	 */
40
-	public function isCli()
41
-	{
42
-		return (PHP_SAPI === 'cli' || defined('STDIN'));
43
-	}
44
-
45
-	/**
46
-	 * Return's the protocol that the request was made with.
47
-	 *
48
-	 * @return string
49
-	 */
50
-	public function protocol()
51
-	{
52
-		if ($this->server('HTTPS') == 'on' ||
53
-			$this->server('HTTPS') == 1 ||
54
-			$this->server('SERVER_PORT') == 443 ||
55
-			(config('security.allow-x-headers', false) && $this->server('HTTP_X_FORWARDED_PROTO') == 'https') ||
56
-			(config('security.allow-x-headers', false) && $this->server('HTTP_X_FORWARDED_PORT') == 443))
57
-		{
58
-			return 'https';
59
-		}
60
-
61
-		return 'http';
62
-	}
63
-
64
-	/**
65
-	 * Fetch an item from the COOKIE array.
66
-	 *
67
-	 * @param  string  $index  The index key
68
-	 * @param  mixed  $default  The default value
69
-	 *
70
-	 * @return string|array
71
-	 */
72
-	public function cookie($index = null, $default = null)
73
-	{
74
-		return (func_num_args() === 0) ? $_COOKIE : Arr::get($_COOKIE, strtoupper($index), $default);
75
-	}
76
-
77
-	/**
78
-	 * Fetch an item from the FILE array.
79
-	 *
80
-	 * @param  string  $index  The index key
81
-	 * @param  mixed  $default  The default value
82
-	 *
83
-	 * @return string|array
84
-	 */
85
-	public function file($index = null, $default = null)
86
-	{
87
-		return (func_num_args() === 0) ? $_FILES : Arr::get($_FILES, strtoupper($index), $default);
88
-	}
89
-
90
-	/**
91
-	 * Fetch an item from the SERVER array.
92
-	 *
93
-	 * @param  string  $index  The index key
94
-	 * @param  mixed  $default  The default value
95
-	 *
96
-	 * @return string|array
97
-	 */
98
-	public function server($index = null, $default = null)
99
-	{
100
-		return (func_num_args() === 0) ? $_SERVER : Arr::get($_SERVER, strtoupper($index), $default);
101
-	}
35
+    /**
36
+     * Determines if this request was made from the command line (CLI).
37
+     * 
38
+     * @return bool
39
+     */
40
+    public function isCli()
41
+    {
42
+        return (PHP_SAPI === 'cli' || defined('STDIN'));
43
+    }
44
+
45
+    /**
46
+     * Return's the protocol that the request was made with.
47
+     *
48
+     * @return string
49
+     */
50
+    public function protocol()
51
+    {
52
+        if ($this->server('HTTPS') == 'on' ||
53
+            $this->server('HTTPS') == 1 ||
54
+            $this->server('SERVER_PORT') == 443 ||
55
+            (config('security.allow-x-headers', false) && $this->server('HTTP_X_FORWARDED_PROTO') == 'https') ||
56
+            (config('security.allow-x-headers', false) && $this->server('HTTP_X_FORWARDED_PORT') == 443))
57
+        {
58
+            return 'https';
59
+        }
60
+
61
+        return 'http';
62
+    }
63
+
64
+    /**
65
+     * Fetch an item from the COOKIE array.
66
+     *
67
+     * @param  string  $index  The index key
68
+     * @param  mixed  $default  The default value
69
+     *
70
+     * @return string|array
71
+     */
72
+    public function cookie($index = null, $default = null)
73
+    {
74
+        return (func_num_args() === 0) ? $_COOKIE : Arr::get($_COOKIE, strtoupper($index), $default);
75
+    }
76
+
77
+    /**
78
+     * Fetch an item from the FILE array.
79
+     *
80
+     * @param  string  $index  The index key
81
+     * @param  mixed  $default  The default value
82
+     *
83
+     * @return string|array
84
+     */
85
+    public function file($index = null, $default = null)
86
+    {
87
+        return (func_num_args() === 0) ? $_FILES : Arr::get($_FILES, strtoupper($index), $default);
88
+    }
89
+
90
+    /**
91
+     * Fetch an item from the SERVER array.
92
+     *
93
+     * @param  string  $index  The index key
94
+     * @param  mixed  $default  The default value
95
+     *
96
+     * @return string|array
97
+     */
98
+    public function server($index = null, $default = null)
99
+    {
100
+        return (func_num_args() === 0) ? $_SERVER : Arr::get($_SERVER, strtoupper($index), $default);
101
+    }
102 102
 	
103
-	/**
104
-	 * Gets the URI Protocol based setting, will attempt to detect the path 
105
-	 * portion of the current URI.
106
-	 * 
107
-	 * @param  string  $protocol
108
-	 * 
109
-	 * @return string
110
-	 */
111
-	public function detectPath(string $protocol = '') 
112
-	{
113
-		if (empty($protocol))
114
-		{
115
-			$protocol = 'REQUEST_URI';
116
-		}
117
-
118
-		switch($protocol)
119
-		{
120
-			case 'REQUEST_URI':
121
-				$path = $this->parseRequestUri();
122
-				break;
123
-			case 'QUERY_STRING':
124
-				$path = $this->parseQueryString();
125
-				break;
126
-			case 'PATH_INFO':
127
-			default:
128
-				$path = $this->server($protocol) ?? $this->parseRequestUri();
129
-				break;
130
-		}
131
-
132
-		return $path;
133
-	}
134
-
135
-	/**
136
-	 * Filters a value from the start of a string in this case the passed URI string.
137
-	 *
138
-	 * @return string
139
-	 */
140
-	protected function parseRequestUri()
141
-	{
142
-		if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']))
143
-		{
144
-			return '';
145
-		}
146
-
147
-		$requestURI = $this->server('REQUEST_URI') ?? '/';
148
-		$components = parse_url($requestURI);
149
-		$query      = $components['query'] ?? '';
150
-		$uri        = $components['path'] ?? '';
151
-
152
-		// If the search value is at the start
153
-		if (isset($this->server('SCRIPT_NAME')[0]))
154
-		{
155
-			if (0 === strpos($uri, $this->server('SCRIPT_NAME')))
156
-			{
157
-				$uri = (string) substr($uri, strlen($this->server('SCRIPT_NAME')));
158
-			}
159
-			elseif (0 < strpos($uri, $this->server('SCRIPT_NAME')))
160
-			{
161
-				$uri = (string) substr($uri, strpos($uri, $this->server('SCRIPT_NAME')) + strlen($this->server('SCRIPT_NAME')));
162
-			}
163
-			elseif (0 === strpos($uri, dirname($this->server('SCRIPT_NAME'))))
164
-			{
165
-				$uri = (string) substr($uri, strlen(dirname($this->server('SCRIPT_NAME'))));
166
-			}
167
-		}
168
-
169
-		// This section ensures that even on servers that require the URI to contain 
170
-		// the query string (Nginx) is the correctly
171
-		if ('' === trim($uri, '/') && 0 === strncmp($query, '/', 1)) 
172
-		{
173
-			$query					 = explode('?', $query, 2);
174
-			$uri  					 = $query[0];
175
-			$_SERVER['QUERY_STRING'] = $query[1] ?? '';
176
-		}
177
-		else
178
-		{
179
-			$_SERVER['QUERY_STRING'] = $query;
180
-		}
181
-
182
-		// Parses the string into variables
183
-		parse_str($_SERVER['QUERY_STRING'], $_GET);
184
-
185
-		if ('/' === $uri || '' === $uri)
186
-		{
187
-			return '';
188
-		}
189
-
190
-		return $this->filterDecode($uri);
191
-	}
192
-
193
-	/**
194
-	 * Will parse QUERY_STRING and automatically detect the URI from it.
195
-	 * 
196
-	 * @return string
197
-	 */
198
-	protected function parseQueryString()
199
-	{
200
-		$uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');
201
-
202
-		if (trim($uri, '/') === '')
203
-		{
204
-			return '';
205
-		}
206
-		elseif (0 === strncmp($uri, '/', 1))
207
-		{
208
-			$uri    				 = explode('?', $uri, 2);
209
-			$_SERVER['QUERY_STRING'] = $uri[1] ?? '';
210
-			$uri    				 = $uri[0] ?? '';
211
-		}
212
-
213
-		parse_str($_SERVER['QUERY_STRING'], $_GET);
214
-
215
-		return $this->filterDecode($uri);
216
-	}
217
-
218
-	/**
219
-	 * Filters the uri string remove any malicious characters and inappropriate slashes.
220
-	 *
221
-	 * @param  string  $uri
222
-	 *
223
-	 * @return string
224
-	 */
225
-	protected function filterDecode($uri)
226
-	{
227
-		// Remove all characters except letters,
228
-		// digits and $-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=.
229
-		$uri = filter_var(rawurldecode($uri), FILTER_SANITIZE_URL);
103
+    /**
104
+     * Gets the URI Protocol based setting, will attempt to detect the path 
105
+     * portion of the current URI.
106
+     * 
107
+     * @param  string  $protocol
108
+     * 
109
+     * @return string
110
+     */
111
+    public function detectPath(string $protocol = '') 
112
+    {
113
+        if (empty($protocol))
114
+        {
115
+            $protocol = 'REQUEST_URI';
116
+        }
117
+
118
+        switch($protocol)
119
+        {
120
+            case 'REQUEST_URI':
121
+                $path = $this->parseRequestUri();
122
+                break;
123
+            case 'QUERY_STRING':
124
+                $path = $this->parseQueryString();
125
+                break;
126
+            case 'PATH_INFO':
127
+            default:
128
+                $path = $this->server($protocol) ?? $this->parseRequestUri();
129
+                break;
130
+        }
131
+
132
+        return $path;
133
+    }
134
+
135
+    /**
136
+     * Filters a value from the start of a string in this case the passed URI string.
137
+     *
138
+     * @return string
139
+     */
140
+    protected function parseRequestUri()
141
+    {
142
+        if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']))
143
+        {
144
+            return '';
145
+        }
146
+
147
+        $requestURI = $this->server('REQUEST_URI') ?? '/';
148
+        $components = parse_url($requestURI);
149
+        $query      = $components['query'] ?? '';
150
+        $uri        = $components['path'] ?? '';
151
+
152
+        // If the search value is at the start
153
+        if (isset($this->server('SCRIPT_NAME')[0]))
154
+        {
155
+            if (0 === strpos($uri, $this->server('SCRIPT_NAME')))
156
+            {
157
+                $uri = (string) substr($uri, strlen($this->server('SCRIPT_NAME')));
158
+            }
159
+            elseif (0 < strpos($uri, $this->server('SCRIPT_NAME')))
160
+            {
161
+                $uri = (string) substr($uri, strpos($uri, $this->server('SCRIPT_NAME')) + strlen($this->server('SCRIPT_NAME')));
162
+            }
163
+            elseif (0 === strpos($uri, dirname($this->server('SCRIPT_NAME'))))
164
+            {
165
+                $uri = (string) substr($uri, strlen(dirname($this->server('SCRIPT_NAME'))));
166
+            }
167
+        }
168
+
169
+        // This section ensures that even on servers that require the URI to contain 
170
+        // the query string (Nginx) is the correctly
171
+        if ('' === trim($uri, '/') && 0 === strncmp($query, '/', 1)) 
172
+        {
173
+            $query					 = explode('?', $query, 2);
174
+            $uri  					 = $query[0];
175
+            $_SERVER['QUERY_STRING'] = $query[1] ?? '';
176
+        }
177
+        else
178
+        {
179
+            $_SERVER['QUERY_STRING'] = $query;
180
+        }
181
+
182
+        // Parses the string into variables
183
+        parse_str($_SERVER['QUERY_STRING'], $_GET);
184
+
185
+        if ('/' === $uri || '' === $uri)
186
+        {
187
+            return '';
188
+        }
189
+
190
+        return $this->filterDecode($uri);
191
+    }
192
+
193
+    /**
194
+     * Will parse QUERY_STRING and automatically detect the URI from it.
195
+     * 
196
+     * @return string
197
+     */
198
+    protected function parseQueryString()
199
+    {
200
+        $uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');
201
+
202
+        if (trim($uri, '/') === '')
203
+        {
204
+            return '';
205
+        }
206
+        elseif (0 === strncmp($uri, '/', 1))
207
+        {
208
+            $uri    				 = explode('?', $uri, 2);
209
+            $_SERVER['QUERY_STRING'] = $uri[1] ?? '';
210
+            $uri    				 = $uri[0] ?? '';
211
+        }
212
+
213
+        parse_str($_SERVER['QUERY_STRING'], $_GET);
214
+
215
+        return $this->filterDecode($uri);
216
+    }
217
+
218
+    /**
219
+     * Filters the uri string remove any malicious characters and inappropriate slashes.
220
+     *
221
+     * @param  string  $uri
222
+     *
223
+     * @return string
224
+     */
225
+    protected function filterDecode($uri)
226
+    {
227
+        // Remove all characters except letters,
228
+        // digits and $-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=.
229
+        $uri = filter_var(rawurldecode($uri), FILTER_SANITIZE_URL);
230 230
 		
231
-		// Return argument if not empty or return a single slash
232
-		return trim($uri, '/') ?: '/';
233
-	}
231
+        // Return argument if not empty or return a single slash
232
+        return trim($uri, '/') ?: '/';
233
+    }
234 234
 	
235
-	/**
236
-	 * Parse the base URL.
237
-	 * 
238
-	 * @return string
239
-	 */
240
-	public function parseBaseUrl() 
241
-	{
242
-		$filename = basename($this->server('SCRIPT_FILENAME'));
235
+    /**
236
+     * Parse the base URL.
237
+     * 
238
+     * @return string
239
+     */
240
+    public function parseBaseUrl() 
241
+    {
242
+        $filename = basename($this->server('SCRIPT_FILENAME'));
243 243
 		
244
-		if ($filename === basename($this->server('SCRIPT_NAME')))
245
-		{
246
-			$baseUrl = $this->server('SCRIPT_NAME');
247
-		}
248
-		elseif ($filename === basename($this->server('PHP_SELF')))
249
-		{
250
-			$baseUrl = $this->server('PHP_SELF');
251
-		}
252
-		elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME')))
253
-		{
254
-			$baseUrl = $this->server('ORIG_SCRIPT_NAME');
255
-		}
256
-		else
257
-		{
258
-			$path    = $this->server('PHP_SELF', '');
259
-			$file    = $this->server('SCRIPT_FILENAME', '');
260
-			$segs    = explode('/', trim($file, '/'));
261
-			$segs    = array_reverse($segs);
262
-			$index   = 0;
263
-			$last    = count($segs);
264
-			$baseUrl = '';
244
+        if ($filename === basename($this->server('SCRIPT_NAME')))
245
+        {
246
+            $baseUrl = $this->server('SCRIPT_NAME');
247
+        }
248
+        elseif ($filename === basename($this->server('PHP_SELF')))
249
+        {
250
+            $baseUrl = $this->server('PHP_SELF');
251
+        }
252
+        elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME')))
253
+        {
254
+            $baseUrl = $this->server('ORIG_SCRIPT_NAME');
255
+        }
256
+        else
257
+        {
258
+            $path    = $this->server('PHP_SELF', '');
259
+            $file    = $this->server('SCRIPT_FILENAME', '');
260
+            $segs    = explode('/', trim($file, '/'));
261
+            $segs    = array_reverse($segs);
262
+            $index   = 0;
263
+            $last    = count($segs);
264
+            $baseUrl = '';
265 265
 			
266
-			do
267
-			{
268
-				$seg     = $segs[$index];
269
-				$baseUrl = '/'.$seg.$baseUrl;
270
-				++$index;
271
-			} while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
272
-		}
273
-
274
-		// Does the baseUrl have anything in common with the request_uri?
275
-		$requestUri = $this->parseRequestUri();
276
-
277
-		if ('' !== $requestUri && '/' !== $requestUri[0])
278
-		{
279
-			$requestUri = '/'.$requestUri;
280
-		}
281
-
282
-		$baseUrl = dirname($baseUrl);
283
-
284
-		if (empty($baseUrl) || false !== strpos(rawurldecode($requestUri), $baseUrl))
285
-		{
286
-			// no match whatsoever; set it blank
287
-			return '';
288
-		}
266
+            do
267
+            {
268
+                $seg     = $segs[$index];
269
+                $baseUrl = '/'.$seg.$baseUrl;
270
+                ++$index;
271
+            } while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
272
+        }
273
+
274
+        // Does the baseUrl have anything in common with the request_uri?
275
+        $requestUri = $this->parseRequestUri();
276
+
277
+        if ('' !== $requestUri && '/' !== $requestUri[0])
278
+        {
279
+            $requestUri = '/'.$requestUri;
280
+        }
281
+
282
+        $baseUrl = dirname($baseUrl);
283
+
284
+        if (empty($baseUrl) || false !== strpos(rawurldecode($requestUri), $baseUrl))
285
+        {
286
+            // no match whatsoever; set it blank
287
+            return '';
288
+        }
289 289
 		
290
-		// If using mod_rewrite or ISAPI_Rewrite strip the script filename
291
-		// out of baseUrl. $pos !== 0 makes sure it is not matching a value
292
-		// from PATH_INFO or QUERY_STRING
293
-		if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && 0 !== $pos)
294
-		{
295
-			$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
296
-		}
290
+        // If using mod_rewrite or ISAPI_Rewrite strip the script filename
291
+        // out of baseUrl. $pos !== 0 makes sure it is not matching a value
292
+        // from PATH_INFO or QUERY_STRING
293
+        if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && 0 !== $pos)
294
+        {
295
+            $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
296
+        }
297 297
 		
298
-		return rtrim($baseUrl, '/'.DIRECTORY_SEPARATOR);
299
-	}
300
-
301
-	/**
302
-	 * Parse the path info.
303
-	 * 
304
-	 * @return string
305
-	 */
306
-	public function parsePathInfo()
307
-	{
308
-		if (null === ($requestUri = $this->parseRequestUri()))
309
-		{
310
-			return '/';
311
-		}
312
-
313
-		// Remove the query string from REQUEST_URI
314
-		if (false !== $pos = strpos($requestUri, '?'))
315
-		{
316
-			$requestUri = substr($requestUri, 0, $pos);
317
-		}
318
-
319
-		if ('' !== $requestUri && '/' !== $requestUri[0])
320
-		{
321
-			$requestUri = '/'.$requestUri;
322
-		}
323
-
324
-		if (null === ($baseUrl = $this->parseBaseUrl()))
325
-		{
326
-			return $requestUri;
327
-		}
328
-
329
-		$pathInfo = substr($requestUri, strlen($baseUrl));
330
-
331
-		if (false === $pathInfo && '' === $pathInfo)
332
-		{
333
-			return '/';
334
-		}
298
+        return rtrim($baseUrl, '/'.DIRECTORY_SEPARATOR);
299
+    }
300
+
301
+    /**
302
+     * Parse the path info.
303
+     * 
304
+     * @return string
305
+     */
306
+    public function parsePathInfo()
307
+    {
308
+        if (null === ($requestUri = $this->parseRequestUri()))
309
+        {
310
+            return '/';
311
+        }
312
+
313
+        // Remove the query string from REQUEST_URI
314
+        if (false !== $pos = strpos($requestUri, '?'))
315
+        {
316
+            $requestUri = substr($requestUri, 0, $pos);
317
+        }
318
+
319
+        if ('' !== $requestUri && '/' !== $requestUri[0])
320
+        {
321
+            $requestUri = '/'.$requestUri;
322
+        }
323
+
324
+        if (null === ($baseUrl = $this->parseBaseUrl()))
325
+        {
326
+            return $requestUri;
327
+        }
328
+
329
+        $pathInfo = substr($requestUri, strlen($baseUrl));
330
+
331
+        if (false === $pathInfo && '' === $pathInfo)
332
+        {
333
+            return '/';
334
+        }
335 335
 		
336
-		return (string) $pathInfo;
337
-	}
336
+        return (string) $pathInfo;
337
+    }
338 338
 }
339 339
\ 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
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
 			$protocol = 'REQUEST_URI';
116 116
 		}
117 117
 
118
-		switch($protocol)
118
+		switch ($protocol)
119 119
 		{
120 120
 			case 'REQUEST_URI':
121 121
 				$path = $this->parseRequestUri();
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -155,12 +155,10 @@  discard block
 block discarded – undo
155 155
 			if (0 === strpos($uri, $this->server('SCRIPT_NAME')))
156 156
 			{
157 157
 				$uri = (string) substr($uri, strlen($this->server('SCRIPT_NAME')));
158
-			}
159
-			elseif (0 < strpos($uri, $this->server('SCRIPT_NAME')))
158
+			} elseif (0 < strpos($uri, $this->server('SCRIPT_NAME')))
160 159
 			{
161 160
 				$uri = (string) substr($uri, strpos($uri, $this->server('SCRIPT_NAME')) + strlen($this->server('SCRIPT_NAME')));
162
-			}
163
-			elseif (0 === strpos($uri, dirname($this->server('SCRIPT_NAME'))))
161
+			} elseif (0 === strpos($uri, dirname($this->server('SCRIPT_NAME'))))
164 162
 			{
165 163
 				$uri = (string) substr($uri, strlen(dirname($this->server('SCRIPT_NAME'))));
166 164
 			}
@@ -173,8 +171,7 @@  discard block
 block discarded – undo
173 171
 			$query					 = explode('?', $query, 2);
174 172
 			$uri  					 = $query[0];
175 173
 			$_SERVER['QUERY_STRING'] = $query[1] ?? '';
176
-		}
177
-		else
174
+		} else
178 175
 		{
179 176
 			$_SERVER['QUERY_STRING'] = $query;
180 177
 		}
@@ -202,8 +199,7 @@  discard block
 block discarded – undo
202 199
 		if (trim($uri, '/') === '')
203 200
 		{
204 201
 			return '';
205
-		}
206
-		elseif (0 === strncmp($uri, '/', 1))
202
+		} elseif (0 === strncmp($uri, '/', 1))
207 203
 		{
208 204
 			$uri    				 = explode('?', $uri, 2);
209 205
 			$_SERVER['QUERY_STRING'] = $uri[1] ?? '';
@@ -244,16 +240,13 @@  discard block
 block discarded – undo
244 240
 		if ($filename === basename($this->server('SCRIPT_NAME')))
245 241
 		{
246 242
 			$baseUrl = $this->server('SCRIPT_NAME');
247
-		}
248
-		elseif ($filename === basename($this->server('PHP_SELF')))
243
+		} elseif ($filename === basename($this->server('PHP_SELF')))
249 244
 		{
250 245
 			$baseUrl = $this->server('PHP_SELF');
251
-		}
252
-		elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME')))
246
+		} elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME')))
253 247
 		{
254 248
 			$baseUrl = $this->server('ORIG_SCRIPT_NAME');
255
-		}
256
-		else
249
+		} else
257 250
 		{
258 251
 			$path    = $this->server('PHP_SELF', '');
259 252
 			$file    = $this->server('SCRIPT_FILENAME', '');
Please login to merge, or discard this patch.