From 2a20b6e2fa5e92e1bb35d45461384ee835427e65 Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Sat, 4 May 2024 15:24:48 +0530 Subject: [PATCH 01/11] Allow Adding array or string for web and api routes --- .../Configuration/ApplicationBuilder.php | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 642830bbe743..50448d661ce1 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -96,7 +96,7 @@ public function withEvents(array|bool $discover = []) AppEventServiceProvider::disableEventDiscovery(); } - if (! isset($this->pendingProviders[AppEventServiceProvider::class])) { + if (!isset($this->pendingProviders[AppEventServiceProvider::class])) { $this->app->booting(function () { $this->app->register(AppEventServiceProvider::class); }); @@ -117,7 +117,7 @@ public function withEvents(array|bool $discover = []) public function withBroadcasting(string $channels, array $attributes = []) { $this->app->booted(function () use ($channels, $attributes) { - Broadcast::routes(! empty($attributes) ? $attributes : null); + Broadcast::routes(!empty($attributes) ? $attributes : null); if (file_exists($channels)) { require $channels; @@ -140,17 +140,18 @@ public function withBroadcasting(string $channels, array $attributes = []) * @param callable|null $then * @return $this */ - public function withRouting(?Closure $using = null, - ?string $web = null, + public function withRouting( + ?Closure $using = null, + string|array $web = null, ?string $api = null, ?string $commands = null, ?string $channels = null, ?string $pages = null, ?string $health = null, string $apiPrefix = 'api', - ?callable $then = null) - { - if (is_null($using) && (is_string($web) || is_string($api) || is_string($pages) || is_string($health)) || is_callable($then)) { + ?callable $then = null + ) { + if (is_null($using) && (is_string($web) || is_array($web) || is_string($api) || is_array($api) || is_string($pages) || is_string($health)) || is_callable($then)) { $using = $this->buildRoutingCallback($web, $api, $pages, $health, $apiPrefix, $then); } @@ -182,33 +183,52 @@ public function withRouting(?Closure $using = null, * @param callable|null $then * @return \Closure */ - protected function buildRoutingCallback(?string $web, - ?string $api, + protected function buildRoutingCallback( + string|array $web, + string|array $api, ?string $pages, ?string $health, string $apiPrefix, - ?callable $then) - { + ?callable $then + ) { return function () use ($web, $api, $pages, $health, $apiPrefix, $then) { - if (is_string($api) && realpath($api) !== false) { - Route::middleware('api')->prefix($apiPrefix)->group($api); + if ((is_string($api) || is_array($api)) !== false) { + if (is_array($api)) { + foreach ($api as $apiRoute) { + if (realpath($apiRoute) !== false) { + Route::middleware('api')->prefix($apiPrefix)->group($apiRoute); + } + } + } else { + Route::middleware('api')->prefix($apiPrefix)->group($api); + } } if (is_string($health)) { Route::middleware('web')->get($health, function () { Event::dispatch(new DiagnosingHealth); - return View::file(__DIR__.'/../resources/health-up.blade.php'); + return View::file(__DIR__ . '/../resources/health-up.blade.php'); }); } - if (is_string($web) && realpath($web) !== false) { - Route::middleware('web')->group($web); + if ((is_string($web) || is_array($web)) !== false) { + if (is_array($web)) { + foreach ($web as $webRoute) { + if (realpath($webRoute) !== false) { + Route::middleware('web')->group($webRoute); + } + } + } else { + Route::middleware('web')->group($web); + } } - if (is_string($pages) && + if ( + is_string($pages) && realpath($pages) !== false && - class_exists(Folio::class)) { + class_exists(Folio::class) + ) { Folio::route($pages, middleware: $this->pageMiddleware); } @@ -230,7 +250,7 @@ public function withMiddleware(?callable $callback = null) $middleware = (new Middleware) ->redirectGuestsTo(fn () => route('login')); - if (! is_null($callback)) { + if (!is_null($callback)) { $callback($middleware); } From 234fc60944dee5d97ff19995063c4bb345a1a0ea Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Sat, 4 May 2024 15:58:59 +0530 Subject: [PATCH 02/11] Update ApplicationBuilder.php --- .../Configuration/ApplicationBuilder.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 50448d661ce1..2a05f5f7a753 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -131,8 +131,8 @@ public function withBroadcasting(string $channels, array $attributes = []) * Register the routing services for the application. * * @param \Closure|null $using - * @param string|null $web - * @param string|null $api + * @param string|array|null $web + * @param string|array|null $api * @param string|null $commands * @param string|null $channels * @param string|null $pages @@ -143,7 +143,7 @@ public function withBroadcasting(string $channels, array $attributes = []) public function withRouting( ?Closure $using = null, string|array $web = null, - ?string $api = null, + string|array $api = null, ?string $commands = null, ?string $channels = null, ?string $pages = null, @@ -175,8 +175,8 @@ public function withRouting( /** * Create the routing callback for the application. * - * @param string|null $web - * @param string|null $api + * @param string|array|null $web + * @param string|array|null $api * @param string|null $pages * @param string|null $health * @param string $apiPrefix @@ -184,8 +184,8 @@ public function withRouting( * @return \Closure */ protected function buildRoutingCallback( - string|array $web, - string|array $api, + string|array $web = null, + string|array $api = null, ?string $pages, ?string $health, string $apiPrefix, From 1ca23731f63fbd13fa510185a6642454a5e4f0a8 Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Sat, 4 May 2024 16:01:11 +0530 Subject: [PATCH 03/11] Update ApplicationBuilder.php --- .../Foundation/Configuration/ApplicationBuilder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 2a05f5f7a753..52d0587f0325 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -96,7 +96,7 @@ public function withEvents(array|bool $discover = []) AppEventServiceProvider::disableEventDiscovery(); } - if (!isset($this->pendingProviders[AppEventServiceProvider::class])) { + if (! isset($this->pendingProviders[AppEventServiceProvider::class])) { $this->app->booting(function () { $this->app->register(AppEventServiceProvider::class); }); @@ -117,7 +117,7 @@ public function withEvents(array|bool $discover = []) public function withBroadcasting(string $channels, array $attributes = []) { $this->app->booted(function () use ($channels, $attributes) { - Broadcast::routes(!empty($attributes) ? $attributes : null); + Broadcast::routes(! empty($attributes) ? $attributes : null); if (file_exists($channels)) { require $channels; @@ -208,7 +208,7 @@ protected function buildRoutingCallback( Route::middleware('web')->get($health, function () { Event::dispatch(new DiagnosingHealth); - return View::file(__DIR__ . '/../resources/health-up.blade.php'); + return View::file(__DIR__.'/../resources/health-up.blade.php'); }); } From 297fa8dfa9aa80d9e4b9ce83ce402ed9b1f62492 Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Sat, 4 May 2024 16:02:25 +0530 Subject: [PATCH 04/11] Update ApplicationBuilder.php --- src/Illuminate/Foundation/Configuration/ApplicationBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 52d0587f0325..4bb8ee39c074 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -250,7 +250,7 @@ public function withMiddleware(?callable $callback = null) $middleware = (new Middleware) ->redirectGuestsTo(fn () => route('login')); - if (!is_null($callback)) { + if (! is_null($callback)) { $callback($middleware); } From c152357dcbf7505e126dcfe59f16fce3d330f4de Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Thu, 9 May 2024 17:20:07 +0530 Subject: [PATCH 05/11] Fixed Code Pattern --- .../Configuration/ApplicationBuilder.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 4bb8ee39c074..5c415ad4b402 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -140,8 +140,7 @@ public function withBroadcasting(string $channels, array $attributes = []) * @param callable|null $then * @return $this */ - public function withRouting( - ?Closure $using = null, + public function withRouting(?Closure $using = null, string|array $web = null, string|array $api = null, ?string $commands = null, @@ -149,8 +148,7 @@ public function withRouting( ?string $pages = null, ?string $health = null, string $apiPrefix = 'api', - ?callable $then = null - ) { + ?callable $then = null) { if (is_null($using) && (is_string($web) || is_array($web) || is_string($api) || is_array($api) || is_string($pages) || is_string($health)) || is_callable($then)) { $using = $this->buildRoutingCallback($web, $api, $pages, $health, $apiPrefix, $then); } @@ -183,14 +181,12 @@ public function withRouting( * @param callable|null $then * @return \Closure */ - protected function buildRoutingCallback( - string|array $web = null, + protected function buildRoutingCallback(string|array $web = null, string|array $api = null, ?string $pages, ?string $health, string $apiPrefix, - ?callable $then - ) { + ?callable $then) { return function () use ($web, $api, $pages, $health, $apiPrefix, $then) { if ((is_string($api) || is_array($api)) !== false) { if (is_array($api)) { @@ -224,11 +220,9 @@ protected function buildRoutingCallback( } } - if ( - is_string($pages) && + if (is_string($pages) && realpath($pages) !== false && - class_exists(Folio::class) - ) { + class_exists(Folio::class)) { Folio::route($pages, middleware: $this->pageMiddleware); } From 5d3ce57cff8d7f3636cca0e29722a0921daeab3e Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Thu, 9 May 2024 17:21:26 +0530 Subject: [PATCH 06/11] Fixed Code Pattern --- src/Illuminate/Foundation/Configuration/ApplicationBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 5c415ad4b402..63bf1d413fe6 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -186,7 +186,8 @@ protected function buildRoutingCallback(string|array $web = null, ?string $pages, ?string $health, string $apiPrefix, - ?callable $then) { + ?callable $then) + { return function () use ($web, $api, $pages, $health, $apiPrefix, $then) { if ((is_string($api) || is_array($api)) !== false) { if (is_array($api)) { From 0bc95fc669c23f5b402ed1e4bc3ebe25f03dee1e Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Thu, 9 May 2024 17:22:06 +0530 Subject: [PATCH 07/11] Fixed Code Pattern --- src/Illuminate/Foundation/Configuration/ApplicationBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 63bf1d413fe6..a6cdd8740eb4 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -148,7 +148,8 @@ public function withRouting(?Closure $using = null, ?string $pages = null, ?string $health = null, string $apiPrefix = 'api', - ?callable $then = null) { + ?callable $then = null) + { if (is_null($using) && (is_string($web) || is_array($web) || is_string($api) || is_array($api) || is_string($pages) || is_string($health)) || is_callable($then)) { $using = $this->buildRoutingCallback($web, $api, $pages, $health, $apiPrefix, $then); } From e05ec56d91803038563251a9aa4cf30baead1168 Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Thu, 9 May 2024 17:23:10 +0530 Subject: [PATCH 08/11] Fixed Code Pattern --- .../Foundation/Configuration/ApplicationBuilder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index a6cdd8740eb4..05450f96887d 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -149,7 +149,7 @@ public function withRouting(?Closure $using = null, ?string $health = null, string $apiPrefix = 'api', ?callable $then = null) - { + { if (is_null($using) && (is_string($web) || is_array($web) || is_string($api) || is_array($api) || is_string($pages) || is_string($health)) || is_callable($then)) { $using = $this->buildRoutingCallback($web, $api, $pages, $health, $apiPrefix, $then); } @@ -188,7 +188,7 @@ protected function buildRoutingCallback(string|array $web = null, ?string $health, string $apiPrefix, ?callable $then) - { + { return function () use ($web, $api, $pages, $health, $apiPrefix, $then) { if ((is_string($api) || is_array($api)) !== false) { if (is_array($api)) { From cae2b0280c41092a2a15461b110900faf379950b Mon Sep 17 00:00:00 2001 From: Prashant Rijal Date: Fri, 10 May 2024 15:30:19 +0530 Subject: [PATCH 09/11] Added Null for the arguement on methods --- .../Foundation/Configuration/ApplicationBuilder.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 05450f96887d..1a8b13c09ca1 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -141,8 +141,8 @@ public function withBroadcasting(string $channels, array $attributes = []) * @return $this */ public function withRouting(?Closure $using = null, - string|array $web = null, - string|array $api = null, + string|array|null $web = null, + string|array|null $api = null, ?string $commands = null, ?string $channels = null, ?string $pages = null, @@ -182,8 +182,8 @@ public function withRouting(?Closure $using = null, * @param callable|null $then * @return \Closure */ - protected function buildRoutingCallback(string|array $web = null, - string|array $api = null, + protected function buildRoutingCallback(string|array|null $web = null, + string|array|null $api = null, ?string $pages, ?string $health, string $apiPrefix, From d43ab89679584ecb34edc23fac02de59b22c6fc8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 13 May 2024 12:44:50 -0500 Subject: [PATCH 10/11] formatting --- .../Foundation/Configuration/ApplicationBuilder.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 1a8b13c09ca1..9dce2d033805 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -174,8 +174,8 @@ public function withRouting(?Closure $using = null, /** * Create the routing callback for the application. * - * @param string|array|null $web - * @param string|array|null $api + * @param array|string|null $web + * @param array|string|null $api * @param string|null $pages * @param string|null $health * @param string $apiPrefix @@ -183,14 +183,14 @@ public function withRouting(?Closure $using = null, * @return \Closure */ protected function buildRoutingCallback(string|array|null $web = null, - string|array|null $api = null, + array|string|null $api = null, ?string $pages, ?string $health, string $apiPrefix, ?callable $then) { return function () use ($web, $api, $pages, $health, $apiPrefix, $then) { - if ((is_string($api) || is_array($api)) !== false) { + if (is_string($api) || is_array($api)) { if (is_array($api)) { foreach ($api as $apiRoute) { if (realpath($apiRoute) !== false) { @@ -210,7 +210,7 @@ protected function buildRoutingCallback(string|array|null $web = null, }); } - if ((is_string($web) || is_array($web)) !== false) { + if (is_string($web) || is_array($web)) { if (is_array($web)) { foreach ($web as $webRoute) { if (realpath($webRoute) !== false) { From fca7e6f4cbbf78710f8ed485f504d6d47161f54d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 13 May 2024 12:47:10 -0500 Subject: [PATCH 11/11] Formatting --- .../Foundation/Configuration/ApplicationBuilder.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 9dce2d033805..6a77645787fb 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -131,8 +131,8 @@ public function withBroadcasting(string $channels, array $attributes = []) * Register the routing services for the application. * * @param \Closure|null $using - * @param string|array|null $web - * @param string|array|null $api + * @param array|string|null $web + * @param array|string|null $api * @param string|null $commands * @param string|null $channels * @param string|null $pages @@ -141,8 +141,8 @@ public function withBroadcasting(string $channels, array $attributes = []) * @return $this */ public function withRouting(?Closure $using = null, - string|array|null $web = null, - string|array|null $api = null, + array|string|null $web = null, + array|string|null $api = null, ?string $commands = null, ?string $channels = null, ?string $pages = null, @@ -182,7 +182,7 @@ public function withRouting(?Closure $using = null, * @param callable|null $then * @return \Closure */ - protected function buildRoutingCallback(string|array|null $web = null, + protected function buildRoutingCallback(array|string|null $web = null, array|string|null $api = null, ?string $pages, ?string $health,