Skip to content

Commit

Permalink
[11.x] Allow adding array or string for web and api routes in bootst…
Browse files Browse the repository at this point in the history
…rap/app.php (#51356)

* Allow Adding array or string for web and api routes

* Update ApplicationBuilder.php

* Update ApplicationBuilder.php

* Update ApplicationBuilder.php

* Fixed Code Pattern

* Fixed Code Pattern

* Fixed Code Pattern

* Fixed Code Pattern

* Added Null for the arguement on methods

* formatting

* Formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
mrthito and taylorotwell authored May 13, 2024
1 parent 9d1d397 commit 78e3dce
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/Illuminate/Foundation/Configuration/ApplicationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 array|string|null $web
* @param array|string|null $api
* @param string|null $commands
* @param string|null $channels
* @param string|null $pages
Expand All @@ -141,16 +141,16 @@ public function withBroadcasting(string $channels, array $attributes = [])
* @return $this
*/
public function withRouting(?Closure $using = null,
?string $web = null,
?string $api = null,
array|string|null $web = null,
array|string|null $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)) {
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);
}

Expand All @@ -174,24 +174,32 @@ public function withRouting(?Closure $using = null,
/**
* Create the routing callback for the application.
*
* @param string|null $web
* @param string|null $api
* @param array|string|null $web
* @param array|string|null $api
* @param string|null $pages
* @param string|null $health
* @param string $apiPrefix
* @param callable|null $then
* @return \Closure
*/
protected function buildRoutingCallback(?string $web,
?string $api,
protected function buildRoutingCallback(array|string|null $web = 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) && realpath($api) !== false) {
Route::middleware('api')->prefix($apiPrefix)->group($api);
if (is_string($api) || is_array($api)) {
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)) {
Expand All @@ -202,8 +210,16 @@ protected function buildRoutingCallback(?string $web,
});
}

if (is_string($web) && realpath($web) !== false) {
Route::middleware('web')->group($web);
if (is_string($web) || is_array($web)) {
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) &&
Expand Down

0 comments on commit 78e3dce

Please sign in to comment.