Skip to content

Commit 477b703

Browse files
authored
feat(ApplicationBuilder): add withScopedSingletons (#56460)
1 parent db875da commit 477b703

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Illuminate/Foundation/Configuration/ApplicationBuilder.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,25 @@ public function withSingletons(array $singletons)
417417
});
418418
}
419419

420+
/**
421+
* Register an array of scoped singleton container bindings to be bound when the application is booting.
422+
*
423+
* @param array $scopedSingletons
424+
* @return $this
425+
*/
426+
public function withScopedSingletons(array $scopedSingletons)
427+
{
428+
return $this->registered(function ($app) use ($scopedSingletons) {
429+
foreach ($scopedSingletons as $abstract => $concrete) {
430+
if (is_string($abstract)) {
431+
$app->scoped($abstract, $concrete);
432+
} else {
433+
$app->scoped($concrete);
434+
}
435+
}
436+
});
437+
}
438+
420439
/**
421440
* Register a callback to be invoked when the application's service providers are registered.
422441
*

0 commit comments

Comments
 (0)