This commit is contained in:
2021-04-27 17:13:21 +08:00
parent c93bb59cc3
commit d37fec9e64
+10 -11
View File
@@ -42,21 +42,20 @@ class Service extends Component
*/ */
public function get($id, $try = true): mixed public function get($id, $try = true): mixed
{ {
if (!isset($this->_components[$id])) { if (isset($this->_components[$id])) {
if (!isset($this->_definition[$id])) { return $this->_components[$id];
throw new ComponentException("Unknown component ID: $id"); }
} if (isset($this->_definition[$id])) {
$config = $this->_definition[$id]; $config = $this->_definition[$id];
if (is_object($config)) { if (!is_object($config)) {
return $config; $config = Snowflake::createObject($config);
} }
$this->_components[$id] = Snowflake::createObject($config); return $this->_components[$id] = $config;
} }
$object = $this->_components[$id]; if ($try !== false) {
if (method_exists($object, 'afterInit')) { throw new ComponentException("Unknown component ID: $id");
$object->afterInit();
} }
return $object; return null;
} }
/** /**