Passed
Push — 0.7.0 ( a316e5...a89e02 )
by Alexander
03:01
created
src/components/Database/Connectors/SqlServerConnector.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -76,8 +76,7 @@
 block discarded – undo
76 76
         if (in_array('dblib', $this->getAvailableDrivers()))
77 77
         {
78 78
             return "dblib:host={$host}{$port};dbname={$database}";
79
-        } 
80
-        else 
79
+        } else 
81 80
         {
82 81
             $dbName = $database != '' ? ";Database={$database}" : '';
83 82
             
Please login to merge, or discard this patch.
src/components/Routing/RouteFileRegister.php 1 patch
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,6 @@
 block discarded – undo
41 41
      * Create a new route file registrar instance.
42 42
      *
43 43
      * @param  \Syscodes\Routing\Router  $router
44
-
45 44
      * @return void
46 45
      */
47 46
     public function __construct(Router $router)
Please login to merge, or discard this patch.
src/components/Routing/RouteGroup.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -32,100 +32,100 @@
 block discarded – undo
32 32
  */
33 33
 class RouteGroup
34 34
 {
35
- 	/**
36
-	 * Merge the given group attributes.
37
-	 * 
38
-	 * @param  array  $new
39
-	 * @param  array  $old
40
-	 * 
41
-	 * @return array
42
-	 */
43
-	public static function mergeGroup($new, $old)
44
-	{
45
-		if (isset($new['domain']))
46
-		{
47
-			unset($old['domain']);
48
-		}
35
+        /**
36
+         * Merge the given group attributes.
37
+         * 
38
+         * @param  array  $new
39
+         * @param  array  $old
40
+         * 
41
+         * @return array
42
+         */
43
+    public static function mergeGroup($new, $old)
44
+    {
45
+        if (isset($new['domain']))
46
+        {
47
+            unset($old['domain']);
48
+        }
49 49
 
50
-		$new = array_merge(static::formatUseAs($new, $old), [
50
+        $new = array_merge(static::formatUseAs($new, $old), [
51 51
             'namespace' => static::formatUseNamespace($new, $old),
52 52
             'prefix' => static::formatUsePrefix($new, $old),
53 53
             'where' => static::formatUseWhere($new, $old)
54 54
         ]);
55 55
 		
56
-		return array_merge_recursive(
57
-			Arr::except($old, array('namespace', 'prefix', 'where', 'as')), $new
58
-		);
59
-	}
56
+        return array_merge_recursive(
57
+            Arr::except($old, array('namespace', 'prefix', 'where', 'as')), $new
58
+        );
59
+    }
60 60
 
61
-	/**
62
-	 * Format the uses namespace for the new group attributes.
63
-	 * 
64
-	 * @param  array  $new
65
-	 * @param  array  $old
66
-	 * 
67
-	 * @return string|null
68
-	 */
69
-	protected static function formatUseNamespace($new, $old)
70
-	{
71
-		if (isset($new['namespace']))
72
-		{
73
-			return isset($old['namespace'])
74
-				   ? trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\')
75
-				   : trim($new['namespace'], '\\');
76
-		}
61
+    /**
62
+     * Format the uses namespace for the new group attributes.
63
+     * 
64
+     * @param  array  $new
65
+     * @param  array  $old
66
+     * 
67
+     * @return string|null
68
+     */
69
+    protected static function formatUseNamespace($new, $old)
70
+    {
71
+        if (isset($new['namespace']))
72
+        {
73
+            return isset($old['namespace'])
74
+                   ? trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\')
75
+                   : trim($new['namespace'], '\\');
76
+        }
77 77
 
78
-		return $old['namespace'] ?? null;
79
-	}
78
+        return $old['namespace'] ?? null;
79
+    }
80 80
 
81
-	/**
82
-	 * Format the prefix for the new group attributes.
83
-	 * 
84
-	 * @param  array  $new
85
-	 * @param  array  $old
86
-	 * 
87
-	 * @return string|null
88
-	 */
89
-	protected static function formatUsePrefix($new, $old)
90
-	{
91
-		$old = $old['prefix'] ?? null;
81
+    /**
82
+     * Format the prefix for the new group attributes.
83
+     * 
84
+     * @param  array  $new
85
+     * @param  array  $old
86
+     * 
87
+     * @return string|null
88
+     */
89
+    protected static function formatUsePrefix($new, $old)
90
+    {
91
+        $old = $old['prefix'] ?? null;
92 92
 
93
-		return isset($new['prefix']) 
94
-					? trim($old, '/').'/'.trim($new['prefix'], '/')
95
-					: $old;
96
-	}
93
+        return isset($new['prefix']) 
94
+                    ? trim($old, '/').'/'.trim($new['prefix'], '/')
95
+                    : $old;
96
+    }
97 97
 
98
-	/**
99
-	 * Format the "wheres" for the new group attributes.
100
-	 * 
101
-	 * @param  array  $new
102
-	 * @param  array  $old
103
-	 * 
104
-	 * @return array
105
-	 */
106
-	protected static function formatUseWhere($new, $old)
107
-	{
108
-		return array_merge(
109
-			$old['where'] ?? [],
110
-			$new['where'] ?? []
111
-		);
112
-	}
98
+    /**
99
+     * Format the "wheres" for the new group attributes.
100
+     * 
101
+     * @param  array  $new
102
+     * @param  array  $old
103
+     * 
104
+     * @return array
105
+     */
106
+    protected static function formatUseWhere($new, $old)
107
+    {
108
+        return array_merge(
109
+            $old['where'] ?? [],
110
+            $new['where'] ?? []
111
+        );
112
+    }
113 113
 
114
-	/**
115
-	 * Format the "as" clause of the new group attributes.
116
-	 * 
117
-	 * @param  array  $new
118
-	 * @param  array  $old
119
-	 * 
120
-	 * @return array
121
-	 */
122
-	protected static function formatUseAs($new, $old)
123
-	{
124
-		if (isset($old['as'])) 
125
-		{
114
+    /**
115
+     * Format the "as" clause of the new group attributes.
116
+     * 
117
+     * @param  array  $new
118
+     * @param  array  $old
119
+     * 
120
+     * @return array
121
+     */
122
+    protected static function formatUseAs($new, $old)
123
+    {
124
+        if (isset($old['as'])) 
125
+        {
126 126
             $new['as'] = $old['as'].($new['as'] ?? '');
127 127
         }
128 128
 
129
-		return $new;
130
-	}
129
+        return $new;
130
+    }
131 131
 }
132 132
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Routing/RoutingServiceProvider.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected function registerRouter()
55 55
     {
56
-        $this->app->singleton('router', function ($app) {
56
+        $this->app->singleton('router', function($app) {
57 57
             return new Router($app);
58 58
         });
59 59
     }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      */
78 78
     protected function registerUrlGenerator()
79 79
     {
80
-        $this->app->singleton('url', function ($app) {
80
+        $this->app->singleton('url', function($app) {
81 81
             
82 82
             $routes = $app['router']->getRoutes();
83 83
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     protected function registerRedirector()
95 95
     {
96
-        $this->app->singleton('redirect', function ($app) {
96
+        $this->app->singleton('redirect', function($app) {
97 97
             return new Redirector($app['url']);
98 98
         });
99 99
     }
Please login to merge, or discard this patch.
src/components/Routing/Route.php 3 patches
Indentation   +666 added lines, -666 removed lines patch added patch discarded remove patch
@@ -41,686 +41,686 @@
 block discarded – undo
41 41
  */
42 42
 class Route 
43 43
 {
44
-	use Concerns\RouteCondition,
45
-	    Concerns\RouteDependencyResolver;
44
+    use Concerns\RouteCondition,
45
+        Concerns\RouteDependencyResolver;
46 46
 	
47
-	/**
48
-	 * Action that the route will use when called.
49
-	 *
50
-	 * @var \Closure|string|array $action
51
-	 */
52
-	public $action;
53
-
54
-	/**
55
-	 * The container instance used by the route.
56
-	 * 
57
-	 * @var \Syscodes\Container\Container $container
58
-	 */
59
-	protected $container;
60
-
61
-	/**
62
-	 * The controller instance.
63
-	 * 
64
-	 * @var string $controller
65
-	 */
66
-	public $controller;
67
-
68
-	/**
69
-	 * The default values for the route.
70
-	 * 
71
-	 * @var array $defaults
72
-	 */
73
-	public $defaults = [];
74
-
75
-	/**
76
-	 * Variable of HTTP method.
77
-	 *  
78
-	 * @var array|string $method
79
-	 */
80
-	public $method;
81
-
82
-	/**
83
-	 * The array of matched parameters.
84
-	 * 
85
-	 * @var array $parameters
86
-	 */
87
-	public $parameters = [];
88
-
89
-	/**
90
-	 * The parameter names for the route.
91
-	 * 
92
-	 * @var string|null $parameterNames
93
-	 */
94
-	public $parameterNames;
95
-
96
-	/**
97
-	* Patterns that should be replaced.
98
-	*
99
-	* @var array $patterns 
100
-	*/
101
-	public $patterns = [
102
-		'~/~'                    =>  '\/',               // Slash
103
-		'~{an:[^\/{}]+}~'        => '([0-9a-zA-Z]++)',   // Placeholder accepts alphabetic and numeric chars
104
-		'~{n:[^\/{}]+}~'         => '([0-9]++)',         // Placeholder accepts only numeric
105
-		'~{a:[^\/{}]+}~'         => '([a-zA-Z]++)',      // Placeholder accepts only alphabetic chars
106
-		'~{w:[^\/{}]+}~'         => '([0-9a-zA-Z-_]++)', // Placeholder accepts alphanumeric and underscore
107
-		'~{\*:[^\/{}]+}~'        => '(.++)',             // Placeholder match rest of url
108
-		'~(\\\/)?{\?:[^\/{}]+}~' => '\/?([^\/]*)',		 // Optional placeholder
109
-		'~{[^\/{}]+}~'           => '([^\/]++)'			 // Normal placeholder
110
-	];
111
-
112
-	/**
113
-	 * The URI pattern the route responds to.
114
-	 *
115
-	 * @var array $uri
116
-	 */
117
-	public $uri = [];
118
-
119
-	/**
120
-	 * Contains the arguments of the current route.
121
-	 *
122
-	 * @var array $where
123
-	 */
124
-	public $wheres = [];
125
-
126
-	/**
127
-	 * Constructor. Initialize route.
128
-	 *
129
-	 * @param  array|string|null  $method  (null by default)
130
-	 * @param  string|null  $uri  (null by default)
131
-	 * @param  \Closure|string|null  $action  (null by default)
132
-	 *
133
-	 * @return void
134
-	 */
135
-	public function __construct($method = null, $uri = null, $action = null)
136
-	{
137
-		$this->uri = $uri;
138
-
139
-		// Set the method
140
-		$this->parseMethod($method);
141
-
142
-		// Set the action
143
-		$this->parseAction($action);
144
-
145
-		if (is_null($prefix = Arr::get($this->action, 'prefix')))
146
-		{
147
-			$this->prefix($prefix);
148
-		}
149
-	}
150
-
151
-	// Getters
152
-
153
-	/**
154
-	 * Get the action of the current route.
155
-	 *
156
-	 * @return \Closure|string
157
-	 */
158
-	public function getAction()
159
-	{
160
-		return $this->action;
161
-	}
162
-
163
-	/**
164
-	 * Get the arguments of the current route.
165
-	 *
166
-	 * @return string
167
-	 */
168
-	public function getArguments()
169
-	{
170
-		return $this->wheres;
171
-	}
172
-
173
-	/**
174
-	 * Get the controller instance for the route.
175
-	 * 
176
-	 * @return mixed
177
-	 */
178
-	public function getController()
179
-	{
180
-		if ( ! $this->controller)
181
-		{
182
-			$class = $this->parseControllerCallback()[0];
47
+    /**
48
+     * Action that the route will use when called.
49
+     *
50
+     * @var \Closure|string|array $action
51
+     */
52
+    public $action;
53
+
54
+    /**
55
+     * The container instance used by the route.
56
+     * 
57
+     * @var \Syscodes\Container\Container $container
58
+     */
59
+    protected $container;
60
+
61
+    /**
62
+     * The controller instance.
63
+     * 
64
+     * @var string $controller
65
+     */
66
+    public $controller;
67
+
68
+    /**
69
+     * The default values for the route.
70
+     * 
71
+     * @var array $defaults
72
+     */
73
+    public $defaults = [];
74
+
75
+    /**
76
+     * Variable of HTTP method.
77
+     *  
78
+     * @var array|string $method
79
+     */
80
+    public $method;
81
+
82
+    /**
83
+     * The array of matched parameters.
84
+     * 
85
+     * @var array $parameters
86
+     */
87
+    public $parameters = [];
88
+
89
+    /**
90
+     * The parameter names for the route.
91
+     * 
92
+     * @var string|null $parameterNames
93
+     */
94
+    public $parameterNames;
95
+
96
+    /**
97
+     * Patterns that should be replaced.
98
+     *
99
+     * @var array $patterns 
100
+     */
101
+    public $patterns = [
102
+        '~/~'                    =>  '\/',               // Slash
103
+        '~{an:[^\/{}]+}~'        => '([0-9a-zA-Z]++)',   // Placeholder accepts alphabetic and numeric chars
104
+        '~{n:[^\/{}]+}~'         => '([0-9]++)',         // Placeholder accepts only numeric
105
+        '~{a:[^\/{}]+}~'         => '([a-zA-Z]++)',      // Placeholder accepts only alphabetic chars
106
+        '~{w:[^\/{}]+}~'         => '([0-9a-zA-Z-_]++)', // Placeholder accepts alphanumeric and underscore
107
+        '~{\*:[^\/{}]+}~'        => '(.++)',             // Placeholder match rest of url
108
+        '~(\\\/)?{\?:[^\/{}]+}~' => '\/?([^\/]*)',		 // Optional placeholder
109
+        '~{[^\/{}]+}~'           => '([^\/]++)'			 // Normal placeholder
110
+    ];
111
+
112
+    /**
113
+     * The URI pattern the route responds to.
114
+     *
115
+     * @var array $uri
116
+     */
117
+    public $uri = [];
118
+
119
+    /**
120
+     * Contains the arguments of the current route.
121
+     *
122
+     * @var array $where
123
+     */
124
+    public $wheres = [];
125
+
126
+    /**
127
+     * Constructor. Initialize route.
128
+     *
129
+     * @param  array|string|null  $method  (null by default)
130
+     * @param  string|null  $uri  (null by default)
131
+     * @param  \Closure|string|null  $action  (null by default)
132
+     *
133
+     * @return void
134
+     */
135
+    public function __construct($method = null, $uri = null, $action = null)
136
+    {
137
+        $this->uri = $uri;
138
+
139
+        // Set the method
140
+        $this->parseMethod($method);
141
+
142
+        // Set the action
143
+        $this->parseAction($action);
144
+
145
+        if (is_null($prefix = Arr::get($this->action, 'prefix')))
146
+        {
147
+            $this->prefix($prefix);
148
+        }
149
+    }
150
+
151
+    // Getters
152
+
153
+    /**
154
+     * Get the action of the current route.
155
+     *
156
+     * @return \Closure|string
157
+     */
158
+    public function getAction()
159
+    {
160
+        return $this->action;
161
+    }
162
+
163
+    /**
164
+     * Get the arguments of the current route.
165
+     *
166
+     * @return string
167
+     */
168
+    public function getArguments()
169
+    {
170
+        return $this->wheres;
171
+    }
172
+
173
+    /**
174
+     * Get the controller instance for the route.
175
+     * 
176
+     * @return mixed
177
+     */
178
+    public function getController()
179
+    {
180
+        if ( ! $this->controller)
181
+        {
182
+            $class = $this->parseControllerCallback()[0];
183 183
  
184
-			$this->controller = $this->container->make(ltrim($class, '\\'));
185
-		}
186
-
187
-		return $this->controller;
188
-	}
189
-
190
-	/**
191
-	 * Get the controller method used for the route.
192
-	 * 
193
-	 * @return string
194
-	 */
195
-	public function getControllerMethod()
196
-	{
197
-		return $this->parseControllerCallback()[1];
198
-	}
199
-
200
-	/**
201
-	 * Get the request method of the current route.
202
-	 *
203
-	 * @return array
204
-	 */
205
-	public function getMethod()
206
-	{
207
-		return $this->method;
208
-	}
209
-
210
-	/**
211
-	 * Get the url of the current route.
212
-	 *
213
-	 * @return string
214
-	 */
215
-	public function getName()
216
-	{
217
-		return $this->action['as'] ?? null;
218
-	}
219
-
220
-	/**
221
-	 * Get the url of the current route.
222
-	 *
223
-	 * @return string
224
-	 */
225
-	public function getRoute()
226
-	{
227
-		return $this->uri;
228
-	}
229
-
230
-	/**
231
-	 * Get or set the domain for the route.
232
-	 * 
233
-	 * @param  string|null  $domain  (null by default)
234
-	 * 
235
-	 * @return $this
236
-	 */
237
-	public function domain($domain = null)
238
-	{
239
-		if (is_null($domain))
240
-		{
241
-			return $this->getDomain();
242
-		}
243
-
244
-		$this->action['domain'] = $this->parseRoute($domain);
245
-
246
-		return $this;
247
-	}
248
-
249
-	/**
250
-	 * Get the domain defined for the route.
251
-	 * 
252
-	 * @return string|null
253
-	 */
254
-	public function getDomain()
255
-	{
256
-		return isset($this->action['domain'])
257
-				? str_replace(['http://', 'https://'], '', $this->action['domain'])
258
-				: null;
259
-	}
260
-
261
-	/**
262
-	 * Parse the controller.
263
-	 * 
264
-	 * @return array
265
-	 */
266
-	public function parseControllerCallback()
267
-	{
268
-		return Str::parseCallback($this->action['uses']);
269
-	}
184
+            $this->controller = $this->container->make(ltrim($class, '\\'));
185
+        }
186
+
187
+        return $this->controller;
188
+    }
189
+
190
+    /**
191
+     * Get the controller method used for the route.
192
+     * 
193
+     * @return string
194
+     */
195
+    public function getControllerMethod()
196
+    {
197
+        return $this->parseControllerCallback()[1];
198
+    }
199
+
200
+    /**
201
+     * Get the request method of the current route.
202
+     *
203
+     * @return array
204
+     */
205
+    public function getMethod()
206
+    {
207
+        return $this->method;
208
+    }
209
+
210
+    /**
211
+     * Get the url of the current route.
212
+     *
213
+     * @return string
214
+     */
215
+    public function getName()
216
+    {
217
+        return $this->action['as'] ?? null;
218
+    }
219
+
220
+    /**
221
+     * Get the url of the current route.
222
+     *
223
+     * @return string
224
+     */
225
+    public function getRoute()
226
+    {
227
+        return $this->uri;
228
+    }
229
+
230
+    /**
231
+     * Get or set the domain for the route.
232
+     * 
233
+     * @param  string|null  $domain  (null by default)
234
+     * 
235
+     * @return $this
236
+     */
237
+    public function domain($domain = null)
238
+    {
239
+        if (is_null($domain))
240
+        {
241
+            return $this->getDomain();
242
+        }
243
+
244
+        $this->action['domain'] = $this->parseRoute($domain);
245
+
246
+        return $this;
247
+    }
248
+
249
+    /**
250
+     * Get the domain defined for the route.
251
+     * 
252
+     * @return string|null
253
+     */
254
+    public function getDomain()
255
+    {
256
+        return isset($this->action['domain'])
257
+                ? str_replace(['http://', 'https://'], '', $this->action['domain'])
258
+                : null;
259
+    }
260
+
261
+    /**
262
+     * Parse the controller.
263
+     * 
264
+     * @return array
265
+     */
266
+    public function parseControllerCallback()
267
+    {
268
+        return Str::parseCallback($this->action['uses']);
269
+    }
270 270
 	
271
-	/**
272
-	 * Checks whether the route's action is a controller.
273
-	 * 
274
-	 * @return bool
275
-	 */
276
-	public function isControllerAction()
277
-	{
278
-		return is_string($this->action['uses']);
279
-	}
280
-
281
-	/**
282
-	 * Get the dispatcher for the route's controller.
283
-	 * 
284
-	 * @return \Syscodes\Controller\ControllerDispacther
285
-	 */
286
-	private function controllerDispatcher()
287
-	{
288
-		return new ControllerDispatcher($this->container);
289
-	}
290
-
291
-	// Setters
271
+    /**
272
+     * Checks whether the route's action is a controller.
273
+     * 
274
+     * @return bool
275
+     */
276
+    public function isControllerAction()
277
+    {
278
+        return is_string($this->action['uses']);
279
+    }
280
+
281
+    /**
282
+     * Get the dispatcher for the route's controller.
283
+     * 
284
+     * @return \Syscodes\Controller\ControllerDispacther
285
+     */
286
+    private function controllerDispatcher()
287
+    {
288
+        return new ControllerDispatcher($this->container);
289
+    }
290
+
291
+    // Setters
292 292
 	
293
-	/**
294
-	 * Run the route action and return the response.
295
-	 * 
296
-	 * @return mixed
297
-	 */
298
-	public function runResolver()
299
-	{
300
-		$this->container = $this->container ?: new Container;
301
-
302
-		try
303
-		{
304
-			if ($this->isControllerAction())
305
-			{
306
-				return $this->runResolverController();
307
-			}
308
-
309
-			return $this->runResolverCallable();
310
-		}
311
-		catch (HttpResponseException $e)
312
-		{
313
-			return $e->getResponse();
314
-		}
315
-	}
316
-
317
-	/**
318
-	 * Run the route action and return the response.
319
-	 *  
320
-	 * @return mixed
321
-	 */
322
-	protected function runResolverCallable()
323
-	{
324
-		$callable = $this->action['uses'];
325
-
326
-		return $callable(...array_values($this->resolveMethodDependencies(
327
-			$this->parametersWithouNulls(), new ReflectionFunction($this->action['uses'])
328
-		)));
329
-	}
330
-
331
-	/**
332
-	 * Run the route action and return the response.
333
-	 * 
334
-	 * @return mixed
335
-	 */
336
-	protected function runResolverController()
337
-	{
338
-		return $this->controllerDispatcher()->dispatch($this, $this->getController(), $this->getControllerMethod());
339
-	}
340
-
341
-	/**
342
-	 * Set the action.
343
-	 *
344
-	 * @param  \Closure|string  $action
345
-	 *
346
-	 * @return $this
347
-	 *
348
-	 * @throws \InvalidArgumentException
349
-	 */
350
-	public function parseAction($action)
351
-	{
352
-		if ( ! (is_object($action) && ($action instanceof Closure)) && ($action === null || $action === ''))
353
-		{
354
-			throw new InvalidArgumentException(__('route.actionClosureOrFunction'));
355
-		}
356
-
357
-		$this->action = RouteAction::parse($this->uri, $action);
358
-
359
-		return $this;
360
-	}
361
-
362
-	/**
363
-	 * Set the method of the current route.
364
-	 *
365
-	 * @param  array  $method
366
-	 *
367
-	 * @return string $this
368
-	 * 
369
-	 * @throws \InvalidArgumentException
370
-	 */
371
-	public function parseMethod($method)
372
-	{
373
-		if ($method === null || ! is_array($method) || empty($method))
374
-		{
375
-			throw new InvalidArgumentException(__('route.methodNotProvided'));
293
+    /**
294
+     * Run the route action and return the response.
295
+     * 
296
+     * @return mixed
297
+     */
298
+    public function runResolver()
299
+    {
300
+        $this->container = $this->container ?: new Container;
301
+
302
+        try
303
+        {
304
+            if ($this->isControllerAction())
305
+            {
306
+                return $this->runResolverController();
307
+            }
308
+
309
+            return $this->runResolverCallable();
310
+        }
311
+        catch (HttpResponseException $e)
312
+        {
313
+            return $e->getResponse();
314
+        }
315
+    }
316
+
317
+    /**
318
+     * Run the route action and return the response.
319
+     *  
320
+     * @return mixed
321
+     */
322
+    protected function runResolverCallable()
323
+    {
324
+        $callable = $this->action['uses'];
325
+
326
+        return $callable(...array_values($this->resolveMethodDependencies(
327
+            $this->parametersWithouNulls(), new ReflectionFunction($this->action['uses'])
328
+        )));
329
+    }
330
+
331
+    /**
332
+     * Run the route action and return the response.
333
+     * 
334
+     * @return mixed
335
+     */
336
+    protected function runResolverController()
337
+    {
338
+        return $this->controllerDispatcher()->dispatch($this, $this->getController(), $this->getControllerMethod());
339
+    }
340
+
341
+    /**
342
+     * Set the action.
343
+     *
344
+     * @param  \Closure|string  $action
345
+     *
346
+     * @return $this
347
+     *
348
+     * @throws \InvalidArgumentException
349
+     */
350
+    public function parseAction($action)
351
+    {
352
+        if ( ! (is_object($action) && ($action instanceof Closure)) && ($action === null || $action === ''))
353
+        {
354
+            throw new InvalidArgumentException(__('route.actionClosureOrFunction'));
355
+        }
356
+
357
+        $this->action = RouteAction::parse($this->uri, $action);
358
+
359
+        return $this;
360
+    }
361
+
362
+    /**
363
+     * Set the method of the current route.
364
+     *
365
+     * @param  array  $method
366
+     *
367
+     * @return string $this
368
+     * 
369
+     * @throws \InvalidArgumentException
370
+     */
371
+    public function parseMethod($method)
372
+    {
373
+        if ($method === null || ! is_array($method) || empty($method))
374
+        {
375
+            throw new InvalidArgumentException(__('route.methodNotProvided'));
376 376
 			
377
-		}
377
+        }
378 378
 
379
-		foreach ($method as $httpMethod) 
380
-		{
381
-			if ( ! in_array($httpMethod, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'ANY']))	
382
-			{
383
-				throw new InvalidArgumentException(__('route.methodNotAllowed'));
379
+        foreach ($method as $httpMethod) 
380
+        {
381
+            if ( ! in_array($httpMethod, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'ANY']))	
382
+            {
383
+                throw new InvalidArgumentException(__('route.methodNotAllowed'));
384 384
 				
385
-			}
386
-		}
387
-
388
-	    $this->method = $method;
389
-
390
-	    return $this;
391
-	}
392
-
393
-	/**
394
-	 * Set the route.
395
-	 *
396
-	 * @param  string  $uri
397
-	 *
398
-	 * @return string
399
-	 *
400
-	 * @throws  \InvalidArgumentException
401
-	 */
402
-	public function parseRoute($uri)
403
-	{
404
-		if ($uri === null) 
405
-		{
406
-			throw new InvalidArgumentException(__('route.uriNotProvided'));
407
-		}	
408
-
409
-		$this->uri = $this->parseRoutePath($uri);
410
-
411
-		return $this;
412
-	}
413
-
414
-	/**
415
-	 * Replace word patterns with regex in route uri.
416
-	 * 
417
-	 * @param  string  $uri
418
-	 * 
419
-	 * @return string
420
-	 */
421
-	protected function parseRoutePath($uri)
422
-	{
423
-		$uri = trim($uri, '\/?');
424
-		$uri = trim($uri, '\/');
385
+            }
386
+        }
387
+
388
+        $this->method = $method;
389
+
390
+        return $this;
391
+    }
392
+
393
+    /**
394
+     * Set the route.
395
+     *
396
+     * @param  string  $uri
397
+     *
398
+     * @return string
399
+     *
400
+     * @throws  \InvalidArgumentException
401
+     */
402
+    public function parseRoute($uri)
403
+    {
404
+        if ($uri === null) 
405
+        {
406
+            throw new InvalidArgumentException(__('route.uriNotProvided'));
407
+        }	
408
+
409
+        $this->uri = $this->parseRoutePath($uri);
410
+
411
+        return $this;
412
+    }
413
+
414
+    /**
415
+     * Replace word patterns with regex in route uri.
416
+     * 
417
+     * @param  string  $uri
418
+     * 
419
+     * @return string
420
+     */
421
+    protected function parseRoutePath($uri)
422
+    {
423
+        $uri = trim($uri, '\/?');
424
+        $uri = trim($uri, '\/');
425 425
 		
426
-		preg_match_all('/\{([\w\:]+?)\??\}/', $uri, $matches);
426
+        preg_match_all('/\{([\w\:]+?)\??\}/', $uri, $matches);
427 427
 		
428
-		foreach ($matches[1] as $match)
429
-		{
430
-			if (strpos($match, ':') === false)
431
-			{
432
-				continue;
433
-			}
428
+        foreach ($matches[1] as $match)
429
+        {
430
+            if (strpos($match, ':') === false)
431
+            {
432
+                continue;
433
+            }
434 434
 			
435
-			$pattern  = array_keys($this->patterns);
436
-			$replace  = array_values($this->patterns);
437
-			$segments = explode(':', trim($match, '{}?'));
435
+            $pattern  = array_keys($this->patterns);
436
+            $replace  = array_values($this->patterns);
437
+            $segments = explode(':', trim($match, '{}?'));
438 438
 			
439
-			$uri = strpos($match, ':') !== false
440
-					? preg_replace($pattern, $replace, $uri)
441
-					: str_replace($match, '{'.$segments[0].'}', $uri);
442
-		}
439
+            $uri = strpos($match, ':') !== false
440
+                    ? preg_replace($pattern, $replace, $uri)
441
+                    : str_replace($match, '{'.$segments[0].'}', $uri);
442
+        }
443 443
 		
444
-		return $uri;
445
-	}
446
-
447
-	/**
448
-	 * Add a prefix to the route URI.
449
-	 * 
450
-	 * @param  string  $prefix
451
-	 * 
452
-	 * @return $this
453
-	 */
454
-	public function prefix($prefix)
455
-	{
456
-		if ( ! empty($newPrefix = trim(rtrim($prefix, '/').'/'.ltrim($this->action['prefix'] ?? '', '/'), '/'))) 
457
-		{
458
-			$this->action['prefix'] = $newPrefix;
459
-		}
444
+        return $uri;
445
+    }
446
+
447
+    /**
448
+     * Add a prefix to the route URI.
449
+     * 
450
+     * @param  string  $prefix
451
+     * 
452
+     * @return $this
453
+     */
454
+    public function prefix($prefix)
455
+    {
456
+        if ( ! empty($newPrefix = trim(rtrim($prefix, '/').'/'.ltrim($this->action['prefix'] ?? '', '/'), '/'))) 
457
+        {
458
+            $this->action['prefix'] = $newPrefix;
459
+        }
460 460
 		
461
-		$uri = rtrim($prefix, '/').'/'.ltrim($this->uri, '/');
461
+        $uri = rtrim($prefix, '/').'/'.ltrim($this->uri, '/');
462 462
 		
463
-		return $this->parseRoute($uri !== '/' ? trim($uri, '/') : $uri);
464
-	}
465
-
466
-	/**
467
-	 * Set the action array for the route.
468
-	 * 
469
-	 * @param  array  $action
470
-	 * 
471
-	 * @return $this
472
-	 */
473
-	public function setAction(array $action)
474
-	{
475
-		$this->action = $action;
476
-
477
-		if (isset($this->action['domain']))
478
-		{
479
-			$this->domain($this->action['domain']);
480
-		}
463
+        return $this->parseRoute($uri !== '/' ? trim($uri, '/') : $uri);
464
+    }
465
+
466
+    /**
467
+     * Set the action array for the route.
468
+     * 
469
+     * @param  array  $action
470
+     * 
471
+     * @return $this
472
+     */
473
+    public function setAction(array $action)
474
+    {
475
+        $this->action = $action;
476
+
477
+        if (isset($this->action['domain']))
478
+        {
479
+            $this->domain($this->action['domain']);
480
+        }
481 481
 		
482
-		return $this;
483
-	}
484
-
485
-	/**
486
-	 * Set the name.
487
-	 *
488
-	 * @param  string  $name
489
-	 *
490
-	 * @return string
491
-	 */
492
-	public function name($name)
493
-	{
494
-		$this->action['as'] = isset($this->action['as']) ? $this->action['as'].$name : $name;
495
-
496
-		return $this;
497
-	}
498
-
499
-	/**
500
-	 * Determine whether the route's name matches the given patterns.
501
-	 * 
502
-	 * @param  mixed  ...$patterns
503
-	 * 
504
-	 * @return bool
505
-	 */
506
-	public function named(...$patterns)
507
-	{
508
-		if (is_null($routeName = $this->getName()))
509
-		{
510
-			return false;
511
-		}
512
-
513
-		foreach ($patterns as $pattern)
514
-		{
515
-			if (Str::is($pattern, $routeName))
516
-			{
517
-				return true;
518
-			}
519
-		}
520
-
521
-		return false;
522
-	}
523
-
524
-	/**
525
-	 * Set a default value for the route.
526
-	 * 
527
-	 * @param  string  $key
528
-	 * @param  mixed   $value
529
-	 * 
530
-	 * @return $this
531
-	 */
532
-	public function defaults($key, $value)
533
-	{
534
-		$this->defaults[$key] = $value;
535
-
536
-		return $this;
537
-	}
538
-
539
-	/**
540
-	 * Set a default values for the route.
541
-	 * 
542
-	 * @param  string  $defaults
543
-	 * 
544
-	 * @return $this
545
-	 */
546
-	public function setDefaults(array $defaults)
547
-	{
548
-		$this->defaults = $defaults;
549
-
550
-		return $this;
551
-	}
552
-
553
-	/**
554
-	 * Set the where.
555
-	 *
556
-	 * @param  array|string  $name
557
-	 * @param  string|null  $expression  (null by default)
558
-	 *
559
-	 * @return $this
560
-	 */
561
-	public function where($name, string $expression = null)
562
-	{
563
-		$wheres = is_array($name) ? $name : [$name => $expression];
482
+        return $this;
483
+    }
484
+
485
+    /**
486
+     * Set the name.
487
+     *
488
+     * @param  string  $name
489
+     *
490
+     * @return string
491
+     */
492
+    public function name($name)
493
+    {
494
+        $this->action['as'] = isset($this->action['as']) ? $this->action['as'].$name : $name;
495
+
496
+        return $this;
497
+    }
498
+
499
+    /**
500
+     * Determine whether the route's name matches the given patterns.
501
+     * 
502
+     * @param  mixed  ...$patterns
503
+     * 
504
+     * @return bool
505
+     */
506
+    public function named(...$patterns)
507
+    {
508
+        if (is_null($routeName = $this->getName()))
509
+        {
510
+            return false;
511
+        }
512
+
513
+        foreach ($patterns as $pattern)
514
+        {
515
+            if (Str::is($pattern, $routeName))
516
+            {
517
+                return true;
518
+            }
519
+        }
520
+
521
+        return false;
522
+    }
523
+
524
+    /**
525
+     * Set a default value for the route.
526
+     * 
527
+     * @param  string  $key
528
+     * @param  mixed   $value
529
+     * 
530
+     * @return $this
531
+     */
532
+    public function defaults($key, $value)
533
+    {
534
+        $this->defaults[$key] = $value;
535
+
536
+        return $this;
537
+    }
538
+
539
+    /**
540
+     * Set a default values for the route.
541
+     * 
542
+     * @param  string  $defaults
543
+     * 
544
+     * @return $this
545
+     */
546
+    public function setDefaults(array $defaults)
547
+    {
548
+        $this->defaults = $defaults;
549
+
550
+        return $this;
551
+    }
552
+
553
+    /**
554
+     * Set the where.
555
+     *
556
+     * @param  array|string  $name
557
+     * @param  string|null  $expression  (null by default)
558
+     *
559
+     * @return $this
560
+     */
561
+    public function where($name, string $expression = null)
562
+    {
563
+        $wheres = is_array($name) ? $name : [$name => $expression];
564 564
 		
565
-		foreach ($wheres as $name => $expression)
566
-		{
567
-			$this->wheres[$name] = $expression;
568
-		}
569
-
570
-		return $this;
571
-	}
572
-
573
-	/**
574
-	 * Bind the route to a given request for execution.
575
-	 * 
576
-	 * @param  \Syscodes\Http\Request  $request
577
-	 * 
578
-	 * @return $this
579
-	 */
580
-	public function bind(Request $request)
581
-	{
582
-		$this->parameters = (new RouteParamBinding($this))->parameters($request);
583
-
584
-		return $this;
585
-	}
586
-
587
-	/**
588
-	 * Get all of the parameter names for the route.
589
-	 * 
590
-	 * @return array
591
-	 */
592
-	public function parameterNames()
593
-	{
594
-		if (isset($this->parameterNames))
595
-		{
596
-			return $this->parameterNames;
597
-		}
598
-
599
-		return $this->parameterNames = $this->compileParamNames();
600
-	}
601
-
602
-	/**
603
-	 * Get the parameter names for the route.
604
-	 * 
605
-	 * @return array
606
-	 */
607
-	protected function compileParamNames()
608
-	{
609
-		preg_match_all('~[^\/\{(.*?)\}]~', $this->domain().$this->uri, $matches);
610
-
611
-		return array_map(function ($match) {
612
-			return trim($match, '?');
613
-		}, $matches[0]);
614
-	}
615
-
616
-	/**
617
-	 * Get a given parameter from the route.
618
-	 * 
619
-	 * @param  string  $name
620
-	 * @param  mixed  $default  (null by default)
621
-	 * 
622
-	 * @return array
623
-	 */
624
-	public function parameter($name, $default = null)
625
-	{
626
-		return Arr::get($this->parameters(), $name, $default);
627
-	}
628
-
629
-	/**
630
-	 * Set a parameter to the given value.
631
-	 * 
632
-	 * @param  string  $name
633
-	 * @param  mixed  $value
634
-	 * 
635
-	 * @return array
636
-	 */
637
-	public function setParameter($name, $value)
638
-	{
639
-		$this->parameters();
640
-
641
-		$this->parameters[$name] = $value;
642
-	}
643
-
644
-	/**
645
-	 * Get the key / value list of parameters without null values.
646
-	 * 
647
-	 * @return array
648
-	 */
649
-	public function parametersWithouNulls()
650
-	{
651
-		return array_filter($this->parameters(), function ($parameter) {
652
-			return ! is_null($parameter);
653
-		});
654
-	}
655
-
656
-	/**
657
-	 * Get the key / value list of parameters for the route.
658
-	 * 
659
-	 * @return array
660
-	 */
661
-	public function parameters()
662
-	{
663
-		if (isset($this->parameters))
664
-		{
665
-			return $this->parameters;
666
-		}
667
-
668
-		throw new LogicException('The route is not bound.');
669
-	}
670
-
671
-	/**
672
-	 * Determine if the route only responds to HTTP requests.
673
-	 * 
674
-	 * @return bool
675
-	 */
676
-	public function httpOnly()
677
-	{
678
-		return in_array('http', $this->action, true);
679
-	}
680
-
681
-	/**
682
-	 * Determine if the route only responds to HTTPS requests.
683
-	 * 
684
-	 * @return bool
685
-	 */
686
-	public function httpsOnly()
687
-	{
688
-		return $this->secure();
689
-	}
690
-
691
-	/**
692
-	 * Determine if the route only responds to HTTPS requests.
693
-	 * 
694
-	 * @return bool
695
-	 */
696
-	public function secure()
697
-	{
698
-		return in_array('https', $this->action, true);
699
-	}
700
-
701
-	/**
702
-	 * Set the container instance on the route.
703
-	 * 
704
-	 * @param  \Syscodes\Container\Container  $container
705
-	 * 
706
-	 * @return $this
707
-	 */
708
-	public function setContainer(Container $container)
709
-	{
710
-		$this->container = $container;
711
-
712
-		return $this;
713
-	}
714
-
715
-	/**
716
-	 * Dynamically access route parameters.
717
-	 * 
718
-	 * @param  string  $key
719
-	 * 
720
-	 * @return mixed
721
-	 */
722
-	public function __get($key)
723
-	{
724
-		return $this->parameter($key);
725
-	}
565
+        foreach ($wheres as $name => $expression)
566
+        {
567
+            $this->wheres[$name] = $expression;
568
+        }
569
+
570
+        return $this;
571
+    }
572
+
573
+    /**
574
+     * Bind the route to a given request for execution.
575
+     * 
576
+     * @param  \Syscodes\Http\Request  $request
577
+     * 
578
+     * @return $this
579
+     */
580
+    public function bind(Request $request)
581
+    {
582
+        $this->parameters = (new RouteParamBinding($this))->parameters($request);
583
+
584
+        return $this;
585
+    }
586
+
587
+    /**
588
+     * Get all of the parameter names for the route.
589
+     * 
590
+     * @return array
591
+     */
592
+    public function parameterNames()
593
+    {
594
+        if (isset($this->parameterNames))
595
+        {
596
+            return $this->parameterNames;
597
+        }
598
+
599
+        return $this->parameterNames = $this->compileParamNames();
600
+    }
601
+
602
+    /**
603
+     * Get the parameter names for the route.
604
+     * 
605
+     * @return array
606
+     */
607
+    protected function compileParamNames()
608
+    {
609
+        preg_match_all('~[^\/\{(.*?)\}]~', $this->domain().$this->uri, $matches);
610
+
611
+        return array_map(function ($match) {
612
+            return trim($match, '?');
613
+        }, $matches[0]);
614
+    }
615
+
616
+    /**
617
+     * Get a given parameter from the route.
618
+     * 
619
+     * @param  string  $name
620
+     * @param  mixed  $default  (null by default)
621
+     * 
622
+     * @return array
623
+     */
624
+    public function parameter($name, $default = null)
625
+    {
626
+        return Arr::get($this->parameters(), $name, $default);
627
+    }
628
+
629
+    /**
630
+     * Set a parameter to the given value.
631
+     * 
632
+     * @param  string  $name
633
+     * @param  mixed  $value
634
+     * 
635
+     * @return array
636
+     */
637
+    public function setParameter($name, $value)
638
+    {
639
+        $this->parameters();
640
+
641
+        $this->parameters[$name] = $value;
642
+    }
643
+
644
+    /**
645
+     * Get the key / value list of parameters without null values.
646
+     * 
647
+     * @return array
648
+     */
649
+    public function parametersWithouNulls()
650
+    {
651
+        return array_filter($this->parameters(), function ($parameter) {
652
+            return ! is_null($parameter);
653
+        });
654
+    }
655
+
656
+    /**
657
+     * Get the key / value list of parameters for the route.
658
+     * 
659
+     * @return array
660
+     */
661
+    public function parameters()
662
+    {
663
+        if (isset($this->parameters))
664
+        {
665
+            return $this->parameters;
666
+        }
667
+
668
+        throw new LogicException('The route is not bound.');
669
+    }
670
+
671
+    /**
672
+     * Determine if the route only responds to HTTP requests.
673
+     * 
674
+     * @return bool
675
+     */
676
+    public function httpOnly()
677
+    {
678
+        return in_array('http', $this->action, true);
679
+    }
680
+
681
+    /**
682
+     * Determine if the route only responds to HTTPS requests.
683
+     * 
684
+     * @return bool
685
+     */
686
+    public function httpsOnly()
687
+    {
688
+        return $this->secure();
689
+    }
690
+
691
+    /**
692
+     * Determine if the route only responds to HTTPS requests.
693
+     * 
694
+     * @return bool
695
+     */
696
+    public function secure()
697
+    {
698
+        return in_array('https', $this->action, true);
699
+    }
700
+
701
+    /**
702
+     * Set the container instance on the route.
703
+     * 
704
+     * @param  \Syscodes\Container\Container  $container
705
+     * 
706
+     * @return $this
707
+     */
708
+    public function setContainer(Container $container)
709
+    {
710
+        $this->container = $container;
711
+
712
+        return $this;
713
+    }
714
+
715
+    /**
716
+     * Dynamically access route parameters.
717
+     * 
718
+     * @param  string  $key
719
+     * 
720
+     * @return mixed
721
+     */
722
+    public function __get($key)
723
+    {
724
+        return $this->parameter($key);
725
+    }
726 726
 }
727 727
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 	* @var array $patterns 
100 100
 	*/
101 101
 	public $patterns = [
102
-		'~/~'                    =>  '\/',               // Slash
103
-		'~{an:[^\/{}]+}~'        => '([0-9a-zA-Z]++)',   // Placeholder accepts alphabetic and numeric chars
104
-		'~{n:[^\/{}]+}~'         => '([0-9]++)',         // Placeholder accepts only numeric
105
-		'~{a:[^\/{}]+}~'         => '([a-zA-Z]++)',      // Placeholder accepts only alphabetic chars
102
+		'~/~'                    =>  '\/', // Slash
103
+		'~{an:[^\/{}]+}~'        => '([0-9a-zA-Z]++)', // Placeholder accepts alphabetic and numeric chars
104
+		'~{n:[^\/{}]+}~'         => '([0-9]++)', // Placeholder accepts only numeric
105
+		'~{a:[^\/{}]+}~'         => '([a-zA-Z]++)', // Placeholder accepts only alphabetic chars
106 106
 		'~{w:[^\/{}]+}~'         => '([0-9a-zA-Z-_]++)', // Placeholder accepts alphanumeric and underscore
107
-		'~{\*:[^\/{}]+}~'        => '(.++)',             // Placeholder match rest of url
108
-		'~(\\\/)?{\?:[^\/{}]+}~' => '\/?([^\/]*)',		 // Optional placeholder
107
+		'~{\*:[^\/{}]+}~'        => '(.++)', // Placeholder match rest of url
108
+		'~(\\\/)?{\?:[^\/{}]+}~' => '\/?([^\/]*)', // Optional placeholder
109 109
 		'~{[^\/{}]+}~'           => '([^\/]++)'			 // Normal placeholder
110 110
 	];
111 111
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 	{
609 609
 		preg_match_all('~[^\/\{(.*?)\}]~', $this->domain().$this->uri, $matches);
610 610
 
611
-		return array_map(function ($match) {
611
+		return array_map(function($match) {
612 612
 			return trim($match, '?');
613 613
 		}, $matches[0]);
614 614
 	}
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 	 */
649 649
 	public function parametersWithouNulls()
650 650
 	{
651
-		return array_filter($this->parameters(), function ($parameter) {
651
+		return array_filter($this->parameters(), function($parameter) {
652 652
 			return ! is_null($parameter);
653 653
 		});
654 654
 	}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -307,8 +307,7 @@
 block discarded – undo
307 307
 			}
308 308
 
309 309
 			return $this->runResolverCallable();
310
-		}
311
-		catch (HttpResponseException $e)
310
+		} catch (HttpResponseException $e)
312 311
 		{
313 312
 			return $e->getResponse();
314 313
 		}
Please login to merge, or discard this patch.
src/components/Routing/UrlGenerator.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 
271 271
         $uri = $this->trimUrl($root, $this->replaceRouteParameters($route->getRoute(), $parameters));
272 272
 
273
-        return $forced ? $uri : '/' .ltrim(str_replace($root, '', $uri), '/');
273
+        return $forced ? $uri : '/'.ltrim(str_replace($root, '', $uri), '/');
274 274
     }
275 275
     
276 276
     /**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
      */
334 334
     protected function replaceNamedParameters($path, &$parameters)
335 335
     {
336
-        return preg_replace_callback('/\{(.*?)\??\}/', function ($match) use (&$parameters)
336
+        return preg_replace_callback('/\{(.*?)\??\}/', function($match) use (&$parameters)
337 337
         {
338 338
             return isset($parameters[$match[1]]) ? Arr::pull($parameters, $match[1]) : $match[0];
339 339
         }, $path);
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -104,8 +104,7 @@  discard block
 block discarded – undo
104 104
         if ($url)
105 105
         {
106 106
             return $url;
107
-        }
108
-        elseif ($fallback)
107
+        } elseif ($fallback)
109 108
         {
110 109
             return $this->to($fallback);
111 110
         }
@@ -417,8 +416,7 @@  discard block
 block discarded – undo
417 416
         if ($route->httpOnly)
418 417
         {
419 418
             return $this->getScheme(false);
420
-        }
421
-        elseif ($route->httpsOnly)
419
+        } elseif ($route->httpsOnly)
422 420
         {
423 421
             return $this->getScheme(true);
424 422
         }
Please login to merge, or discard this patch.
src/components/Routing/Router.php 3 patches
Indentation   +579 added lines, -579 removed lines patch added patch discarded remove patch
@@ -40,603 +40,603 @@
 block discarded – undo
40 40
  */
41 41
 class Router implements Routable
42 42
 {
43
-	use Concerns\RouteMap,
44
-	    Concerns\RouteResolver;
45
-
46
-	/**
47
-	 * The registered route value binders.
48
-	 * 
49
-	 * @var array $binders
50
-	 */
51
-	protected $binders = [];
52
-
53
-	/**
54
-	 * The container instance used by the router.
55
-	 * 
56
-	 * @var \Syscodes\Contracts\Container\Container $container
57
-	 */
58
-	protected $container;
59
-
60
-	/**
61
-	 * Variable of group route.
62
-	 *  
63
-	 * @var array $groupStack
64
-	 */
65
-	protected $groupStack = [];
43
+    use Concerns\RouteMap,
44
+        Concerns\RouteResolver;
45
+
46
+    /**
47
+     * The registered route value binders.
48
+     * 
49
+     * @var array $binders
50
+     */
51
+    protected $binders = [];
52
+
53
+    /**
54
+     * The container instance used by the router.
55
+     * 
56
+     * @var \Syscodes\Contracts\Container\Container $container
57
+     */
58
+    protected $container;
59
+
60
+    /**
61
+     * Variable of group route.
62
+     *  
63
+     * @var array $groupStack
64
+     */
65
+    protected $groupStack = [];
66 66
 	
67
-	/**
68
-	 * The registered string macros.
69
-	 * 
70
-	 * @var array $macros
71
-	 */
72
-	protected $macros = [];
73
-
74
-	/**
75
-	 * Middleware for function of filters
76
-	 *  
77
-	 * @var string[] $middleware
78
-	 */
79
-	protected $middleware = [];
67
+    /**
68
+     * The registered string macros.
69
+     * 
70
+     * @var array $macros
71
+     */
72
+    protected $macros = [];
73
+
74
+    /**
75
+     * Middleware for function of filters
76
+     *  
77
+     * @var string[] $middleware
78
+     */
79
+    protected $middleware = [];
80 80
 	
81
-	/**
82
-	 * The globally available parameter patterns.
83
-	 * 
84
-	 * @var array $patterns
85
-	 */
86
-	protected $patterns = [];
87
-
88
-	/** 
89
-	 * The route collection instance. 
90
-	 * 
91
-	 * @var \Syscodes\Routing\RouteCollection $routes
92
-	 */
93
-	protected $routes;
94
-
95
-	/**
96
-	 * The Resource instance.
97
-	 * 
98
-	 * @var \Syscodes\Routing\ResourceRegister $resources
99
-	 */
100
-	protected $resources;
101
-
102
-	/**
103
-	 * Constructor. Create a new Router instance.
104
-	 *
105
-	 * @param  \Syscodes\Contracts\Container\Container|null  $container  (null by default)
106
-	 * 
107
-	 * @return void
108
-	 */
109
-	public function __construct(Container $container = null)
110
-	{
111
-		$this->routes = new RouteCollection();
112
-
113
-		$this->container = $container ?: new Container;
114
-	}
115
-
116
-	/**
117
-	 * Get the prefix from the group on the stack.
118
-	 *
119
-	 * @return string
120
-	 */
121
-	public function getGroupPrefix()
122
-	{
123
-		if ( ! empty($this->groupStack))
124
-		{
125
-			$last = end($this->groupStack);
126
-
127
-			return $last['prefix'] ?? '';
128
-		}
129
-
130
-		return '';
131
-	}
132
-
133
-	/**
134
-	 * Group a series of routes under a single URL segment. This is handy
135
-	 * for grouping items into an admin area, like:
136
-	 *
137
-	 *   Example:
138
-	 *      // Creates route: /admin show the word 'User'
139
-	 *      Route::group(['prefix' => 'admin'], function() {	 
140
-	 *
141
-	 *          Route::get('/user', function() {
142
-	 *	            echo 'Hello world..!';
143
-	 *          });
144
-	 *
145
-	 *      }); /admin/user
146
-	 *
147
-	 * @param  array  $attributes
148
-	 * @param  \Closure|string  $callback
149
-	 *
150
-	 * @return void
151
-	 */
152
-	public function group(array $attributes, $callback) 
153
-	{
154
-		$this->updateGroupStack($attributes);
155
-
156
-		$this->loadRoutes($callback);
157
-
158
-		array_pop($this->groupStack);
159
-
160
-		return $this;
161
-	}
162
-
163
-	/**
164
-	 * Update the group stack with the given attributes.
165
-	 * 
166
-	 * @param  array  $attributes
167
-	 * 
168
-	 * @return void
169
-	 */
170
-	protected function updateGroupStack(array $attributes)
171
-	{
172
-		if ( ! empty($this->groupStack))
173
-		{
174
-			$attributes = $this->mergeGroup($attributes);
175
-		}
176
-
177
-		$this->groupStack[] = $attributes;
178
-	}
179
-
180
-	/**
181
-	 * Merge the given group attributes.
182
-	 * 
183
-	 * @param  array  $new
184
-	 * 
185
-	 * @return array
186
-	 */
187
-	protected function mergeGroup($new)
188
-	{
189
-		return RouteGroup::mergeGroup($new, end($this->groupStack));
190
-	}
81
+    /**
82
+     * The globally available parameter patterns.
83
+     * 
84
+     * @var array $patterns
85
+     */
86
+    protected $patterns = [];
87
+
88
+    /** 
89
+     * The route collection instance. 
90
+     * 
91
+     * @var \Syscodes\Routing\RouteCollection $routes
92
+     */
93
+    protected $routes;
94
+
95
+    /**
96
+     * The Resource instance.
97
+     * 
98
+     * @var \Syscodes\Routing\ResourceRegister $resources
99
+     */
100
+    protected $resources;
101
+
102
+    /**
103
+     * Constructor. Create a new Router instance.
104
+     *
105
+     * @param  \Syscodes\Contracts\Container\Container|null  $container  (null by default)
106
+     * 
107
+     * @return void
108
+     */
109
+    public function __construct(Container $container = null)
110
+    {
111
+        $this->routes = new RouteCollection();
112
+
113
+        $this->container = $container ?: new Container;
114
+    }
115
+
116
+    /**
117
+     * Get the prefix from the group on the stack.
118
+     *
119
+     * @return string
120
+     */
121
+    public function getGroupPrefix()
122
+    {
123
+        if ( ! empty($this->groupStack))
124
+        {
125
+            $last = end($this->groupStack);
126
+
127
+            return $last['prefix'] ?? '';
128
+        }
129
+
130
+        return '';
131
+    }
132
+
133
+    /**
134
+     * Group a series of routes under a single URL segment. This is handy
135
+     * for grouping items into an admin area, like:
136
+     *
137
+     *   Example:
138
+     *      // Creates route: /admin show the word 'User'
139
+     *      Route::group(['prefix' => 'admin'], function() {	 
140
+     *
141
+     *          Route::get('/user', function() {
142
+     *	            echo 'Hello world..!';
143
+     *          });
144
+     *
145
+     *      }); /admin/user
146
+     *
147
+     * @param  array  $attributes
148
+     * @param  \Closure|string  $callback
149
+     *
150
+     * @return void
151
+     */
152
+    public function group(array $attributes, $callback) 
153
+    {
154
+        $this->updateGroupStack($attributes);
155
+
156
+        $this->loadRoutes($callback);
157
+
158
+        array_pop($this->groupStack);
159
+
160
+        return $this;
161
+    }
162
+
163
+    /**
164
+     * Update the group stack with the given attributes.
165
+     * 
166
+     * @param  array  $attributes
167
+     * 
168
+     * @return void
169
+     */
170
+    protected function updateGroupStack(array $attributes)
171
+    {
172
+        if ( ! empty($this->groupStack))
173
+        {
174
+            $attributes = $this->mergeGroup($attributes);
175
+        }
176
+
177
+        $this->groupStack[] = $attributes;
178
+    }
179
+
180
+    /**
181
+     * Merge the given group attributes.
182
+     * 
183
+     * @param  array  $new
184
+     * 
185
+     * @return array
186
+     */
187
+    protected function mergeGroup($new)
188
+    {
189
+        return RouteGroup::mergeGroup($new, end($this->groupStack));
190
+    }
191 191
 	
192
-	/**
193
-	 * Load the provided routes.
194
-	 * 
195
-	 * @param  \Closure|string  $callback
196
-	 * 
197
-	 * @return void
198
-	 */
199
-	protected function loadRoutes($callback)
200
-	{
201
-		if ($callback instanceof Closure) 
202
-		{
203
-			$callback($this);
204
-		}
205
-		else
206
-		{
207
-			(new RouteFileRegister($this))->register($callback);
208
-		}
209
-	}
210
-
211
-	/**
212
-	 * Add a route to the underlying route collection. 
213
-	 *
214
-	 * @param  array|string  $method
215
-	 * @param  string  $route
216
-	 * @param  mixed  $action
217
-	 *
218
-	 * @return \Syscodes\Routing\Route
219
-	 */
220
-	public function addRoute($method, $route, $action)
221
-	{
222
-		return $this->routes->add($this->map($method, $route, $action));
223
-	}
224
-
225
-	/**
226
-	 * Create a redirect from one URI to another.
227
-	 * 
228
-	 * @param  string  $uri
229
-	 * @param  string  $destination
230
-	 * @param  int  $status  (302 by default)
231
-	 * 
232
-	 * @return \Syscodes\Routing\Route
233
-	 */
234
-	public function redirect($uri, $destination, $status = 302)
235
-	{
236
-		return $this->any($uri, function () use ($destination, $status) 
237
-		{
238
-			return new RedirectResponse($destination, $status);
239
-		});
240
-	}
241
-
242
-	/**
243
-	 * Register a new route that returns a view.
244
-	 * 
245
-	 * @param  string  $uri
246
-	 * @param  string  $view
247
-	 * @param  array  $data
248
-	 * 
249
-	 * @return \Syscodes\Routing\Route
250
-	 */
251
-	public function view($uri, $view, $data = [])
252
-	{
253
-		return $this->match(['GET', 'HEAD'], $uri, function () use ($view, $data) 
254
-		{
255
-			return $this->container->make('view')->make($view, $data);
256
-		});
257
-	}
258
-
259
-	/**
260
-	 * Add new route to routes array.
261
-	 *
262
-	 * @param  array|string  $method
263
-	 * @param  string  $route
264
-	 * @param  mixed  $action
265
-	 *
266
-	 * @return void
267
-	 * 
268
-	 * @throws \InvalidArgumentException
269
-	 */
270
-	public function map($method, $route, $action) 
271
-	{
272
-		if ($this->actionReferencesController($action))
273
-		{
274
-			$action = $this->convertToControllerAction($action);
275
-		}
276
-
277
-		$route = $this->newRoute(
278
-				array_map('strtoupper', (array) $method),
279
-				$this->prefix($route),
280
-				$action
281
-		);
282
-
283
-		if ($this->hasGroupStack())
284
-		{
285
-			$this->mergeGroupAttributesIntoRoute($route);			
286
-		}
287
-
288
-		$this->addWhereClausesToRoute($route);
192
+    /**
193
+     * Load the provided routes.
194
+     * 
195
+     * @param  \Closure|string  $callback
196
+     * 
197
+     * @return void
198
+     */
199
+    protected function loadRoutes($callback)
200
+    {
201
+        if ($callback instanceof Closure) 
202
+        {
203
+            $callback($this);
204
+        }
205
+        else
206
+        {
207
+            (new RouteFileRegister($this))->register($callback);
208
+        }
209
+    }
210
+
211
+    /**
212
+     * Add a route to the underlying route collection. 
213
+     *
214
+     * @param  array|string  $method
215
+     * @param  string  $route
216
+     * @param  mixed  $action
217
+     *
218
+     * @return \Syscodes\Routing\Route
219
+     */
220
+    public function addRoute($method, $route, $action)
221
+    {
222
+        return $this->routes->add($this->map($method, $route, $action));
223
+    }
224
+
225
+    /**
226
+     * Create a redirect from one URI to another.
227
+     * 
228
+     * @param  string  $uri
229
+     * @param  string  $destination
230
+     * @param  int  $status  (302 by default)
231
+     * 
232
+     * @return \Syscodes\Routing\Route
233
+     */
234
+    public function redirect($uri, $destination, $status = 302)
235
+    {
236
+        return $this->any($uri, function () use ($destination, $status) 
237
+        {
238
+            return new RedirectResponse($destination, $status);
239
+        });
240
+    }
241
+
242
+    /**
243
+     * Register a new route that returns a view.
244
+     * 
245
+     * @param  string  $uri
246
+     * @param  string  $view
247
+     * @param  array  $data
248
+     * 
249
+     * @return \Syscodes\Routing\Route
250
+     */
251
+    public function view($uri, $view, $data = [])
252
+    {
253
+        return $this->match(['GET', 'HEAD'], $uri, function () use ($view, $data) 
254
+        {
255
+            return $this->container->make('view')->make($view, $data);
256
+        });
257
+    }
258
+
259
+    /**
260
+     * Add new route to routes array.
261
+     *
262
+     * @param  array|string  $method
263
+     * @param  string  $route
264
+     * @param  mixed  $action
265
+     *
266
+     * @return void
267
+     * 
268
+     * @throws \InvalidArgumentException
269
+     */
270
+    public function map($method, $route, $action) 
271
+    {
272
+        if ($this->actionReferencesController($action))
273
+        {
274
+            $action = $this->convertToControllerAction($action);
275
+        }
276
+
277
+        $route = $this->newRoute(
278
+                array_map('strtoupper', (array) $method),
279
+                $this->prefix($route),
280
+                $action
281
+        );
282
+
283
+        if ($this->hasGroupStack())
284
+        {
285
+            $this->mergeGroupAttributesIntoRoute($route);			
286
+        }
287
+
288
+        $this->addWhereClausesToRoute($route);
289 289
 		
290
-		return $route;
291
-	}
290
+        return $route;
291
+    }
292 292
 	
293
-	/**
294
-	 * Determine if the action is routing to a controller.
295
-	 * 
296
-	 * @param  array  $action
297
-	 * 
298
-	 * @return bool
299
-	 */
300
-	protected function actionReferencesController($action)
301
-	{
302
-		if ($action instanceof Closure)
303
-		{
304
-			return false;
305
-		}
293
+    /**
294
+     * Determine if the action is routing to a controller.
295
+     * 
296
+     * @param  array  $action
297
+     * 
298
+     * @return bool
299
+     */
300
+    protected function actionReferencesController($action)
301
+    {
302
+        if ($action instanceof Closure)
303
+        {
304
+            return false;
305
+        }
306 306
 		
307
-		return is_string($action) || (isset($action['uses']) && is_string($action['uses']));
308
-	}
307
+        return is_string($action) || (isset($action['uses']) && is_string($action['uses']));
308
+    }
309 309
 	
310
-	/**
311
-	 * Add a controller based route action to the action array.
312
-	 * 
313
-	 * @param  array|string  $action
314
-	 * 
315
-	 * @return array
316
-	 */
317
-	protected function convertToControllerAction($action)
318
-	{
319
-		if (is_string($action))
320
-		{
321
-			$action = ['uses' => $action];
322
-		}
310
+    /**
311
+     * Add a controller based route action to the action array.
312
+     * 
313
+     * @param  array|string  $action
314
+     * 
315
+     * @return array
316
+     */
317
+    protected function convertToControllerAction($action)
318
+    {
319
+        if (is_string($action))
320
+        {
321
+            $action = ['uses' => $action];
322
+        }
323 323
 		
324
-		if ( ! empty($this->groupStack))
325
-		{
326
-			$action['uses'] = $this->prependGroupUses($action['uses']);
327
-		}
324
+        if ( ! empty($this->groupStack))
325
+        {
326
+            $action['uses'] = $this->prependGroupUses($action['uses']);
327
+        }
328 328
 		
329
-		$action['controller'] = $action['uses'];
329
+        $action['controller'] = $action['uses'];
330 330
 		
331
-		return $action;
332
-	}
331
+        return $action;
332
+    }
333 333
 	
334
-	/**
335
-	 * Prepend the last group uses onto the use clause.
336
-	 * 
337
-	 * @param  string  $uses
338
-	 * 
339
-	 * @return string
340
-	 */
341
-	protected function prependGroupUses($uses)
342
-	{
343
-		$group = end($this->groupStack);
334
+    /**
335
+     * Prepend the last group uses onto the use clause.
336
+     * 
337
+     * @param  string  $uses
338
+     * 
339
+     * @return string
340
+     */
341
+    protected function prependGroupUses($uses)
342
+    {
343
+        $group = end($this->groupStack);
344 344
 		
345
-		return isset($group['namespace']) ? $group['namespace'].'\\'.$uses : $uses;
346
-	}
347
-
348
-	/**
349
-	 * Create a new Route object.
350
-	 * 
351
-	 * @param  array|string  $method
352
-	 * @param  string  $uri
353
-	 * @param  mixed  $action
354
-	 * 
355
-	 * @return \Syscodes\Routing\Route
356
-	 */
357
-	public function newRoute($method, $uri, $action)
358
-	{
359
-		return take(new Route($method, $uri, $action))
360
-		              ->setContainer($this->container);
361
-	}
345
+        return isset($group['namespace']) ? $group['namespace'].'\\'.$uses : $uses;
346
+    }
347
+
348
+    /**
349
+     * Create a new Route object.
350
+     * 
351
+     * @param  array|string  $method
352
+     * @param  string  $uri
353
+     * @param  mixed  $action
354
+     * 
355
+     * @return \Syscodes\Routing\Route
356
+     */
357
+    public function newRoute($method, $uri, $action)
358
+    {
359
+        return take(new Route($method, $uri, $action))
360
+                        ->setContainer($this->container);
361
+    }
362 362
 	
363
-	/**
364
-	 * Determine if the router currently has a group stack.
365
-	 * 
366
-	 * @return bool
367
-	 */
368
-	public function hasGroupStack()
369
-	{
370
-		return ! empty($this->groupStack);
371
-	}
363
+    /**
364
+     * Determine if the router currently has a group stack.
365
+     * 
366
+     * @return bool
367
+     */
368
+    public function hasGroupStack()
369
+    {
370
+        return ! empty($this->groupStack);
371
+    }
372 372
 	
373
-	/**
374
-	 * Merge the group stack with the controller action.
375
-	 * 
376
-	 * @param  \Syscpde\Routing\Route  $route
377
-	 * 
378
-	 * @return void
379
-	 */
380
-	protected function mergeGroupAttributesIntoRoute($route)
381
-	{
382
-		$action = static::mergeGroup($route->getAction(), end($this->groupStack));
373
+    /**
374
+     * Merge the group stack with the controller action.
375
+     * 
376
+     * @param  \Syscpde\Routing\Route  $route
377
+     * 
378
+     * @return void
379
+     */
380
+    protected function mergeGroupAttributesIntoRoute($route)
381
+    {
382
+        $action = static::mergeGroup($route->getAction(), end($this->groupStack));
383 383
 		
384
-		$route->setAction($action);
385
-	}
384
+        $route->setAction($action);
385
+    }
386 386
 	
387
-	/**
388
-	 * Add the necessary where clauses to the route based on its initial registration.
389
-	 * 
390
-	 * @param  \Syscodes\Routing\Route  $route
391
-	 * 
392
-	 * @return \Syscodes\Routing\Route
393
-	 */
394
-	protected function addWhereClausesToRoute($route)
395
-	{
396
-		return $route->where(array_merge(
397
-			$this->patterns, Arr::get($route->getAction(), 'where', [])
398
-		));
399
-	}
400
-
401
-	/**
402
-	 * Add a prefix to the route URI.
403
-	 *
404
-	 * @param  string  $uri
405
-	 *
406
-	 * @return string
407
-	 */
408
-	protected function prefix($uri)
409
-	{
410
-		$uri = is_null($uri) ? '' : trim($uri, '/').'/';
411
-
412
-		$uri = filter_var($uri, FILTER_SANITIZE_STRING);
413
-
414
-		// While we want to add a route within a group of '/',
415
-		// it doens't work with matching, so remove them...
416
-		if ($uri != '/')
417
-		{
418
-			$uri = ltrim($uri, '/');
419
-		}
420
-
421
-		return trim(trim($this->getGroupPrefix(), '/').'/'.trim($uri, '/'), '/') ?: '/';
422
-	}
423
-
424
-	/**
425
-	 * Set a global where pattern on all routes.
426
-	 * 
427
-	 * @param  string  $name
428
-	 * @param  string  $pattern
429
-	 * 
430
-	 * @return void
431
-	 */
432
-	public function pattern($name, $pattern)
433
-	{
434
-		return $this->patterns[$name] = $pattern;
435
-	}
436
-
437
-	/**
438
-	 * Set a group of global where patterns on all routes.
439
-	 * 
440
-	 * @param  array  $patterns
441
-	 * 
442
-	 * @return void
443
-	 */
444
-	public function patterns($patterns)
445
-	{
446
-		foreach ($patterns as $key => $pattern)
447
-		{
448
-			$this->patterns[$key] = $pattern;
449
-		}
450
-	}
451
-
452
-	/**
453
-	 * Get a Resource instance.
454
-	 * 
455
-	 * @return \Syscodes\Routing\ResourceRegister
456
-	 */
457
-	public function getResource()
458
-	{
459
-		if (isset($this->resources))
460
-		{
461
-			return $this->resources;
462
-		}
463
-
464
-		return $this->resources = new ResourceRegister($this);
465
-	}
466
-
467
-	/**
468
-	 * Dispatches the given url and call the method that belongs to the route.
469
-	 *
470
-	 * @param  \Syscodes\Http\Request  $request
471
-	 *
472
-	 * @return mixed
473
-	 */
474
-	public function dispatch(Request $request)
475
-	{
476
-		return $this->resolve($request, $this->routes);
477
-	}
478
-
479
-	/**
480
-	 * Check if a route with the given name exists.
481
-	 * 
482
-	 * @param  string  $name
483
-	 * 
484
-	 * @return bool
485
-	 */
486
-	public function has($name)
487
-	{
488
-		$names = is_array($name) ? $name : func_get_args();
489
-
490
-		foreach ($names as $value)
491
-		{
492
-			if ( ! $this->routes->hasNamedRoute($value))
493
-			{
494
-				return false;
495
-			}
496
-		}
497
-
498
-		return true;
499
-	}
500
-
501
-	/**
502
-	 * Get the currently dispatched route instance.
503
-	 * 
504
-	 * @return \Syscodes\Routing\Route|null
505
-	 */
506
-	public function current()
507
-	{
508
-		return $this->current;
509
-	}
510
-
511
-	/**
512
-	 * Determine if the current route matches a pattern.
513
-	 * 
514
-	 * @param  mixed  ...$patterns
515
-	 * 
516
-	 * @return bool
517
-	 */
518
-	public function is(...$patterns)
519
-	{
520
-		return $this->currentRouteNamed(...$patterns);
521
-	}
522
-
523
-	/**
524
-	 * Determine if the current route matches a pattern.
525
-	 * 
526
-	 * @param  mixed  ...$patterns
527
-	 * 
528
-	 * @return bool
529
-	 */
530
-	public function currentRouteNamed(...$patterns)
531
-	{
532
-		return $this->current() && $this->current()->named(...$patterns);
533
-	}
534
-
535
-	/**
536
-	 * Register an array of resource controllers.
537
-	 * 
538
-	 * @param  array  $resources
539
-	 * @param  array  $options
540
-	 * 
541
-	 * @return void
542
-	 */
543
-	public function resources(array $resources, array $options = [])
544
-	{
545
-		foreach ($resources as $name => $controller)
546
-		{
547
-			$this->resource($name, $controller, $options);
548
-		}
549
-	}
550
-
551
-	/**
552
-	 * Route a resource to a controller.
553
-	 * 
554
-	 * @param  string  $name
555
-	 * @param  string  $controller
556
-	 * @param  array  $options
557
-	 * 
558
-	 * @return \Syscodes\Routing\AwaitingResourceRegistration
559
-	 */
560
-	public function resource($name, $controller, array $options = []) 
561
-	{
562
-		if ($this->container)
563
-		{
564
-			$register = $this->container->make(ResourceRegister::class);
565
-		}
566
-		else
567
-		{
568
-			$register = new ResourceRegister($this);
569
-		}
570
-
571
-		return new AwaitingResourceRegistration(
572
-			$register, $name, $controller, $options
573
-		);
574
-	}
575
-
576
-	/**
577
-	 * Get the route collection.
578
-	 *
579
-	 * @return array   
580
-	 */
581
-	public function getRoutes()
582
-	{
583
-		return $this->routes;
584
-	}
585
-
586
-	/**
587
-	 * Get or set the verbs used in the resource URIs.
588
-	 * 
589
-	 * @param  array  $verbs
590
-	 * 
591
-	 * @return array|null
592
-	 */
593
-	public function resourceVerbs(array $verbs = [])
594
-	{
595
-		ResourceRegister::verbs($verbs);
596
-	}
387
+    /**
388
+     * Add the necessary where clauses to the route based on its initial registration.
389
+     * 
390
+     * @param  \Syscodes\Routing\Route  $route
391
+     * 
392
+     * @return \Syscodes\Routing\Route
393
+     */
394
+    protected function addWhereClausesToRoute($route)
395
+    {
396
+        return $route->where(array_merge(
397
+            $this->patterns, Arr::get($route->getAction(), 'where', [])
398
+        ));
399
+    }
400
+
401
+    /**
402
+     * Add a prefix to the route URI.
403
+     *
404
+     * @param  string  $uri
405
+     *
406
+     * @return string
407
+     */
408
+    protected function prefix($uri)
409
+    {
410
+        $uri = is_null($uri) ? '' : trim($uri, '/').'/';
411
+
412
+        $uri = filter_var($uri, FILTER_SANITIZE_STRING);
413
+
414
+        // While we want to add a route within a group of '/',
415
+        // it doens't work with matching, so remove them...
416
+        if ($uri != '/')
417
+        {
418
+            $uri = ltrim($uri, '/');
419
+        }
420
+
421
+        return trim(trim($this->getGroupPrefix(), '/').'/'.trim($uri, '/'), '/') ?: '/';
422
+    }
423
+
424
+    /**
425
+     * Set a global where pattern on all routes.
426
+     * 
427
+     * @param  string  $name
428
+     * @param  string  $pattern
429
+     * 
430
+     * @return void
431
+     */
432
+    public function pattern($name, $pattern)
433
+    {
434
+        return $this->patterns[$name] = $pattern;
435
+    }
436
+
437
+    /**
438
+     * Set a group of global where patterns on all routes.
439
+     * 
440
+     * @param  array  $patterns
441
+     * 
442
+     * @return void
443
+     */
444
+    public function patterns($patterns)
445
+    {
446
+        foreach ($patterns as $key => $pattern)
447
+        {
448
+            $this->patterns[$key] = $pattern;
449
+        }
450
+    }
451
+
452
+    /**
453
+     * Get a Resource instance.
454
+     * 
455
+     * @return \Syscodes\Routing\ResourceRegister
456
+     */
457
+    public function getResource()
458
+    {
459
+        if (isset($this->resources))
460
+        {
461
+            return $this->resources;
462
+        }
463
+
464
+        return $this->resources = new ResourceRegister($this);
465
+    }
466
+
467
+    /**
468
+     * Dispatches the given url and call the method that belongs to the route.
469
+     *
470
+     * @param  \Syscodes\Http\Request  $request
471
+     *
472
+     * @return mixed
473
+     */
474
+    public function dispatch(Request $request)
475
+    {
476
+        return $this->resolve($request, $this->routes);
477
+    }
478
+
479
+    /**
480
+     * Check if a route with the given name exists.
481
+     * 
482
+     * @param  string  $name
483
+     * 
484
+     * @return bool
485
+     */
486
+    public function has($name)
487
+    {
488
+        $names = is_array($name) ? $name : func_get_args();
489
+
490
+        foreach ($names as $value)
491
+        {
492
+            if ( ! $this->routes->hasNamedRoute($value))
493
+            {
494
+                return false;
495
+            }
496
+        }
497
+
498
+        return true;
499
+    }
500
+
501
+    /**
502
+     * Get the currently dispatched route instance.
503
+     * 
504
+     * @return \Syscodes\Routing\Route|null
505
+     */
506
+    public function current()
507
+    {
508
+        return $this->current;
509
+    }
510
+
511
+    /**
512
+     * Determine if the current route matches a pattern.
513
+     * 
514
+     * @param  mixed  ...$patterns
515
+     * 
516
+     * @return bool
517
+     */
518
+    public function is(...$patterns)
519
+    {
520
+        return $this->currentRouteNamed(...$patterns);
521
+    }
522
+
523
+    /**
524
+     * Determine if the current route matches a pattern.
525
+     * 
526
+     * @param  mixed  ...$patterns
527
+     * 
528
+     * @return bool
529
+     */
530
+    public function currentRouteNamed(...$patterns)
531
+    {
532
+        return $this->current() && $this->current()->named(...$patterns);
533
+    }
534
+
535
+    /**
536
+     * Register an array of resource controllers.
537
+     * 
538
+     * @param  array  $resources
539
+     * @param  array  $options
540
+     * 
541
+     * @return void
542
+     */
543
+    public function resources(array $resources, array $options = [])
544
+    {
545
+        foreach ($resources as $name => $controller)
546
+        {
547
+            $this->resource($name, $controller, $options);
548
+        }
549
+    }
550
+
551
+    /**
552
+     * Route a resource to a controller.
553
+     * 
554
+     * @param  string  $name
555
+     * @param  string  $controller
556
+     * @param  array  $options
557
+     * 
558
+     * @return \Syscodes\Routing\AwaitingResourceRegistration
559
+     */
560
+    public function resource($name, $controller, array $options = []) 
561
+    {
562
+        if ($this->container)
563
+        {
564
+            $register = $this->container->make(ResourceRegister::class);
565
+        }
566
+        else
567
+        {
568
+            $register = new ResourceRegister($this);
569
+        }
570
+
571
+        return new AwaitingResourceRegistration(
572
+            $register, $name, $controller, $options
573
+        );
574
+    }
575
+
576
+    /**
577
+     * Get the route collection.
578
+     *
579
+     * @return array   
580
+     */
581
+    public function getRoutes()
582
+    {
583
+        return $this->routes;
584
+    }
585
+
586
+    /**
587
+     * Get or set the verbs used in the resource URIs.
588
+     * 
589
+     * @param  array  $verbs
590
+     * 
591
+     * @return array|null
592
+     */
593
+    public function resourceVerbs(array $verbs = [])
594
+    {
595
+        ResourceRegister::verbs($verbs);
596
+    }
597 597
 	
598
-	/**
599
-	 * Register a custom macro.
600
-	 * 
601
-	 * @param  string  $name
602
-	 * @param  callable  $callback
603
-	 * 
604
-	 * @return void
605
-	 */
606
-	public function macro($name, callable $callback)
607
-	{
608
-		$this->macros[$name] = $callback;
609
-	}
598
+    /**
599
+     * Register a custom macro.
600
+     * 
601
+     * @param  string  $name
602
+     * @param  callable  $callback
603
+     * 
604
+     * @return void
605
+     */
606
+    public function macro($name, callable $callback)
607
+    {
608
+        $this->macros[$name] = $callback;
609
+    }
610 610
 	
611
-	/**
612
-	 * Checks if macro is registered.
613
-	 * 
614
-	 * @param  string  $name
615
-	 * 
616
-	 * @return boolean
617
-	 */
618
-	public function hasMacro($name)
619
-	{
620
-		return isset($this->macros[$name]);
621
-	}
611
+    /**
612
+     * Checks if macro is registered.
613
+     * 
614
+     * @param  string  $name
615
+     * 
616
+     * @return boolean
617
+     */
618
+    public function hasMacro($name)
619
+    {
620
+        return isset($this->macros[$name]);
621
+    }
622 622
 	
623
-	/**
624
-	 * Dynamically handle calls into the router instance.
625
-	 * 
626
-	 * @param  string  $method
627
-	 * @param  array  $parameters
628
-	 * 
629
-	 * @return mixed
630
-	 */
631
-	public function __call($method, $parameters)
632
-	{
633
-		if (isset($this->macros[$method]))
634
-		{
635
-			$callback = $this->macros[$method];
636
-
637
-			return call_user_func_array($callback, $parameters);
638
-		}
623
+    /**
624
+     * Dynamically handle calls into the router instance.
625
+     * 
626
+     * @param  string  $method
627
+     * @param  array  $parameters
628
+     * 
629
+     * @return mixed
630
+     */
631
+    public function __call($method, $parameters)
632
+    {
633
+        if (isset($this->macros[$method]))
634
+        {
635
+            $callback = $this->macros[$method];
636
+
637
+            return call_user_func_array($callback, $parameters);
638
+        }
639 639
 		
640
-		return (new RouteRegister($this))->attribute($method, $parameters[0]);
641
-	}
640
+        return (new RouteRegister($this))->attribute($method, $parameters[0]);
641
+    }
642 642
 }
643 643
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	 */
234 234
 	public function redirect($uri, $destination, $status = 302)
235 235
 	{
236
-		return $this->any($uri, function () use ($destination, $status) 
236
+		return $this->any($uri, function() use ($destination, $status) 
237 237
 		{
238 238
 			return new RedirectResponse($destination, $status);
239 239
 		});
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 */
251 251
 	public function view($uri, $view, $data = [])
252 252
 	{
253
-		return $this->match(['GET', 'HEAD'], $uri, function () use ($view, $data) 
253
+		return $this->match(['GET', 'HEAD'], $uri, function() use ($view, $data) 
254 254
 		{
255 255
 			return $this->container->make('view')->make($view, $data);
256 256
 		});
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -201,8 +201,7 @@  discard block
 block discarded – undo
201 201
 		if ($callback instanceof Closure) 
202 202
 		{
203 203
 			$callback($this);
204
-		}
205
-		else
204
+		} else
206 205
 		{
207 206
 			(new RouteFileRegister($this))->register($callback);
208 207
 		}
@@ -562,8 +561,7 @@  discard block
 block discarded – undo
562 561
 		if ($this->container)
563 562
 		{
564 563
 			$register = $this->container->make(ResourceRegister::class);
565
-		}
566
-		else
564
+		} else
567 565
 		{
568 566
 			$register = new ResourceRegister($this);
569 567
 		}
Please login to merge, or discard this patch.
src/components/Routing/Concerns/RouteMap.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -30,139 +30,139 @@
 block discarded – undo
30 30
  */
31 31
 trait RouteMap
32 32
 {
33
-	/**
34
-	 * All of the verbs supported by the router.
35
-	 * 
36
-	 * @var array $verbs
37
-	 */
38
-	public static $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
33
+    /**
34
+     * All of the verbs supported by the router.
35
+     * 
36
+     * @var array $verbs
37
+     */
38
+    public static $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
39 39
 
40
-	/**
41
-	 * Add a route to the underlying route collection.
42
-	 *
43
-	 * @param  string  $method
44
-	 * @param  string  $route
45
-	 * @param  mixed  $action
46
-	 *
47
-	 * @return \Syscodes\Routing\Route
48
-	 */
49
-	abstract public function addRoute($method, $route, $action);
40
+    /**
41
+     * Add a route to the underlying route collection.
42
+     *
43
+     * @param  string  $method
44
+     * @param  string  $route
45
+     * @param  mixed  $action
46
+     *
47
+     * @return \Syscodes\Routing\Route
48
+     */
49
+    abstract public function addRoute($method, $route, $action);
50 50
 
51
-	/**
52
-	 * Add a route for all posible methods.
53
-	 *
54
-	 * @param  string  $route
55
-	 * @param  string|callable  $action
56
-	 *
57
-	 * @return void
58
-	 */
59
-	public function any($route, $action = null) 
60
-	{		
61
-		return $this->addRoute(self::$verbs, $route, $action);
62
-	}
51
+    /**
52
+     * Add a route for all posible methods.
53
+     *
54
+     * @param  string  $route
55
+     * @param  string|callable  $action
56
+     *
57
+     * @return void
58
+     */
59
+    public function any($route, $action = null) 
60
+    {		
61
+        return $this->addRoute(self::$verbs, $route, $action);
62
+    }
63 63
 	
64
-	/**
65
-	 * Add a route with delete method.
66
-	 *
67
-	 * @param  string  $route
68
-	 * @param  string|callable  $action
69
-	 *
70
-	 * @return void
71
-	 */
72
-	public function delete($route, $action = null) 
73
-	{
74
-		return $this->addRoute('DELETE', $route, $action);
75
-	}
64
+    /**
65
+     * Add a route with delete method.
66
+     *
67
+     * @param  string  $route
68
+     * @param  string|callable  $action
69
+     *
70
+     * @return void
71
+     */
72
+    public function delete($route, $action = null) 
73
+    {
74
+        return $this->addRoute('DELETE', $route, $action);
75
+    }
76 76
 
77
-	/**
78
-	 * Add a route with get method.
79
-	 *
80
-	 * @param  string  $route
81
-	 * @param  string|callable  $action
82
-	 *
83
-	 * @return void
84
-	 */
85
-	public function get($route, $action = null) 
86
-	{
87
-		return $this->addRoute(['GET', 'HEAD'], $route, $action);
88
-	}
77
+    /**
78
+     * Add a route with get method.
79
+     *
80
+     * @param  string  $route
81
+     * @param  string|callable  $action
82
+     *
83
+     * @return void
84
+     */
85
+    public function get($route, $action = null) 
86
+    {
87
+        return $this->addRoute(['GET', 'HEAD'], $route, $action);
88
+    }
89 89
 
90
-	/**
91
-	 * Add a route with head method.
92
-	 *
93
-	 * @param  string  $route
94
-	 * @param  string|callable  $action
95
-	 *
96
-	 * @return void
97
-	 */
98
-	public function head($route, $action = null)
99
-	{
100
-		return $this->addRoute('HEAD', $route, $action);
101
-	}
90
+    /**
91
+     * Add a route with head method.
92
+     *
93
+     * @param  string  $route
94
+     * @param  string|callable  $action
95
+     *
96
+     * @return void
97
+     */
98
+    public function head($route, $action = null)
99
+    {
100
+        return $this->addRoute('HEAD', $route, $action);
101
+    }
102 102
 
103
-	/**
104
-	 * Register a new route with the given methods.
105
-	 * 
106
-	 * @param  array|string  $methods
107
-	 * @param  string  $route
108
-	 * @param  string|null|callable  $action
109
-	 * 
110
-	 * @return void
111
-	 */
112
-	public function match($methods, $route, $action = null)
113
-	{
114
-		return $this->addRoute(array_map('strtoupper', (array) $methods), $route, $action);
115
-	}
103
+    /**
104
+     * Register a new route with the given methods.
105
+     * 
106
+     * @param  array|string  $methods
107
+     * @param  string  $route
108
+     * @param  string|null|callable  $action
109
+     * 
110
+     * @return void
111
+     */
112
+    public function match($methods, $route, $action = null)
113
+    {
114
+        return $this->addRoute(array_map('strtoupper', (array) $methods), $route, $action);
115
+    }
116 116
 
117
-	/**
118
-	 * Add a route with options method.
119
-	 *
120
-	 * @param  string  $route
121
-	 * @param  string|callable  $action
122
-	 *
123
-	 * @return void
124
-	 */
125
-	public function options($route, $action = null) 
126
-	{
127
-		return $this->addRoute('OPTIONS', $route, $action);
128
-	}
117
+    /**
118
+     * Add a route with options method.
119
+     *
120
+     * @param  string  $route
121
+     * @param  string|callable  $action
122
+     *
123
+     * @return void
124
+     */
125
+    public function options($route, $action = null) 
126
+    {
127
+        return $this->addRoute('OPTIONS', $route, $action);
128
+    }
129 129
 
130
-	/**
131
-	 * Add a route with patch method.
132
-	 *
133
-	 * @param  string  $route
134
-	 * @param  string|callable  $action
135
-	 *
136
-	 * @return void
137
-	 */
138
-	public function patch($route, $action = null)
139
-	{
140
-		return $this->addRoute('PATCH', $route, $action);
141
-	}
130
+    /**
131
+     * Add a route with patch method.
132
+     *
133
+     * @param  string  $route
134
+     * @param  string|callable  $action
135
+     *
136
+     * @return void
137
+     */
138
+    public function patch($route, $action = null)
139
+    {
140
+        return $this->addRoute('PATCH', $route, $action);
141
+    }
142 142
 
143
-	/**
144
-	 * Add a route with post method.
145
-	 *
146
-	 * @param  string  $route
147
-	 * @param  string|callable  $action
148
-	 *
149
-	 * @return void
150
-	 */
151
-	public function post($route, $action = null) 
152
-	{
153
-		return $this->addRoute('POST', $route, $action);
154
-	}
143
+    /**
144
+     * Add a route with post method.
145
+     *
146
+     * @param  string  $route
147
+     * @param  string|callable  $action
148
+     *
149
+     * @return void
150
+     */
151
+    public function post($route, $action = null) 
152
+    {
153
+        return $this->addRoute('POST', $route, $action);
154
+    }
155 155
 
156
-	/**
157
-	 * Add a route with put method.
158
-	 *
159
-	 * @param  string  $route
160
-	 * @param  string|callable  $action
161
-	 *
162
-	 * @return void
163
-	 */
164
-	public function put($route, $action = null) 
165
-	{
166
-		return $this->addRoute('PUT', $route, $action);
167
-	}  
156
+    /**
157
+     * Add a route with put method.
158
+     *
159
+     * @param  string  $route
160
+     * @param  string|callable  $action
161
+     *
162
+     * @return void
163
+     */
164
+    public function put($route, $action = null) 
165
+    {
166
+        return $this->addRoute('PUT', $route, $action);
167
+    }  
168 168
 }
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Routing/Concerns/RouteDependencyResolver.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@
 block discarded – undo
117 117
      */
118 118
     protected function getInParameters($class, array $parameters)
119 119
     {
120
-        return ! is_null(Arr::first($parameters, function ($value) use ($class) {
120
+        return ! is_null(Arr::first($parameters, function($value) use ($class) {
121 121
             return $value instanceof $class;
122 122
         }));
123 123
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,8 +79,7 @@
 block discarded – undo
79 79
                 $count++;
80 80
 
81 81
                 $this->spliceOnParameters($parameters, $key, $instance);
82
-            }
83
-            elseif ( ! isset($values[$key - $count]) && $parameter->isDefaultValueAvailable())
82
+            } elseif ( ! isset($values[$key - $count]) && $parameter->isDefaultValueAvailable())
84 83
             {
85 84
                 $this->spliceOnParameters($parameters, $key, $parameter->getDefaultValue());
86 85
             }            
Please login to merge, or discard this patch.