This commit is contained in:
2021-04-27 17:14:19 +08:00
parent 4cb92ed021
commit c2cd9e4439
+15 -9
View File
@@ -45,19 +45,25 @@ class Service extends Component
if (isset($this->_components[$id])) { if (isset($this->_components[$id])) {
return $this->_components[$id]; return $this->_components[$id];
} }
if (isset($this->_definition[$id])) { if (!isset($this->_definition[$id]) && !isset($this->_alias[$id])) {
$config = $this->_definition[$id]; if ($try === false) {
if (!is_object($config)) { return null;
$config = Snowflake::createObject($config);
} }
return $this->_components[$id] = $config;
}
if ($try !== false) {
throw new ComponentException("Unknown component ID: $id"); throw new ComponentException("Unknown component ID: $id");
} }
return null; if (isset($this->_definition[$id])) {
} $config = $this->_definition[$id];
if (is_object($config)) {
return $this->_components[$id] = $config;
}
$object = Snowflake::createObject($config);
} else {
$config = $this->_alias[$id];
$object = Snowflake::createObject($config);
}
return $this->_components[$id] = $object;
}
/** /**
* @param string $className * @param string $className