Passed
Push — master ( 7c1ca3...71b9d8 )
by Alexander
19:53 queued 16:06
created
src/bundles/WebResourceBundle/Autoloader/Autoload.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -27,32 +27,32 @@
 block discarded – undo
27 27
  */
28 28
 final class Autoload extends AutoloadConfig
29 29
 {
30
-	/**
31
-	 * Map of class names and locations.
32
-	 * 
33
-	 * @var array $classmap
34
-	 */
35
-	public $classmap = [];
30
+    /**
31
+     * Map of class names and locations.
32
+     * 
33
+     * @var array $classmap
34
+     */
35
+    public $classmap = [];
36 36
 	
37
-	/**
38
-	 * If true, then auto-enabled will happen across all namespaces
39
-	 * loaded by Composer, as well as the namespaces configured locally.
40
-	 * 
41
-	 * @var bool $enabledInComposer
42
-	 */
43
-	public $enabledInComposer = true;
37
+    /**
38
+     * If true, then auto-enabled will happen across all namespaces
39
+     * loaded by Composer, as well as the namespaces configured locally.
40
+     * 
41
+     * @var bool $enabledInComposer
42
+     */
43
+    public $enabledInComposer = true;
44 44
 	
45
-	/**
46
-	 * Array of files for autoloading.
47
-	 * 
48
-	 * @var array $files
49
-	 */
50
-	public $files = [];
45
+    /**
46
+     * Array of files for autoloading.
47
+     * 
48
+     * @var array $files
49
+     */
50
+    public $files = [];
51 51
 	
52
-	/**
53
-	 * Array of namespaces for autoloading.
54
-	 * 
55
-	 * @var array $psr4
56
-	 */
57
-	public $psr4 = [];
52
+    /**
53
+     * Array of namespaces for autoloading.
54
+     * 
55
+     * @var array $psr4
56
+     */
57
+    public $psr4 = [];
58 58
 }
59 59
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Routing/Router.php 1 patch
Indentation   +657 added lines, -657 removed lines patch added patch discarded remove patch
@@ -43,691 +43,691 @@
 block discarded – undo
43 43
  */
44 44
 class Router implements Routable
45 45
 {
46
-	use Concerns\RouteMap,
47
-	    Macroable {
48
-		    __call as macroCall;
49
-	    }
50
-
51
-	/**
52
-	 * The registered route value binders.
53
-	 * 
54
-	 * @var array $binders
55
-	 */
56
-	protected $binders = [];
57
-
58
-	/**
59
-	 * The container instance used by the router.
60
-	 * 
61
-	 * @var \Syscodes\Components\Contracts\Container\Container $container
62
-	 */
63
-	protected $container;
64
-
65
-	/**
66
-	 * Variable of group route.
67
-	 *  
68
-	 * @var array $groupStack
69
-	 */
70
-	protected $groupStack = [];
71
-
72
-	/**
73
-	 * Middleware for function of filters
74
-	 *  
75
-	 * @var array $middleware
76
-	 */
77
-	protected $middleware = [];
46
+    use Concerns\RouteMap,
47
+        Macroable {
48
+            __call as macroCall;
49
+        }
50
+
51
+    /**
52
+     * The registered route value binders.
53
+     * 
54
+     * @var array $binders
55
+     */
56
+    protected $binders = [];
57
+
58
+    /**
59
+     * The container instance used by the router.
60
+     * 
61
+     * @var \Syscodes\Components\Contracts\Container\Container $container
62
+     */
63
+    protected $container;
64
+
65
+    /**
66
+     * Variable of group route.
67
+     *  
68
+     * @var array $groupStack
69
+     */
70
+    protected $groupStack = [];
71
+
72
+    /**
73
+     * Middleware for function of filters
74
+     *  
75
+     * @var array $middleware
76
+     */
77
+    protected $middleware = [];
78 78
 	
79
-	/**
80
-	 * All of the middleware groups.
81
-	 * 
82
-	 * @var array $middlewareGroups
83
-	 */
84
-	protected $middlewareGroups = [];
79
+    /**
80
+     * All of the middleware groups.
81
+     * 
82
+     * @var array $middlewareGroups
83
+     */
84
+    protected $middlewareGroups = [];
85 85
 	
86
-	/**
87
-	 * The priority-sorted list of middleware.
88
-	 * 
89
-	 * @var array $middlewarePriority
90
-	 */
91
-	public $middlewarePriority = [];
86
+    /**
87
+     * The priority-sorted list of middleware.
88
+     * 
89
+     * @var array $middlewarePriority
90
+     */
91
+    public $middlewarePriority = [];
92 92
 	
93
-	/**
94
-	 * The globally available parameter patterns.
95
-	 * 
96
-	 * @var array $patterns
97
-	 */
98
-	protected $patterns = [];
99
-
100
-	/**
101
-	 * Resolve the given route.
102
-	 * 
103
-	 * @var \Syscodes\Components\Routing\Resolver\RouteResolver $resolves
104
-	 */
105
-	protected $resolves;
106
-
107
-	/**
108
-	 * The Resource instance.
109
-	 * 
110
-	 * @var \Syscodes\Components\Routing\Resources\ResourceRegister $resources
111
-	 */
112
-	protected $resources;
113
-
114
-	/** 
115
-	 * The route collection instance. 
116
-	 * 
117
-	 * @var \Syscodes\Components\Routing\Collections\RouteCollection $routes
118
-	 */
119
-	protected $routes;
120
-
121
-	/**
122
-	 * Constructor. Create a new Router instance.
123
-	 *
124
-	 * @param  \Syscodes\Components\Contracts\Container\Container|null  $container
125
-	 * 
126
-	 * @return void
127
-	 */
128
-	public function __construct(Container $container = null)
129
-	{
130
-		$this->routes    = new RouteCollection;
131
-		$this->container = $container ?: new Container;
132
-		$this->resolves  = new RouteResolver($this, $this->routes, $this->container);
133
-	}
134
-
135
-	/**
136
-	 * Get the prefix from the group on the stack.
137
-	 *
138
-	 * @return string
139
-	 */
140
-	public function getGroupPrefix(): string
141
-	{
142
-		if ($this->hasGroupStack()) {
143
-			$last = end($this->groupStack);
144
-
145
-			return $last['prefix'] ?? '';
146
-		}
147
-
148
-		return '';
149
-	}
150
-
151
-	/**
152
-	 * Group a series of routes under a single URL segment. This is handy
153
-	 * for grouping items into an admin area, like:
154
-	 *
155
-	 *   Example:
156
-	 *      // Creates route: /admin show the word 'User'
157
-	 *      Route::group(['prefix' => 'admin'], function() {	 
158
-	 *
159
-	 *          Route::get('/user', function() {
160
-	 *	            echo 'Hello world..!';
161
-	 *          });
162
-	 *
163
-	 *      }); /admin/user
164
-	 *
165
-	 * @param  array  $attributes
166
-	 * @param  \Closure|array|string  $callback
167
-	 *
168
-	 * @return void
169
-	 */
170
-	public function group(array $attributes, $routes): void
171
-	{
172
-		foreach (Arr::wrap($routes) as $groupRoutes) {
173
-			$this->updateGroupStack($attributes);
93
+    /**
94
+     * The globally available parameter patterns.
95
+     * 
96
+     * @var array $patterns
97
+     */
98
+    protected $patterns = [];
99
+
100
+    /**
101
+     * Resolve the given route.
102
+     * 
103
+     * @var \Syscodes\Components\Routing\Resolver\RouteResolver $resolves
104
+     */
105
+    protected $resolves;
106
+
107
+    /**
108
+     * The Resource instance.
109
+     * 
110
+     * @var \Syscodes\Components\Routing\Resources\ResourceRegister $resources
111
+     */
112
+    protected $resources;
113
+
114
+    /** 
115
+     * The route collection instance. 
116
+     * 
117
+     * @var \Syscodes\Components\Routing\Collections\RouteCollection $routes
118
+     */
119
+    protected $routes;
120
+
121
+    /**
122
+     * Constructor. Create a new Router instance.
123
+     *
124
+     * @param  \Syscodes\Components\Contracts\Container\Container|null  $container
125
+     * 
126
+     * @return void
127
+     */
128
+    public function __construct(Container $container = null)
129
+    {
130
+        $this->routes    = new RouteCollection;
131
+        $this->container = $container ?: new Container;
132
+        $this->resolves  = new RouteResolver($this, $this->routes, $this->container);
133
+    }
134
+
135
+    /**
136
+     * Get the prefix from the group on the stack.
137
+     *
138
+     * @return string
139
+     */
140
+    public function getGroupPrefix(): string
141
+    {
142
+        if ($this->hasGroupStack()) {
143
+            $last = end($this->groupStack);
144
+
145
+            return $last['prefix'] ?? '';
146
+        }
147
+
148
+        return '';
149
+    }
150
+
151
+    /**
152
+     * Group a series of routes under a single URL segment. This is handy
153
+     * for grouping items into an admin area, like:
154
+     *
155
+     *   Example:
156
+     *      // Creates route: /admin show the word 'User'
157
+     *      Route::group(['prefix' => 'admin'], function() {	 
158
+     *
159
+     *          Route::get('/user', function() {
160
+     *	            echo 'Hello world..!';
161
+     *          });
162
+     *
163
+     *      }); /admin/user
164
+     *
165
+     * @param  array  $attributes
166
+     * @param  \Closure|array|string  $callback
167
+     *
168
+     * @return void
169
+     */
170
+    public function group(array $attributes, $routes): void
171
+    {
172
+        foreach (Arr::wrap($routes) as $groupRoutes) {
173
+            $this->updateGroupStack($attributes);
174 174
 	
175
-			$this->loadRoutes($groupRoutes);
175
+            $this->loadRoutes($groupRoutes);
176 176
 	
177
-			array_pop($this->groupStack);			
178
-		}
179
-	}
180
-
181
-	/**
182
-	 * Update the group stack with the given attributes.
183
-	 * 
184
-	 * @param  array  $attributes
185
-	 * 
186
-	 * @return void
187
-	 */
188
-	protected function updateGroupStack(array $attributes): void
189
-	{
190
-		if ($this->hasGroupStack()) {
191
-			$attributes = $this->mergeLastGroup($attributes);
192
-		}
193
-
194
-		$this->groupStack[] = $attributes;
195
-	}
196
-
197
-	/**
198
-	 * Merge the given group attributes.
199
-	 * 
200
-	 * @param  array  $new
201
-	 * @param  bool  $existsPrefix
202
-	 * 
203
-	 * @return array
204
-	 */
205
-	public function mergeLastGroup($new, bool $existsPrefix = true): array
206
-	{
207
-		return RouteGroup::mergeGroup($new, end($this->groupStack), $existsPrefix);
208
-	}
177
+            array_pop($this->groupStack);			
178
+        }
179
+    }
180
+
181
+    /**
182
+     * Update the group stack with the given attributes.
183
+     * 
184
+     * @param  array  $attributes
185
+     * 
186
+     * @return void
187
+     */
188
+    protected function updateGroupStack(array $attributes): void
189
+    {
190
+        if ($this->hasGroupStack()) {
191
+            $attributes = $this->mergeLastGroup($attributes);
192
+        }
193
+
194
+        $this->groupStack[] = $attributes;
195
+    }
196
+
197
+    /**
198
+     * Merge the given group attributes.
199
+     * 
200
+     * @param  array  $new
201
+     * @param  bool  $existsPrefix
202
+     * 
203
+     * @return array
204
+     */
205
+    public function mergeLastGroup($new, bool $existsPrefix = true): array
206
+    {
207
+        return RouteGroup::mergeGroup($new, end($this->groupStack), $existsPrefix);
208
+    }
209 209
 	
210
-	/**
211
-	 * Load the provided routes.
212
-	 * 
213
-	 * @param  \Closure|string  $callback
214
-	 * 
215
-	 * @return void
216
-	 */
217
-	protected function loadRoutes($callback): void
218
-	{
219
-		if ($callback instanceof Closure) {
220
-			$callback($this);
221
-		} else {
222
-			(new RouteFileRegister($this))->register($callback);
223
-		}
224
-	}
225
-
226
-	/**
227
-	 * Add a route to the underlying route collection. 
228
-	 *
229
-	 * @param  array|string  $method
230
-	 * @param  string  $route
231
-	 * @param  mixed  $action
232
-	 *
233
-	 * @return \Syscodes\Components\Routing\Route
234
-	 */
235
-	public function addRoute($method, $route, $action)
236
-	{
237
-		return $this->routes->add($this->map($method, $route, $action));
238
-	}
210
+    /**
211
+     * Load the provided routes.
212
+     * 
213
+     * @param  \Closure|string  $callback
214
+     * 
215
+     * @return void
216
+     */
217
+    protected function loadRoutes($callback): void
218
+    {
219
+        if ($callback instanceof Closure) {
220
+            $callback($this);
221
+        } else {
222
+            (new RouteFileRegister($this))->register($callback);
223
+        }
224
+    }
225
+
226
+    /**
227
+     * Add a route to the underlying route collection. 
228
+     *
229
+     * @param  array|string  $method
230
+     * @param  string  $route
231
+     * @param  mixed  $action
232
+     *
233
+     * @return \Syscodes\Components\Routing\Route
234
+     */
235
+    public function addRoute($method, $route, $action)
236
+    {
237
+        return $this->routes->add($this->map($method, $route, $action));
238
+    }
239 239
 	
240
-	/**
241
-	 * Register a new fallback route with the router.
242
-	 * 
243
-	 * @param  array|string|callable|null  $action
244
-	 * 
245
-	 * @return \Syscodes\Components\Routing\Route
246
-	 */
247
-	public function fallback($action)
248
-	{
249
-		$placeholder = 'fallbackPlaceholder';
240
+    /**
241
+     * Register a new fallback route with the router.
242
+     * 
243
+     * @param  array|string|callable|null  $action
244
+     * 
245
+     * @return \Syscodes\Components\Routing\Route
246
+     */
247
+    public function fallback($action)
248
+    {
249
+        $placeholder = 'fallbackPlaceholder';
250 250
 		
251
-		return $this->addRoute('GET', "{{$placeholder}}", $action)
252
-		            ->where($placeholder, '.*')
253
-		            ->fallback();
254
-	}
255
-
256
-	/**
257
-	 * Create a redirect from one URI to another.
258
-	 * 
259
-	 * @param  string  $uri
260
-	 * @param  string  $destination
261
-	 * @param  int  $status
262
-	 * 
263
-	 * @return \Syscodes\Components\Routing\Route
264
-	 */
265
-	public function redirect($uri, $destination, $status = 302)
266
-	{
267
-		return $this->any($uri, '\Syscodes\Components\Routing\Controllers\RedirectController')
268
-		            ->defaults('destination', $destination)
269
-		            ->defaults('status', $status);
270
-	}
251
+        return $this->addRoute('GET', "{{$placeholder}}", $action)
252
+                    ->where($placeholder, '.*')
253
+                    ->fallback();
254
+    }
255
+
256
+    /**
257
+     * Create a redirect from one URI to another.
258
+     * 
259
+     * @param  string  $uri
260
+     * @param  string  $destination
261
+     * @param  int  $status
262
+     * 
263
+     * @return \Syscodes\Components\Routing\Route
264
+     */
265
+    public function redirect($uri, $destination, $status = 302)
266
+    {
267
+        return $this->any($uri, '\Syscodes\Components\Routing\Controllers\RedirectController')
268
+                    ->defaults('destination', $destination)
269
+                    ->defaults('status', $status);
270
+    }
271 271
 	
272
-	/**
273
-	 * Create a permanent redirect from one URI to another.
274
-	 * 
275
-	 * @param  string  $uri
276
-	 * @param  string  $destination
277
-	 * 
278
-	 * @return \Syscodes\Components\Routing\Route
279
-	 */
280
-	public function permanentRedirect($uri, $destination)
281
-	{
282
-		return $this->redirect($uri, $destination, 301);
283
-	}
284
-
285
-	/**
286
-	 * Register a new route that returns a view.
287
-	 * 
288
-	 * @param  string  $uri
289
-	 * @param  string  $view
290
-	 * @param  array  $data
291
-	 * @param  int|array  $status
292
-	 * @param  array  $headers
293
-	 * 
294
-	 * @return \Syscodes\Components\Routing\Route
295
-	 */
296
-	public function view($uri, $view, $data = [], $status = 200, array $headers = [])
297
-	{
298
-		return $this->match(['GET', 'HEAD'], $uri, '\Syscodes\Components\Routing\Controllers\ViewController')
299
-		            ->setDefaults([
300
-		                'view' => $view,
301
-		                'data' => $data,
302
-		                'status' => is_array($status) ? 200 : $status,
303
-		                'headers' => is_array($status) ? $status : $headers,
304
-		            ]);
305
-	}
306
-
307
-	/**
308
-	 * Add new route to routes array.
309
-	 *
310
-	 * @param  array|string  $method
311
-	 * @param  string  $route
312
-	 * @param  mixed  $action
313
-	 *
314
-	 * @return \Syscodes\Components\Routing\Route
315
-	 * 
316
-	 * @throws \InvalidArgumentException
317
-	 */
318
-	public function map($method, $route, $action): Route
319
-	{
320
-		if ($this->actionReferencesController($action)) {
321
-			$action = $this->convertToControllerAction($action);
322
-		}
323
-
324
-		$route = $this->newRoute(
325
-		              $method,
326
-		              $this->prefix($route),
327
-		              $action
328
-		         );
329
-
330
-		if ($this->hasGroupStack()) {
331
-			$this->mergeGroupAttributesIntoRoute($route);			
332
-		}
333
-
334
-		$this->addWhereClausesToRoute($route);
272
+    /**
273
+     * Create a permanent redirect from one URI to another.
274
+     * 
275
+     * @param  string  $uri
276
+     * @param  string  $destination
277
+     * 
278
+     * @return \Syscodes\Components\Routing\Route
279
+     */
280
+    public function permanentRedirect($uri, $destination)
281
+    {
282
+        return $this->redirect($uri, $destination, 301);
283
+    }
284
+
285
+    /**
286
+     * Register a new route that returns a view.
287
+     * 
288
+     * @param  string  $uri
289
+     * @param  string  $view
290
+     * @param  array  $data
291
+     * @param  int|array  $status
292
+     * @param  array  $headers
293
+     * 
294
+     * @return \Syscodes\Components\Routing\Route
295
+     */
296
+    public function view($uri, $view, $data = [], $status = 200, array $headers = [])
297
+    {
298
+        return $this->match(['GET', 'HEAD'], $uri, '\Syscodes\Components\Routing\Controllers\ViewController')
299
+                    ->setDefaults([
300
+                        'view' => $view,
301
+                        'data' => $data,
302
+                        'status' => is_array($status) ? 200 : $status,
303
+                        'headers' => is_array($status) ? $status : $headers,
304
+                    ]);
305
+    }
306
+
307
+    /**
308
+     * Add new route to routes array.
309
+     *
310
+     * @param  array|string  $method
311
+     * @param  string  $route
312
+     * @param  mixed  $action
313
+     *
314
+     * @return \Syscodes\Components\Routing\Route
315
+     * 
316
+     * @throws \InvalidArgumentException
317
+     */
318
+    public function map($method, $route, $action): Route
319
+    {
320
+        if ($this->actionReferencesController($action)) {
321
+            $action = $this->convertToControllerAction($action);
322
+        }
323
+
324
+        $route = $this->newRoute(
325
+                        $method,
326
+                        $this->prefix($route),
327
+                        $action
328
+                    );
329
+
330
+        if ($this->hasGroupStack()) {
331
+            $this->mergeGroupAttributesIntoRoute($route);			
332
+        }
333
+
334
+        $this->addWhereClausesToRoute($route);
335 335
 		
336
-		return $route;
337
-	}
336
+        return $route;
337
+    }
338 338
 	
339
-	/**
340
-	 * Determine if the action is routing to a controller.
341
-	 * 
342
-	 * @param  array  $action
343
-	 * 
344
-	 * @return bool
345
-	 */
346
-	protected function actionReferencesController($action): bool
347
-	{
348
-		if ( ! $action instanceof Closure) {
349
-			return is_string($action) || (isset($action['uses']) && is_string($action['uses']));
350
-		}
339
+    /**
340
+     * Determine if the action is routing to a controller.
341
+     * 
342
+     * @param  array  $action
343
+     * 
344
+     * @return bool
345
+     */
346
+    protected function actionReferencesController($action): bool
347
+    {
348
+        if ( ! $action instanceof Closure) {
349
+            return is_string($action) || (isset($action['uses']) && is_string($action['uses']));
350
+        }
351 351
 		
352
-		return false;
353
-	}
352
+        return false;
353
+    }
354 354
 	
355
-	/**
356
-	 * Add a controller based route action to the action array.
357
-	 * 
358
-	 * @param  array|string  $action
359
-	 * 
360
-	 * @return array
361
-	 */
362
-	protected function convertToControllerAction($action): array
363
-	{
364
-		if (is_string($action)) {
365
-			$action = ['uses' => $action];
366
-		}
355
+    /**
356
+     * Add a controller based route action to the action array.
357
+     * 
358
+     * @param  array|string  $action
359
+     * 
360
+     * @return array
361
+     */
362
+    protected function convertToControllerAction($action): array
363
+    {
364
+        if (is_string($action)) {
365
+            $action = ['uses' => $action];
366
+        }
367 367
 		
368
-		if ($this->hasGroupStack()) {
369
-			$action['uses'] = $this->prependGroupController($action['uses']);
370
-			$action['uses'] = $this->prependGroupNamespace($action['uses']);
371
-		}
368
+        if ($this->hasGroupStack()) {
369
+            $action['uses'] = $this->prependGroupController($action['uses']);
370
+            $action['uses'] = $this->prependGroupNamespace($action['uses']);
371
+        }
372 372
 		
373
-		$action['controller'] = $action['uses'];
373
+        $action['controller'] = $action['uses'];
374 374
 		
375
-		return $action;
376
-	}
375
+        return $action;
376
+    }
377 377
 	
378
-	/**
379
-	 * Prepend the last group namespaces onto the use clause.
380
-	 * 
381
-	 * @param  string  $class
382
-	 * 
383
-	 * @return string
384
-	 */
385
-	protected function prependGroupNamespace($class): string
386
-	{
387
-		$group = end($this->groupStack);
378
+    /**
379
+     * Prepend the last group namespaces onto the use clause.
380
+     * 
381
+     * @param  string  $class
382
+     * 
383
+     * @return string
384
+     */
385
+    protected function prependGroupNamespace($class): string
386
+    {
387
+        $group = end($this->groupStack);
388 388
 		
389
-		return isset($group['namespace']) && ! Str::startsWith($class, '\\') && ! Str::startsWith($class, $group['namespace']) 
390
-		            ? $group['namespace'].'\\'.$class 
391
-					: $class;
392
-	}
389
+        return isset($group['namespace']) && ! Str::startsWith($class, '\\') && ! Str::startsWith($class, $group['namespace']) 
390
+                    ? $group['namespace'].'\\'.$class 
391
+                    : $class;
392
+    }
393 393
 	
394
-	/**
395
-	 * Prepend the last group controller onto the use clause.
396
-	 * 
397
-	 * @param  string  $class
398
-	 * 
399
-	 * @return string
400
-	 */
401
-	protected function prependGroupController($class): string
402
-	{
403
-		$group = end($this->groupStack);
394
+    /**
395
+     * Prepend the last group controller onto the use clause.
396
+     * 
397
+     * @param  string  $class
398
+     * 
399
+     * @return string
400
+     */
401
+    protected function prependGroupController($class): string
402
+    {
403
+        $group = end($this->groupStack);
404 404
 		
405
-		if ( ! isset($group['controller'])) {
406
-			return $class;
407
-		}
405
+        if ( ! isset($group['controller'])) {
406
+            return $class;
407
+        }
408 408
 		
409
-		if (class_exists($class)) {
410
-			return $class;
411
-		}
409
+        if (class_exists($class)) {
410
+            return $class;
411
+        }
412 412
 		
413
-		if (Str::contains($class, '@')) {
414
-			return $class;
415
-		}
413
+        if (Str::contains($class, '@')) {
414
+            return $class;
415
+        }
416 416
 		
417
-		return $group['controller'].'@'.$class;
418
-	}
419
-
420
-	/**
421
-	 * Create a new Route object.
422
-	 * 
423
-	 * @param  array|string  $method
424
-	 * @param  string  $uri
425
-	 * @param  mixed  $action
426
-	 * 
427
-	 * @return \Syscodes\Components\Routing\Route
428
-	 */
429
-	public function newRoute($method, $uri, $action): route
430
-	{
431
-		return take(new Route($method, $uri, $action))
432
-		                ->setContainer($this->container);
433
-	}
417
+        return $group['controller'].'@'.$class;
418
+    }
419
+
420
+    /**
421
+     * Create a new Route object.
422
+     * 
423
+     * @param  array|string  $method
424
+     * @param  string  $uri
425
+     * @param  mixed  $action
426
+     * 
427
+     * @return \Syscodes\Components\Routing\Route
428
+     */
429
+    public function newRoute($method, $uri, $action): route
430
+    {
431
+        return take(new Route($method, $uri, $action))
432
+                        ->setContainer($this->container);
433
+    }
434 434
 	
435
-	/**
436
-	 * Determine if the router currently has a group stack.
437
-	 * 
438
-	 * @return bool
439
-	 */
440
-	public function hasGroupStack(): bool
441
-	{
442
-		return ! empty($this->groupStack);
443
-	}
435
+    /**
436
+     * Determine if the router currently has a group stack.
437
+     * 
438
+     * @return bool
439
+     */
440
+    public function hasGroupStack(): bool
441
+    {
442
+        return ! empty($this->groupStack);
443
+    }
444 444
 	
445
-	/**
446
-	 * Merge the group stack with the controller action.
447
-	 * 
448
-	 * @param  \Syscpde\Routing\Route  $route
449
-	 * 
450
-	 * @return void
451
-	 */
452
-	protected function mergeGroupAttributesIntoRoute($route): void
453
-	{
454
-		$action = $this->mergeLastGroup(
455
-			$route->getAction(),
456
-			$existsPrefix = false
457
-		);
445
+    /**
446
+     * Merge the group stack with the controller action.
447
+     * 
448
+     * @param  \Syscpde\Routing\Route  $route
449
+     * 
450
+     * @return void
451
+     */
452
+    protected function mergeGroupAttributesIntoRoute($route): void
453
+    {
454
+        $action = $this->mergeLastGroup(
455
+            $route->getAction(),
456
+            $existsPrefix = false
457
+        );
458 458
 		
459
-		$route->setAction($action);
460
-	}
459
+        $route->setAction($action);
460
+    }
461 461
 	
462
-	/**
463
-	 * Add the necessary where clauses to the route based on its initial registration.
464
-	 * 
465
-	 * @param  \Syscodes\Components\Routing\Route  $route
466
-	 * 
467
-	 * @return \Syscodes\Components\Routing\Route
468
-	 */
469
-	protected function addWhereClausesToRoute($route): Route
470
-	{
471
-		$route->where(array_merge(
472
-			$this->patterns, Arr::get($route->getAction(), 'where', [])
473
-		));
474
-
475
-		return $route;
476
-	}
477
-
478
-	/**
479
-	 * Add a prefix to the route URI.
480
-	 *
481
-	 * @param  string  $uri
482
-	 *
483
-	 * @return string
484
-	 */
485
-	protected function prefix($uri): string
486
-	{
487
-		return trim(trim($this->getGroupPrefix(), '/').'/'.trim($uri, '/'), '/') ?: '/';
488
-	}
489
-
490
-	/**
491
-	 * Set a global where pattern on all routes.
492
-	 * 
493
-	 * @param  string  $name
494
-	 * @param  string  $pattern
495
-	 * 
496
-	 * @return void
497
-	 */
498
-	public function pattern($name, $pattern): void
499
-	{
500
-		$this->patterns[$name] = $pattern;
501
-	}
502
-
503
-	/**
504
-	 * Set a group of global where patterns on all routes.
505
-	 * 
506
-	 * @param  array  $patterns
507
-	 * 
508
-	 * @return void
509
-	 */
510
-	public function patterns($patterns): void
511
-	{
512
-		foreach ($patterns as $key => $pattern) {
513
-			$this->patterns[$key] = $pattern;
514
-		}
515
-	}
516
-
517
-	/**
518
-	 * Get a Resource instance.
519
-	 * 
520
-	 * @return \Syscodes\Components\Routing\ResourceRegister
521
-	 */
522
-	public function getResource()
523
-	{
524
-		if (isset($this->resources)) {
525
-			return $this->resources;
526
-		}
527
-
528
-		return $this->resources = new ResourceRegister($this);
529
-	}
530
-
531
-	/**
532
-	 * Dispatches the given url and call the method that belongs to the route.
533
-	 *
534
-	 * @param  \Syscodes\Components\Http\Request  $request
535
-	 *
536
-	 * @return mixed
537
-	 */
538
-	public function dispatch(Request $request)
539
-	{
540
-		return $this->resolves->resolve($request);
541
-	}
542
-
543
-	/**
544
-	 * Gather the middleware for the given route.
545
-	 * 
546
-	 * @param  \Syscodes\Components\Routing\Route  $route
547
-	 * 
548
-	 * @return array
549
-	 */
550
-	public function gatherRouteMiddleware(Route $route): array
551
-	{
552
-		$middleware = array_map(
553
-		                    fn ($name) => MiddlewareResolver::resolve($name, $this->middleware, $this->middlewareGroups),
554
-		                    $route->gatherMiddleware()
555
-		              );
462
+    /**
463
+     * Add the necessary where clauses to the route based on its initial registration.
464
+     * 
465
+     * @param  \Syscodes\Components\Routing\Route  $route
466
+     * 
467
+     * @return \Syscodes\Components\Routing\Route
468
+     */
469
+    protected function addWhereClausesToRoute($route): Route
470
+    {
471
+        $route->where(array_merge(
472
+            $this->patterns, Arr::get($route->getAction(), 'where', [])
473
+        ));
474
+
475
+        return $route;
476
+    }
477
+
478
+    /**
479
+     * Add a prefix to the route URI.
480
+     *
481
+     * @param  string  $uri
482
+     *
483
+     * @return string
484
+     */
485
+    protected function prefix($uri): string
486
+    {
487
+        return trim(trim($this->getGroupPrefix(), '/').'/'.trim($uri, '/'), '/') ?: '/';
488
+    }
489
+
490
+    /**
491
+     * Set a global where pattern on all routes.
492
+     * 
493
+     * @param  string  $name
494
+     * @param  string  $pattern
495
+     * 
496
+     * @return void
497
+     */
498
+    public function pattern($name, $pattern): void
499
+    {
500
+        $this->patterns[$name] = $pattern;
501
+    }
502
+
503
+    /**
504
+     * Set a group of global where patterns on all routes.
505
+     * 
506
+     * @param  array  $patterns
507
+     * 
508
+     * @return void
509
+     */
510
+    public function patterns($patterns): void
511
+    {
512
+        foreach ($patterns as $key => $pattern) {
513
+            $this->patterns[$key] = $pattern;
514
+        }
515
+    }
516
+
517
+    /**
518
+     * Get a Resource instance.
519
+     * 
520
+     * @return \Syscodes\Components\Routing\ResourceRegister
521
+     */
522
+    public function getResource()
523
+    {
524
+        if (isset($this->resources)) {
525
+            return $this->resources;
526
+        }
527
+
528
+        return $this->resources = new ResourceRegister($this);
529
+    }
530
+
531
+    /**
532
+     * Dispatches the given url and call the method that belongs to the route.
533
+     *
534
+     * @param  \Syscodes\Components\Http\Request  $request
535
+     *
536
+     * @return mixed
537
+     */
538
+    public function dispatch(Request $request)
539
+    {
540
+        return $this->resolves->resolve($request);
541
+    }
542
+
543
+    /**
544
+     * Gather the middleware for the given route.
545
+     * 
546
+     * @param  \Syscodes\Components\Routing\Route  $route
547
+     * 
548
+     * @return array
549
+     */
550
+    public function gatherRouteMiddleware(Route $route): array
551
+    {
552
+        $middleware = array_map(
553
+                            fn ($name) => MiddlewareResolver::resolve($name, $this->middleware, $this->middlewareGroups),
554
+                            $route->gatherMiddleware()
555
+                        );
556 556
 		
557
-		return Arr::flatten($middleware);
558
-	}
559
-
560
-	/**
561
-	 * Get all of the defined middleware
562
-	 * 
563
-	 * @return array
564
-	 */
565
-	public function getMiddleware(): array
566
-	{
567
-		return $this->middleware;
568
-	}
569
-
570
-	/**
571
-	 * Register a short-hand name for a middleware.
572
-	 * 
573
-	 * @param  string  $name
574
-	 * @param  string  $class
575
-	 * 
576
-	 * @return static
577
-	 */
578
-	public function aliasMiddleware($name, $class): static
579
-	{
580
-		$this->middleware[$name] = $class;
581
-
582
-		return $this;
583
-	}
584
-
585
-	/**
586
-	 * Register a group of middleware.
587
-	 * 
588
-	 * @param  string  $name
589
-	 * @param  array  $middleware
590
-	 * 
591
-	 * @return static
592
-	 */
593
-	public function middlewareGroup($name, array $middleware): static
594
-	{
595
-		$this->middlewareGroups[$name] = $middleware;
596
-
597
-		return $this;
598
-	}
599
-
600
-	/**
601
-	 * Check if a route with the given name exists.
602
-	 * 
603
-	 * @param  string  $name
604
-	 * 
605
-	 * @return bool
606
-	 */
607
-	public function has($name): bool
608
-	{
609
-		$names = is_array($name) ? $name : func_get_args();
610
-
611
-		foreach ($names as $value) {
612
-			if ( ! $this->routes->hasNamedRoute($value)) {
613
-				return false;
614
-			}
615
-		}
616
-
617
-		return true;
618
-	}
619
-
620
-	/**
621
-	 * Determine if the current route matches a pattern.
622
-	 * 
623
-	 * @param  mixed  ...$patterns
624
-	 * 
625
-	 * @return bool
626
-	 */
627
-	public function is(...$patterns): bool
628
-	{
629
-		return $this->currentRouteNamed(...$patterns);
630
-	}
631
-
632
-	/**
633
-	 * Determine if the current route matches a pattern.
634
-	 * 
635
-	 * @param  mixed  ...$patterns
636
-	 * 
637
-	 * @return bool
638
-	 */
639
-	public function currentRouteNamed(...$patterns): bool
640
-	{
641
-		return $this->resolves->current() && $this->resolves->current()->named(...$patterns);
642
-	}
643
-
644
-	/**
645
-	 * Register an array of resource controllers.
646
-	 * 
647
-	 * @param  array  $resources
648
-	 * @param  array  $options
649
-	 * 
650
-	 * @return void
651
-	 */
652
-	public function resources(array $resources, array $options = []): void
653
-	{
654
-		foreach ($resources as $name => $controller) {
655
-			$this->resource($name, $controller, $options);
656
-		}
657
-	}
658
-
659
-	/**
660
-	 * Route a resource to a controller.
661
-	 * 
662
-	 * @param  string  $name
663
-	 * @param  string  $controller
664
-	 * @param  array  $options
665
-	 * 
666
-	 * @return \Syscodes\Components\Routing\Resources\AwaitingResourceRegistration
667
-	 */
668
-	public function resource($name, $controller, array $options = []) 
669
-	{
670
-		if ($this->container) {
671
-			$register = $this->container->make(ResourceRegister::class);
672
-		} else {
673
-			$register = new ResourceRegister($this);
674
-		}
675
-
676
-		return new AwaitingResourceRegistration(
677
-			$register, $name, $controller, $options
678
-		);
679
-	}
680
-
681
-	/**
682
-	 * Get the route collection.
683
-	 *
684
-	 * @return array   
685
-	 */
686
-	public function getRoutes()
687
-	{
688
-		return $this->routes;
689
-	}
690
-
691
-	/**
692
-	 * Get or set the verbs used in the resource URIs.
693
-	 * 
694
-	 * @param  array  $verbs
695
-	 * 
696
-	 * @return array|null
697
-	 */
698
-	public function resourceVerbs(array $verbs = [])
699
-	{
700
-		ResourceRegister::verbs($verbs);
701
-	}
557
+        return Arr::flatten($middleware);
558
+    }
559
+
560
+    /**
561
+     * Get all of the defined middleware
562
+     * 
563
+     * @return array
564
+     */
565
+    public function getMiddleware(): array
566
+    {
567
+        return $this->middleware;
568
+    }
569
+
570
+    /**
571
+     * Register a short-hand name for a middleware.
572
+     * 
573
+     * @param  string  $name
574
+     * @param  string  $class
575
+     * 
576
+     * @return static
577
+     */
578
+    public function aliasMiddleware($name, $class): static
579
+    {
580
+        $this->middleware[$name] = $class;
581
+
582
+        return $this;
583
+    }
584
+
585
+    /**
586
+     * Register a group of middleware.
587
+     * 
588
+     * @param  string  $name
589
+     * @param  array  $middleware
590
+     * 
591
+     * @return static
592
+     */
593
+    public function middlewareGroup($name, array $middleware): static
594
+    {
595
+        $this->middlewareGroups[$name] = $middleware;
596
+
597
+        return $this;
598
+    }
599
+
600
+    /**
601
+     * Check if a route with the given name exists.
602
+     * 
603
+     * @param  string  $name
604
+     * 
605
+     * @return bool
606
+     */
607
+    public function has($name): bool
608
+    {
609
+        $names = is_array($name) ? $name : func_get_args();
610
+
611
+        foreach ($names as $value) {
612
+            if ( ! $this->routes->hasNamedRoute($value)) {
613
+                return false;
614
+            }
615
+        }
616
+
617
+        return true;
618
+    }
619
+
620
+    /**
621
+     * Determine if the current route matches a pattern.
622
+     * 
623
+     * @param  mixed  ...$patterns
624
+     * 
625
+     * @return bool
626
+     */
627
+    public function is(...$patterns): bool
628
+    {
629
+        return $this->currentRouteNamed(...$patterns);
630
+    }
631
+
632
+    /**
633
+     * Determine if the current route matches a pattern.
634
+     * 
635
+     * @param  mixed  ...$patterns
636
+     * 
637
+     * @return bool
638
+     */
639
+    public function currentRouteNamed(...$patterns): bool
640
+    {
641
+        return $this->resolves->current() && $this->resolves->current()->named(...$patterns);
642
+    }
643
+
644
+    /**
645
+     * Register an array of resource controllers.
646
+     * 
647
+     * @param  array  $resources
648
+     * @param  array  $options
649
+     * 
650
+     * @return void
651
+     */
652
+    public function resources(array $resources, array $options = []): void
653
+    {
654
+        foreach ($resources as $name => $controller) {
655
+            $this->resource($name, $controller, $options);
656
+        }
657
+    }
658
+
659
+    /**
660
+     * Route a resource to a controller.
661
+     * 
662
+     * @param  string  $name
663
+     * @param  string  $controller
664
+     * @param  array  $options
665
+     * 
666
+     * @return \Syscodes\Components\Routing\Resources\AwaitingResourceRegistration
667
+     */
668
+    public function resource($name, $controller, array $options = []) 
669
+    {
670
+        if ($this->container) {
671
+            $register = $this->container->make(ResourceRegister::class);
672
+        } else {
673
+            $register = new ResourceRegister($this);
674
+        }
675
+
676
+        return new AwaitingResourceRegistration(
677
+            $register, $name, $controller, $options
678
+        );
679
+    }
680
+
681
+    /**
682
+     * Get the route collection.
683
+     *
684
+     * @return array   
685
+     */
686
+    public function getRoutes()
687
+    {
688
+        return $this->routes;
689
+    }
690
+
691
+    /**
692
+     * Get or set the verbs used in the resource URIs.
693
+     * 
694
+     * @param  array  $verbs
695
+     * 
696
+     * @return array|null
697
+     */
698
+    public function resourceVerbs(array $verbs = [])
699
+    {
700
+        ResourceRegister::verbs($verbs);
701
+    }
702 702
 	
703
-	/**
704
-	 * Remove any duplicate middleware from the given array.
705
-	 * 
706
-	 * @param  array  $middleware
707
-	 * 
708
-	 * @return array
709
-	 */
710
-	public static function uniqueMiddleware(array $middleware): array
711
-	{
712
-		return array_unique($middleware, SORT_REGULAR);
713
-	}
714
-
715
-	/**
716
-	 * Magic method.
717
-	 * 
718
-	 * Dynamically handle calls into the router instance.
719
-	 * 
720
-	 * @param  string  $method
721
-	 * @param  array  $parameters
722
-	 * 
723
-	 * @return mixed
724
-	 */
725
-	public function __call($method, $parameters)
726
-	{
727
-		if (static::hasMacro($method)) {
728
-			return $this->macroCall($method, $parameters);
729
-		}
703
+    /**
704
+     * Remove any duplicate middleware from the given array.
705
+     * 
706
+     * @param  array  $middleware
707
+     * 
708
+     * @return array
709
+     */
710
+    public static function uniqueMiddleware(array $middleware): array
711
+    {
712
+        return array_unique($middleware, SORT_REGULAR);
713
+    }
714
+
715
+    /**
716
+     * Magic method.
717
+     * 
718
+     * Dynamically handle calls into the router instance.
719
+     * 
720
+     * @param  string  $method
721
+     * @param  array  $parameters
722
+     * 
723
+     * @return mixed
724
+     */
725
+    public function __call($method, $parameters)
726
+    {
727
+        if (static::hasMacro($method)) {
728
+            return $this->macroCall($method, $parameters);
729
+        }
730 730
 		
731
-		return (new RouteRegister($this))->attribute($method, $parameters[0]);
732
-	}
731
+        return (new RouteRegister($this))->attribute($method, $parameters[0]);
732
+    }
733 733
 }
734 734
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Loaders/Parameters.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -34,160 +34,160 @@
 block discarded – undo
34 34
  */
35 35
 class Parameters implements IteratorAggregate, Countable
36 36
 {
37
-	/**
38
-	 * Array parameters from the Server global.
39
-	 *
40
-	 * @var array $parameters
41
-	 */
42
-	protected $parameters;
43
-
44
-	/**
45
-	 * Parameter Object Constructor.
46
-	 *
47
-	 * @param  array  $parameters
48
-	 *
49
-	 * @return array
50
-	 */
51
-	public function __construct(array $parameters = [])
52
-	{
53
-		$this->parameters = $parameters;
54
-	}
55
-
56
-	/**
57
-	 * Returns the parameters.
58
-	 * 
59
-	 * @param  string|null  $key
60
-	 * 
61
-	 * @return array
62
-	 */
63
-	public function all(string $key = null): array
64
-	{
65
-		if (null === $key) {
66
-			return $this->parameters;
67
-		}
68
-
69
-		if ( ! is_array($value = $this->parameters[$key] ?? [])) {
70
-			throw new BadRequestException(
71
-				sprintf('Unexpected value for parameter "%s", got "%s"', $key, get_debug_type($value))
72
-			);
73
-		}
74
-
75
-		return $value;
76
-	}
77
-
78
-	/**
79
-	 * Returns the parameter keys.
80
-	 * 
81
-	 * @return array
82
-	 */
83
-	public function keys(): array
84
-	{
85
-		return array_keys($this->parameters);
86
-	}
87
-
88
-	/**
89
-	 * Replaces the current parameters.
90
-	 * 
91
-	 * @param  array  $parameters
92
-	 * 
93
-	 * @return void
94
-	 */
95
-	public function replace(array $parameters = []): void
96
-	{
97
-		$this->parameters = $parameters;
98
-	}
99
-
100
-	/**
101
-	 * Adds parameters.
102
-	 * 
103
-	 * @param  array  $parameters
104
-	 * 
105
-	 * @return void
106
-	 */
107
-	public function add(array $parameters = []): void
108
-	{
109
-		$this->parameters = array_replace($this->parameters, $parameters);
110
-	}
111
-
112
-	/**
113
-	 * Get a parameter array item.
114
-	 *
115
-	 * @param  string  $key
116
-	 * @param  mixed  $default  
117
-	 *
118
-	 * @return mixed
119
-	 */
120
-	public function get(string $key, mixed $default = null): mixed
121
-	{
122
-		return $this->has($key) ? $this->parameters[$key] : $default;
123
-	}
124
-
125
-	/**
126
-	 * Check if a parameter array item exists.
127
-	 *
128
-	 * @param  string  $key
129
-	 *
130
-	 * @return bool
131
-	 */
132
-	public function has(string $key): bool
133
-	{
134
-		return Arr::exists($this->parameters, $key);
135
-	}
136
-
137
-	/**
138
-	 * Set a parameter array item.
139
-	 *
140
-	 * @param  string  $key
141
-	 * @param  string  $value 
142
-	 *
143
-	 * @return void
144
-	 */
145
-	public function set(string $key, $value): void
146
-	{
147
-		$this->parameters[$key] = $value;
148
-	}
149
-
150
-	/**
151
-	 * Remove a parameter array item.
152
-	 *
153
-	 * @param  string  $key 
154
-	 *
155
-	 * @return void
156
-	 */
157
-	public function remove(string $key): void
158
-	{
159
-		unset($this->parameters[$key]);
160
-	}
161
-
162
-	/*
37
+    /**
38
+     * Array parameters from the Server global.
39
+     *
40
+     * @var array $parameters
41
+     */
42
+    protected $parameters;
43
+
44
+    /**
45
+     * Parameter Object Constructor.
46
+     *
47
+     * @param  array  $parameters
48
+     *
49
+     * @return array
50
+     */
51
+    public function __construct(array $parameters = [])
52
+    {
53
+        $this->parameters = $parameters;
54
+    }
55
+
56
+    /**
57
+     * Returns the parameters.
58
+     * 
59
+     * @param  string|null  $key
60
+     * 
61
+     * @return array
62
+     */
63
+    public function all(string $key = null): array
64
+    {
65
+        if (null === $key) {
66
+            return $this->parameters;
67
+        }
68
+
69
+        if ( ! is_array($value = $this->parameters[$key] ?? [])) {
70
+            throw new BadRequestException(
71
+                sprintf('Unexpected value for parameter "%s", got "%s"', $key, get_debug_type($value))
72
+            );
73
+        }
74
+
75
+        return $value;
76
+    }
77
+
78
+    /**
79
+     * Returns the parameter keys.
80
+     * 
81
+     * @return array
82
+     */
83
+    public function keys(): array
84
+    {
85
+        return array_keys($this->parameters);
86
+    }
87
+
88
+    /**
89
+     * Replaces the current parameters.
90
+     * 
91
+     * @param  array  $parameters
92
+     * 
93
+     * @return void
94
+     */
95
+    public function replace(array $parameters = []): void
96
+    {
97
+        $this->parameters = $parameters;
98
+    }
99
+
100
+    /**
101
+     * Adds parameters.
102
+     * 
103
+     * @param  array  $parameters
104
+     * 
105
+     * @return void
106
+     */
107
+    public function add(array $parameters = []): void
108
+    {
109
+        $this->parameters = array_replace($this->parameters, $parameters);
110
+    }
111
+
112
+    /**
113
+     * Get a parameter array item.
114
+     *
115
+     * @param  string  $key
116
+     * @param  mixed  $default  
117
+     *
118
+     * @return mixed
119
+     */
120
+    public function get(string $key, mixed $default = null): mixed
121
+    {
122
+        return $this->has($key) ? $this->parameters[$key] : $default;
123
+    }
124
+
125
+    /**
126
+     * Check if a parameter array item exists.
127
+     *
128
+     * @param  string  $key
129
+     *
130
+     * @return bool
131
+     */
132
+    public function has(string $key): bool
133
+    {
134
+        return Arr::exists($this->parameters, $key);
135
+    }
136
+
137
+    /**
138
+     * Set a parameter array item.
139
+     *
140
+     * @param  string  $key
141
+     * @param  string  $value 
142
+     *
143
+     * @return void
144
+     */
145
+    public function set(string $key, $value): void
146
+    {
147
+        $this->parameters[$key] = $value;
148
+    }
149
+
150
+    /**
151
+     * Remove a parameter array item.
152
+     *
153
+     * @param  string  $key 
154
+     *
155
+     * @return void
156
+     */
157
+    public function remove(string $key): void
158
+    {
159
+        unset($this->parameters[$key]);
160
+    }
161
+
162
+    /*
163 163
 	|-----------------------------------------------------------------
164 164
 	| IteratorAggregate Method
165 165
 	|-----------------------------------------------------------------
166 166
 	*/
167 167
 	
168
-	/**
169
-	 * Retrieve an external iterator.
170
-	 * 
171
-	 * @return \ArrayIterator
172
-	 */
173
-	public function getIterator(): Traversable
174
-	{
175
-		return new ArrayIterator($this->parameters);
176
-	}
168
+    /**
169
+     * Retrieve an external iterator.
170
+     * 
171
+     * @return \ArrayIterator
172
+     */
173
+    public function getIterator(): Traversable
174
+    {
175
+        return new ArrayIterator($this->parameters);
176
+    }
177 177
 	
178
-	/*
178
+    /*
179 179
 	|-----------------------------------------------------------------
180 180
 	| Countable Method
181 181
 	|-----------------------------------------------------------------
182 182
 	*/
183 183
 	
184
-	/**
185
-	 * Returns the number of parameters.
186
-	 * 
187
-	 * @return int The number of parameters
188
-	 */
189
-	public function count(): int
190
-	{
191
-		return count($this->parameters);
192
-	}
184
+    /**
185
+     * Returns the number of parameters.
186
+     * 
187
+     * @return int The number of parameters
188
+     */
189
+    public function count(): int
190
+    {
191
+        return count($this->parameters);
192
+    }
193 193
 }
194 194
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Loaders/Inputs.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -30,70 +30,70 @@
 block discarded – undo
30 30
  */
31 31
 final class Inputs extends Parameters
32 32
 {
33
-	/**
34
-	 * Replaces the current parameters.
35
-	 * 
36
-	 * @param  array  $parameters
37
-	 * 
38
-	 * @return void
39
-	 */
40
-	public function replace(array $inputs = []): void
41
-	{
42
-		$this->parameters = [];
43
-		$this->add($inputs);
44
-	}
33
+    /**
34
+     * Replaces the current parameters.
35
+     * 
36
+     * @param  array  $parameters
37
+     * 
38
+     * @return void
39
+     */
40
+    public function replace(array $inputs = []): void
41
+    {
42
+        $this->parameters = [];
43
+        $this->add($inputs);
44
+    }
45 45
 	
46
-	/**
47
-	 * Adds parameters.
48
-	 * 
49
-	 * @param  array  $parameters
50
-	 * 
51
-	 * @return void
52
-	 */
53
-	public function add(array $inputs = []): void
54
-	{
55
-		foreach ($inputs as $input => $file) {
56
-			$this->set($input, $file);
57
-		}
58
-	}
46
+    /**
47
+     * Adds parameters.
48
+     * 
49
+     * @param  array  $parameters
50
+     * 
51
+     * @return void
52
+     */
53
+    public function add(array $inputs = []): void
54
+    {
55
+        foreach ($inputs as $input => $file) {
56
+            $this->set($input, $file);
57
+        }
58
+    }
59 59
 	
60
-	/**
61
-	 * Gets a string input value by name.
62
-	 * 
63
-	 * @param  string  $key
64
-	 * @param  mixed  $default  
65
-	 * 
66
-	 * @return string|int|float|bool|null
67
-	 */
68
-	public function get(string $key, mixed $default = null): string|int|float|bool|null
69
-	{
70
-		if (null !== $default && ! is_scalar($default) && ! method_exists($default, '__toString')) {
71
-			throw new BadRequestHttpException(sprintf('Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead', __METHOD__));
72
-		}
60
+    /**
61
+     * Gets a string input value by name.
62
+     * 
63
+     * @param  string  $key
64
+     * @param  mixed  $default  
65
+     * 
66
+     * @return string|int|float|bool|null
67
+     */
68
+    public function get(string $key, mixed $default = null): string|int|float|bool|null
69
+    {
70
+        if (null !== $default && ! is_scalar($default) && ! method_exists($default, '__toString')) {
71
+            throw new BadRequestHttpException(sprintf('Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead', __METHOD__));
72
+        }
73 73
 		
74
-		$value = parent::get($key, $this);
74
+        $value = parent::get($key, $this);
75 75
 		
76
-		if (null !== $value && $this !== $value && ! is_scalar($value) && ! method_exists($value, '__toString')) {
77
-			throw new BadRequestHttpException(sprintf('Retrieving a non-string value from "%s()" is deprecated, and will throw a exception in Syscodes, use "%s::all($key)" instead', __METHOD__, __CLASS__));
78
-		}
76
+        if (null !== $value && $this !== $value && ! is_scalar($value) && ! method_exists($value, '__toString')) {
77
+            throw new BadRequestHttpException(sprintf('Retrieving a non-string value from "%s()" is deprecated, and will throw a exception in Syscodes, use "%s::all($key)" instead', __METHOD__, __CLASS__));
78
+        }
79 79
 		
80
-		return $this === $value ? $default : $value;
81
-	}
80
+        return $this === $value ? $default : $value;
81
+    }
82 82
 	
83
-	/**
84
-	 * Sets an input by name.
85
-	 * 
86
-	 * @param  string  $key
87
-	 * @param  mixed  $value
88
-	 * 
89
-	 * @return void
90
-	 */
91
-	public function set(string $key, mixed $value): void
92
-	{
93
-		if (null !== $value && ! is_scalar($value) && ! is_array($value) && ! method_exists($value, '__toString')) {
94
-			throw new BadRequestHttpException(sprintf('Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a string, array, or null instead', get_debug_type($value), __METHOD__));
95
-		}
83
+    /**
84
+     * Sets an input by name.
85
+     * 
86
+     * @param  string  $key
87
+     * @param  mixed  $value
88
+     * 
89
+     * @return void
90
+     */
91
+    public function set(string $key, mixed $value): void
92
+    {
93
+        if (null !== $value && ! is_scalar($value) && ! is_array($value) && ! method_exists($value, '__toString')) {
94
+            throw new BadRequestHttpException(sprintf('Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a string, array, or null instead', get_debug_type($value), __METHOD__));
95
+        }
96 96
 		
97
-		$this->parameters[$key] = $value;
98
-	}
97
+        $this->parameters[$key] = $value;
98
+    }
99 99
 }
100 100
\ 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
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 	 * 
66 66
 	 * @return string|int|float|bool|null
67 67
 	 */
68
-	public function get(string $key, mixed $default = null): string|int|float|bool|null
68
+	public function get(string $key, mixed $default = null): string | int | float | bool | null
69 69
 	{
70 70
 		if (null !== $default && ! is_scalar($default) && ! method_exists($default, '__toString')) {
71 71
 			throw new BadRequestHttpException(sprintf('Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead', __METHOD__));
Please login to merge, or discard this patch.
src/components/Http/Loaders/Files.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -40,29 +40,29 @@
 block discarded – undo
40 40
     }
41 41
 
42 42
     /**
43
-	 * Replaces the current parameters.
44
-	 * 
45
-	 * @param  array  $parameters
46
-	 * 
47
-	 * @return void
48
-	 */
49
-	public function replace(array $files = []): void
50
-	{
51
-		$this->parameters = [];
43
+     * Replaces the current parameters.
44
+     * 
45
+     * @param  array  $parameters
46
+     * 
47
+     * @return void
48
+     */
49
+    public function replace(array $files = []): void
50
+    {
51
+        $this->parameters = [];
52 52
         $this->add($files);
53
-	}
53
+    }
54 54
 
55
-	/**
56
-	 * Adds parameters.
57
-	 * 
58
-	 * @param  array  $parameters
59
-	 * 
60
-	 * @return void
61
-	 */
62
-	public function add(array $files = []): void
63
-	{
55
+    /**
56
+     * Adds parameters.
57
+     * 
58
+     * @param  array  $parameters
59
+     * 
60
+     * @return void
61
+     */
62
+    public function add(array $files = []): void
63
+    {
64 64
         foreach ($files as $key => $file) {
65 65
             $this->set($key, $file);
66 66
         }
67
-	}
67
+    }
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Loaders/Headers.php 1 patch
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -35,266 +35,266 @@
 block discarded – undo
35 35
  */
36 36
 class Headers implements IteratorAggregate, Countable
37 37
 {
38
-	protected const STRING_UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
39
-	protected const STRING_LOWER = '-abcdefghijklmnopqrstuvwxyz';
38
+    protected const STRING_UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
39
+    protected const STRING_LOWER = '-abcdefghijklmnopqrstuvwxyz';
40 40
 
41
-	/**
42
-	 * An array of HTTP headers.
43
-	 * 
44
-	 * @var array $herders
45
-	 */
46
-	protected $headers = [];
41
+    /**
42
+     * An array of HTTP headers.
43
+     * 
44
+     * @var array $herders
45
+     */
46
+    protected $headers = [];
47 47
 	
48
-	/**
49
-	 * Specifies the directives for the caching mechanisms in both
50
-	 * the requests and the responses.
51
-	 * 
52
-	 * @var array $cacheControl
53
-	 */
54
-	protected $cacheControl = [];
48
+    /**
49
+     * Specifies the directives for the caching mechanisms in both
50
+     * the requests and the responses.
51
+     * 
52
+     * @var array $cacheControl
53
+     */
54
+    protected $cacheControl = [];
55 55
 	
56
-	/**
57
-	 * Constructor. The Headers class instance.
58
-	 * 
59
-	 * @param  array  $headers
60
-	 * 
61
-	 * @return void
62
-	 */
63
-	public function __construct(array $headers = [])
64
-	{
65
-		foreach ($headers as $key => $values) {
66
-			$this->set($key, $values);
67
-		}
68
-	}
56
+    /**
57
+     * Constructor. The Headers class instance.
58
+     * 
59
+     * @param  array  $headers
60
+     * 
61
+     * @return void
62
+     */
63
+    public function __construct(array $headers = [])
64
+    {
65
+        foreach ($headers as $key => $values) {
66
+            $this->set($key, $values);
67
+        }
68
+    }
69 69
 	
70
-	/**
71
-	 * Returns all the headers.
72
-	 * 
73
-	 * @param  string|null  $key  The name of the headers
74
-	 * 
75
-	 * @return array
76
-	 */
77
-	public function all(string $key = null): array
78
-	{
79
-		if (null !== $key) {
80
-			return $this->headers[strtr($key, self::STRING_UPPER, self::STRING_LOWER)] ?? [];
81
-		}
70
+    /**
71
+     * Returns all the headers.
72
+     * 
73
+     * @param  string|null  $key  The name of the headers
74
+     * 
75
+     * @return array
76
+     */
77
+    public function all(string $key = null): array
78
+    {
79
+        if (null !== $key) {
80
+            return $this->headers[strtr($key, self::STRING_UPPER, self::STRING_LOWER)] ?? [];
81
+        }
82 82
 
83
-		return $this->headers;
84
-	}
83
+        return $this->headers;
84
+    }
85 85
 	
86
-	/**
87
-	 * Returns the parameter keys.
88
-	 * 
89
-	 * @return array An array of parameter keys
90
-	 */
91
-	public function keys(): array
92
-	{
93
-		return array_keys($this->all());
94
-	}
86
+    /**
87
+     * Returns the parameter keys.
88
+     * 
89
+     * @return array An array of parameter keys
90
+     */
91
+    public function keys(): array
92
+    {
93
+        return array_keys($this->all());
94
+    }
95 95
 	
96
-	/**
97
-	 * Replaces the current HTTP headers by a new set.
98
-	 * 
99
-	 * @param  array  $headers
100
-	 * 
101
-	 * @return void
102
-	 */
103
-	public function replace(array $headers = []): void
104
-	{
105
-		$this->headers = [];
106
-		$this->add($headers);
107
-	}
96
+    /**
97
+     * Replaces the current HTTP headers by a new set.
98
+     * 
99
+     * @param  array  $headers
100
+     * 
101
+     * @return void
102
+     */
103
+    public function replace(array $headers = []): void
104
+    {
105
+        $this->headers = [];
106
+        $this->add($headers);
107
+    }
108 108
 	
109
-	/**
110
-	 * Adds multiple header to the queue.
111
-	 * 
112
-	 * @param  array  $headers  The header name
113
-	 * 
114
-	 * @return mixed
115
-	 */
116
-	public function add(array $headers = [])
117
-	{
118
-		foreach ($headers as $key => $values) {
119
-			$this->set($key, $values);
120
-		}
121
-	}
109
+    /**
110
+     * Adds multiple header to the queue.
111
+     * 
112
+     * @param  array  $headers  The header name
113
+     * 
114
+     * @return mixed
115
+     */
116
+    public function add(array $headers = [])
117
+    {
118
+        foreach ($headers as $key => $values) {
119
+            $this->set($key, $values);
120
+        }
121
+    }
122 122
 	
123
-	/**
124
-	 * Gets a header value by name.
125
-	 *
126
-	 * @param  string  $key  The header name, or null for all headers
127
-	 * @param  string|null  $default  The default value
128
-	 *
129
-	 * @return mixed
130
-	 */
131
-	public function get(string $key, string $default = null): ?string
132
-	{
133
-		$headers = $this->all($key);
123
+    /**
124
+     * Gets a header value by name.
125
+     *
126
+     * @param  string  $key  The header name, or null for all headers
127
+     * @param  string|null  $default  The default value
128
+     *
129
+     * @return mixed
130
+     */
131
+    public function get(string $key, string $default = null): ?string
132
+    {
133
+        $headers = $this->all($key);
134 134
 		
135
-		if ( ! $headers) {
136
-			return $default;
137
-		}
135
+        if ( ! $headers) {
136
+            return $default;
137
+        }
138 138
 		
139
-		if (null === $headers[0]) {
140
-			return null;
141
-		}
139
+        if (null === $headers[0]) {
140
+            return null;
141
+        }
142 142
 		
143
-		return (string) $headers[0];
144
-	}
143
+        return (string) $headers[0];
144
+    }
145 145
 
146
-	/**
147
-	 * Sets a header by name.
148
-	 * 
149
-	 * @param  string  $key  The header name
150
-	 * @param  string|string[]|null  $values  The value or an array of values
151
-	 * @param  bool  $replace  If you want to replace the value exists by the header, 
152
-	 * 					       it is not overwritten / overwritten when it is false
153
-	 *
154
-	 * @return void
155
-	 */
156
-	public function set(string $key, $values, bool $replace = true): void
157
-	{
158
-		$key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
146
+    /**
147
+     * Sets a header by name.
148
+     * 
149
+     * @param  string  $key  The header name
150
+     * @param  string|string[]|null  $values  The value or an array of values
151
+     * @param  bool  $replace  If you want to replace the value exists by the header, 
152
+     * 					       it is not overwritten / overwritten when it is false
153
+     *
154
+     * @return void
155
+     */
156
+    public function set(string $key, $values, bool $replace = true): void
157
+    {
158
+        $key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
159 159
 
160
-		if (is_array($values)) {
161
-			$values = array_values($values);
160
+        if (is_array($values)) {
161
+            $values = array_values($values);
162 162
 
163
-			if (true === $replace || ! isset($this->headers[$key])) {
164
-				$this->headers[$key] = $values;
165
-			} else {
166
-				$this->headers[$key] = array_merge($this->headers[$key], $values);
167
-			}
168
-		} else {
169
-			if (true === $replace || ! isset($this->headers[$key])) {
170
-				$this->headers[$key] = [$values];
171
-			} else {
172
-				$this->headers[$key][] = $values;
173
-			}
174
-		}
163
+            if (true === $replace || ! isset($this->headers[$key])) {
164
+                $this->headers[$key] = $values;
165
+            } else {
166
+                $this->headers[$key] = array_merge($this->headers[$key], $values);
167
+            }
168
+        } else {
169
+            if (true === $replace || ! isset($this->headers[$key])) {
170
+                $this->headers[$key] = [$values];
171
+            } else {
172
+                $this->headers[$key][] = $values;
173
+            }
174
+        }
175 175
 		
176
-		if ('cache-control' === $key) {
177
-			$this->cacheControl = $this->parseCacheControl(implode(', ', $this->headers[$key]));
178
-		}
179
-	}
176
+        if ('cache-control' === $key) {
177
+            $this->cacheControl = $this->parseCacheControl(implode(', ', $this->headers[$key]));
178
+        }
179
+    }
180 180
 
181
-	/**
182
-	 * Returns true if the HTTP header is defined.
183
-	 * 
184
-	 * @param  string  $key  The HTTP header
185
-	 * 
186
-	 * @return bool  true if the parameter exists, false otherwise
187
-	 */
188
-	public function has(string $key): bool
189
-	{
190
-		return array_key_exists(strtr($key, self::STRING_UPPER, self::STRING_LOWER), $this->all());
191
-	}
181
+    /**
182
+     * Returns true if the HTTP header is defined.
183
+     * 
184
+     * @param  string  $key  The HTTP header
185
+     * 
186
+     * @return bool  true if the parameter exists, false otherwise
187
+     */
188
+    public function has(string $key): bool
189
+    {
190
+        return array_key_exists(strtr($key, self::STRING_UPPER, self::STRING_LOWER), $this->all());
191
+    }
192 192
 
193
-	/**
194
-	 * Removes a header.
195
-	 * 
196
-	 * @param  string  $name  The header name
197
-	 * 
198
-	 * @return mixed
199
-	 */
200
-	public function remove(string $key)
201
-	{
202
-		$key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
193
+    /**
194
+     * Removes a header.
195
+     * 
196
+     * @param  string  $name  The header name
197
+     * 
198
+     * @return mixed
199
+     */
200
+    public function remove(string $key)
201
+    {
202
+        $key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
203 203
 
204
-		unset($this->headers[$key]);
204
+        unset($this->headers[$key]);
205 205
 
206
-		if ('cache-control' === $key) {
207
-			$this->cacheControl = [];
208
-		}
209
-	}
206
+        if ('cache-control' === $key) {
207
+            $this->cacheControl = [];
208
+        }
209
+    }
210 210
 	
211
-	/**
212
-	 * Returns the HTTP header value converted to a date.
213
-	 * 
214
-	 * @param  string  $key
215
-	 * @param  DateTime|null  $default
216
-	 * 
217
-	 * @throws \RuntimeException When the HTTP header is not parseable
218
-	 */
219
-	public function getDate(string $key, DateTime $default = null): ?DateTimeInterface
220
-	{
221
-		if (null === $value = $this->get($key)) {
222
-			return $default;
223
-		}
211
+    /**
212
+     * Returns the HTTP header value converted to a date.
213
+     * 
214
+     * @param  string  $key
215
+     * @param  DateTime|null  $default
216
+     * 
217
+     * @throws \RuntimeException When the HTTP header is not parseable
218
+     */
219
+    public function getDate(string $key, DateTime $default = null): ?DateTimeInterface
220
+    {
221
+        if (null === $value = $this->get($key)) {
222
+            return $default;
223
+        }
224 224
 		
225
-		if (false === $date = DateTime::createFromFormat(DATE_RFC2822, $value)) {
226
-			throw new RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
227
-		}
225
+        if (false === $date = DateTime::createFromFormat(DATE_RFC2822, $value)) {
226
+            throw new RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
227
+        }
228 228
 		
229
-		return $date;
230
-	}
229
+        return $date;
230
+    }
231 231
 	
232
-	/**
233
-	 * Returns an iterator for headers.
234
-	 * 
235
-	 * @return \ArrayIterator An \ArrayIterator instance
236
-	 */
237
-	public function getIterator(): Traversable
238
-	{
239
-		return new ArrayIterator($this->headers);
240
-	}
232
+    /**
233
+     * Returns an iterator for headers.
234
+     * 
235
+     * @return \ArrayIterator An \ArrayIterator instance
236
+     */
237
+    public function getIterator(): Traversable
238
+    {
239
+        return new ArrayIterator($this->headers);
240
+    }
241 241
 	
242
-	/**
243
-	 * Returns the number of headers.
244
-	 * 
245
-	 * @return int The number of headers
246
-	 */
247
-	public function count(): int
248
-	{
249
-		return count($this->headers);
250
-	}
242
+    /**
243
+     * Returns the number of headers.
244
+     * 
245
+     * @return int The number of headers
246
+     */
247
+    public function count(): int
248
+    {
249
+        return count($this->headers);
250
+    }
251 251
 	
252
-	/**
253
-	 * Parses a Cache-Control HTTP header.
254
-	 * 
255
-	 * @param string $header The value of the Cache-Control HTTP header
256
-	 * 
257
-	 * @return array An array representing the attribute values
258
-	 */
259
-	protected function parseCacheControl($header): array
260
-	{
261
-		$cacheControl = [];
252
+    /**
253
+     * Parses a Cache-Control HTTP header.
254
+     * 
255
+     * @param string $header The value of the Cache-Control HTTP header
256
+     * 
257
+     * @return array An array representing the attribute values
258
+     */
259
+    protected function parseCacheControl($header): array
260
+    {
261
+        $cacheControl = [];
262 262
 		
263
-		preg_match_all('~([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?~', $header, $matches, PREG_SET_ORDER);
263
+        preg_match_all('~([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?~', $header, $matches, PREG_SET_ORDER);
264 264
 		
265
-		foreach ($matches as $match) {
266
-			$cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
267
-		}
265
+        foreach ($matches as $match) {
266
+            $cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true);
267
+        }
268 268
 		
269
-		return $cacheControl;
270
-	}
269
+        return $cacheControl;
270
+    }
271 271
 	
272
-	/**
273
-	 * Magic method.
274
-	 * 
275
-	 * Returns the headers as a string.
276
-	 * 
277
-	 * @return string The headers
278
-	 */
279
-	public function __toString(): string
280
-	{
281
-		if ( ! $headers = $this->all()) {
282
-			return '';
283
-		}
272
+    /**
273
+     * Magic method.
274
+     * 
275
+     * Returns the headers as a string.
276
+     * 
277
+     * @return string The headers
278
+     */
279
+    public function __toString(): string
280
+    {
281
+        if ( ! $headers = $this->all()) {
282
+            return '';
283
+        }
284 284
 		
285
-		ksort($headers);
285
+        ksort($headers);
286 286
 		
287
-		$max     = max(array_map('strlen', array_keys($headers))) + 1;
288
-		$content = '';
287
+        $max     = max(array_map('strlen', array_keys($headers))) + 1;
288
+        $content = '';
289 289
 		
290
-		foreach ($headers as $name => $values) {
291
-			$name = ucwords($name, '-');
290
+        foreach ($headers as $name => $values) {
291
+            $name = ucwords($name, '-');
292 292
 			
293
-			foreach ($values as $value) {
294
-				$content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
295
-			}
296
-		}
293
+            foreach ($values as $value) {
294
+                $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value);
295
+            }
296
+        }
297 297
 
298
-		return $content;
299
-	}
298
+        return $content;
299
+    }
300 300
 }
301 301
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/URI.php 1 patch
Indentation   +493 added lines, -493 removed lines patch added patch discarded remove patch
@@ -31,499 +31,499 @@
 block discarded – undo
31 31
  */
32 32
 class URI
33 33
 {
34
-	/**
35
-	 * Returns default schemes/ports.
36
-	 * 
37
-	 * @var array $defaultPorts
38
-	 */
39
-	protected $defaultPorts = [
40
-		'http'  => 80,
41
-		'https' => 443,
42
-		'ftp'   => 21,
43
-		'sftp'  => 22
44
-	];
45
-
46
-	/**
47
-	 * The name of any fragment.
48
-	 * 
49
-	 * @var string $fragment
50
-	 */
51
-	protected $fragment = '';
52
-
53
-	/**
54
-	 * The URI Host.
55
-	 * 
56
-	 * @var string $host
57
-	 */
58
-	protected $host;
34
+    /**
35
+     * Returns default schemes/ports.
36
+     * 
37
+     * @var array $defaultPorts
38
+     */
39
+    protected $defaultPorts = [
40
+        'http'  => 80,
41
+        'https' => 443,
42
+        'ftp'   => 21,
43
+        'sftp'  => 22
44
+    ];
45
+
46
+    /**
47
+     * The name of any fragment.
48
+     * 
49
+     * @var string $fragment
50
+     */
51
+    protected $fragment = '';
52
+
53
+    /**
54
+     * The URI Host.
55
+     * 
56
+     * @var string $host
57
+     */
58
+    protected $host;
59 59
 	
60
-	/**
61
-	 * The URI User Password.
62
-	 * 
63
-	 * @var string $password
64
-	 */
65
-	protected $password;
66
-
67
-	/**
68
-	 * The URI path.
69
-	 * 
70
-	 * @var string $path
71
-	 */
72
-	protected $path;
73
-
74
-	/**
75
-	 * The URI Port.
76
-	 * 
77
-	 * @var int $port
78
-	 */
79
-	protected $port;
80
-
81
-	/**
82
-	 * The query string.
83
-	 * 
84
-	 * @var string $query
85
-	 */
86
-	protected $query;
87
-
88
-	/**
89
-	 * The URI Scheme.
90
-	 * 
91
-	 * @var string $scheme
92
-	 */
93
-	protected $scheme = 'http';
94
-
95
-	/**
96
-	 * Whether passwords should be shown in userInfo/authority calls.
97
-	 * 
98
-	 * @var boolean $showPassword
99
-	 */
100
-	protected $showPassword = false;
60
+    /**
61
+     * The URI User Password.
62
+     * 
63
+     * @var string $password
64
+     */
65
+    protected $password;
66
+
67
+    /**
68
+     * The URI path.
69
+     * 
70
+     * @var string $path
71
+     */
72
+    protected $path;
73
+
74
+    /**
75
+     * The URI Port.
76
+     * 
77
+     * @var int $port
78
+     */
79
+    protected $port;
80
+
81
+    /**
82
+     * The query string.
83
+     * 
84
+     * @var string $query
85
+     */
86
+    protected $query;
87
+
88
+    /**
89
+     * The URI Scheme.
90
+     * 
91
+     * @var string $scheme
92
+     */
93
+    protected $scheme = 'http';
94
+
95
+    /**
96
+     * Whether passwords should be shown in userInfo/authority calls.
97
+     * 
98
+     * @var boolean $showPassword
99
+     */
100
+    protected $showPassword = false;
101 101
 	
102
-	/**
103
-	 * The URI User Info.
104
-	 * 
105
-	 * @var string $user
106
-	 */
107
-	protected $user;
108
-
109
-	/**
110
-	 * Constructor. The URI class instance.
111
-	 * 
112
-	 * @param  string|null  $uri  
113
-	 * 
114
-	 * @return void
115
-	 * 
116
-	 * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
117
-	 */
118
-	public function __construct(string $uri = null)
119
-	{
120
-		if ( ! is_null($uri)) {
121
-			$this->setUri($uri);
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * Sets and overwrites any current URI information.
127
-	 * 
128
-	 * @param  string|null  $uri  
129
-	 * 
130
-	 * @return static
131
-	 * 
132
-	 * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
133
-	 */
134
-	public function setUri(string $uri = null): static
135
-	{
136
-		if ( ! is_null($uri)) {
137
-			$parts = parse_url($uri);
138
-
139
-			if ($parts === false) {
140
-				throw HttpURIException::UnableToParseURI($uri);
141
-			}
142
-
143
-			$this->applyParts($parts);
144
-		}
145
-
146
-		return $this;
147
-	}
148
-
149
-	/**
150
-	 * Returns the full URI string.
151
-	 *
152
-	 * @return string  The URI string
153
-	 */
154
-	public function get(): string
155
-	{
156
-		return '/'.ltrim($this->path, '/');
157
-	}
158
-
159
-	/**
160
-	 * Sets of URI string.
161
-	 * 
162
-	 * @param  string  $uri
163
-	 * 
164
-	 * @return static
165
-	 */
166
-	public function set(string $uri): static
167
-	{
168
-		$this->path = $uri;
169
-
170
-		return $this;
171
-	}
172
-
173
-	/**
174
-	 * Retrieve the path component of the URI. The path can either be empty or absolute 
175
-	 * (starting with a slash) or rootless (not starting with a slash).
176
-	 * 
177
-	 * @return string
178
-	 */
179
-	public function getPath(): string
180
-	{
181
-		return (is_null($this->path) ? '' : $this->path);
182
-	}
183
-
184
-	/**
185
-	 * Sets the path portion of the URI.
186
-	 * 
187
-	 * @param  string  $uri
188
-	 *
189
-	 * @return array
190
-	 */
191
-	public function setPath(string $uri): array
192
-	{
193
-		$this->path = $this->filterPath($uri);
194
-
195
-		$tempPath = trim($this->path, '/');
196
-
197
-		return $this->filterSegments($tempPath);
198
-	} 
199
-
200
-	/**
201
-	 * Encodes any dangerous characters.
202
-	 * 
203
-	 * @param  string  $uri
204
-	 * 
205
-	 * @return string
206
-	 */
207
-	protected function filterPath(string $uri): string
208
-	{
209
-		return urldecode($uri);
210
-	}
211
-
212
-	/**
213
-	 * Filter the segments of path.
214
-	 * 
215
-	 * @param  string  $uri
216
-	 * 
217
-	 * @return string[]
218
-	 */
219
-	protected function filterSegments(string $uri): array
220
-	{
221
-		return ($uri == '') ? [] : explode('/', $uri);
222
-	}
223
-
224
-	/**
225
-	 * Get the specified URI segment, return default if it doesn't exist.
226
-	 * Segment index is 1 based, not 0 based.
227
-	 *
228
-	 * @param  int  $index  The 1-based segment index
229
-	 * @param  mixed  $default  The default value
230
-	 *
231
-	 * @return mixed
232
-	 */
233
-	public function getSegment(int $index, $default = null): mixed
234
-	{
235
-		return Arr::get($this->getSegments(), $index - 1, $default);
236
-	}
237
-
238
-	/**
239
-	 * Returns the segments of the path as an array.
240
-	 *
241
-	 * @return array  The URI segments
242
-	 */
243
-	public function getSegments(): array
244
-	{
245
-		$segments = $this->setPath(Request::decodedPath());
246
-
247
-		return array_values(array_filter($segments, fn ($value) => $value != ''));
248
-	}
249
-
250
-	/**
251
-	 * Returns the total number of segment.
252
-	 *
253
-	 * @return int  
254
-	 */
255
-	public function getTotalSegments(): int
256
-	{
257
-		return count($this->getSegments());
258
-	}
259
-
260
-	/**
261
-	 * Retrieve the scheme component of the URI.
262
-	 * 
263
-	 * @return string
264
-	 */
265
-	public function getScheme(): string
266
-	{
267
-		return $this->scheme;
268
-	}
269
-
270
-	/**
271
-	 * Sets the scheme for this URI.
272
-	 * 
273
-	 * @param  string  $str
274
-	 * 
275
-	 * @return string
276
-	 */
277
-	public function setScheme(string $str): string
278
-	{
279
-		$str = preg_replace('~:(//)?$~', '', strtolower($str));
280
-
281
-		$this->scheme = $str;
282
-
283
-		return $this->scheme;
284
-	}
285
-
286
-	/**
287
-	 * Retrieve the user component of the URI.
288
-	 * 
289
-	 * @return string|null
290
-	 */
291
-	public function getUserInfo()
292
-	{
293
-		$user = $this->user;
294
-		$pass = $this->password;
295
-
296
-		if ($this->showPassword === true && ! empty($pass)) {
297
-			$user .= ":$pass";
298
-		}
299
-
300
-		return $user;
301
-	}
302
-
303
-	/**
304
-	 * Sets the user portion of the URI.
305
-	 * 
306
-	 * @param  string  $user
307
-	 * 
308
-	 * @return string|null
309
-	 */
310
-	public function setUser($user): string
311
-	{
312
-		$this->user = trim($user);
313
-
314
-		return $this->user;
315
-	}
316
-
317
-	/**
318
-	 * Sets the password portion of the URI.
319
-	 * 
320
-	 * @param  string  $password
321
-	 * 
322
-	 * @return string|null
323
-	 */
324
-	public function setPassword($password): string
325
-	{
326
-		$this->password = trim($password);
327
-
328
-		return $this->password;
329
-	}
330
-
331
-	/**
332
-	 * Temporarily sets the URI to show a password in userInfo.
333
-	 * 
334
-	 * @param  boolean  $option  
335
-	 * 
336
-	 * @return static
337
-	 */
338
-	public function showPassword(bool $option = true): static
339
-	{
340
-		$this->showPassword = $option;
341
-
342
-		return $this;
343
-	}
344
-
345
-	/**
346
-	 * Retrieve the authority component of the URI.
347
-	 * 
348
-	 * @param  boolean  $ignore  
349
-	 * 
350
-	 * @return string
351
-	 */
352
-	public function getAuthority(bool $ignore = false): string
353
-	{
354
-		if (empty($this->host)) {
355
-			return '';
356
-		}
357
-
358
-		$authority = $this->host;
359
-
360
-		if ( ! empty($this->getUserInfo())) {
361
-			$authority = $this->getUserInfo().'@'.$authority;
362
-		}
363
-
364
-		if ( ! empty($this->port) && ! $ignore) {
365
-			if ($this->port !== $this->defaultPorts[$this->scheme]) {
366
-				$authority .= ":$this->port";
367
-			}
368
-		}
369
-
370
-		$this->showPassword = false;
371
-
372
-		return $authority;
373
-	}
374
-
375
-	/**
376
-	 * Parses the given string an saves the appropriate authority pieces.
377
-	 * 
378
-	 * @param  string  $str
379
-	 * 
380
-	 * @return static
381
-	 */
382
-	public function setAuthority(string $str): static
383
-	{
384
-		$parts = parse_url($str);
385
-
386
-		if (empty($parts['host']) && ! empty($parts['path'])) {
387
-			$parts['host'] = $parts['path'];
388
-			unset($parts['path']);
389
-		}
390
-
391
-		$this->applyParts($parts);
392
-
393
-		return $this;
394
-	}
395
-
396
-	/**
397
-	 * Retrieve the host component of the URI.
398
-	 * 
399
-	 * @return string
400
-	 */
401
-	public function getHost(): string
402
-	{
403
-		return $this->host;
404
-	}
405
-
406
-	/**
407
-	 * Sets the host name to use.
408
-	 * 
409
-	 * @param  string  $str
410
-	 * 
411
-	 * @return string
412
-	 */
413
-	public function setHost(string $str): string
414
-	{
415
-		$this->host = trim($str);
416
-
417
-		return $this->host;
418
-	}
419
-
420
-	/**
421
-	 * Retrieve the port component of the URI.
422
-	 * 
423
-	 * @return int|null
424
-	 */
425
-	public function getPort()
426
-	{
427
-		return $this->port;
428
-	}
429
-
430
-	/**
431
-	 * Sets the port portion of the URI.
432
-	 * 
433
-	 * @param  int|null  $port  
434
-	 * 
435
-	 * @return string
436
-	 */
437
-	public function setPort(int $port = null): string
438
-	{
439
-		if (is_null($port)) {
440
-			return $this;
441
-		}
442
-
443
-		if ($port <= 0 || $port > 65355) {
444
-			throw HttpURIException::invalidPort($port);
445
-		}
446
-
447
-		$this->port = $port;
448
-
449
-		return $this->port;
450
-	}
451
-
452
-	/**
453
-	 * Retrieve a URI fragment.
454
-	 * 
455
-	 * @return string
456
-	 */
457
-	public function getFragment(): string
458
-	{
459
-		return is_null($this->fragment) ? '' : $this->fragment;
460
-	}
461
-
462
-	/**
463
-	 * Sets the fragment portion of the URI.
464
-	 * 
465
-	 * @param  string  $str
466
-	 * 
467
-	 * @return string
468
-	 */
469
-	public function setFragment(string $str): string
470
-	{
471
-		$this->fragment = trim($str, '# ');
472
-
473
-		return $this->fragment;
474
-	}
475
-
476
-	/**
477
-	 * Saves our parts from a parse_url call.
478
-	 * 
479
-	 * @param  array  $parts
480
-	 * 
481
-	 * @return mixed
482
-	 */
483
-	public function applyParts(array $paths)
484
-	{
485
-		if (isset($parts['scheme'])) {
486
-			$this->SetScheme(rtrim($parts['scheme'], ':/'));
487
-		} else {
488
-			$this->setScheme('http');
489
-		}
490
-
491
-		if ( ! empty($parts['host'])) {
492
-			$this->host = $parts['host'];
493
-		}
494
-
495
-		if (isset($parts['port'])) {
496
-			if ( ! is_null($parts['port'])) {
497
-				$this->port = $parts['port'];
498
-			}
499
-		}
500
-
501
-		if ( ! empty($parts['user'])) {
502
-			$this->user = $parts['user'];
503
-		}
504
-
505
-		if ( ! empty($parts['pass'])) {
506
-			$this->password = $parts['pass'];
507
-		}
508
-
509
-		if ( ! empty($parts['path'])) {
510
-			$this->path = $this->filterPath($parts['path']);
511
-		}
512
-
513
-		if ( ! empty($parts['fragment'])) {
514
-			$this->fragment = $parts['fragment'];
515
-		}
516
-	}
517
-
518
-	/**
519
-	 * Magic method.
520
-	 * 
521
-	 * Returns the URI string.
522
-	 *
523
-	 * @return string
524
-	 */
525
-	public function __toString(): string
526
-	{
527
-		return (string) $this->getPath();
528
-	}
102
+    /**
103
+     * The URI User Info.
104
+     * 
105
+     * @var string $user
106
+     */
107
+    protected $user;
108
+
109
+    /**
110
+     * Constructor. The URI class instance.
111
+     * 
112
+     * @param  string|null  $uri  
113
+     * 
114
+     * @return void
115
+     * 
116
+     * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
117
+     */
118
+    public function __construct(string $uri = null)
119
+    {
120
+        if ( ! is_null($uri)) {
121
+            $this->setUri($uri);
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Sets and overwrites any current URI information.
127
+     * 
128
+     * @param  string|null  $uri  
129
+     * 
130
+     * @return static
131
+     * 
132
+     * @throws \Syscodes\Components\Http\Exceptions\HttpURIException
133
+     */
134
+    public function setUri(string $uri = null): static
135
+    {
136
+        if ( ! is_null($uri)) {
137
+            $parts = parse_url($uri);
138
+
139
+            if ($parts === false) {
140
+                throw HttpURIException::UnableToParseURI($uri);
141
+            }
142
+
143
+            $this->applyParts($parts);
144
+        }
145
+
146
+        return $this;
147
+    }
148
+
149
+    /**
150
+     * Returns the full URI string.
151
+     *
152
+     * @return string  The URI string
153
+     */
154
+    public function get(): string
155
+    {
156
+        return '/'.ltrim($this->path, '/');
157
+    }
158
+
159
+    /**
160
+     * Sets of URI string.
161
+     * 
162
+     * @param  string  $uri
163
+     * 
164
+     * @return static
165
+     */
166
+    public function set(string $uri): static
167
+    {
168
+        $this->path = $uri;
169
+
170
+        return $this;
171
+    }
172
+
173
+    /**
174
+     * Retrieve the path component of the URI. The path can either be empty or absolute 
175
+     * (starting with a slash) or rootless (not starting with a slash).
176
+     * 
177
+     * @return string
178
+     */
179
+    public function getPath(): string
180
+    {
181
+        return (is_null($this->path) ? '' : $this->path);
182
+    }
183
+
184
+    /**
185
+     * Sets the path portion of the URI.
186
+     * 
187
+     * @param  string  $uri
188
+     *
189
+     * @return array
190
+     */
191
+    public function setPath(string $uri): array
192
+    {
193
+        $this->path = $this->filterPath($uri);
194
+
195
+        $tempPath = trim($this->path, '/');
196
+
197
+        return $this->filterSegments($tempPath);
198
+    } 
199
+
200
+    /**
201
+     * Encodes any dangerous characters.
202
+     * 
203
+     * @param  string  $uri
204
+     * 
205
+     * @return string
206
+     */
207
+    protected function filterPath(string $uri): string
208
+    {
209
+        return urldecode($uri);
210
+    }
211
+
212
+    /**
213
+     * Filter the segments of path.
214
+     * 
215
+     * @param  string  $uri
216
+     * 
217
+     * @return string[]
218
+     */
219
+    protected function filterSegments(string $uri): array
220
+    {
221
+        return ($uri == '') ? [] : explode('/', $uri);
222
+    }
223
+
224
+    /**
225
+     * Get the specified URI segment, return default if it doesn't exist.
226
+     * Segment index is 1 based, not 0 based.
227
+     *
228
+     * @param  int  $index  The 1-based segment index
229
+     * @param  mixed  $default  The default value
230
+     *
231
+     * @return mixed
232
+     */
233
+    public function getSegment(int $index, $default = null): mixed
234
+    {
235
+        return Arr::get($this->getSegments(), $index - 1, $default);
236
+    }
237
+
238
+    /**
239
+     * Returns the segments of the path as an array.
240
+     *
241
+     * @return array  The URI segments
242
+     */
243
+    public function getSegments(): array
244
+    {
245
+        $segments = $this->setPath(Request::decodedPath());
246
+
247
+        return array_values(array_filter($segments, fn ($value) => $value != ''));
248
+    }
249
+
250
+    /**
251
+     * Returns the total number of segment.
252
+     *
253
+     * @return int  
254
+     */
255
+    public function getTotalSegments(): int
256
+    {
257
+        return count($this->getSegments());
258
+    }
259
+
260
+    /**
261
+     * Retrieve the scheme component of the URI.
262
+     * 
263
+     * @return string
264
+     */
265
+    public function getScheme(): string
266
+    {
267
+        return $this->scheme;
268
+    }
269
+
270
+    /**
271
+     * Sets the scheme for this URI.
272
+     * 
273
+     * @param  string  $str
274
+     * 
275
+     * @return string
276
+     */
277
+    public function setScheme(string $str): string
278
+    {
279
+        $str = preg_replace('~:(//)?$~', '', strtolower($str));
280
+
281
+        $this->scheme = $str;
282
+
283
+        return $this->scheme;
284
+    }
285
+
286
+    /**
287
+     * Retrieve the user component of the URI.
288
+     * 
289
+     * @return string|null
290
+     */
291
+    public function getUserInfo()
292
+    {
293
+        $user = $this->user;
294
+        $pass = $this->password;
295
+
296
+        if ($this->showPassword === true && ! empty($pass)) {
297
+            $user .= ":$pass";
298
+        }
299
+
300
+        return $user;
301
+    }
302
+
303
+    /**
304
+     * Sets the user portion of the URI.
305
+     * 
306
+     * @param  string  $user
307
+     * 
308
+     * @return string|null
309
+     */
310
+    public function setUser($user): string
311
+    {
312
+        $this->user = trim($user);
313
+
314
+        return $this->user;
315
+    }
316
+
317
+    /**
318
+     * Sets the password portion of the URI.
319
+     * 
320
+     * @param  string  $password
321
+     * 
322
+     * @return string|null
323
+     */
324
+    public function setPassword($password): string
325
+    {
326
+        $this->password = trim($password);
327
+
328
+        return $this->password;
329
+    }
330
+
331
+    /**
332
+     * Temporarily sets the URI to show a password in userInfo.
333
+     * 
334
+     * @param  boolean  $option  
335
+     * 
336
+     * @return static
337
+     */
338
+    public function showPassword(bool $option = true): static
339
+    {
340
+        $this->showPassword = $option;
341
+
342
+        return $this;
343
+    }
344
+
345
+    /**
346
+     * Retrieve the authority component of the URI.
347
+     * 
348
+     * @param  boolean  $ignore  
349
+     * 
350
+     * @return string
351
+     */
352
+    public function getAuthority(bool $ignore = false): string
353
+    {
354
+        if (empty($this->host)) {
355
+            return '';
356
+        }
357
+
358
+        $authority = $this->host;
359
+
360
+        if ( ! empty($this->getUserInfo())) {
361
+            $authority = $this->getUserInfo().'@'.$authority;
362
+        }
363
+
364
+        if ( ! empty($this->port) && ! $ignore) {
365
+            if ($this->port !== $this->defaultPorts[$this->scheme]) {
366
+                $authority .= ":$this->port";
367
+            }
368
+        }
369
+
370
+        $this->showPassword = false;
371
+
372
+        return $authority;
373
+    }
374
+
375
+    /**
376
+     * Parses the given string an saves the appropriate authority pieces.
377
+     * 
378
+     * @param  string  $str
379
+     * 
380
+     * @return static
381
+     */
382
+    public function setAuthority(string $str): static
383
+    {
384
+        $parts = parse_url($str);
385
+
386
+        if (empty($parts['host']) && ! empty($parts['path'])) {
387
+            $parts['host'] = $parts['path'];
388
+            unset($parts['path']);
389
+        }
390
+
391
+        $this->applyParts($parts);
392
+
393
+        return $this;
394
+    }
395
+
396
+    /**
397
+     * Retrieve the host component of the URI.
398
+     * 
399
+     * @return string
400
+     */
401
+    public function getHost(): string
402
+    {
403
+        return $this->host;
404
+    }
405
+
406
+    /**
407
+     * Sets the host name to use.
408
+     * 
409
+     * @param  string  $str
410
+     * 
411
+     * @return string
412
+     */
413
+    public function setHost(string $str): string
414
+    {
415
+        $this->host = trim($str);
416
+
417
+        return $this->host;
418
+    }
419
+
420
+    /**
421
+     * Retrieve the port component of the URI.
422
+     * 
423
+     * @return int|null
424
+     */
425
+    public function getPort()
426
+    {
427
+        return $this->port;
428
+    }
429
+
430
+    /**
431
+     * Sets the port portion of the URI.
432
+     * 
433
+     * @param  int|null  $port  
434
+     * 
435
+     * @return string
436
+     */
437
+    public function setPort(int $port = null): string
438
+    {
439
+        if (is_null($port)) {
440
+            return $this;
441
+        }
442
+
443
+        if ($port <= 0 || $port > 65355) {
444
+            throw HttpURIException::invalidPort($port);
445
+        }
446
+
447
+        $this->port = $port;
448
+
449
+        return $this->port;
450
+    }
451
+
452
+    /**
453
+     * Retrieve a URI fragment.
454
+     * 
455
+     * @return string
456
+     */
457
+    public function getFragment(): string
458
+    {
459
+        return is_null($this->fragment) ? '' : $this->fragment;
460
+    }
461
+
462
+    /**
463
+     * Sets the fragment portion of the URI.
464
+     * 
465
+     * @param  string  $str
466
+     * 
467
+     * @return string
468
+     */
469
+    public function setFragment(string $str): string
470
+    {
471
+        $this->fragment = trim($str, '# ');
472
+
473
+        return $this->fragment;
474
+    }
475
+
476
+    /**
477
+     * Saves our parts from a parse_url call.
478
+     * 
479
+     * @param  array  $parts
480
+     * 
481
+     * @return mixed
482
+     */
483
+    public function applyParts(array $paths)
484
+    {
485
+        if (isset($parts['scheme'])) {
486
+            $this->SetScheme(rtrim($parts['scheme'], ':/'));
487
+        } else {
488
+            $this->setScheme('http');
489
+        }
490
+
491
+        if ( ! empty($parts['host'])) {
492
+            $this->host = $parts['host'];
493
+        }
494
+
495
+        if (isset($parts['port'])) {
496
+            if ( ! is_null($parts['port'])) {
497
+                $this->port = $parts['port'];
498
+            }
499
+        }
500
+
501
+        if ( ! empty($parts['user'])) {
502
+            $this->user = $parts['user'];
503
+        }
504
+
505
+        if ( ! empty($parts['pass'])) {
506
+            $this->password = $parts['pass'];
507
+        }
508
+
509
+        if ( ! empty($parts['path'])) {
510
+            $this->path = $this->filterPath($parts['path']);
511
+        }
512
+
513
+        if ( ! empty($parts['fragment'])) {
514
+            $this->fragment = $parts['fragment'];
515
+        }
516
+    }
517
+
518
+    /**
519
+     * Magic method.
520
+     * 
521
+     * Returns the URI string.
522
+     *
523
+     * @return string
524
+     */
525
+    public function __toString(): string
526
+    {
527
+        return (string) $this->getPath();
528
+    }
529 529
 }
530 530
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/ResponseHeaders.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -30,210 +30,210 @@
 block discarded – undo
30 30
  */
31 31
 class ResponseHeaders extends Headers
32 32
 {
33
-	const COOKIE_FLAT = 'flat';
34
-	const COOKIE_ARRAY = 'array';
33
+    const COOKIE_FLAT = 'flat';
34
+    const COOKIE_ARRAY = 'array';
35 35
 	
36
-	/**
37
-	 * The list of cookies.
38
-	 * 
39
-	 * @var array $cookies
40
-	 */
41
-	protected $cookies = [];
36
+    /**
37
+     * The list of cookies.
38
+     * 
39
+     * @var array $cookies
40
+     */
41
+    protected $cookies = [];
42 42
 
43 43
     /**
44 44
      * The header names.
45
-	 * 
46
-	 * @var array $headerNames 
45
+     * 
46
+     * @var array $headerNames 
47
+     */
48
+    protected $headerNames = [];
49
+
50
+    /**
51
+     * Constructor. Create a new ResponseHeaders class instance.
52
+     * 
53
+     * @param  array  $headers
54
+     * 
55
+     * @return void 
47 56
      */
48
-	protected $headerNames = [];
49
-
50
-	/**
51
-	 * Constructor. Create a new ResponseHeaders class instance.
52
-	 * 
53
-	 * @param  array  $headers
54
-	 * 
55
-	 * @return void 
56
-	 */
57
-	public function __construct(array $headers = [])
58
-	{
59
-		parent::__construct($headers);
57
+    public function __construct(array $headers = [])
58
+    {
59
+        parent::__construct($headers);
60 60
 		
61
-		if ( ! isset($this->headers['cache-control'])) {
62
-			$this->set('Cache-Control', '');
63
-		}
64
-
65
-		if ( ! isset($this->headers['date'])) {
66
-			$this->initDate();
67
-		}
68
-	}
69
-
70
-	/**
71
-	 * Returns the headers, without cookies.
72
-	 * 
73
-	 * @return mixed
74
-	 */
75
-	public function allPreserveCaseWithoutCookies()
76
-	{
77
-		$headers = $this->allPreserveCase();
61
+        if ( ! isset($this->headers['cache-control'])) {
62
+            $this->set('Cache-Control', '');
63
+        }
64
+
65
+        if ( ! isset($this->headers['date'])) {
66
+            $this->initDate();
67
+        }
68
+    }
69
+
70
+    /**
71
+     * Returns the headers, without cookies.
72
+     * 
73
+     * @return mixed
74
+     */
75
+    public function allPreserveCaseWithoutCookies()
76
+    {
77
+        $headers = $this->allPreserveCase();
78 78
 		
79
-		if (isset($this->headerNames['set-cookie'])) {
80
-			unset($headers[$this->headerNames['set-cookie']]);
81
-		}
79
+        if (isset($this->headerNames['set-cookie'])) {
80
+            unset($headers[$this->headerNames['set-cookie']]);
81
+        }
82 82
 		
83
-		return $headers;
84
-	}
83
+        return $headers;
84
+    }
85 85
 
86 86
     /**
87
-	 * Returns the headers, with original capitalizations.
88
-	 * 
89
-	 * @return array An array of headers
90
-	 */
91
-	public function allPreserveCase(): array
92
-	{
93
-		$headers = [];
87
+     * Returns the headers, with original capitalizations.
88
+     * 
89
+     * @return array An array of headers
90
+     */
91
+    public function allPreserveCase(): array
92
+    {
93
+        $headers = [];
94 94
 		
95
-		foreach ($this->all() as $name => $value) {
96
-			$headers[$this->headerNames[$name] ?? $name] = $value;
97
-		}
95
+        foreach ($this->all() as $name => $value) {
96
+            $headers[$this->headerNames[$name] ?? $name] = $value;
97
+        }
98 98
 		
99
-		return $headers;
100
-	}
99
+        return $headers;
100
+    }
101 101
 	
102
-	/**
103
-	 * Returns all the headers.
104
-	 * 
105
-	 * @param  string|null  $key  The name of the headers
106
-	 * 
107
-	 * @return array
108
-	 */
109
-	public function all(string $key = null): array
110
-	{
111
-		$headers = parent::all();
102
+    /**
103
+     * Returns all the headers.
104
+     * 
105
+     * @param  string|null  $key  The name of the headers
106
+     * 
107
+     * @return array
108
+     */
109
+    public function all(string $key = null): array
110
+    {
111
+        $headers = parent::all();
112 112
 		
113
-		if (null !== $key) {
114
-			$key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
113
+        if (null !== $key) {
114
+            $key = strtr($key, self::STRING_UPPER, self::STRING_LOWER);
115 115
 			
116
-			return 'set-cookie' !== $key ? $headers[$key] ?? [] : array_map('strval', $this->getCookies());
117
-		}
116
+            return 'set-cookie' !== $key ? $headers[$key] ?? [] : array_map('strval', $this->getCookies());
117
+        }
118 118
 		
119
-		foreach ($this->getCookies() as $cookie) {
120
-			$headers['set-cookie'][] = (string) $cookie;
121
-		}
119
+        foreach ($this->getCookies() as $cookie) {
120
+            $headers['set-cookie'][] = (string) $cookie;
121
+        }
122 122
 		
123
-		return $headers;
124
-	}
125
-
126
-	/**
127
-	 * Replaces the current HTTP headers by a new set.
128
-	 * 
129
-	 * @param  array  $headers
130
-	 * 
131
-	 * @return void
132
-	 */
133
-	public function replace(array $headers = []): void
134
-	{
135
-		$this->headerNames = [];
136
-
137
-		parent::replace($headers);
138
-
139
-		if ( ! isset($this->headers['cache-control'])) {
140
-			$this->set('Cache-Control', '');
141
-		}
123
+        return $headers;
124
+    }
125
+
126
+    /**
127
+     * Replaces the current HTTP headers by a new set.
128
+     * 
129
+     * @param  array  $headers
130
+     * 
131
+     * @return void
132
+     */
133
+    public function replace(array $headers = []): void
134
+    {
135
+        $this->headerNames = [];
136
+
137
+        parent::replace($headers);
138
+
139
+        if ( ! isset($this->headers['cache-control'])) {
140
+            $this->set('Cache-Control', '');
141
+        }
142 142
 		
143
-		if ( ! isset($this->headers['date'])) {
144
-			$this->initDate();
145
-		}
146
-	}
147
-
148
-	/**
149
-	 * Sets a header by name.
150
-	 * 
151
-	 * @param  string  $key  The header name
152
-	 * @param  string|string[]|null  $values  The value or an array of values
153
-	 * @param  bool  $replace  If you want to replace the value exists by the header, 
154
-	 * 					       it is not overwritten / overwritten when it is false
155
-	 *
156
-	 * @return void
157
-	 */
158
-	public function set(string $key, $values, bool $replace = true): void
159
-	{
160
-		$unique = strtr($key, self::STRING_UPPER, self::STRING_LOWER); 
143
+        if ( ! isset($this->headers['date'])) {
144
+            $this->initDate();
145
+        }
146
+    }
147
+
148
+    /**
149
+     * Sets a header by name.
150
+     * 
151
+     * @param  string  $key  The header name
152
+     * @param  string|string[]|null  $values  The value or an array of values
153
+     * @param  bool  $replace  If you want to replace the value exists by the header, 
154
+     * 					       it is not overwritten / overwritten when it is false
155
+     *
156
+     * @return void
157
+     */
158
+    public function set(string $key, $values, bool $replace = true): void
159
+    {
160
+        $unique = strtr($key, self::STRING_UPPER, self::STRING_LOWER); 
161 161
 		
162
-		if ('set-cookie' === $unique) {
163
-			if ($replace) {
164
-				$this->cookies = [];
165
-			}
162
+        if ('set-cookie' === $unique) {
163
+            if ($replace) {
164
+                $this->cookies = [];
165
+            }
166 166
 			
167
-			foreach ((array) $values as $cookie) {
168
-				$this->setCookie($cookie);
169
-			}
167
+            foreach ((array) $values as $cookie) {
168
+                $this->setCookie($cookie);
169
+            }
170 170
 			
171
-			$this->headerNames[$unique] = $key;
171
+            $this->headerNames[$unique] = $key;
172 172
 
173
-			return;
174
-		}
173
+            return;
174
+        }
175 175
 		
176
-		$this->headerNames[$unique] = $key;
176
+        $this->headerNames[$unique] = $key;
177 177
 		
178
-		parent::set($key, $values, $replace);
179
-	}
178
+        parent::set($key, $values, $replace);
179
+    }
180 180
 	
181
-	/**
182
-	 * Gets an array with all cookies.
183
-	 * 
184
-	 * @param  string  $format
185
-	 * 
186
-	 * @return Cookie[]
187
-	 * 
188
-	 * @throws \InvalidArgumentException
189
-	 */
190
-	public function getCookies(string $format = self::COOKIE_FLAT): array
191
-	{
192
-		if ( ! in_array($format, [self::COOKIE_FLAT, self::COOKIE_ARRAY])) {
193
-			throw new InvalidArgumentException(
194
-				sprintf('Format "%s" invalid (%s)', $format, implode(', ', [self::COOKIE_FLAT, self::COOKIE_ARRAY])
195
-			));
196
-		}
181
+    /**
182
+     * Gets an array with all cookies.
183
+     * 
184
+     * @param  string  $format
185
+     * 
186
+     * @return Cookie[]
187
+     * 
188
+     * @throws \InvalidArgumentException
189
+     */
190
+    public function getCookies(string $format = self::COOKIE_FLAT): array
191
+    {
192
+        if ( ! in_array($format, [self::COOKIE_FLAT, self::COOKIE_ARRAY])) {
193
+            throw new InvalidArgumentException(
194
+                sprintf('Format "%s" invalid (%s)', $format, implode(', ', [self::COOKIE_FLAT, self::COOKIE_ARRAY])
195
+            ));
196
+        }
197 197
 		
198
-		if (self::COOKIE_ARRAY === $format) {
199
-			return $this->cookies;
200
-		}
198
+        if (self::COOKIE_ARRAY === $format) {
199
+            return $this->cookies;
200
+        }
201 201
 		
202
-		$stringCookies = [];
203
-
204
-		foreach ($this->cookies as $path) {
205
-			foreach ($path as $cookies) {
206
-				foreach ($cookies as $cookie) {
207
-					$stringCookies[] = $cookie;
208
-				}
209
-			}
210
-		}
202
+        $stringCookies = [];
203
+
204
+        foreach ($this->cookies as $path) {
205
+            foreach ($path as $cookies) {
206
+                foreach ($cookies as $cookie) {
207
+                    $stringCookies[] = $cookie;
208
+                }
209
+            }
210
+        }
211 211
 		
212
-		return $stringCookies;
212
+        return $stringCookies;
213 213
     }
214 214
 
215
-	/**
216
-	 * Sets the cookie.
217
-	 * 
218
-	 * @param  \Syscodes\Components\Http\Cookie  $cookie
219
-	 * 
220
-	 * @return static
221
-	 */
222
-	public function setCookie(Cookie $cookie): static
223
-	{
224
-		$this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
225
-		$this->headerNames['set-cookie'] = 'Set-Cookie';
226
-
227
-		return $this;
228
-	}
229
-
230
-	/**
231
-	 * Initialize the date.
232
-	 * 
233
-	 * @return void
234
-	 */
235
-	private function initDate(): void
236
-	{
237
-		$this->set('Date', gmdate('D, d M Y H:i:s').' GMT');
238
-	}
215
+    /**
216
+     * Sets the cookie.
217
+     * 
218
+     * @param  \Syscodes\Components\Http\Cookie  $cookie
219
+     * 
220
+     * @return static
221
+     */
222
+    public function setCookie(Cookie $cookie): static
223
+    {
224
+        $this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
225
+        $this->headerNames['set-cookie'] = 'Set-Cookie';
226
+
227
+        return $this;
228
+    }
229
+
230
+    /**
231
+     * Initialize the date.
232
+     * 
233
+     * @return void
234
+     */
235
+    private function initDate(): void
236
+    {
237
+        $this->set('Date', gmdate('D, d M Y H:i:s').' GMT');
238
+    }
239 239
 }
240 240
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Http/Resources/HttpResources.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -29,211 +29,211 @@
 block discarded – undo
29 29
  */
30 30
 trait HttpResources
31 31
 {
32
-	/**
33
-	 * Filters a value from the start of a string in this case the passed URI string.
34
-	 *
35
-	 * @return string
36
-	 */
37
-	protected function parseRequestUri(): string
38
-	{
39
-		$requestUri = '';
40
-		
41
-		if ('1' == $this->server->get('IIS_WasUrlRewritten') && '' != $this->server->get('UNENCODED_URL')) {
42
-			// IIS7 with URL Rewrite: make sure we get the unencoded URL (double slash problem)
43
-			$requestUri = $this->server->get('UNENCODED_URL');
44
-			$this->server->remove('UNENCODED_URL');
45
-			$this->server->remove('IIS_WasUrlRewritten');
46
-		} elseif ($this->server->has('REQUEST_URI')) {
47
-			$requestUri = $this->server->get('REQUEST_URI');
32
+    /**
33
+     * Filters a value from the start of a string in this case the passed URI string.
34
+     *
35
+     * @return string
36
+     */
37
+    protected function parseRequestUri(): string
38
+    {
39
+        $requestUri = '';
40
+		
41
+        if ('1' == $this->server->get('IIS_WasUrlRewritten') && '' != $this->server->get('UNENCODED_URL')) {
42
+            // IIS7 with URL Rewrite: make sure we get the unencoded URL (double slash problem)
43
+            $requestUri = $this->server->get('UNENCODED_URL');
44
+            $this->server->remove('UNENCODED_URL');
45
+            $this->server->remove('IIS_WasUrlRewritten');
46
+        } elseif ($this->server->has('REQUEST_URI')) {
47
+            $requestUri = $this->server->get('REQUEST_URI');
48 48
 			
49
-			if ('' !== $requestUri && '/' === $requestUri[0]) {
50
-				// To only use path and query remove the fragment.
51
-				if (false !== $pos = strpos($requestUri, '#')) {
52
-					$requestUri = substr($requestUri, 0, $pos);
53
-				}
54
-			} else {
55
-				// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
56
-				// only use URL path.
57
-				$uriComponents = parse_url($requestUri);
49
+            if ('' !== $requestUri && '/' === $requestUri[0]) {
50
+                // To only use path and query remove the fragment.
51
+                if (false !== $pos = strpos($requestUri, '#')) {
52
+                    $requestUri = substr($requestUri, 0, $pos);
53
+                }
54
+            } else {
55
+                // HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
56
+                // only use URL path.
57
+                $uriComponents = parse_url($requestUri);
58 58
 				
59
-				if (isset($uriComponents['path'])) {
60
-					$requestUri = $uriComponents['path'];
61
-				}
59
+                if (isset($uriComponents['path'])) {
60
+                    $requestUri = $uriComponents['path'];
61
+                }
62 62
 				
63
-				if (isset($uriComponents['query'])) {
64
-					$requestUri .= '?'.$uriComponents['query'];
65
-				}
66
-			}
67
-		} elseif ($this->server->has('ORIG_PATH_INFO')) {
68
-			// IIS 5.0, PHP as CGI
69
-			$requestUri = $this->server->get('ORIG_PATH_INFO');
63
+                if (isset($uriComponents['query'])) {
64
+                    $requestUri .= '?'.$uriComponents['query'];
65
+                }
66
+            }
67
+        } elseif ($this->server->has('ORIG_PATH_INFO')) {
68
+            // IIS 5.0, PHP as CGI
69
+            $requestUri = $this->server->get('ORIG_PATH_INFO');
70 70
 			
71
-			if ('' != $this->server->get('QUERY_STRING')) {
72
-				$requestUri .= '?'.$this->server->get('QUERY_STRING');
73
-			}
71
+            if ('' != $this->server->get('QUERY_STRING')) {
72
+                $requestUri .= '?'.$this->server->get('QUERY_STRING');
73
+            }
74 74
 			
75
-			$this->server->remove('ORIG_PATH_INFO');
76
-		}
75
+            $this->server->remove('ORIG_PATH_INFO');
76
+        }
77 77
 		
78
-		// normalize the request URI to ease creating sub-requests from this request
79
-		$this->server->set('REQUEST_URI', $requestUri);
78
+        // normalize the request URI to ease creating sub-requests from this request
79
+        $this->server->set('REQUEST_URI', $requestUri);
80 80
 		
81
-		return $this->filterDecode($requestUri);
82
-	}
81
+        return $this->filterDecode($requestUri);
82
+    }
83 83
 
84
-	/**
85
-	 * Will parse QUERY_STRING and automatically detect the URI from it.
86
-	 * 
87
-	 * @return string
88
-	 */
89
-	protected function parseQueryString(): string
90
-	{
91
-		$uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');
84
+    /**
85
+     * Will parse QUERY_STRING and automatically detect the URI from it.
86
+     * 
87
+     * @return string
88
+     */
89
+    protected function parseQueryString(): string
90
+    {
91
+        $uri = $_SERVER['QUERY_STRING'] ?? @getenv('QUERY_STRING');
92 92
 
93
-		if (trim($uri, '/') === '') {
94
-			return '';
95
-		} elseif (0 === strncmp($uri, '/', 1)) {
96
-			$uri    				 = explode('?', $uri, 2);
97
-			$_SERVER['QUERY_STRING'] = $uri[1] ?? '';
98
-			$uri    				 = $uri[0] ?? '';
99
-		}
93
+        if (trim($uri, '/') === '') {
94
+            return '';
95
+        } elseif (0 === strncmp($uri, '/', 1)) {
96
+            $uri    				 = explode('?', $uri, 2);
97
+            $_SERVER['QUERY_STRING'] = $uri[1] ?? '';
98
+            $uri    				 = $uri[0] ?? '';
99
+        }
100 100
 
101
-		parse_str($_SERVER['QUERY_STRING'], $_GET);
101
+        parse_str($_SERVER['QUERY_STRING'], $_GET);
102 102
 
103
-		return $this->filterDecode($uri);
104
-	}
103
+        return $this->filterDecode($uri);
104
+    }
105 105
 	
106
-	/**
107
-	 * Parse the base URL.
108
-	 * 
109
-	 * @return string
110
-	 */
111
-	public function parseBaseUrl(): string
112
-	{
113
-		$filename = basename($this->server('SCRIPT_FILENAME'));
114
-		
115
-		if ($filename === basename($this->server('SCRIPT_NAME'))) {
116
-			$baseUrl = $this->server('SCRIPT_NAME');
117
-		} elseif ($filename === basename($this->server('PHP_SELF'))) {
118
-			$baseUrl = $this->server('PHP_SELF');
119
-		} elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME'))) {
120
-			$baseUrl = $this->server('ORIG_SCRIPT_NAME');
121
-		} else {
122
-			$path    = $this->server('PHP_SELF', '');
123
-			$file    = $this->server('SCRIPT_NAME', '');
124
-			$segs    = explode('/', trim($file, '/'));
125
-			$segs    = array_reverse($segs);
126
-			$index   = 0;
127
-			$last    = count($segs);
128
-			$baseUrl = '';
106
+    /**
107
+     * Parse the base URL.
108
+     * 
109
+     * @return string
110
+     */
111
+    public function parseBaseUrl(): string
112
+    {
113
+        $filename = basename($this->server('SCRIPT_FILENAME'));
114
+		
115
+        if ($filename === basename($this->server('SCRIPT_NAME'))) {
116
+            $baseUrl = $this->server('SCRIPT_NAME');
117
+        } elseif ($filename === basename($this->server('PHP_SELF'))) {
118
+            $baseUrl = $this->server('PHP_SELF');
119
+        } elseif ($filename === basename($this->server('ORIG_SCRIPT_NAME'))) {
120
+            $baseUrl = $this->server('ORIG_SCRIPT_NAME');
121
+        } else {
122
+            $path    = $this->server('PHP_SELF', '');
123
+            $file    = $this->server('SCRIPT_NAME', '');
124
+            $segs    = explode('/', trim($file, '/'));
125
+            $segs    = array_reverse($segs);
126
+            $index   = 0;
127
+            $last    = count($segs);
128
+            $baseUrl = '';
129 129
 			
130
-			do 	{
131
-				$seg     = $segs[$index];
132
-				$baseUrl = '/'.$seg.$baseUrl;
133
-				++$index;
134
-			} while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
135
-		}
136
-		
137
-		// Does the baseUrl have anything in common with the request_uri?
138
-		$requestUri = $this->getRequestUri();
139
-		
140
-		if ('' !== $requestUri && '/' !== $requestUri[0]) {
141
-			$requestUri = '/'.$requestUri;
142
-		}
143
-		
144
-		if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, $baseUrl)) {
145
-			// Full $baseUrl matches
146
-			return $this->filterDecode($uri);
147
-		}
148
-		
149
-		if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, rtrim(dirname($baseUrl), '/'.DIRECTORY_SEPARATOR))) {
150
-			// Directory portion of $baseUrl matches
151
-			return $this->filterDecode($uri);
152
-		}
130
+            do 	{
131
+                $seg     = $segs[$index];
132
+                $baseUrl = '/'.$seg.$baseUrl;
133
+                ++$index;
134
+            } while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
135
+        }
136
+		
137
+        // Does the baseUrl have anything in common with the request_uri?
138
+        $requestUri = $this->getRequestUri();
139
+		
140
+        if ('' !== $requestUri && '/' !== $requestUri[0]) {
141
+            $requestUri = '/'.$requestUri;
142
+        }
143
+		
144
+        if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, $baseUrl)) {
145
+            // Full $baseUrl matches
146
+            return $this->filterDecode($uri);
147
+        }
148
+		
149
+        if ($baseUrl && null !== $uri = $this->getUrlencoded($requestUri, rtrim(dirname($baseUrl), '/'.DIRECTORY_SEPARATOR))) {
150
+            // Directory portion of $baseUrl matches
151
+            return $this->filterDecode($uri);
152
+        }
153 153
 
154
-		$baseUrl = dirname($baseUrl ?? '');
154
+        $baseUrl = dirname($baseUrl ?? '');
155 155
 		
156
-		// If using mod_rewrite or ISAPI_Rewrite strip the script filename
157
-		// out of baseUrl. $pos !== 0 makes sure it is not matching a value
158
-		// from PATH_INFO or QUERY_STRING
159
-		if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && 0 !== $pos) {
160
-			$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
161
-		}
156
+        // If using mod_rewrite or ISAPI_Rewrite strip the script filename
157
+        // out of baseUrl. $pos !== 0 makes sure it is not matching a value
158
+        // from PATH_INFO or QUERY_STRING
159
+        if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && 0 !== $pos) {
160
+            $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
161
+        }
162 162
 		
163
-		return $this->filterDecode($baseUrl);
164
-	}
163
+        return $this->filterDecode($baseUrl);
164
+    }
165 165
 	
166
-	/**
167
-	 * Returns the prefix as encoded in the string when the string starts with
168
-	 * the given prefix, null otherwise.
169
-	 *
170
-	 * return string|null
171
-	 */
172
-	private function getUrlencoded(string $string, string $prefix): ?string
173
-	{
174
-		if ( ! Str::startsWith(rawurldecode($string), $prefix)) {
175
-			return null;
176
-		}
177
-		
178
-		$length = strlen($prefix);
179
-		
180
-		if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $length), $string, $match)) {
181
-			return $match[0];
182
-		}
183
-		
184
-		return null;
185
-	}
166
+    /**
167
+     * Returns the prefix as encoded in the string when the string starts with
168
+     * the given prefix, null otherwise.
169
+     *
170
+     * return string|null
171
+     */
172
+    private function getUrlencoded(string $string, string $prefix): ?string
173
+    {
174
+        if ( ! Str::startsWith(rawurldecode($string), $prefix)) {
175
+            return null;
176
+        }
177
+		
178
+        $length = strlen($prefix);
179
+		
180
+        if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $length), $string, $match)) {
181
+            return $match[0];
182
+        }
183
+		
184
+        return null;
185
+    }
186 186
 
187 187
 
188
-	/**
189
-	 * Parse the path info.
190
-	 * 
191
-	 * @return string
192
-	 */
193
-	public function parsePathInfo(): string
194
-	{
195
-		if (null === ($requestUri = $this->getRequestUri())) {
196
-			return '/';
197
-		}
198
-		
199
-		// Remove the query string from REQUEST_URI
200
-		if (false !== $pos = strpos($requestUri, '?')) {
201
-			$requestUri = substr($requestUri, 0, $pos);
202
-		}
203
-		
204
-		if ('' !== $requestUri && '/' !== $requestUri[0]) {
205
-			$requestUri = '/'.$requestUri;
206
-		}
207
-		
208
-		if (null === ($baseUrl = $this->getBaseUrl())) {
209
-			return $requestUri;
210
-		}
211
-		
212
-		$pathInfo = substr($requestUri, \strlen($baseUrl));
213
-		
214
-		if (false === $pathInfo || '' === $pathInfo) {
215
-			// If substr() returns false then PATH_INFO is set to an empty string
216
-			return '/';
217
-		}
218
-		
219
-		return $this->filterDecode($pathInfo);
220
-	}
188
+    /**
189
+     * Parse the path info.
190
+     * 
191
+     * @return string
192
+     */
193
+    public function parsePathInfo(): string
194
+    {
195
+        if (null === ($requestUri = $this->getRequestUri())) {
196
+            return '/';
197
+        }
198
+		
199
+        // Remove the query string from REQUEST_URI
200
+        if (false !== $pos = strpos($requestUri, '?')) {
201
+            $requestUri = substr($requestUri, 0, $pos);
202
+        }
203
+		
204
+        if ('' !== $requestUri && '/' !== $requestUri[0]) {
205
+            $requestUri = '/'.$requestUri;
206
+        }
207
+		
208
+        if (null === ($baseUrl = $this->getBaseUrl())) {
209
+            return $requestUri;
210
+        }
211
+		
212
+        $pathInfo = substr($requestUri, \strlen($baseUrl));
213
+		
214
+        if (false === $pathInfo || '' === $pathInfo) {
215
+            // If substr() returns false then PATH_INFO is set to an empty string
216
+            return '/';
217
+        }
218
+		
219
+        return $this->filterDecode($pathInfo);
220
+    }
221 221
 
222
-	/**
223
-	 * Filters the uri string remove any malicious characters and inappropriate slashes.
224
-	 *
225
-	 * @param  string  $uri
226
-	 *
227
-	 * @return string
228
-	 */
229
-	protected function filterDecode($uri): string
230
-	{
231
-		// Remove all characters except letters,
232
-		// digits and $-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=.
233
-		$uri = filter_var(rawurldecode($uri), FILTER_SANITIZE_URL);
234
-		$uri = mb_strtolower(trim($uri), 'UTF-8');
235
-		
236
-		// Return argument if not empty or return a single slash
237
-		return trim($uri);
238
-	}
222
+    /**
223
+     * Filters the uri string remove any malicious characters and inappropriate slashes.
224
+     *
225
+     * @param  string  $uri
226
+     *
227
+     * @return string
228
+     */
229
+    protected function filterDecode($uri): string
230
+    {
231
+        // Remove all characters except letters,
232
+        // digits and $-_.+!*'(),{}|\\^~[]`<>#%";/?:@&=.
233
+        $uri = filter_var(rawurldecode($uri), FILTER_SANITIZE_URL);
234
+        $uri = mb_strtolower(trim($uri), 'UTF-8');
235
+		
236
+        // Return argument if not empty or return a single slash
237
+        return trim($uri);
238
+    }
239 239
 }
240 240
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@
 block discarded – undo
127 127
 			$last    = count($segs);
128 128
 			$baseUrl = '';
129 129
 			
130
-			do 	{
130
+			do {
131 131
 				$seg     = $segs[$index];
132 132
 				$baseUrl = '/'.$seg.$baseUrl;
133 133
 				++$index;
Please login to merge, or discard this patch.