From 8794b9552846fbf813192b3c13190ec074c7d407 Mon Sep 17 00:00:00 2001 From: gaobinzhan Date: Mon, 15 Mar 2021 11:49:06 +0800 Subject: [PATCH] add: rebind --- src/Kernel/ServiceContainer.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Kernel/ServiceContainer.php b/src/Kernel/ServiceContainer.php index e057a6f..42fb55d 100644 --- a/src/Kernel/ServiceContainer.php +++ b/src/Kernel/ServiceContainer.php @@ -24,12 +24,12 @@ public function __construct(array $config = null, string $name = null, array $va $this->registerProviders($this->getProviders()); } - public function getName():string + public function getName(): string { return $this->name; } - public function getConfig():array + public function getConfig(): array { return $this->config ?? []; } @@ -51,6 +51,12 @@ public function registerProviders(array $providers) } } + public function rebind($name, $value) + { + $this->offsetUnset($name); + $this->offsetSet($name, $value); + } + public function __get($name) { return $this->offsetGet($name); @@ -60,4 +66,4 @@ public function __set($name, $value) { $this->offsetSet($name, $value); } -} \ No newline at end of file +}