Skip to content

Commit

Permalink
make deferred service providers operation scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
tornike committed Aug 2, 2024
1 parent 6b7c52f commit 1ffecfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ public function bootstrap(Application $app, array $initialInstances = []): Appli

$app->bootstrapWith($this->getBootstrappers($app));

$app->loadDeferredProviders();
// We will register all but operation scoped deferred providers right away so
// they are resolved once, during boot. Remaining operation providers will
// be registered with classical approach, during the occasions of need.
foreach ($app->getDeferredServices() as $service => $provider) {
if (!in_array($provider, $app->make('config')->get('octane.op_service_providers', []))) {
$app->loadDeferredProvider($service);
}
}

return $app;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Listeners/RegisterOperationServiceProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public function handle($event): void
$resolved_providers = [];

foreach ($event->sandbox->make('config')->get('octane.op_service_providers', []) as $provider) {
$provider = $event->sandbox->resolveProvider($provider);
if ($provider->isDeferred()) continue;
$resolved_providers[] = $event->sandbox->register($provider, boot: false);
}

Expand Down

0 comments on commit 1ffecfe

Please sign in to comment.