From 073dee78b93251f93a896f9b9f7a7d6bdb189503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 31 Aug 2020 14:02:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/Application.php | 16 ++++++++++++++++ system/Di/Service.php | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/system/Application.php b/system/Application.php index c4304267..37431a7e 100644 --- a/system/Application.php +++ b/system/Application.php @@ -47,6 +47,22 @@ class Application extends BaseApplication } + /** + * @param $name + * @param $service + * @return Application + * @throws Exception + */ + public function import(string $name, string $service) + { + $class = $this->set($name, ['class' => $service]); + if (method_exists($class, 'onImport')) { + $class->onImport($this); + } + return $this; + } + + /** * @throws Exception */ diff --git a/system/Di/Service.php b/system/Di/Service.php index 06604cae..88ba5817 100644 --- a/system/Di/Service.php +++ b/system/Di/Service.php @@ -76,7 +76,6 @@ class Service extends Component if ($definition === NULL) { return $this->remove($id); } - unset($this->_components[$id]); if (is_object($definition) || is_callable($definition, TRUE)) { return $this->_definition[$id] = $definition;