From 500ebbf7f12ffb757626cb18228d90c47051a066 Mon Sep 17 00:00:00 2001 From: whwyy Date: Fri, 1 Dec 2023 22:57:25 +0800 Subject: [PATCH] eee --- Container.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Container.php b/Container.php index 07fc298..107d446 100644 --- a/Container.php +++ b/Container.php @@ -57,14 +57,18 @@ class Container implements ContainerInterface private array $_interfaces = []; - private static self|null $container = null; + /** + * @var Container|null + */ + private static ?Container $container = null; /** - * + * Construct \ContainerInterface */ private function __construct() { + $this->_singletons[ContainerInterface::class] = $this; } @@ -87,12 +91,12 @@ class Container implements ContainerInterface */ public function get(string $id): object { - if ($id === ContainerInterface::class) return $this; if (isset($this->_singletons[$id])) return $this->_singletons[$id]; if (isset($this->_interfaces[$id])) { - $id = $this->_interfaces[$id]; + return $this->_singletons[$id] = $this->make($this->_interfaces[$id]); + } else { + return $this->_singletons[$id] = $this->make($id); } - return $this->_singletons[$id] = $this->make($id); }