Skip to content

Commit 0fe0619

Browse files
authored
🩹 Use existing configuration when booting a fresh application (Fixes #451) (#454)
1 parent 51a9fed commit 0fe0619

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

‎src/Roots/Acorn/Application/Concerns/Bootable.php‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515
trait Bootable
1616
{
1717
/**
18-
* Boot the application's service providers.
19-
*
20-
* @return $this
18+
* The configuration used to boot the application.
2119
*/
22-
public function bootAcorn()
20+
protected array $bootConfiguration = [];
21+
22+
/**
23+
* Boot the application and handle the request.
24+
*/
25+
public function bootAcorn(array $bootConfiguration = []): static
2326
{
2427
if ($this->isBooted()) {
2528
return $this;
2629
}
2730

31+
$this->bootConfiguration = $bootConfiguration;
32+
2833
if (! defined('LARAVEL_START')) {
2934
define('LARAVEL_START', microtime(true));
3035
}
@@ -232,4 +237,12 @@ protected function registerRequestHandler(
232237
exit((int) $response->isServerError());
233238
}, 100);
234239
}
240+
241+
/**
242+
* Retrieve the boot configuration.
243+
*/
244+
public function getBootConfiguration(): array
245+
{
246+
return $this->bootConfiguration;
247+
}
235248
}

‎src/Roots/Acorn/Configuration/ApplicationBuilder.php‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class ApplicationBuilder extends FoundationApplicationBuilder
1313
{
1414
use Paths;
1515

16+
/**
17+
* The application builder configuration.
18+
*/
19+
protected array $config = [];
20+
1621
/**
1722
* Register the standard kernel classes for the application.
1823
*
@@ -81,6 +86,17 @@ public function withRouting(?Closure $using = null,
8186
$this->app->handleWordPressRequests();
8287
}
8388

89+
$this->config['routing'] = [
90+
'web' => $web,
91+
'api' => $api,
92+
'commands' => $commands,
93+
'channels' => $channels,
94+
'pages' => $pages,
95+
'health' => $health,
96+
'apiPrefix' => $apiPrefix,
97+
'wordpress' => $wordpress,
98+
];
99+
84100
return $this;
85101
}
86102

@@ -126,6 +142,11 @@ public function withProviders(array $providers = [], bool $withBootstrapProvider
126142
: null
127143
);
128144

145+
$this->config['providers'] = [
146+
...$this->config['providers'] ?? [],
147+
...$providers,
148+
];
149+
129150
return $this;
130151
}
131152

@@ -146,6 +167,6 @@ public function create()
146167
*/
147168
public function boot()
148169
{
149-
return $this->app->bootAcorn();
170+
return $this->app->bootAcorn($this->config);
150171
}
151172
}

‎src/Roots/Acorn/Console/Concerns/GetsFreshApplication.php‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@ protected function getFreshApplication()
1515
{
1616
$application = get_class($app = Application::getInstance());
1717

18+
$config = $app->getBootConfiguration();
19+
20+
$routing = $config['routing'] ?? [];
21+
1822
return $application::configure($app->basePath())
1923
->withPaths(...$this->getApplicationPaths($app))
20-
->withRouting()
24+
->withProviders($config['providers'] ?? [])
25+
->withRouting(
26+
web: $routing['web'] ?? null,
27+
api: $routing['api'] ?? null,
28+
commands: $routing['commands'] ?? null,
29+
channels: $routing['channels'] ?? null,
30+
pages: $routing['pages'] ?? null,
31+
health: $routing['health'] ?? null,
32+
apiPrefix: $routing['apiPrefix'] ?? 'api',
33+
wordpress: $routing['wordpress'] ?? false,
34+
)
2135
->boot();
2236
}
2337

0 commit comments

Comments
 (0)