From f552dc994c43d828fc9484c969c16ce6b4bd357b Mon Sep 17 00:00:00 2001 From: whwyy Date: Thu, 30 Nov 2023 17:02:20 +0800 Subject: [PATCH] eee --- Container.php | 5 +-- LocalService.php | 92 ------------------------------------------------ 2 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 LocalService.php diff --git a/Container.php b/Container.php index d738c49..d0a5d1d 100644 --- a/Container.php +++ b/Container.php @@ -127,11 +127,12 @@ class Container implements ContainerInterface /** * @param string $interface * @param object $object - * @return void + * @return object */ - public function bind(string $interface, object $object): void + public function bind(string $interface, object $object): object { $this->_singletons[$interface] = $object; + return $object; } diff --git a/LocalService.php b/LocalService.php deleted file mode 100644 index 8f7c5cf..0000000 --- a/LocalService.php +++ /dev/null @@ -1,92 +0,0 @@ -_components[$name]); - - $this->_definition[$name] = $define; - if (is_object($define) || $define instanceof Closure) { - $this->_components[$name] = $this->get($name, $define); - } - } - - - /** - * @throws Exception - */ - public function get(string $name, $throwException = true) - { - if (isset($this->_components[$name])) { - return $this->_components[$name]; - } - if (isset($this->_definition[$name])) { - $definition = $this->_definition[$name]; - if (is_object($definition) && !$definition instanceof Closure) { - return $this->_components[$name] = $definition; - } - return $this->_components[$name] = Kiri::createObject($definition); - } else if ($throwException) { - throw new Exception("Unknown component ID: $name"); - } - return null; - } - - - /** - * @param array $components - * @throws Exception - */ - public function setComponents(array $components): void - { - foreach ($components as $name => $component) { - $this->set($name, $component); - } - } - - - /** - * @param $id - * @return bool - */ - public function has($id): bool - { - return isset($this->_components[$id]) || isset($this->_definition[$id]); - } - - - /** - * @param $id - */ - public function remove($id): void - { - unset($this->_components[$id], $this->_definition[$id]); - } - - -}