Passed
Push — 0.7.0 ( e442b6...679d5f )
by Alexander
11:21 queued 12s
created

Route::getMiddleware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php 
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Routing;
24
25
use Closure;
26
use LogicException;
27
use ReflectionFunction;
28
use Syscodes\Support\Str;
29
use Syscodes\Http\Request;
30
use InvalidArgumentException;
31
use Syscodes\Collections\Arr;
32
use Syscodes\Container\Container;
33
use Syscodes\Controller\ControllerDispatcher;
34
use Syscodes\Http\Exceptions\HttpResponseException;
35
36
/**
37
 * A Route describes a route and its parameters.
38
 * 
39
 * @author Alexander Campo <[email protected]>
40
 */
41
class Route 
42
{
43
	use Concerns\RouteCondition,
0 ignored issues
show
Bug introduced by
The trait Syscodes\Routing\Concerns\RouteDependencyResolver requires the property $name which is not provided by Syscodes\Routing\Route.
Loading history...
44
	    Concerns\RouteDependencyResolver;
45
	
46
	/**
47
	 * Action that the route will use when called.
48
	 *
49
	 * @var \Closure|string|array $action
50
	 */
51
	public $action;
52
53
	/**
54
	 * The computed gathered middleware.
55
	 * 
56
	 * @var array|null $computedMiddleware
57
	 */
58
	public $computedMiddleware;
59
60
	/**
61
	 * The container instance used by the route.
62
	 * 
63
	 * @var \Syscodes\Container\Container $container
64
	 */
65
	protected $container;
66
67
	/**
68
	 * The controller instance.
69
	 * 
70
	 * @var string $controller
71
	 */
72
	public $controller;
73
74
	/**
75
	 * The default values for the route.
76
	 * 
77
	 * @var array $defaults
78
	 */
79
	public $defaults = [];
80
81
	/**
82
	 * Variable of HTTP method.
83
	 *  
84
	 * @var array|string $method
85
	 */
86
	public $method;
87
88
	/**
89
	 * The array of matched parameters.
90
	 * 
91
	 * @var array $parameters
92
	 */
93
	public $parameters = [];
94
95
	/**
96
	 * The parameter names for the route.
97
	 * 
98
	 * @var string|null $parameterNames
99
	 */
100
	public $parameterNames;
101
102
	/**
103
	* Patterns that should be replaced.
104
	*
105
	* @var array $patterns 
106
	*/
107
	public $patterns = [
108
		'~/~'                    =>  '\/',               // Slash
109
		'~{an:[^\/{}]+}~'        => '([0-9a-zA-Z]++)',   // Placeholder accepts alphabetic and numeric chars
110
		'~{n:[^\/{}]+}~'         => '([0-9]++)',         // Placeholder accepts only numeric
111
		'~{a:[^\/{}]+}~'         => '([a-zA-Z]++)',      // Placeholder accepts only alphabetic chars
112
		'~{w:[^\/{}]+}~'         => '([0-9a-zA-Z-_]++)', // Placeholder accepts alphanumeric and underscore
113
		'~{\*:[^\/{}]+}~'        => '(.++)',             // Placeholder match rest of url
114
		'~(\\\/)?{\?:[^\/{}]+}~' => '\/?([^\/]*)',		 // Optional placeholder
115
		'~{[^\/{}]+}~'           => '([^\/]++)'			 // Normal placeholder
116
	];
117
118
	/**
119
	 * The URI pattern the route responds to.
120
	 *
121
	 * @var array $uri
122
	 */
123
	public $uri = [];
124
125
	/**
126
	 * Contains the arguments of the current route.
127
	 *
128
	 * @var array $where
129
	 */
130
	public $wheres = [];
131
132
	/**
133
	 * Constructor. Initialize route.
134
	 *
135
	 * @param  array|string|null  $method  
136
	 * @param  string|null  $uri  
137
	 * @param  \Closure|string|null  $action  
138
	 *
139
	 * @return void
140
	 */
141
	public function __construct($method = null, $uri = null, $action = null)
142
	{
143
		$this->uri = $uri;
0 ignored issues
show
Documentation Bug introduced by
It seems like $uri can also be of type string. However, the property $uri is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
144
145
		// Set the method
146
		$this->parseMethod($method);
0 ignored issues
show
Bug introduced by
It seems like $method can also be of type string; however, parameter $method of Syscodes\Routing\Route::parseMethod() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

146
		$this->parseMethod(/** @scrutinizer ignore-type */ $method);
Loading history...
147
148
		// Set the action
149
		$this->action = Arr::except($this->parseAction($action), ['prefix']);
0 ignored issues
show
Bug introduced by
$this->parseAction($action) of type Syscodes\Routing\Route is incompatible with the type array expected by parameter $array of Syscodes\Collections\Arr::except(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

149
		$this->action = Arr::except(/** @scrutinizer ignore-type */ $this->parseAction($action), ['prefix']);
Loading history...
150
151
		if (is_null($prefix = Arr::get($this->action, 'prefix'))) {
152
			$this->prefix($prefix);
153
		}
154
	}
155
156
	// Getters
157
158
	/**
159
	 * Get the action of the current route.
160
	 *
161
	 * @return \Closure|string|array
162
	 */
163
	public function getAction()
164
	{
165
		return $this->action;
166
	}
167
168
	/**
169
	 * Get the arguments of the current route.
170
	 *
171
	 * @return array
172
	 */
173
	public function getArguments()
174
	{
175
		return $this->wheres;
176
	}
177
178
	/**
179
	 * Get the controller instance for the route.
180
	 * 
181
	 * @return mixed
182
	 */
183
	public function getController()
184
	{
185
		if ( ! $this->controller) {
186
			$class = $this->parseControllerCallback()[0];
187
 
188
			$this->controller = $this->container->make(ltrim($class, '\\'));
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->container->make(ltrim($class, '\')) of type object is incompatible with the declared type string of property $controller.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
189
		}
190
191
		return $this->controller;
192
	}
193
194
	/**
195
	 * Get the controller method used for the route.
196
	 * 
197
	 * @return string
198
	 */
199
	public function getControllerMethod()
200
	{
201
		return $this->parseControllerCallback()[1];
202
	}
203
204
	/**
205
	 * Get the request method of the current route.
206
	 *
207
	 * @return array|string
208
	 */
209
	public function getMethod()
210
	{
211
		return $this->method;
212
	}
213
214
	/**
215
	 * Get the url of the current route.
216
	 *
217
	 * @return string
218
	 */
219
	public function getName()
220
	{
221
		return $this->action['as'] ?? null;
222
	}
223
224
	/**
225
	 * Get the url of the current route.
226
	 *
227
	 * @return array
228
	 */
229
	public function getRoute()
230
	{
231
		return $this->uri;
232
	}
233
234
	/**
235
	 * Get or set the domain for the route.
236
	 * 
237
	 * @param  string|null  $domain  
238
	 * 
239
	 * @return $this
240
	 */
241
	public function domain($domain = null)
242
	{
243
		if (is_null($domain)) {
244
			return $this->getDomain();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getDomain() also could return the type string which is incompatible with the documented return type Syscodes\Routing\Route.
Loading history...
245
		}
246
247
		$this->action['domain'] = $this->parseRoute($domain);
248
249
		return $this;
250
	}
251
252
	/**
253
	 * Get the domain defined for the route.
254
	 * 
255
	 * @return string|null
256
	 */
257
	public function getDomain()
258
	{
259
		return isset($this->action['domain'])
260
				? str_replace(['http://', 'https://'], '', $this->action['domain'])
261
				: null;
262
	}
263
264
	/**
265
	 * Parse the controller.
266
	 * 
267
	 * @return array
268
	 */
269
	public function parseControllerCallback()
270
	{
271
		return Str::parseCallback($this->action['uses']);
272
	}
273
	
274
	/**
275
	 * Checks whether the route's action is a controller.
276
	 * 
277
	 * @return bool
278
	 */
279
	public function isControllerAction()
280
	{
281
		return is_string($this->action['uses']);
282
	}
283
284
	/**
285
	 * Get the dispatcher for the route's controller.
286
	 * 
287
	 * @return \Syscodes\Controller\ControllerDispatcher
288
	 */
289
	private function controllerDispatcher()
290
	{
291
		return new ControllerDispatcher($this->container);
292
	}
293
294
	// Setters
295
	
296
	/**
297
	 * Run the route action and return the response.
298
	 * 
299
	 * @return mixed
300
	 */
301
	public function runResolver()
302
	{
303
		$this->container = $this->container ?: new Container;
304
305
		try {
306
			if ($this->isControllerAction()) {
307
				return $this->runResolverController();
308
			}
309
310
			return $this->runResolverCallable();
311
		} catch (HttpResponseException $e) {
312
			return $e->getResponse();
313
		}
314
	}
315
316
	/**
317
	 * Run the route action and return the response.
318
	 *  
319
	 * @return mixed
320
	 */
321
	protected function runResolverCallable()
322
	{
323
		$callable = $this->action['uses'];
324
325
		return $callable(...array_values($this->resolveMethodDependencies(
326
			$this->parametersWithouNulls(), new ReflectionFunction($this->action['uses'])
327
		)));
328
	}
329
330
	/**
331
	 * Run the route action and return the response.
332
	 * 
333
	 * @return mixed
334
	 */
335
	protected function runResolverController()
336
	{
337
		return $this->controllerDispatcher()->dispatch($this, $this->getController(), $this->getControllerMethod());
338
	}
339
340
	/**
341
	 * Set the action.
342
	 *
343
	 * @param  \Closure|string  $action
344
	 *
345
	 * @return $this
346
	 *
347
	 * @throws \InvalidArgumentException
348
	 */
349
	public function parseAction($action)
350
	{
351
		if ( ! (is_object($action) && ($action instanceof Closure)) && ($action === null || $action === '')) {
352
			throw new InvalidArgumentException(__('route.actionClosureOrFunction'));
353
		}
354
355
		return RouteAction::parse($this->uri, $action);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Syscodes\Routing\...se($this->uri, $action) returns the type array which is incompatible with the documented return type Syscodes\Routing\Route.
Loading history...
356
	}
357
358
	/**
359
	 * Set the method of the current route.
360
	 *
361
	 * @param  array  $method
362
	 *
363
	 * @return string $this
364
	 * 
365
	 * @throws \InvalidArgumentException
366
	 */
367
	public function parseMethod($method)
368
	{
369
		if ($method === null || empty($method)) {
370
			throw new InvalidArgumentException(__('route.methodNotProvided'));			
371
		}
372
373
		foreach ((array) $method as $httpMethod) {
374
			if ( ! in_array($httpMethod, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'ANY'])) {
375
				throw new InvalidArgumentException(__('route.methodNotAllowed'));				
376
			}
377
		}
378
379
	    $this->method = $method;
380
381
	    return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Syscodes\Routing\Route which is incompatible with the documented return type string.
Loading history...
382
	}
383
384
	/**
385
	 * Set the route.
386
	 *
387
	 * @param  string|array|null  $uri
388
	 *
389
	 * @return string
390
	 *
391
	 * @throws  \InvalidArgumentException
392
	 */
393
	public function parseRoute($uri)
394
	{
395
		if ($uri === null) {
396
			throw new InvalidArgumentException(__('route.uriNotProvided'));
397
		}	
398
399
		$this->uri = $this->parseRoutePath($uri);
0 ignored issues
show
Bug introduced by
It seems like $uri can also be of type array; however, parameter $uri of Syscodes\Routing\Route::parseRoutePath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

399
		$this->uri = $this->parseRoutePath(/** @scrutinizer ignore-type */ $uri);
Loading history...
Documentation Bug introduced by
It seems like $this->parseRoutePath($uri) of type string is incompatible with the declared type array of property $uri.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
400
401
		return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Syscodes\Routing\Route which is incompatible with the documented return type string.
Loading history...
402
	}
403
404
	/**
405
	 * Replace word patterns with regex in route uri.
406
	 * 
407
	 * @param  string  $uri
408
	 * 
409
	 * @return string
410
	 */
411
	protected function parseRoutePath($uri)
412
	{
413
		$uri = trim($uri, '\/?');
414
		$uri = trim($uri, '\/');
415
		
416
		preg_match_all('/\{([\w\:]+?)\??\}/', $uri, $matches);
417
		
418
		foreach ($matches[1] as $match) {
419
			if (strpos($match, ':') === false) {
420
				continue;
421
			}
422
			
423
			$pattern  = array_keys($this->patterns);
424
			$replace  = array_values($this->patterns);
425
			$segments = explode(':', trim($match, '{}?'));
426
			
427
			$uri = strpos($match, ':') !== false
428
					? preg_replace($pattern, $replace, $uri)
429
					: str_replace($match, '{'.$segments[0].'}', $uri);
430
		}
431
		
432
		return $uri;
433
	}
434
435
	/**
436
	 * Add a prefix to the route URI.
437
	 * 
438
	 * @param  string  $prefix
439
	 * 
440
	 * @return $this
441
	 */
442
	public function prefix($prefix)
443
	{
444
		if ( ! empty($newPrefix = trim(rtrim($prefix, '/').'/'.ltrim($this->action['prefix'] ?? '', '/'), '/'))) {
445
			$this->action['prefix'] = $newPrefix;
446
		}
447
		
448
		$uri = rtrim($prefix, '/').'/'.ltrim($this->uri, '/');
0 ignored issues
show
Bug introduced by
$this->uri of type array is incompatible with the type string expected by parameter $string of ltrim(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

448
		$uri = rtrim($prefix, '/').'/'.ltrim(/** @scrutinizer ignore-type */ $this->uri, '/');
Loading history...
449
		
450
		return $this->parseRoute($uri !== '/' ? trim($uri, '/') : $uri);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parseRoute...trim($uri, '/') : $uri) returns the type string which is incompatible with the documented return type Syscodes\Routing\Route.
Loading history...
451
	}
452
453
	/**
454
	 * Set the action array for the route.
455
	 * 
456
	 * @param  array  $action
457
	 * 
458
	 * @return $this
459
	 */
460
	public function setAction(array $action)
461
	{
462
		$this->action = $action;
463
464
		if (isset($this->action['domain'])) {
465
			$this->domain($this->action['domain']);
466
		}
467
		
468
		return $this;
469
	}
470
471
	/**
472
	 * Set the name.
473
	 *
474
	 * @param  string  $name
475
	 *
476
	 * @return $this
477
	 */
478
	public function name($name)
479
	{
480
		$this->action['as'] = isset($this->action['as']) ? $this->action['as'].$name : $name;
481
482
		return $this;
483
	}
484
485
	/**
486
	 * Determine whether the route's name matches the given patterns.
487
	 * 
488
	 * @param  mixed  ...$patterns
489
	 * 
490
	 * @return bool
491
	 */
492
	public function named(...$patterns)
493
	{
494
		if (is_null($routeName = $this->getName())) {
0 ignored issues
show
introduced by
The condition is_null($routeName = $this->getName()) is always false.
Loading history...
495
			return false;
496
		}
497
498
		foreach ($patterns as $pattern) {
499
			if (Str::is($pattern, $routeName)) {
500
				return true;
501
			}
502
		}
503
504
		return false;
505
	}
506
507
	/**
508
	 * Set a default value for the route.
509
	 * 
510
	 * @param  string  $key
511
	 * @param  mixed   $value
512
	 * 
513
	 * @return $this
514
	 */
515
	public function defaults($key, $value)
516
	{
517
		$this->defaults[$key] = $value;
518
519
		return $this;
520
	}
521
522
	/**
523
	 * Set a default values for the route.
524
	 * 
525
	 * @param  string  $defaults
526
	 * 
527
	 * @return $this
528
	 */
529
	public function setDefaults(array $defaults)
530
	{
531
		$this->defaults = $defaults;
532
533
		return $this;
534
	}
535
536
	/**
537
	 * Set the where.
538
	 *
539
	 * @param  array|string  $name
540
	 * @param  string|null  $expression  
541
	 *
542
	 * @return $this
543
	 */
544
	public function where($name, string $expression = null)
545
	{
546
		$wheres = is_array($name) ? $name : [$name => $expression];
547
		
548
		foreach ($wheres as $name => $expression) {
0 ignored issues
show
introduced by
$name is overwriting one of the parameters of this function.
Loading history...
549
			$this->wheres[$name] = $expression;
550
		}
551
552
		return $this;
553
	}
554
555
	/**
556
	 * Bind the route to a given request for execution.
557
	 * 
558
	 * @param  \Syscodes\Http\Request  $request
559
	 * 
560
	 * @return $this
561
	 */
562
	public function bind(Request $request)
563
	{
564
		$this->parameters = (new RouteParamBinding($this))->parameters($request);
565
566
		return $this;
567
	}
568
569
	/**
570
	 * Get all of the parameter names for the route.
571
	 * 
572
	 * @return array
573
	 */
574
	public function parameterNames()
575
	{
576
		if (isset($this->parameterNames)) {
577
			return $this->parameterNames;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parameterNames also could return the type string which is incompatible with the documented return type array.
Loading history...
578
		}
579
580
		return $this->parameterNames = $this->compileParamNames();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->compileParamNames() of type array is incompatible with the declared type null|string of property $parameterNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
581
	}
582
583
	/**
584
	 * Get the parameter names for the route.
585
	 * 
586
	 * @return array
587
	 */
588
	protected function compileParamNames()
589
	{
590
		preg_match_all('~[^\/\{(.*?)\}]~', $this->domain().$this->uri, $matches);
0 ignored issues
show
Bug introduced by
Are you sure $this->domain() of type Syscodes\Routing\Route can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

590
		preg_match_all('~[^\/\{(.*?)\}]~', /** @scrutinizer ignore-type */ $this->domain().$this->uri, $matches);
Loading history...
591
592
		return array_map(function ($match) {
593
			return trim($match, '?');
594
		}, $matches[0]);
595
	}
596
597
	/**
598
	 * Get a given parameter from the route.
599
	 * 
600
	 * @param  string  $name
601
	 * @param  mixed  $default  
602
	 * 
603
	 * @return array
604
	 */
605
	public function parameter($name, $default = null)
606
	{
607
		return Arr::get($this->parameters(), $name, $default);
608
	}
609
610
	/**
611
	 * Set a parameter to the given value.
612
	 * 
613
	 * @param  string  $name
614
	 * @param  mixed  $value
615
	 * 
616
	 * @return array
617
	 */
618
	public function setParameter($name, $value)
619
	{
620
		$this->parameters();
621
622
		$this->parameters[$name] = $value;
623
	}
624
625
	/**
626
	 * Get the key / value list of parameters without null values.
627
	 * 
628
	 * @return array
629
	 */
630
	public function parametersWithouNulls()
631
	{
632
		return array_filter($this->parameters(), function ($parameter) {
633
			return ! is_null($parameter);
634
		});
635
	}
636
637
	/**
638
	 * Get the key / value list of parameters for the route.
639
	 * 
640
	 * @return array
641
	 */
642
	public function parameters()
643
	{
644
		if (isset($this->parameters)) {
645
			return $this->parameters;
646
		}
647
648
		throw new LogicException('The route is not bound.');
649
	}
650
651
	/**
652
	 * Get all middleware, including the ones from the controller.
653
	 * 
654
	 * @return array
655
	 */
656
	public function gatherMiddleware()
657
	{
658
		if ( ! is_null($this->computedMiddleware)) {
659
			return $this->computedMiddleware;
660
		}
661
662
		$this->computedMiddleware = [];
663
664
		return $this->computedMiddleware = array_unique(array_merge(
665
			$this->middleware(),
666
			$this->controllerMiddleware()
667
		), SORT_REGULAR);
668
	}
669
670
	/**
671
	 * Get or set the middlewares attached to the route.
672
	 * 
673
	 * @param  array|string|null  $middleware
674
	 * 
675
	 * @return $this|array
676
	 */
677
	public function middleware($middleware = null)
678
	{
679
		if (is_null($middleware)) {
680
			return $this->getMiddleware();
681
		}
682
683
		if (is_string($middleware)) {
684
			$middleware = func_get_args();
685
		}
686
687
		$this->action['middleware'] = array_merge(
688
			$this->getMiddleware(),
689
			$middleware
690
		);
691
692
		return $this;
693
	}
694
695
	/**
696
	 * Get the middlewares attached to the route.
697
	 * 
698
	 * @return array
699
	 */
700
	protected function getMiddleware()
701
	{
702
		return (array) ($this->action['middleware'] ?? []);
703
	}
704
705
	/**
706
	 * Get the middleware for the route's controller.
707
	 * 
708
	 * @return array
709
	 */
710
	public function controllerMiddleware()
711
	{
712
		if ( ! $this->isControllerAction()) {
713
			return [];
714
		}
715
716
		return $this->controllerDispatcher()->getMiddleware(
717
			$this->getController(),
0 ignored issues
show
Bug introduced by
$this->getController() of type string is incompatible with the type Syscodes\Controller\Controller expected by parameter $controller of Syscodes\Controller\Cont...atcher::getMiddleware(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

717
			/** @scrutinizer ignore-type */ $this->getController(),
Loading history...
718
			$this->getControllerMethod()
719
		);
720
	}
721
722
	/**
723
	 * Determine if the route only responds to HTTP requests.
724
	 * 
725
	 * @return bool
726
	 */
727
	public function httpOnly()
728
	{
729
		return in_array('http', $this->action, true);
730
	}
731
732
	/**
733
	 * Determine if the route only responds to HTTPS requests.
734
	 * 
735
	 * @return bool
736
	 */
737
	public function httpsOnly()
738
	{
739
		return $this->secure();
740
	}
741
742
	/**
743
	 * Determine if the route only responds to HTTPS requests.
744
	 * 
745
	 * @return bool
746
	 */
747
	public function secure()
748
	{
749
		return in_array('https', $this->action, true);
750
	}
751
752
	/**
753
	 * Set the container instance on the route.
754
	 * 
755
	 * @param  \Syscodes\Container\Container  $container
756
	 * 
757
	 * @return $this
758
	 */
759
	public function setContainer(Container $container)
760
	{
761
		$this->container = $container;
762
763
		return $this;
764
	}
765
766
	/**
767
	 * Dynamically access route parameters.
768
	 * 
769
	 * @param  string  $key
770
	 * 
771
	 * @return mixed
772
	 */
773
	public function __get($key)
774
	{
775
		return $this->parameter($key);
776
	}
777
}