Skip to content

Commit

Permalink
[11.x] Declare bindings and singletons properties in Service Provider (
Browse files Browse the repository at this point in the history
…#52256)

* Declare bindings and singletons "magick" properties

* Update ServiceProvider.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
Anton5360 and taylorotwell authored Jul 26, 2024
1 parent c71cdf7 commit ed28a45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,18 +870,14 @@ public function register($provider, $force = false)
// If there are 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')) {
foreach ($provider->bindings as $key => $value) {
$this->bind($key, $value);
}
foreach ($provider->bindings as $key => $value) {
$this->bind($key, $value);
}

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

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

$this->markAsRegistered($provider);
Expand Down
14 changes: 14 additions & 0 deletions src/Illuminate/Support/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ abstract class ServiceProvider
*/
protected $app;

/**
* All of the container bindings that should be registered.
*
* @var array
*/
public $bindings = [];

/**
* All of the singletons that should be registered.
*
* @var array
*/
public $singletons = [];

/**
* All of the registered booting callbacks.
*
Expand Down

0 comments on commit ed28a45

Please sign in to comment.