From ed28a456f6b4799c33a59840fd68ea9f0922d463 Mon Sep 17 00:00:00 2001 From: Anton5360 <72033639+Anton5360@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:48:25 -0600 Subject: [PATCH] [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 --- src/Illuminate/Foundation/Application.php | 14 +++++--------- src/Illuminate/Support/ServiceProvider.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 14de7d8916b4..e7ab77a88a8a 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -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); diff --git a/src/Illuminate/Support/ServiceProvider.php b/src/Illuminate/Support/ServiceProvider.php index 7395397a3eca..a43ce9d444cd 100755 --- a/src/Illuminate/Support/ServiceProvider.php +++ b/src/Illuminate/Support/ServiceProvider.php @@ -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. *