Skip to content

Commit ed28a45

Browse files
[11.x] Declare bindings and singletons properties in Service Provider (#52256)
* Declare bindings and singletons "magick" properties * Update ServiceProvider.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent c71cdf7 commit ed28a45

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/Illuminate/Foundation/Application.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -870,18 +870,14 @@ public function register($provider, $force = false)
870870
// If there are bindings / singletons set as properties on the provider we
871871
// will spin through them and register them with the application, which
872872
// serves as a convenience layer while registering a lot of bindings.
873-
if (property_exists($provider, 'bindings')) {
874-
foreach ($provider->bindings as $key => $value) {
875-
$this->bind($key, $value);
876-
}
873+
foreach ($provider->bindings as $key => $value) {
874+
$this->bind($key, $value);
877875
}
878876

879-
if (property_exists($provider, 'singletons')) {
880-
foreach ($provider->singletons as $key => $value) {
881-
$key = is_int($key) ? $value : $key;
877+
foreach ($provider->singletons as $key => $value) {
878+
$key = is_int($key) ? $value : $key;
882879

883-
$this->singleton($key, $value);
884-
}
880+
$this->singleton($key, $value);
885881
}
886882

887883
$this->markAsRegistered($provider);

src/Illuminate/Support/ServiceProvider.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ abstract class ServiceProvider
1919
*/
2020
protected $app;
2121

22+
/**
23+
* All of the container bindings that should be registered.
24+
*
25+
* @var array
26+
*/
27+
public $bindings = [];
28+
29+
/**
30+
* All of the singletons that should be registered.
31+
*
32+
* @var array
33+
*/
34+
public $singletons = [];
35+
2236
/**
2337
* All of the registered booting callbacks.
2438
*

0 commit comments

Comments
 (0)