diff --git a/HttpServer/Server.php b/HttpServer/Server.php index 1988d552..a3cc8173 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -113,11 +113,7 @@ class Server extends HttpService return 'ok'; } - Runtime::enableCoroutine(true, SWOOLE_HOOK_TCP | - SWOOLE_HOOK_UNIX | SWOOLE_HOOK_UDP | SWOOLE_HOOK_UDG | - SWOOLE_HOOK_SSL | SWOOLE_HOOK_TLS | SWOOLE_HOOK_SLEEP | - SWOOLE_HOOK_STREAM_FUNCTION | SWOOLE_HOOK_PROC - ); + Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_BLOCKING_FUNCTION); Coroutine::set(['enable_deadlock_check' => false]); diff --git a/System/Di/Service.php b/System/Di/Service.php index b4fe0a15..94c68fae 100644 --- a/System/Di/Service.php +++ b/System/Di/Service.php @@ -42,27 +42,21 @@ class Service extends Component */ public function get($id, $try = true): mixed { - if (isset($this->_components[$id])) { - return $this->_components[$id]; - } - if (!isset($this->_definition[$id]) && !isset($this->_alias[$id])) { - if ($try === false) { - return null; + if (!isset($this->_components[$id])) { + if (!isset($this->_definition[$id])) { + throw new ComponentException("Unknown component ID: $id"); } - throw new ComponentException("Unknown component ID: $id"); - } - if (isset($this->_definition[$id])) { $config = $this->_definition[$id]; if (is_object($config)) { - return $this->_components[$id] = $config; + return $config; } - $object = Snowflake::createObject($config); - } else { - $config = $this->_alias[$id]; - - $object = Snowflake::createObject($config); + $this->_components[$id] = Snowflake::createObject($config); } - return $this->_components[$id] = $object; + $object = $this->_components[$id]; + if (method_exists($object, 'afterInit')) { + $object->afterInit(); + } + return $object; } /**