@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); |
59 | 59 | |
60 | 60 | if ( ! empty($time)) { |
61 | - if (is_string($time) && static::hasRelativeKeywords($time)) { |
|
62 | - $dateTime = new DateTime('now', $this->timezone); |
|
63 | - $dateTime->modify($time); |
|
61 | + if (is_string($time) && static::hasRelativeKeywords($time)) { |
|
62 | + $dateTime = new DateTime('now', $this->timezone); |
|
63 | + $dateTime->modify($time); |
|
64 | 64 | |
65 | - $time = $dateTime->format('Y-m-d H:i:s'); |
|
66 | - } |
|
65 | + $time = $dateTime->format('Y-m-d H:i:s'); |
|
66 | + } |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return parent::__construct($time, $this->timezone); |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @return \Syscodes\Support\Chronos\Time |
119 | 119 | */ |
120 | 120 | public static function yesterday($timezone = null, string $locale = null) |
121 | - { |
|
122 | - return static::parse(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale); |
|
121 | + { |
|
122 | + return static::parse(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @return \Syscodes\Support\Chronos\Time |
132 | 132 | */ |
133 | 133 | public static function tomorrow($timezone = null, string $locale = null) |
134 | - { |
|
135 | - return static::parse(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale); |
|
134 | + { |
|
135 | + return static::parse(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Creates an instance of Time that will be returned during testing |
267 | - * when calling 'Time::now' instead of the current time. |
|
267 | + * when calling 'Time::now' instead of the current time. |
|
268 | 268 | * |
269 | 269 | * @param \Syscodes\Support\Chronos\Time|string $datetime |
270 | 270 | * @param string|null $timezone |
@@ -29,139 +29,139 @@ |
||
29 | 29 | */ |
30 | 30 | trait RouteMap |
31 | 31 | { |
32 | - /** |
|
33 | - * All of the verbs supported by the router. |
|
34 | - * |
|
35 | - * @var array $verbs |
|
36 | - */ |
|
37 | - public static $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']; |
|
32 | + /** |
|
33 | + * All of the verbs supported by the router. |
|
34 | + * |
|
35 | + * @var array $verbs |
|
36 | + */ |
|
37 | + public static $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Add a route to the underlying route collection. |
|
41 | - * |
|
42 | - * @param string $method |
|
43 | - * @param string $route |
|
44 | - * @param mixed $action |
|
45 | - * |
|
46 | - * @return \Syscodes\Routing\Route |
|
47 | - */ |
|
48 | - abstract public function addRoute($method, $route, $action); |
|
39 | + /** |
|
40 | + * Add a route to the underlying route collection. |
|
41 | + * |
|
42 | + * @param string $method |
|
43 | + * @param string $route |
|
44 | + * @param mixed $action |
|
45 | + * |
|
46 | + * @return \Syscodes\Routing\Route |
|
47 | + */ |
|
48 | + abstract public function addRoute($method, $route, $action); |
|
49 | 49 | |
50 | - /** |
|
51 | - * Add a route for all posible methods. |
|
52 | - * |
|
53 | - * @param string $route |
|
54 | - * @param string|callable|null $action |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function any($route, $action = null) |
|
59 | - { |
|
60 | - return $this->addRoute(self::$verbs, $route, $action); |
|
61 | - } |
|
50 | + /** |
|
51 | + * Add a route for all posible methods. |
|
52 | + * |
|
53 | + * @param string $route |
|
54 | + * @param string|callable|null $action |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function any($route, $action = null) |
|
59 | + { |
|
60 | + return $this->addRoute(self::$verbs, $route, $action); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Add a route with delete method. |
|
65 | - * |
|
66 | - * @param string $route |
|
67 | - * @param string|callable|null $action |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function delete($route, $action = null) |
|
72 | - { |
|
73 | - return $this->addRoute('DELETE', $route, $action); |
|
74 | - } |
|
63 | + /** |
|
64 | + * Add a route with delete method. |
|
65 | + * |
|
66 | + * @param string $route |
|
67 | + * @param string|callable|null $action |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function delete($route, $action = null) |
|
72 | + { |
|
73 | + return $this->addRoute('DELETE', $route, $action); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Add a route with get method. |
|
78 | - * |
|
79 | - * @param string $route |
|
80 | - * @param string|callable|null $action |
|
81 | - * |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function get($route, $action = null) |
|
85 | - { |
|
86 | - return $this->addRoute(['GET', 'HEAD'], $route, $action); |
|
87 | - } |
|
76 | + /** |
|
77 | + * Add a route with get method. |
|
78 | + * |
|
79 | + * @param string $route |
|
80 | + * @param string|callable|null $action |
|
81 | + * |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function get($route, $action = null) |
|
85 | + { |
|
86 | + return $this->addRoute(['GET', 'HEAD'], $route, $action); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Add a route with head method. |
|
91 | - * |
|
92 | - * @param string $route |
|
93 | - * @param string|callable|null $action |
|
94 | - * |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function head($route, $action = null) |
|
98 | - { |
|
99 | - return $this->addRoute('HEAD', $route, $action); |
|
100 | - } |
|
89 | + /** |
|
90 | + * Add a route with head method. |
|
91 | + * |
|
92 | + * @param string $route |
|
93 | + * @param string|callable|null $action |
|
94 | + * |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public function head($route, $action = null) |
|
98 | + { |
|
99 | + return $this->addRoute('HEAD', $route, $action); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Register a new route with the given methods. |
|
104 | - * |
|
105 | - * @param array|string $methods |
|
106 | - * @param string $route |
|
107 | - * @param string|callable|null $action |
|
108 | - * |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public function match($methods, $route, $action = null) |
|
112 | - { |
|
113 | - return $this->addRoute(array_map('strtoupper', (array) $methods), $route, $action); |
|
114 | - } |
|
102 | + /** |
|
103 | + * Register a new route with the given methods. |
|
104 | + * |
|
105 | + * @param array|string $methods |
|
106 | + * @param string $route |
|
107 | + * @param string|callable|null $action |
|
108 | + * |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public function match($methods, $route, $action = null) |
|
112 | + { |
|
113 | + return $this->addRoute(array_map('strtoupper', (array) $methods), $route, $action); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Add a route with options method. |
|
118 | - * |
|
119 | - * @param string $route |
|
120 | - * @param string|callable|null $action |
|
121 | - * |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function options($route, $action = null) |
|
125 | - { |
|
126 | - return $this->addRoute('OPTIONS', $route, $action); |
|
127 | - } |
|
116 | + /** |
|
117 | + * Add a route with options method. |
|
118 | + * |
|
119 | + * @param string $route |
|
120 | + * @param string|callable|null $action |
|
121 | + * |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function options($route, $action = null) |
|
125 | + { |
|
126 | + return $this->addRoute('OPTIONS', $route, $action); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Add a route with patch method. |
|
131 | - * |
|
132 | - * @param string $route |
|
133 | - * @param string|callable|null $action |
|
134 | - * |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - public function patch($route, $action = null) |
|
138 | - { |
|
139 | - return $this->addRoute('PATCH', $route, $action); |
|
140 | - } |
|
129 | + /** |
|
130 | + * Add a route with patch method. |
|
131 | + * |
|
132 | + * @param string $route |
|
133 | + * @param string|callable|null $action |
|
134 | + * |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + public function patch($route, $action = null) |
|
138 | + { |
|
139 | + return $this->addRoute('PATCH', $route, $action); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Add a route with post method. |
|
144 | - * |
|
145 | - * @param string $route |
|
146 | - * @param string|callable|null $action |
|
147 | - * |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - public function post($route, $action = null) |
|
151 | - { |
|
152 | - return $this->addRoute('POST', $route, $action); |
|
153 | - } |
|
142 | + /** |
|
143 | + * Add a route with post method. |
|
144 | + * |
|
145 | + * @param string $route |
|
146 | + * @param string|callable|null $action |
|
147 | + * |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + public function post($route, $action = null) |
|
151 | + { |
|
152 | + return $this->addRoute('POST', $route, $action); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Add a route with put method. |
|
157 | - * |
|
158 | - * @param string $route |
|
159 | - * @param string|callable|null $action |
|
160 | - * |
|
161 | - * @return void |
|
162 | - */ |
|
163 | - public function put($route, $action = null) |
|
164 | - { |
|
165 | - return $this->addRoute('PUT', $route, $action); |
|
166 | - } |
|
155 | + /** |
|
156 | + * Add a route with put method. |
|
157 | + * |
|
158 | + * @param string $route |
|
159 | + * @param string|callable|null $action |
|
160 | + * |
|
161 | + * @return void |
|
162 | + */ |
|
163 | + public function put($route, $action = null) |
|
164 | + { |
|
165 | + return $this->addRoute('PUT', $route, $action); |
|
166 | + } |
|
167 | 167 | } |
168 | 168 | \ No newline at end of file |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function dispatchToRouter() |
201 | 201 | { |
202 | - return function ($request) { |
|
202 | + return function($request) { |
|
203 | 203 | $this->app->instance('request', $request); |
204 | 204 | |
205 | 205 | return $this->router->dispatch($request); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | ); |
236 | 236 | |
237 | 237 | foreach ($middlewares as $middleware) { |
238 | - if (! is_string($middleware)) { |
|
238 | + if ( ! is_string($middleware)) { |
|
239 | 239 | continue; |
240 | 240 | } |
241 | 241 |
@@ -39,274 +39,274 @@ |
||
39 | 39 | */ |
40 | 40 | class Lenevor implements LenevorContract |
41 | 41 | { |
42 | - /** |
|
43 | - * The application implementation. |
|
44 | - * |
|
45 | - * @var \Syscodes\Contracts\Core\Application $app |
|
46 | - */ |
|
47 | - protected $app; |
|
42 | + /** |
|
43 | + * The application implementation. |
|
44 | + * |
|
45 | + * @var \Syscodes\Contracts\Core\Application $app |
|
46 | + */ |
|
47 | + protected $app; |
|
48 | 48 | |
49 | - /** |
|
50 | - * The bootstrap classes for the application. |
|
51 | - * |
|
52 | - * @var array $bootstrappers |
|
53 | - */ |
|
54 | - protected $bootstrappers = [ |
|
55 | - \Syscodes\Core\Bootstrap\BootDetectEnvironment::class, |
|
56 | - \Syscodes\Core\Bootstrap\BootConfiguration::class, |
|
57 | - \Syscodes\Core\Bootstrap\BootHandleExceptions::class, |
|
58 | - \Syscodes\Core\Bootstrap\BootRegisterFacades::class, |
|
59 | - \Syscodes\Core\Bootstrap\BootRegisterProviders::class, |
|
60 | - \Syscodes\Core\Bootstrap\BootProviders::class, |
|
61 | - ]; |
|
49 | + /** |
|
50 | + * The bootstrap classes for the application. |
|
51 | + * |
|
52 | + * @var array $bootstrappers |
|
53 | + */ |
|
54 | + protected $bootstrappers = [ |
|
55 | + \Syscodes\Core\Bootstrap\BootDetectEnvironment::class, |
|
56 | + \Syscodes\Core\Bootstrap\BootConfiguration::class, |
|
57 | + \Syscodes\Core\Bootstrap\BootHandleExceptions::class, |
|
58 | + \Syscodes\Core\Bootstrap\BootRegisterFacades::class, |
|
59 | + \Syscodes\Core\Bootstrap\BootRegisterProviders::class, |
|
60 | + \Syscodes\Core\Bootstrap\BootProviders::class, |
|
61 | + ]; |
|
62 | 62 | |
63 | - /** |
|
64 | - * Get the application's middleware. |
|
65 | - * |
|
66 | - * @var array $middleware |
|
67 | - */ |
|
68 | - protected $middleware = []; |
|
63 | + /** |
|
64 | + * Get the application's middleware. |
|
65 | + * |
|
66 | + * @var array $middleware |
|
67 | + */ |
|
68 | + protected $middleware = []; |
|
69 | 69 | |
70 | - /** |
|
71 | - * Get the application's middleware groups. |
|
72 | - * |
|
73 | - * @var array $middlewareGroups |
|
74 | - */ |
|
75 | - protected $middlewareGroups = []; |
|
70 | + /** |
|
71 | + * Get the application's middleware groups. |
|
72 | + * |
|
73 | + * @var array $middlewareGroups |
|
74 | + */ |
|
75 | + protected $middlewareGroups = []; |
|
76 | 76 | |
77 | - /** |
|
78 | - * The router instance. |
|
79 | - * |
|
80 | - * @var \Syscodes\Routing\Router $router |
|
81 | - */ |
|
82 | - protected $router; |
|
77 | + /** |
|
78 | + * The router instance. |
|
79 | + * |
|
80 | + * @var \Syscodes\Routing\Router $router |
|
81 | + */ |
|
82 | + protected $router; |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get the application's route middleware. |
|
86 | - * |
|
87 | - * @var array $routeMiddleware |
|
88 | - */ |
|
89 | - protected $routeMiddleware = []; |
|
84 | + /** |
|
85 | + * Get the application's route middleware. |
|
86 | + * |
|
87 | + * @var array $routeMiddleware |
|
88 | + */ |
|
89 | + protected $routeMiddleware = []; |
|
90 | 90 | |
91 | - /** |
|
92 | - * Total app execution time. |
|
93 | - * |
|
94 | - * @var float $totalTime |
|
95 | - */ |
|
96 | - protected $totalTime; |
|
91 | + /** |
|
92 | + * Total app execution time. |
|
93 | + * |
|
94 | + * @var float $totalTime |
|
95 | + */ |
|
96 | + protected $totalTime; |
|
97 | 97 | |
98 | - /** |
|
99 | - * Constructor. Lenevor class instance. |
|
100 | - * |
|
101 | - * @param \Syscodes\Contracts\Core\Application $app |
|
102 | - * @param \Syscodes\Routing\Router $router |
|
103 | - * |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function __construct(Application $app, Router $router) |
|
107 | - { |
|
108 | - $this->app = $app; |
|
109 | - $this->router = $router; |
|
98 | + /** |
|
99 | + * Constructor. Lenevor class instance. |
|
100 | + * |
|
101 | + * @param \Syscodes\Contracts\Core\Application $app |
|
102 | + * @param \Syscodes\Routing\Router $router |
|
103 | + * |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function __construct(Application $app, Router $router) |
|
107 | + { |
|
108 | + $this->app = $app; |
|
109 | + $this->router = $router; |
|
110 | 110 | |
111 | - $this->syncMiddlewareRoute(); |
|
112 | - } |
|
111 | + $this->syncMiddlewareRoute(); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Initializes the framework, this can only be called once. |
|
116 | - * Launch the application. |
|
117 | - * |
|
118 | - * @param \Syscodes\http\Request $request |
|
119 | - * |
|
120 | - * @return \Syscodes\Http\Response |
|
121 | - */ |
|
122 | - public function handle($request) |
|
123 | - { |
|
124 | - try { |
|
125 | - $response = $this->sendRequestThroughRouter($request); |
|
126 | - } catch (Throwable $e) { |
|
127 | - $this->reportException($e); |
|
114 | + /** |
|
115 | + * Initializes the framework, this can only be called once. |
|
116 | + * Launch the application. |
|
117 | + * |
|
118 | + * @param \Syscodes\http\Request $request |
|
119 | + * |
|
120 | + * @return \Syscodes\Http\Response |
|
121 | + */ |
|
122 | + public function handle($request) |
|
123 | + { |
|
124 | + try { |
|
125 | + $response = $this->sendRequestThroughRouter($request); |
|
126 | + } catch (Throwable $e) { |
|
127 | + $this->reportException($e); |
|
128 | 128 | |
129 | - $response = $this->renderException($request, $e); |
|
130 | - } |
|
129 | + $response = $this->renderException($request, $e); |
|
130 | + } |
|
131 | 131 | |
132 | - return $response; |
|
133 | - } |
|
132 | + return $response; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Send the given request through the router. |
|
137 | - * |
|
138 | - * @param \Syscodes\Http\Request $request |
|
139 | - * |
|
140 | - * @return \Syscodes\Http\Response |
|
141 | - */ |
|
142 | - protected function sendRequestThroughRouter($request) |
|
143 | - { |
|
144 | - $this->app->instance('request', $request); |
|
135 | + /** |
|
136 | + * Send the given request through the router. |
|
137 | + * |
|
138 | + * @param \Syscodes\Http\Request $request |
|
139 | + * |
|
140 | + * @return \Syscodes\Http\Response |
|
141 | + */ |
|
142 | + protected function sendRequestThroughRouter($request) |
|
143 | + { |
|
144 | + $this->app->instance('request', $request); |
|
145 | 145 | |
146 | - Facade::clearResolvedInstance('request'); |
|
146 | + Facade::clearResolvedInstance('request'); |
|
147 | 147 | |
148 | - // Load configuration system |
|
149 | - $this->bootstrap(); |
|
148 | + // Load configuration system |
|
149 | + $this->bootstrap(); |
|
150 | 150 | |
151 | - return (new Pipeline($this->app)) |
|
152 | - ->send($request) |
|
153 | - ->through($this->app->skipGoingMiddleware() ? [] : $this->middleware) |
|
154 | - ->then($this->dispatchToRouter()); |
|
155 | - } |
|
151 | + return (new Pipeline($this->app)) |
|
152 | + ->send($request) |
|
153 | + ->through($this->app->skipGoingMiddleware() ? [] : $this->middleware) |
|
154 | + ->then($this->dispatchToRouter()); |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * Bootstrap the application for HTTP requests. |
|
159 | - * |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - protected function bootstrap() |
|
163 | - { |
|
164 | - if ( ! $this->app->hasBeenBootstrapped()) { |
|
165 | - $this->app->bootstrapWith($this->bootstrappers()); |
|
166 | - } |
|
157 | + /** |
|
158 | + * Bootstrap the application for HTTP requests. |
|
159 | + * |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + protected function bootstrap() |
|
163 | + { |
|
164 | + if ( ! $this->app->hasBeenBootstrapped()) { |
|
165 | + $this->app->bootstrapWith($this->bootstrappers()); |
|
166 | + } |
|
167 | 167 | |
168 | - $this->app->loadDeferredProviders(); |
|
169 | - } |
|
168 | + $this->app->loadDeferredProviders(); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Get the bootstrap classes for the application. |
|
173 | - * |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - protected function bootstrappers() |
|
177 | - { |
|
178 | - return $this->bootstrappers; |
|
179 | - } |
|
171 | + /** |
|
172 | + * Get the bootstrap classes for the application. |
|
173 | + * |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + protected function bootstrappers() |
|
177 | + { |
|
178 | + return $this->bootstrappers; |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Sync the current state of the middleware to the router. |
|
183 | - * |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - protected function syncMiddlewareRoute() |
|
187 | - { |
|
188 | - foreach ($this->middlewareGroups as $key => $middleware) { |
|
189 | - $this->router->middlewareGroup($key, $middleware); |
|
190 | - } |
|
181 | + /** |
|
182 | + * Sync the current state of the middleware to the router. |
|
183 | + * |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + protected function syncMiddlewareRoute() |
|
187 | + { |
|
188 | + foreach ($this->middlewareGroups as $key => $middleware) { |
|
189 | + $this->router->middlewareGroup($key, $middleware); |
|
190 | + } |
|
191 | 191 | |
192 | - foreach ($this->routeMiddleware as $key => $middleware) { |
|
193 | - $this->router->aliasMiddleware($key, $middleware); |
|
194 | - } |
|
195 | - } |
|
192 | + foreach ($this->routeMiddleware as $key => $middleware) { |
|
193 | + $this->router->aliasMiddleware($key, $middleware); |
|
194 | + } |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Get the dispatcher of routes. |
|
199 | - * |
|
200 | - * @return \Closure |
|
201 | - */ |
|
202 | - protected function dispatchToRouter() |
|
203 | - { |
|
204 | - return function ($request) { |
|
205 | - $this->app->instance('request', $request); |
|
197 | + /** |
|
198 | + * Get the dispatcher of routes. |
|
199 | + * |
|
200 | + * @return \Closure |
|
201 | + */ |
|
202 | + protected function dispatchToRouter() |
|
203 | + { |
|
204 | + return function ($request) { |
|
205 | + $this->app->instance('request', $request); |
|
206 | 206 | |
207 | - return $this->router->dispatch($request); |
|
208 | - }; |
|
209 | - } |
|
207 | + return $this->router->dispatch($request); |
|
208 | + }; |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Call the shutdown method on any terminable middleware. |
|
213 | - * |
|
214 | - * @param \Syscodes\Http\Request $request |
|
215 | - * @param \Syscodes\Http\Response $response |
|
216 | - * |
|
217 | - * @return void |
|
218 | - */ |
|
219 | - public function shutdown($request, $response) |
|
220 | - { |
|
221 | - $this->shutdownMiddleware($request, $response); |
|
222 | - } |
|
211 | + /** |
|
212 | + * Call the shutdown method on any terminable middleware. |
|
213 | + * |
|
214 | + * @param \Syscodes\Http\Request $request |
|
215 | + * @param \Syscodes\Http\Response $response |
|
216 | + * |
|
217 | + * @return void |
|
218 | + */ |
|
219 | + public function shutdown($request, $response) |
|
220 | + { |
|
221 | + $this->shutdownMiddleware($request, $response); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Call the terminate method on any terminable middleware. |
|
226 | - * |
|
227 | - * @param \Syscodes\Http\Request $request |
|
228 | - * @param \Syscodes\Http\Response $response |
|
229 | - * |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - protected function shutdownMiddleware($request, $response) |
|
233 | - { |
|
234 | - $middlewares = $this->app->skipGoingMiddleware() ? [] : array_merge( |
|
235 | - $this->gatherRouteMiddleware($request), |
|
236 | - $this->middleware |
|
237 | - ); |
|
224 | + /** |
|
225 | + * Call the terminate method on any terminable middleware. |
|
226 | + * |
|
227 | + * @param \Syscodes\Http\Request $request |
|
228 | + * @param \Syscodes\Http\Response $response |
|
229 | + * |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + protected function shutdownMiddleware($request, $response) |
|
233 | + { |
|
234 | + $middlewares = $this->app->skipGoingMiddleware() ? [] : array_merge( |
|
235 | + $this->gatherRouteMiddleware($request), |
|
236 | + $this->middleware |
|
237 | + ); |
|
238 | 238 | |
239 | - foreach ($middlewares as $middleware) { |
|
240 | - if (! is_string($middleware)) { |
|
241 | - continue; |
|
242 | - } |
|
239 | + foreach ($middlewares as $middleware) { |
|
240 | + if (! is_string($middleware)) { |
|
241 | + continue; |
|
242 | + } |
|
243 | 243 | |
244 | - [$name] = $this->parseMiddleware($middleware); |
|
244 | + [$name] = $this->parseMiddleware($middleware); |
|
245 | 245 | |
246 | - $instance = $this->app->make($name); |
|
246 | + $instance = $this->app->make($name); |
|
247 | 247 | |
248 | - if (method_exists($instance, 'shutdown')) { |
|
249 | - $instance->shutdown($request, $response); |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
248 | + if (method_exists($instance, 'shutdown')) { |
|
249 | + $instance->shutdown($request, $response); |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * Gather the route middleware for the given request. |
|
256 | - * |
|
257 | - * @param \Syscodes\Http\Request $request |
|
258 | - * |
|
259 | - * @return array |
|
260 | - */ |
|
261 | - protected function gatherRouteMiddleware($request) |
|
262 | - { |
|
263 | - if ( ! is_null($route = $request->route())) { |
|
264 | - return $this->router->gatherRouteMiddleware($route); |
|
265 | - } |
|
254 | + /** |
|
255 | + * Gather the route middleware for the given request. |
|
256 | + * |
|
257 | + * @param \Syscodes\Http\Request $request |
|
258 | + * |
|
259 | + * @return array |
|
260 | + */ |
|
261 | + protected function gatherRouteMiddleware($request) |
|
262 | + { |
|
263 | + if ( ! is_null($route = $request->route())) { |
|
264 | + return $this->router->gatherRouteMiddleware($route); |
|
265 | + } |
|
266 | 266 | |
267 | - return []; |
|
268 | - } |
|
267 | + return []; |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Parse a middleware string to get the name and parameters. |
|
272 | - * |
|
273 | - * @param string $middleware |
|
274 | - * |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - protected function parseMiddleware($middleware) |
|
278 | - { |
|
279 | - [$name, $parameters] = array_pad(explode(':', $middleware, 2), 2, []); |
|
270 | + /** |
|
271 | + * Parse a middleware string to get the name and parameters. |
|
272 | + * |
|
273 | + * @param string $middleware |
|
274 | + * |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + protected function parseMiddleware($middleware) |
|
278 | + { |
|
279 | + [$name, $parameters] = array_pad(explode(':', $middleware, 2), 2, []); |
|
280 | 280 | |
281 | - if (is_string($parameters)) { |
|
282 | - $parameters = explode(',', $parameters); |
|
283 | - } |
|
281 | + if (is_string($parameters)) { |
|
282 | + $parameters = explode(',', $parameters); |
|
283 | + } |
|
284 | 284 | |
285 | - return [$name, $parameters]; |
|
285 | + return [$name, $parameters]; |
|
286 | 286 | } |
287 | 287 | |
288 | - /** |
|
289 | - * Report the exception to the exception handler. |
|
290 | - * |
|
291 | - * @param \Throwable $e |
|
292 | - * |
|
293 | - * @return void |
|
294 | - */ |
|
295 | - protected function reportException(Throwable $e) |
|
296 | - { |
|
297 | - return $this->app[ExceptionHandler::class]->report($e); |
|
298 | - } |
|
288 | + /** |
|
289 | + * Report the exception to the exception handler. |
|
290 | + * |
|
291 | + * @param \Throwable $e |
|
292 | + * |
|
293 | + * @return void |
|
294 | + */ |
|
295 | + protected function reportException(Throwable $e) |
|
296 | + { |
|
297 | + return $this->app[ExceptionHandler::class]->report($e); |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Render the exception to a response. |
|
302 | - * |
|
303 | - * @param \Syscodes\Http\Request $request |
|
304 | - * @param \Throwable $e |
|
305 | - * |
|
306 | - * @return \Syscodes\Http\Response |
|
307 | - */ |
|
308 | - protected function renderException($request, Throwable $e) |
|
309 | - { |
|
310 | - return $this->app[ExceptionHandler::class]->render($request, $e); |
|
311 | - } |
|
312 | - } |
|
313 | 300 | \ No newline at end of file |
301 | + /** |
|
302 | + * Render the exception to a response. |
|
303 | + * |
|
304 | + * @param \Syscodes\Http\Request $request |
|
305 | + * @param \Throwable $e |
|
306 | + * |
|
307 | + * @return \Syscodes\Http\Response |
|
308 | + */ |
|
309 | + protected function renderException($request, Throwable $e) |
|
310 | + { |
|
311 | + return $this->app[ExceptionHandler::class]->render($request, $e); |
|
312 | + } |
|
313 | + } |
|
314 | 314 | \ No newline at end of file |
@@ -37,117 +37,117 @@ |
||
37 | 37 | */ |
38 | 38 | trait RouteResolver |
39 | 39 | { |
40 | - /** |
|
41 | - * The currently dispatched route instance. |
|
42 | - * |
|
43 | - * @var \Syscodes\Routing\Route|null |
|
44 | - */ |
|
45 | - protected $current; |
|
40 | + /** |
|
41 | + * The currently dispatched route instance. |
|
42 | + * |
|
43 | + * @var \Syscodes\Routing\Route|null |
|
44 | + */ |
|
45 | + protected $current; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Resolve the given route and call the method that belongs to the route. |
|
49 | - * |
|
50 | - * @param \Syscodes\Http\Request $request |
|
51 | - * |
|
52 | - * @return \Syscodes\Http\Response |
|
53 | - */ |
|
54 | - public function resolve(Request $request) |
|
55 | - { |
|
56 | - return $this->dispatchToRoute($request); |
|
57 | - } |
|
47 | + /** |
|
48 | + * Resolve the given route and call the method that belongs to the route. |
|
49 | + * |
|
50 | + * @param \Syscodes\Http\Request $request |
|
51 | + * |
|
52 | + * @return \Syscodes\Http\Response |
|
53 | + */ |
|
54 | + public function resolve(Request $request) |
|
55 | + { |
|
56 | + return $this->dispatchToRoute($request); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Dispatch the request to a route and return the response. |
|
61 | - * |
|
62 | - * @param \Syscodes\Http\Request $request |
|
63 | - * |
|
64 | - * @return \Syscodes\Http\Response |
|
65 | - */ |
|
66 | - protected function dispatchToRoute(Request $request) |
|
67 | - { |
|
68 | - return $this->runRoute($request, $this->findRoute($request)); |
|
69 | - } |
|
59 | + /** |
|
60 | + * Dispatch the request to a route and return the response. |
|
61 | + * |
|
62 | + * @param \Syscodes\Http\Request $request |
|
63 | + * |
|
64 | + * @return \Syscodes\Http\Response |
|
65 | + */ |
|
66 | + protected function dispatchToRoute(Request $request) |
|
67 | + { |
|
68 | + return $this->runRoute($request, $this->findRoute($request)); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Find the route matching a given request. |
|
73 | - * |
|
74 | - * @param \Syscodes\Http\Request $request |
|
75 | - * |
|
76 | - * @return \Syscodes\Routing\Route |
|
77 | - */ |
|
78 | - protected function findRoute($request) |
|
79 | - { |
|
80 | - // Get all register routes with the same request method |
|
81 | - $this->current = $route = $this->routes->match($request); |
|
71 | + /** |
|
72 | + * Find the route matching a given request. |
|
73 | + * |
|
74 | + * @param \Syscodes\Http\Request $request |
|
75 | + * |
|
76 | + * @return \Syscodes\Routing\Route |
|
77 | + */ |
|
78 | + protected function findRoute($request) |
|
79 | + { |
|
80 | + // Get all register routes with the same request method |
|
81 | + $this->current = $route = $this->routes->match($request); |
|
82 | 82 | |
83 | - $this->container->instance(Route::class, $route); |
|
83 | + $this->container->instance(Route::class, $route); |
|
84 | 84 | |
85 | - return $route; |
|
86 | - } |
|
85 | + return $route; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Return the response for the given route. |
|
90 | - * |
|
91 | - * @param \Syscodes\Http\Request $request |
|
92 | - * @param \Syscodes\Routing\Route $route |
|
93 | - * |
|
94 | - * @return \Syscodes\Http\Response |
|
95 | - */ |
|
96 | - protected function runRoute(Request $request, Route $route) |
|
97 | - { |
|
98 | - $request->setRouteResolver(function () use ($route) { |
|
99 | - return $route; |
|
100 | - }); |
|
88 | + /** |
|
89 | + * Return the response for the given route. |
|
90 | + * |
|
91 | + * @param \Syscodes\Http\Request $request |
|
92 | + * @param \Syscodes\Routing\Route $route |
|
93 | + * |
|
94 | + * @return \Syscodes\Http\Response |
|
95 | + */ |
|
96 | + protected function runRoute(Request $request, Route $route) |
|
97 | + { |
|
98 | + $request->setRouteResolver(function () use ($route) { |
|
99 | + return $route; |
|
100 | + }); |
|
101 | 101 | |
102 | - return $this->callResponse($request, |
|
103 | - $this->runRouteStack($route, $request) |
|
104 | - ); |
|
105 | - } |
|
102 | + return $this->callResponse($request, |
|
103 | + $this->runRouteStack($route, $request) |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Run the given route through a stack response instance. |
|
109 | - * |
|
110 | - * @param \Syscodes\Routing\Route $route |
|
111 | - * @param \Syscodes\Http\Request $request |
|
112 | - * |
|
113 | - * @return mixed |
|
114 | - */ |
|
115 | - protected function runRouteStack(Route $route, Request $request) |
|
116 | - { |
|
117 | - $skipMiddleware = $this->container->bound('middleware.disable') && |
|
118 | - ($this->container->make('middleware.disable') === true); |
|
107 | + /** |
|
108 | + * Run the given route through a stack response instance. |
|
109 | + * |
|
110 | + * @param \Syscodes\Routing\Route $route |
|
111 | + * @param \Syscodes\Http\Request $request |
|
112 | + * |
|
113 | + * @return mixed |
|
114 | + */ |
|
115 | + protected function runRouteStack(Route $route, Request $request) |
|
116 | + { |
|
117 | + $skipMiddleware = $this->container->bound('middleware.disable') && |
|
118 | + ($this->container->make('middleware.disable') === true); |
|
119 | 119 | |
120 | 120 | |
121 | - $middleware = $skipMiddleware ? [] : $this->gatherRouteMiddleware($route); |
|
121 | + $middleware = $skipMiddleware ? [] : $this->gatherRouteMiddleware($route); |
|
122 | 122 | |
123 | - return (new Pipeline($this->container)) |
|
124 | - ->send($request) |
|
125 | - ->through($middleware) |
|
126 | - ->then(function ($request) use ($route) { |
|
127 | - return $this->callResponse( |
|
128 | - $request, $route->runResolver() |
|
129 | - ); |
|
130 | - }); |
|
131 | - } |
|
123 | + return (new Pipeline($this->container)) |
|
124 | + ->send($request) |
|
125 | + ->through($middleware) |
|
126 | + ->then(function ($request) use ($route) { |
|
127 | + return $this->callResponse( |
|
128 | + $request, $route->runResolver() |
|
129 | + ); |
|
130 | + }); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Create a response instance from the given value. |
|
135 | - * |
|
136 | - * @param \Syscodes\Http\Request $request |
|
137 | - * @param mixed $response |
|
138 | - * |
|
139 | - * @return \Syscodes\Http\Response |
|
140 | - */ |
|
141 | - protected function callResponse($request, $response) |
|
142 | - { |
|
143 | - if ( ! $response instanceof Response && |
|
144 | - ($response instanceof Jsonserializable || |
|
145 | - is_array($response))) { |
|
146 | - $response = new JsonResponse($response); |
|
147 | - } elseif ( ! $response instanceof Response) { |
|
148 | - $response = new Response($response, 200, ['Content-Type' => 'text/html']); |
|
149 | - } |
|
133 | + /** |
|
134 | + * Create a response instance from the given value. |
|
135 | + * |
|
136 | + * @param \Syscodes\Http\Request $request |
|
137 | + * @param mixed $response |
|
138 | + * |
|
139 | + * @return \Syscodes\Http\Response |
|
140 | + */ |
|
141 | + protected function callResponse($request, $response) |
|
142 | + { |
|
143 | + if ( ! $response instanceof Response && |
|
144 | + ($response instanceof Jsonserializable || |
|
145 | + is_array($response))) { |
|
146 | + $response = new JsonResponse($response); |
|
147 | + } elseif ( ! $response instanceof Response) { |
|
148 | + $response = new Response($response, 200, ['Content-Type' => 'text/html']); |
|
149 | + } |
|
150 | 150 | |
151 | - return $response->prepare($request); |
|
152 | - } |
|
151 | + return $response->prepare($request); |
|
152 | + } |
|
153 | 153 | } |
154 | 154 | \ No newline at end of file |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | protected function runRoute(Request $request, Route $route) |
97 | 97 | { |
98 | - $request->setRouteResolver(function () use ($route) { |
|
98 | + $request->setRouteResolver(function() use ($route) { |
|
99 | 99 | return $route; |
100 | 100 | }); |
101 | 101 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | return (new Pipeline($this->container)) |
124 | 124 | ->send($request) |
125 | 125 | ->through($middleware) |
126 | - ->then(function ($request) use ($route) { |
|
126 | + ->then(function($request) use ($route) { |
|
127 | 127 | return $this->callResponse( |
128 | 128 | $request, $route->runResolver() |
129 | 129 | ); |
@@ -39,651 +39,651 @@ |
||
39 | 39 | */ |
40 | 40 | class Router implements Routable |
41 | 41 | { |
42 | - use Concerns\RouteMap, |
|
43 | - Concerns\RouteResolver; |
|
44 | - |
|
45 | - /** |
|
46 | - * The registered route value binders. |
|
47 | - * |
|
48 | - * @var array $binders |
|
49 | - */ |
|
50 | - protected $binders = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * The container instance used by the router. |
|
54 | - * |
|
55 | - * @var \Syscodes\Contracts\Container\Container $container |
|
56 | - */ |
|
57 | - protected $container; |
|
58 | - |
|
59 | - /** |
|
60 | - * Variable of group route. |
|
61 | - * |
|
62 | - * @var array $groupStack |
|
63 | - */ |
|
64 | - protected $groupStack = []; |
|
42 | + use Concerns\RouteMap, |
|
43 | + Concerns\RouteResolver; |
|
44 | + |
|
45 | + /** |
|
46 | + * The registered route value binders. |
|
47 | + * |
|
48 | + * @var array $binders |
|
49 | + */ |
|
50 | + protected $binders = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * The container instance used by the router. |
|
54 | + * |
|
55 | + * @var \Syscodes\Contracts\Container\Container $container |
|
56 | + */ |
|
57 | + protected $container; |
|
58 | + |
|
59 | + /** |
|
60 | + * Variable of group route. |
|
61 | + * |
|
62 | + * @var array $groupStack |
|
63 | + */ |
|
64 | + protected $groupStack = []; |
|
65 | 65 | |
66 | - /** |
|
67 | - * The registered string macros. |
|
68 | - * |
|
69 | - * @var array $macros |
|
70 | - */ |
|
71 | - protected $macros = []; |
|
72 | - |
|
73 | - /** |
|
74 | - * Middleware for function of filters |
|
75 | - * |
|
76 | - * @var array $middleware |
|
77 | - */ |
|
78 | - protected $middleware = []; |
|
66 | + /** |
|
67 | + * The registered string macros. |
|
68 | + * |
|
69 | + * @var array $macros |
|
70 | + */ |
|
71 | + protected $macros = []; |
|
72 | + |
|
73 | + /** |
|
74 | + * Middleware for function of filters |
|
75 | + * |
|
76 | + * @var array $middleware |
|
77 | + */ |
|
78 | + protected $middleware = []; |
|
79 | 79 | |
80 | - /** |
|
81 | - * All of the middleware groups. |
|
82 | - * |
|
83 | - * @var array $middlewareGroups |
|
84 | - */ |
|
85 | - protected $middlewareGroups = []; |
|
80 | + /** |
|
81 | + * All of the middleware groups. |
|
82 | + * |
|
83 | + * @var array $middlewareGroups |
|
84 | + */ |
|
85 | + protected $middlewareGroups = []; |
|
86 | 86 | |
87 | - /** |
|
88 | - * The priority-sorted list of middleware. |
|
89 | - * |
|
90 | - * @var array $middlewarePriority |
|
91 | - */ |
|
92 | - public $middlewarePriority = []; |
|
87 | + /** |
|
88 | + * The priority-sorted list of middleware. |
|
89 | + * |
|
90 | + * @var array $middlewarePriority |
|
91 | + */ |
|
92 | + public $middlewarePriority = []; |
|
93 | 93 | |
94 | - /** |
|
95 | - * The globally available parameter patterns. |
|
96 | - * |
|
97 | - * @var array $patterns |
|
98 | - */ |
|
99 | - protected $patterns = []; |
|
100 | - |
|
101 | - /** |
|
102 | - * The route collection instance. |
|
103 | - * |
|
104 | - * @var \Syscodes\Routing\RouteCollection $routes |
|
105 | - */ |
|
106 | - protected $routes; |
|
107 | - |
|
108 | - /** |
|
109 | - * The Resource instance. |
|
110 | - * |
|
111 | - * @var \Syscodes\Routing\ResourceRegister $resources |
|
112 | - */ |
|
113 | - protected $resources; |
|
114 | - |
|
115 | - /** |
|
116 | - * Constructor. Create a new Router instance. |
|
117 | - * |
|
118 | - * @param \Syscodes\Contracts\Container\Container|null $container (null by default) |
|
119 | - * |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function __construct(Container $container = null) |
|
123 | - { |
|
124 | - $this->routes = new RouteCollection(); |
|
125 | - |
|
126 | - $this->container = $container ?: new Container; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Get the prefix from the group on the stack. |
|
131 | - * |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function getGroupPrefix() |
|
135 | - { |
|
136 | - if ( ! empty($this->groupStack)) { |
|
137 | - $last = end($this->groupStack); |
|
138 | - |
|
139 | - return $last['prefix'] ?? ''; |
|
140 | - } |
|
141 | - |
|
142 | - return ''; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Group a series of routes under a single URL segment. This is handy |
|
147 | - * for grouping items into an admin area, like: |
|
148 | - * |
|
149 | - * Example: |
|
150 | - * // Creates route: /admin show the word 'User' |
|
151 | - * Route::group(['prefix' => 'admin'], function() { |
|
152 | - * |
|
153 | - * Route::get('/user', function() { |
|
154 | - * echo 'Hello world..!'; |
|
155 | - * }); |
|
156 | - * |
|
157 | - * }); /admin/user |
|
158 | - * |
|
159 | - * @param array $attributes |
|
160 | - * @param \Closure|string $callback |
|
161 | - * |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - public function group(array $attributes, $callback) |
|
165 | - { |
|
166 | - $this->updateGroupStack($attributes); |
|
167 | - |
|
168 | - $this->loadRoutes($callback); |
|
169 | - |
|
170 | - array_pop($this->groupStack); |
|
171 | - |
|
172 | - return $this; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Update the group stack with the given attributes. |
|
177 | - * |
|
178 | - * @param array $attributes |
|
179 | - * |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - protected function updateGroupStack(array $attributes) |
|
183 | - { |
|
184 | - if ( ! empty($this->groupStack)) { |
|
185 | - $attributes = $this->mergeGroup($attributes); |
|
186 | - } |
|
187 | - |
|
188 | - $this->groupStack[] = $attributes; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Merge the given group attributes. |
|
193 | - * |
|
194 | - * @param array $new |
|
195 | - * |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - protected function mergeGroup($new) |
|
199 | - { |
|
200 | - return RouteGroup::mergeGroup($new, end($this->groupStack)); |
|
201 | - } |
|
94 | + /** |
|
95 | + * The globally available parameter patterns. |
|
96 | + * |
|
97 | + * @var array $patterns |
|
98 | + */ |
|
99 | + protected $patterns = []; |
|
100 | + |
|
101 | + /** |
|
102 | + * The route collection instance. |
|
103 | + * |
|
104 | + * @var \Syscodes\Routing\RouteCollection $routes |
|
105 | + */ |
|
106 | + protected $routes; |
|
107 | + |
|
108 | + /** |
|
109 | + * The Resource instance. |
|
110 | + * |
|
111 | + * @var \Syscodes\Routing\ResourceRegister $resources |
|
112 | + */ |
|
113 | + protected $resources; |
|
114 | + |
|
115 | + /** |
|
116 | + * Constructor. Create a new Router instance. |
|
117 | + * |
|
118 | + * @param \Syscodes\Contracts\Container\Container|null $container (null by default) |
|
119 | + * |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function __construct(Container $container = null) |
|
123 | + { |
|
124 | + $this->routes = new RouteCollection(); |
|
125 | + |
|
126 | + $this->container = $container ?: new Container; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Get the prefix from the group on the stack. |
|
131 | + * |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function getGroupPrefix() |
|
135 | + { |
|
136 | + if ( ! empty($this->groupStack)) { |
|
137 | + $last = end($this->groupStack); |
|
138 | + |
|
139 | + return $last['prefix'] ?? ''; |
|
140 | + } |
|
141 | + |
|
142 | + return ''; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Group a series of routes under a single URL segment. This is handy |
|
147 | + * for grouping items into an admin area, like: |
|
148 | + * |
|
149 | + * Example: |
|
150 | + * // Creates route: /admin show the word 'User' |
|
151 | + * Route::group(['prefix' => 'admin'], function() { |
|
152 | + * |
|
153 | + * Route::get('/user', function() { |
|
154 | + * echo 'Hello world..!'; |
|
155 | + * }); |
|
156 | + * |
|
157 | + * }); /admin/user |
|
158 | + * |
|
159 | + * @param array $attributes |
|
160 | + * @param \Closure|string $callback |
|
161 | + * |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + public function group(array $attributes, $callback) |
|
165 | + { |
|
166 | + $this->updateGroupStack($attributes); |
|
167 | + |
|
168 | + $this->loadRoutes($callback); |
|
169 | + |
|
170 | + array_pop($this->groupStack); |
|
171 | + |
|
172 | + return $this; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Update the group stack with the given attributes. |
|
177 | + * |
|
178 | + * @param array $attributes |
|
179 | + * |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + protected function updateGroupStack(array $attributes) |
|
183 | + { |
|
184 | + if ( ! empty($this->groupStack)) { |
|
185 | + $attributes = $this->mergeGroup($attributes); |
|
186 | + } |
|
187 | + |
|
188 | + $this->groupStack[] = $attributes; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Merge the given group attributes. |
|
193 | + * |
|
194 | + * @param array $new |
|
195 | + * |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + protected function mergeGroup($new) |
|
199 | + { |
|
200 | + return RouteGroup::mergeGroup($new, end($this->groupStack)); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Load the provided routes. |
|
205 | - * |
|
206 | - * @param \Closure|string $callback |
|
207 | - * |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - protected function loadRoutes($callback) |
|
211 | - { |
|
212 | - if ($callback instanceof Closure) { |
|
213 | - $callback($this); |
|
214 | - } else { |
|
215 | - (new RouteFileRegister($this))->register($callback); |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Add a route to the underlying route collection. |
|
221 | - * |
|
222 | - * @param array|string $method |
|
223 | - * @param string $route |
|
224 | - * @param mixed $action |
|
225 | - * |
|
226 | - * @return \Syscodes\Routing\Route |
|
227 | - */ |
|
228 | - public function addRoute($method, $route, $action) |
|
229 | - { |
|
230 | - return $this->routes->add($this->map($method, $route, $action)); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Create a redirect from one URI to another. |
|
235 | - * |
|
236 | - * @param string $uri |
|
237 | - * @param string $destination |
|
238 | - * @param int $status (302 by default) |
|
239 | - * |
|
240 | - * @return \Syscodes\Routing\Route |
|
241 | - */ |
|
242 | - public function redirect($uri, $destination, $status = 302) |
|
243 | - { |
|
244 | - return $this->any($uri, function () use ($destination, $status) { |
|
245 | - return new RedirectResponse($destination, $status); |
|
246 | - }); |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Register a new route that returns a view. |
|
251 | - * |
|
252 | - * @param string $uri |
|
253 | - * @param string $view |
|
254 | - * @param array $data |
|
255 | - * |
|
256 | - * @return \Syscodes\Routing\Route |
|
257 | - */ |
|
258 | - public function view($uri, $view, $data = []) |
|
259 | - { |
|
260 | - return $this->match(['GET', 'HEAD'], $uri, function () use ($view, $data) { |
|
261 | - return $this->container->make('view')->make($view, $data); |
|
262 | - }); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Add new route to routes array. |
|
267 | - * |
|
268 | - * @param array|string $method |
|
269 | - * @param string $route |
|
270 | - * @param mixed $action |
|
271 | - * |
|
272 | - * @return void |
|
273 | - * |
|
274 | - * @throws \InvalidArgumentException |
|
275 | - */ |
|
276 | - public function map($method, $route, $action) |
|
277 | - { |
|
278 | - if ($this->actionReferencesController($action)) { |
|
279 | - $action = $this->convertToControllerAction($action); |
|
280 | - } |
|
281 | - |
|
282 | - $route = $this->newRoute( |
|
283 | - array_map('strtoupper', (array) $method), |
|
284 | - $this->prefix($route), |
|
285 | - $action |
|
286 | - ); |
|
287 | - |
|
288 | - if ($this->hasGroupStack()) { |
|
289 | - $this->mergeGroupAttributesIntoRoute($route); |
|
290 | - } |
|
291 | - |
|
292 | - $this->addWhereClausesToRoute($route); |
|
203 | + /** |
|
204 | + * Load the provided routes. |
|
205 | + * |
|
206 | + * @param \Closure|string $callback |
|
207 | + * |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + protected function loadRoutes($callback) |
|
211 | + { |
|
212 | + if ($callback instanceof Closure) { |
|
213 | + $callback($this); |
|
214 | + } else { |
|
215 | + (new RouteFileRegister($this))->register($callback); |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Add a route to the underlying route collection. |
|
221 | + * |
|
222 | + * @param array|string $method |
|
223 | + * @param string $route |
|
224 | + * @param mixed $action |
|
225 | + * |
|
226 | + * @return \Syscodes\Routing\Route |
|
227 | + */ |
|
228 | + public function addRoute($method, $route, $action) |
|
229 | + { |
|
230 | + return $this->routes->add($this->map($method, $route, $action)); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Create a redirect from one URI to another. |
|
235 | + * |
|
236 | + * @param string $uri |
|
237 | + * @param string $destination |
|
238 | + * @param int $status (302 by default) |
|
239 | + * |
|
240 | + * @return \Syscodes\Routing\Route |
|
241 | + */ |
|
242 | + public function redirect($uri, $destination, $status = 302) |
|
243 | + { |
|
244 | + return $this->any($uri, function () use ($destination, $status) { |
|
245 | + return new RedirectResponse($destination, $status); |
|
246 | + }); |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Register a new route that returns a view. |
|
251 | + * |
|
252 | + * @param string $uri |
|
253 | + * @param string $view |
|
254 | + * @param array $data |
|
255 | + * |
|
256 | + * @return \Syscodes\Routing\Route |
|
257 | + */ |
|
258 | + public function view($uri, $view, $data = []) |
|
259 | + { |
|
260 | + return $this->match(['GET', 'HEAD'], $uri, function () use ($view, $data) { |
|
261 | + return $this->container->make('view')->make($view, $data); |
|
262 | + }); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Add new route to routes array. |
|
267 | + * |
|
268 | + * @param array|string $method |
|
269 | + * @param string $route |
|
270 | + * @param mixed $action |
|
271 | + * |
|
272 | + * @return void |
|
273 | + * |
|
274 | + * @throws \InvalidArgumentException |
|
275 | + */ |
|
276 | + public function map($method, $route, $action) |
|
277 | + { |
|
278 | + if ($this->actionReferencesController($action)) { |
|
279 | + $action = $this->convertToControllerAction($action); |
|
280 | + } |
|
281 | + |
|
282 | + $route = $this->newRoute( |
|
283 | + array_map('strtoupper', (array) $method), |
|
284 | + $this->prefix($route), |
|
285 | + $action |
|
286 | + ); |
|
287 | + |
|
288 | + if ($this->hasGroupStack()) { |
|
289 | + $this->mergeGroupAttributesIntoRoute($route); |
|
290 | + } |
|
291 | + |
|
292 | + $this->addWhereClausesToRoute($route); |
|
293 | 293 | |
294 | - return $route; |
|
295 | - } |
|
294 | + return $route; |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
298 | - * Determine if the action is routing to a controller. |
|
299 | - * |
|
300 | - * @param array $action |
|
301 | - * |
|
302 | - * @return bool |
|
303 | - */ |
|
304 | - protected function actionReferencesController($action) |
|
305 | - { |
|
306 | - if ($action instanceof Closure) { |
|
307 | - return false; |
|
308 | - } |
|
297 | + /** |
|
298 | + * Determine if the action is routing to a controller. |
|
299 | + * |
|
300 | + * @param array $action |
|
301 | + * |
|
302 | + * @return bool |
|
303 | + */ |
|
304 | + protected function actionReferencesController($action) |
|
305 | + { |
|
306 | + if ($action instanceof Closure) { |
|
307 | + return false; |
|
308 | + } |
|
309 | 309 | |
310 | - return is_string($action) || (isset($action['uses']) && is_string($action['uses'])); |
|
311 | - } |
|
310 | + return is_string($action) || (isset($action['uses']) && is_string($action['uses'])); |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * Add a controller based route action to the action array. |
|
315 | - * |
|
316 | - * @param array|string $action |
|
317 | - * |
|
318 | - * @return array |
|
319 | - */ |
|
320 | - protected function convertToControllerAction($action) |
|
321 | - { |
|
322 | - if (is_string($action)) { |
|
323 | - $action = ['uses' => $action]; |
|
324 | - } |
|
313 | + /** |
|
314 | + * Add a controller based route action to the action array. |
|
315 | + * |
|
316 | + * @param array|string $action |
|
317 | + * |
|
318 | + * @return array |
|
319 | + */ |
|
320 | + protected function convertToControllerAction($action) |
|
321 | + { |
|
322 | + if (is_string($action)) { |
|
323 | + $action = ['uses' => $action]; |
|
324 | + } |
|
325 | 325 | |
326 | - if ( ! empty($this->groupStack)) { |
|
327 | - $action['uses'] = $this->prependGroupUses($action['uses']); |
|
328 | - } |
|
326 | + if ( ! empty($this->groupStack)) { |
|
327 | + $action['uses'] = $this->prependGroupUses($action['uses']); |
|
328 | + } |
|
329 | 329 | |
330 | - $action['controller'] = $action['uses']; |
|
330 | + $action['controller'] = $action['uses']; |
|
331 | 331 | |
332 | - return $action; |
|
333 | - } |
|
332 | + return $action; |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * Prepend the last group uses onto the use clause. |
|
337 | - * |
|
338 | - * @param string $uses |
|
339 | - * |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - protected function prependGroupUses($uses) |
|
343 | - { |
|
344 | - $group = end($this->groupStack); |
|
335 | + /** |
|
336 | + * Prepend the last group uses onto the use clause. |
|
337 | + * |
|
338 | + * @param string $uses |
|
339 | + * |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + protected function prependGroupUses($uses) |
|
343 | + { |
|
344 | + $group = end($this->groupStack); |
|
345 | 345 | |
346 | - return isset($group['namespace']) ? $group['namespace'].'\\'.$uses : $uses; |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Create a new Route object. |
|
351 | - * |
|
352 | - * @param array|string $method |
|
353 | - * @param string $uri |
|
354 | - * @param mixed $action |
|
355 | - * |
|
356 | - * @return \Syscodes\Routing\Route |
|
357 | - */ |
|
358 | - public function newRoute($method, $uri, $action) |
|
359 | - { |
|
360 | - return take(new Route($method, $uri, $action)) |
|
361 | - ->setContainer($this->container); |
|
362 | - } |
|
346 | + return isset($group['namespace']) ? $group['namespace'].'\\'.$uses : $uses; |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Create a new Route object. |
|
351 | + * |
|
352 | + * @param array|string $method |
|
353 | + * @param string $uri |
|
354 | + * @param mixed $action |
|
355 | + * |
|
356 | + * @return \Syscodes\Routing\Route |
|
357 | + */ |
|
358 | + public function newRoute($method, $uri, $action) |
|
359 | + { |
|
360 | + return take(new Route($method, $uri, $action)) |
|
361 | + ->setContainer($this->container); |
|
362 | + } |
|
363 | 363 | |
364 | - /** |
|
365 | - * Determine if the router currently has a group stack. |
|
366 | - * |
|
367 | - * @return bool |
|
368 | - */ |
|
369 | - public function hasGroupStack() |
|
370 | - { |
|
371 | - return ! empty($this->groupStack); |
|
372 | - } |
|
364 | + /** |
|
365 | + * Determine if the router currently has a group stack. |
|
366 | + * |
|
367 | + * @return bool |
|
368 | + */ |
|
369 | + public function hasGroupStack() |
|
370 | + { |
|
371 | + return ! empty($this->groupStack); |
|
372 | + } |
|
373 | 373 | |
374 | - /** |
|
375 | - * Merge the group stack with the controller action. |
|
376 | - * |
|
377 | - * @param \Syscpde\Routing\Route $route |
|
378 | - * |
|
379 | - * @return void |
|
380 | - */ |
|
381 | - protected function mergeGroupAttributesIntoRoute($route) |
|
382 | - { |
|
383 | - $action = static::mergeGroup($route->getAction(), end($this->groupStack)); |
|
374 | + /** |
|
375 | + * Merge the group stack with the controller action. |
|
376 | + * |
|
377 | + * @param \Syscpde\Routing\Route $route |
|
378 | + * |
|
379 | + * @return void |
|
380 | + */ |
|
381 | + protected function mergeGroupAttributesIntoRoute($route) |
|
382 | + { |
|
383 | + $action = static::mergeGroup($route->getAction(), end($this->groupStack)); |
|
384 | 384 | |
385 | - $route->setAction($action); |
|
386 | - } |
|
385 | + $route->setAction($action); |
|
386 | + } |
|
387 | 387 | |
388 | - /** |
|
389 | - * Add the necessary where clauses to the route based on its initial registration. |
|
390 | - * |
|
391 | - * @param \Syscodes\Routing\Route $route |
|
392 | - * |
|
393 | - * @return \Syscodes\Routing\Route |
|
394 | - */ |
|
395 | - protected function addWhereClausesToRoute($route) |
|
396 | - { |
|
397 | - return $route->where(array_merge( |
|
398 | - $this->patterns, Arr::get($route->getAction(), 'where', []) |
|
399 | - )); |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Add a prefix to the route URI. |
|
404 | - * |
|
405 | - * @param string $uri |
|
406 | - * |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - protected function prefix($uri) |
|
410 | - { |
|
411 | - $uri = is_null($uri) ? '' : trim($uri, '/').'/'; |
|
412 | - |
|
413 | - $uri = filter_var($uri, FILTER_SANITIZE_STRING); |
|
414 | - |
|
415 | - // While we want to add a route within a group of '/', |
|
416 | - // it doens't work with matching, so remove them... |
|
417 | - if ($uri != '/') { |
|
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 | - $this->patterns[$key] = $pattern; |
|
448 | - } |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Get a Resource instance. |
|
453 | - * |
|
454 | - * @return \Syscodes\Routing\ResourceRegister |
|
455 | - */ |
|
456 | - public function getResource() |
|
457 | - { |
|
458 | - if (isset($this->resources)) { |
|
459 | - return $this->resources; |
|
460 | - } |
|
461 | - |
|
462 | - return $this->resources = new ResourceRegister($this); |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Dispatches the given url and call the method that belongs to the route. |
|
467 | - * |
|
468 | - * @param \Syscodes\Http\Request $request |
|
469 | - * |
|
470 | - * @return mixed |
|
471 | - */ |
|
472 | - public function dispatch(Request $request) |
|
473 | - { |
|
474 | - return $this->resolve($request); |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Gather the middleware for the given route. |
|
479 | - * |
|
480 | - * @param \Syscodes\Routing\Route $route |
|
481 | - * |
|
482 | - * @return array |
|
483 | - */ |
|
484 | - public function gatherRouteMiddleware(Route $route) |
|
485 | - { |
|
486 | - $middleware = array_map(function ($name) { |
|
388 | + /** |
|
389 | + * Add the necessary where clauses to the route based on its initial registration. |
|
390 | + * |
|
391 | + * @param \Syscodes\Routing\Route $route |
|
392 | + * |
|
393 | + * @return \Syscodes\Routing\Route |
|
394 | + */ |
|
395 | + protected function addWhereClausesToRoute($route) |
|
396 | + { |
|
397 | + return $route->where(array_merge( |
|
398 | + $this->patterns, Arr::get($route->getAction(), 'where', []) |
|
399 | + )); |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Add a prefix to the route URI. |
|
404 | + * |
|
405 | + * @param string $uri |
|
406 | + * |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + protected function prefix($uri) |
|
410 | + { |
|
411 | + $uri = is_null($uri) ? '' : trim($uri, '/').'/'; |
|
412 | + |
|
413 | + $uri = filter_var($uri, FILTER_SANITIZE_STRING); |
|
414 | + |
|
415 | + // While we want to add a route within a group of '/', |
|
416 | + // it doens't work with matching, so remove them... |
|
417 | + if ($uri != '/') { |
|
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 | + $this->patterns[$key] = $pattern; |
|
448 | + } |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Get a Resource instance. |
|
453 | + * |
|
454 | + * @return \Syscodes\Routing\ResourceRegister |
|
455 | + */ |
|
456 | + public function getResource() |
|
457 | + { |
|
458 | + if (isset($this->resources)) { |
|
459 | + return $this->resources; |
|
460 | + } |
|
461 | + |
|
462 | + return $this->resources = new ResourceRegister($this); |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Dispatches the given url and call the method that belongs to the route. |
|
467 | + * |
|
468 | + * @param \Syscodes\Http\Request $request |
|
469 | + * |
|
470 | + * @return mixed |
|
471 | + */ |
|
472 | + public function dispatch(Request $request) |
|
473 | + { |
|
474 | + return $this->resolve($request); |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Gather the middleware for the given route. |
|
479 | + * |
|
480 | + * @param \Syscodes\Routing\Route $route |
|
481 | + * |
|
482 | + * @return array |
|
483 | + */ |
|
484 | + public function gatherRouteMiddleware(Route $route) |
|
485 | + { |
|
486 | + $middleware = array_map(function ($name) { |
|
487 | 487 | return MiddlewareResolver::resolve($name, $this->middleware, $this->middlewareGroups); |
488 | 488 | }, $route->gatherMiddleware()); |
489 | 489 | |
490 | 490 | return Arr::flatten($middleware); |
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Get all of the defined middleware |
|
495 | - * |
|
496 | - * @return array |
|
497 | - */ |
|
498 | - public function getMiddleware() |
|
499 | - { |
|
500 | - return $this->middleware; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Register a short-hand name for a middleware. |
|
505 | - * |
|
506 | - * @param string $name |
|
507 | - * @param string $class |
|
508 | - * |
|
509 | - * @return $this |
|
510 | - */ |
|
511 | - public function aliasMiddleware($name, $class) |
|
512 | - { |
|
513 | - $this->middleware[$name] = $class; |
|
514 | - |
|
515 | - return $this; |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Register a group of middleware. |
|
520 | - * |
|
521 | - * @param string $name |
|
522 | - * @param array $middleware |
|
523 | - * |
|
524 | - * @return $this |
|
525 | - */ |
|
526 | - public function middlewareGroup($name, array $middleware) |
|
527 | - { |
|
528 | - $this->middlewareGroups[$name] = $middleware; |
|
529 | - |
|
530 | - return $this; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Check if a route with the given name exists. |
|
535 | - * |
|
536 | - * @param string $name |
|
537 | - * |
|
538 | - * @return bool |
|
539 | - */ |
|
540 | - public function has($name) |
|
541 | - { |
|
542 | - $names = is_array($name) ? $name : func_get_args(); |
|
543 | - |
|
544 | - foreach ($names as $value) { |
|
545 | - if ( ! $this->routes->hasNamedRoute($value)) { |
|
546 | - return false; |
|
547 | - } |
|
548 | - } |
|
549 | - |
|
550 | - return true; |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Get the currently dispatched route instance. |
|
555 | - * |
|
556 | - * @return \Syscodes\Routing\Route|null |
|
557 | - */ |
|
558 | - public function current() |
|
559 | - { |
|
560 | - return $this->current; |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Determine if the current route matches a pattern. |
|
565 | - * |
|
566 | - * @param mixed ...$patterns |
|
567 | - * |
|
568 | - * @return bool |
|
569 | - */ |
|
570 | - public function is(...$patterns) |
|
571 | - { |
|
572 | - return $this->currentRouteNamed(...$patterns); |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * Determine if the current route matches a pattern. |
|
577 | - * |
|
578 | - * @param mixed ...$patterns |
|
579 | - * |
|
580 | - * @return bool |
|
581 | - */ |
|
582 | - public function currentRouteNamed(...$patterns) |
|
583 | - { |
|
584 | - return $this->current() && $this->current()->named(...$patterns); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Register an array of resource controllers. |
|
589 | - * |
|
590 | - * @param array $resources |
|
591 | - * @param array $options |
|
592 | - * |
|
593 | - * @return void |
|
594 | - */ |
|
595 | - public function resources(array $resources, array $options = []) |
|
596 | - { |
|
597 | - foreach ($resources as $name => $controller) { |
|
598 | - $this->resource($name, $controller, $options); |
|
599 | - } |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * Route a resource to a controller. |
|
604 | - * |
|
605 | - * @param string $name |
|
606 | - * @param string $controller |
|
607 | - * @param array $options |
|
608 | - * |
|
609 | - * @return \Syscodes\Routing\AwaitingResourceRegistration |
|
610 | - */ |
|
611 | - public function resource($name, $controller, array $options = []) |
|
612 | - { |
|
613 | - if ($this->container) { |
|
614 | - $register = $this->container->make(ResourceRegister::class); |
|
615 | - } else { |
|
616 | - $register = new ResourceRegister($this); |
|
617 | - } |
|
618 | - |
|
619 | - return new AwaitingResourceRegistration( |
|
620 | - $register, $name, $controller, $options |
|
621 | - ); |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Get the route collection. |
|
626 | - * |
|
627 | - * @return array |
|
628 | - */ |
|
629 | - public function getRoutes() |
|
630 | - { |
|
631 | - return $this->routes; |
|
632 | - } |
|
633 | - |
|
634 | - /** |
|
635 | - * Get or set the verbs used in the resource URIs. |
|
636 | - * |
|
637 | - * @param array $verbs |
|
638 | - * |
|
639 | - * @return array|null |
|
640 | - */ |
|
641 | - public function resourceVerbs(array $verbs = []) |
|
642 | - { |
|
643 | - ResourceRegister::verbs($verbs); |
|
644 | - } |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Get all of the defined middleware |
|
495 | + * |
|
496 | + * @return array |
|
497 | + */ |
|
498 | + public function getMiddleware() |
|
499 | + { |
|
500 | + return $this->middleware; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Register a short-hand name for a middleware. |
|
505 | + * |
|
506 | + * @param string $name |
|
507 | + * @param string $class |
|
508 | + * |
|
509 | + * @return $this |
|
510 | + */ |
|
511 | + public function aliasMiddleware($name, $class) |
|
512 | + { |
|
513 | + $this->middleware[$name] = $class; |
|
514 | + |
|
515 | + return $this; |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Register a group of middleware. |
|
520 | + * |
|
521 | + * @param string $name |
|
522 | + * @param array $middleware |
|
523 | + * |
|
524 | + * @return $this |
|
525 | + */ |
|
526 | + public function middlewareGroup($name, array $middleware) |
|
527 | + { |
|
528 | + $this->middlewareGroups[$name] = $middleware; |
|
529 | + |
|
530 | + return $this; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Check if a route with the given name exists. |
|
535 | + * |
|
536 | + * @param string $name |
|
537 | + * |
|
538 | + * @return bool |
|
539 | + */ |
|
540 | + public function has($name) |
|
541 | + { |
|
542 | + $names = is_array($name) ? $name : func_get_args(); |
|
543 | + |
|
544 | + foreach ($names as $value) { |
|
545 | + if ( ! $this->routes->hasNamedRoute($value)) { |
|
546 | + return false; |
|
547 | + } |
|
548 | + } |
|
549 | + |
|
550 | + return true; |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Get the currently dispatched route instance. |
|
555 | + * |
|
556 | + * @return \Syscodes\Routing\Route|null |
|
557 | + */ |
|
558 | + public function current() |
|
559 | + { |
|
560 | + return $this->current; |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Determine if the current route matches a pattern. |
|
565 | + * |
|
566 | + * @param mixed ...$patterns |
|
567 | + * |
|
568 | + * @return bool |
|
569 | + */ |
|
570 | + public function is(...$patterns) |
|
571 | + { |
|
572 | + return $this->currentRouteNamed(...$patterns); |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * Determine if the current route matches a pattern. |
|
577 | + * |
|
578 | + * @param mixed ...$patterns |
|
579 | + * |
|
580 | + * @return bool |
|
581 | + */ |
|
582 | + public function currentRouteNamed(...$patterns) |
|
583 | + { |
|
584 | + return $this->current() && $this->current()->named(...$patterns); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Register an array of resource controllers. |
|
589 | + * |
|
590 | + * @param array $resources |
|
591 | + * @param array $options |
|
592 | + * |
|
593 | + * @return void |
|
594 | + */ |
|
595 | + public function resources(array $resources, array $options = []) |
|
596 | + { |
|
597 | + foreach ($resources as $name => $controller) { |
|
598 | + $this->resource($name, $controller, $options); |
|
599 | + } |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * Route a resource to a controller. |
|
604 | + * |
|
605 | + * @param string $name |
|
606 | + * @param string $controller |
|
607 | + * @param array $options |
|
608 | + * |
|
609 | + * @return \Syscodes\Routing\AwaitingResourceRegistration |
|
610 | + */ |
|
611 | + public function resource($name, $controller, array $options = []) |
|
612 | + { |
|
613 | + if ($this->container) { |
|
614 | + $register = $this->container->make(ResourceRegister::class); |
|
615 | + } else { |
|
616 | + $register = new ResourceRegister($this); |
|
617 | + } |
|
618 | + |
|
619 | + return new AwaitingResourceRegistration( |
|
620 | + $register, $name, $controller, $options |
|
621 | + ); |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Get the route collection. |
|
626 | + * |
|
627 | + * @return array |
|
628 | + */ |
|
629 | + public function getRoutes() |
|
630 | + { |
|
631 | + return $this->routes; |
|
632 | + } |
|
633 | + |
|
634 | + /** |
|
635 | + * Get or set the verbs used in the resource URIs. |
|
636 | + * |
|
637 | + * @param array $verbs |
|
638 | + * |
|
639 | + * @return array|null |
|
640 | + */ |
|
641 | + public function resourceVerbs(array $verbs = []) |
|
642 | + { |
|
643 | + ResourceRegister::verbs($verbs); |
|
644 | + } |
|
645 | 645 | |
646 | - /** |
|
647 | - * Register a custom macro. |
|
648 | - * |
|
649 | - * @param string $name |
|
650 | - * @param callable $callback |
|
651 | - * |
|
652 | - * @return void |
|
653 | - */ |
|
654 | - public function macro($name, callable $callback) |
|
655 | - { |
|
656 | - $this->macros[$name] = $callback; |
|
657 | - } |
|
646 | + /** |
|
647 | + * Register a custom macro. |
|
648 | + * |
|
649 | + * @param string $name |
|
650 | + * @param callable $callback |
|
651 | + * |
|
652 | + * @return void |
|
653 | + */ |
|
654 | + public function macro($name, callable $callback) |
|
655 | + { |
|
656 | + $this->macros[$name] = $callback; |
|
657 | + } |
|
658 | 658 | |
659 | - /** |
|
660 | - * Checks if macro is registered. |
|
661 | - * |
|
662 | - * @param string $name |
|
663 | - * |
|
664 | - * @return boolean |
|
665 | - */ |
|
666 | - public function hasMacro($name) |
|
667 | - { |
|
668 | - return isset($this->macros[$name]); |
|
669 | - } |
|
659 | + /** |
|
660 | + * Checks if macro is registered. |
|
661 | + * |
|
662 | + * @param string $name |
|
663 | + * |
|
664 | + * @return boolean |
|
665 | + */ |
|
666 | + public function hasMacro($name) |
|
667 | + { |
|
668 | + return isset($this->macros[$name]); |
|
669 | + } |
|
670 | 670 | |
671 | - /** |
|
672 | - * Dynamically handle calls into the router instance. |
|
673 | - * |
|
674 | - * @param string $method |
|
675 | - * @param array $parameters |
|
676 | - * |
|
677 | - * @return mixed |
|
678 | - */ |
|
679 | - public function __call($method, $parameters) |
|
680 | - { |
|
681 | - if (isset($this->macros[$method])) { |
|
682 | - $callback = $this->macros[$method]; |
|
683 | - |
|
684 | - return call_user_func_array($callback, $parameters); |
|
685 | - } |
|
671 | + /** |
|
672 | + * Dynamically handle calls into the router instance. |
|
673 | + * |
|
674 | + * @param string $method |
|
675 | + * @param array $parameters |
|
676 | + * |
|
677 | + * @return mixed |
|
678 | + */ |
|
679 | + public function __call($method, $parameters) |
|
680 | + { |
|
681 | + if (isset($this->macros[$method])) { |
|
682 | + $callback = $this->macros[$method]; |
|
683 | + |
|
684 | + return call_user_func_array($callback, $parameters); |
|
685 | + } |
|
686 | 686 | |
687 | - return (new RouteRegister($this))->attribute($method, $parameters[0]); |
|
688 | - } |
|
687 | + return (new RouteRegister($this))->attribute($method, $parameters[0]); |
|
688 | + } |
|
689 | 689 | } |
690 | 690 | \ No newline at end of file |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public function redirect($uri, $destination, $status = 302) |
243 | 243 | { |
244 | - return $this->any($uri, function () use ($destination, $status) { |
|
244 | + return $this->any($uri, function() use ($destination, $status) { |
|
245 | 245 | return new RedirectResponse($destination, $status); |
246 | 246 | }); |
247 | 247 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function view($uri, $view, $data = []) |
259 | 259 | { |
260 | - return $this->match(['GET', 'HEAD'], $uri, function () use ($view, $data) { |
|
260 | + return $this->match(['GET', 'HEAD'], $uri, function() use ($view, $data) { |
|
261 | 261 | return $this->container->make('view')->make($view, $data); |
262 | 262 | }); |
263 | 263 | } |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | */ |
484 | 484 | public function gatherRouteMiddleware(Route $route) |
485 | 485 | { |
486 | - $middleware = array_map(function ($name) { |
|
486 | + $middleware = array_map(function($name) { |
|
487 | 487 | return MiddlewareResolver::resolve($name, $this->middleware, $this->middlewareGroups); |
488 | 488 | }, $route->gatherMiddleware()); |
489 | 489 |
@@ -94,7 +94,7 @@ |
||
94 | 94 | |
95 | 95 | $middleware = $controller->getMiddleware(); |
96 | 96 | |
97 | - return collect($middleware)->filter(function ($data) use ($method) { |
|
97 | + return collect($middleware)->filter(function($data) use ($method) { |
|
98 | 98 | return static::methodExcludedByOptions($method, $data['options']); |
99 | 99 | })->all(); |
100 | 100 | } |
@@ -29,17 +29,17 @@ |
||
29 | 29 | */ |
30 | 30 | interface Application |
31 | 31 | { |
32 | - /** |
|
33 | - * Runs the current command discovered on the CLI. |
|
34 | - * |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - public function run(); |
|
32 | + /** |
|
33 | + * Runs the current command discovered on the CLI. |
|
34 | + * |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + public function run(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Displays basic information about the Console. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function showHeader(); |
|
39 | + /** |
|
40 | + * Displays basic information about the Console. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function showHeader(); |
|
45 | 45 | } |
46 | 46 | \ No newline at end of file |
@@ -34,57 +34,57 @@ |
||
34 | 34 | */ |
35 | 35 | class Application implements ApplicationContracts |
36 | 36 | { |
37 | - /** |
|
38 | - * The Lenevor application instance.. |
|
39 | - * |
|
40 | - * @var \Syscodes\Contracts\Container|Container $lenevor |
|
41 | - */ |
|
42 | - protected $lenevor; |
|
37 | + /** |
|
38 | + * The Lenevor application instance.. |
|
39 | + * |
|
40 | + * @var \Syscodes\Contracts\Container|Container $lenevor |
|
41 | + */ |
|
42 | + protected $lenevor; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Console constructor. Initialize the console of Lenevor. |
|
46 | - * |
|
47 | - * @param \Syscodes\Contracts\Core\Lenevor $core |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function __construct(Container $lenevor) |
|
52 | - { |
|
53 | - // Initialize the Cli |
|
54 | - if (isCli()) { |
|
55 | - Cli::initialize(); |
|
56 | - } |
|
44 | + /** |
|
45 | + * Console constructor. Initialize the console of Lenevor. |
|
46 | + * |
|
47 | + * @param \Syscodes\Contracts\Core\Lenevor $core |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function __construct(Container $lenevor) |
|
52 | + { |
|
53 | + // Initialize the Cli |
|
54 | + if (isCli()) { |
|
55 | + Cli::initialize(); |
|
56 | + } |
|
57 | 57 | |
58 | - $this->lenevor = $lenevor; |
|
59 | - } |
|
58 | + $this->lenevor = $lenevor; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Runs the current command discovered on the CLI. |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function run() |
|
67 | - { |
|
68 | - $path = Cli::getURI(); |
|
61 | + /** |
|
62 | + * Runs the current command discovered on the CLI. |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function run() |
|
67 | + { |
|
68 | + $path = Cli::getURI(); |
|
69 | 69 | |
70 | 70 | |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Displays basic information about the Console. |
|
75 | - * |
|
76 | - * @return $this |
|
77 | - */ |
|
78 | - public function showHeader() |
|
79 | - { |
|
80 | - Cli::write(Version::PRODUCT.' ' |
|
81 | - .Cli::color(Version::RELEASE, 'cyan').' | ' |
|
82 | - .'Server Time: '.Cli::color(date('Y/m/d H:i:sa'), 'light_yellow').' | ' |
|
83 | - .cli::color('['.PHP_OS.']', 'light_purple') |
|
84 | - ); |
|
73 | + /** |
|
74 | + * Displays basic information about the Console. |
|
75 | + * |
|
76 | + * @return $this |
|
77 | + */ |
|
78 | + public function showHeader() |
|
79 | + { |
|
80 | + Cli::write(Version::PRODUCT.' ' |
|
81 | + .Cli::color(Version::RELEASE, 'cyan').' | ' |
|
82 | + .'Server Time: '.Cli::color(date('Y/m/d H:i:sa'), 'light_yellow').' | ' |
|
83 | + .cli::color('['.PHP_OS.']', 'light_purple') |
|
84 | + ); |
|
85 | 85 | |
86 | - Cli::newLine(1); |
|
86 | + Cli::newLine(1); |
|
87 | 87 | |
88 | - return $this; |
|
89 | - } |
|
88 | + return $this; |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -53,7 +53,7 @@ |
||
53 | 53 | |
54 | 54 | [$name, $parameters] = array_pad(explode(':', $name, 2), 2, null); |
55 | 55 | |
56 | - return ($map[$name] ?? $name).(! is_null($parameters) ? ':'.$parameters : ''); |
|
56 | + return ($map[$name] ?? $name).( ! is_null($parameters) ? ':'.$parameters : ''); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |