This commit is contained in:
xl
2023-11-16 23:50:06 +08:00
parent d3cc7e7afe
commit 1b9c817ceb
+6 -3
View File
@@ -3,6 +3,7 @@ declare(strict_types=1);
namespace Kiri\Di;
use Closure;
use Exception;
use Kiri;
@@ -23,14 +24,15 @@ class LocalService
/**
* @param $name
* @param $define
* @throws Exception
*/
public function set($name, $define): void
{
unset($this->_components[$name]);
$this->_definition[$name] = $define;
if (is_object($define) || $define instanceof \Closure) {
$this->_components[$name] = $define;
if (is_object($define) || $define instanceof Closure) {
$this->_components[$name] = $this->get($name, $define);
}
}
@@ -45,7 +47,7 @@ class LocalService
}
if (isset($this->_definition[$name])) {
$definition = $this->_definition[$name];
if (is_object($definition) && !$definition instanceof \Closure) {
if (is_object($definition) && !$definition instanceof Closure) {
return $this->_components[$name] = $definition;
}
return $this->_components[$name] = Kiri::createObject($definition);
@@ -58,6 +60,7 @@ class LocalService
/**
* @param array $components
* @throws Exception
*/
public function setComponents(array $components): void
{