Skip to content

Commit

Permalink
Add support for $scopedBindings property on a ServiceProvider. Allows…
Browse files Browse the repository at this point in the history
… for convenient registration of scoped bindings, in similar fashion to the existing $bindings and $singletons properties.
  • Loading branch information
freerkminnema authored Aug 14, 2024
1 parent b0fd414 commit ac624de
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public function register($provider, $force = false)

$provider->register();

// If there are bindings / singletons set as properties on the provider we
// If there are (scoped) bindings / singletons set as properties on the provider we
// will spin through them and register them with the application, which
// serves as a convenience layer while registering a lot of bindings.
if (property_exists($provider, 'bindings')) {
Expand All @@ -876,6 +876,14 @@ public function register($provider, $force = false)
}
}

if (property_exists($provider, 'scopedBindings')) {
foreach ($provider->scopedBindings as $key => $value) {
$key = is_int($key) ? $value : $key;

$this->scoped($key, $value);
}
}

if (property_exists($provider, 'singletons')) {
foreach ($provider->singletons as $key => $value) {
$key = is_int($key) ? $value : $key;
Expand Down

0 comments on commit ac624de

Please sign in to comment.