diff --git a/composer.json b/composer.json index f7beeb3..df0a7f2 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,7 @@ ], "require": { "php": ">=7.1.0", - "ext-swoole":"^4.0", - "easyswoole/trigger": "^1.0" + "ext-swoole":"^4.0" }, "autoload": { "psr-4": { diff --git a/src/Context.php b/src/Context.php index e8828a2..845c9ce 100644 --- a/src/Context.php +++ b/src/Context.php @@ -7,7 +7,6 @@ */ namespace EasySwoole\Component; -use EasySwoole\Trigger\Trigger; use Swoole\Coroutine as Co; class Context @@ -23,7 +22,13 @@ function register(string $name,callable $call) return $this; } - function get(string $name,$cid = null) + /** + * @param string $name + * @param null $cid + * @return mixed|null + * @throws \Throwable + */ + function get(string $name, $cid = null) { if($cid === null){ $cid = Co::getUid(); @@ -33,14 +38,9 @@ function get(string $name,$cid = null) }else{ if(isset($this->register[$name])){ $call = $this->register[$name]; - try{ - $res = call_user_func($call); - $this->context[$cid][$name] = $res; - return $res; - }catch (\Throwable $throwable){ - Trigger::throwable($throwable); - return null; - } + $res = call_user_func($call); + $this->context[$cid][$name] = $res; + return $res; }else{ return null; } diff --git a/src/Di.php b/src/Di.php index 966f97b..9281751 100644 --- a/src/Di.php +++ b/src/Di.php @@ -7,7 +7,6 @@ */ namespace EasySwoole\Component; -use EasySwoole\Trigger\Trigger; class Di @@ -37,6 +36,11 @@ function clear():void $this->container = array(); } + /** + * @param $key + * @return null + * @throws \Throwable + */ function get($key) { if(isset($this->container[$key])){ @@ -49,8 +53,7 @@ function get($key) $this->container[$key]['obj'] = new $obj(...$params); return $this->container[$key]['obj']; }catch (\Throwable $throwable){ - Trigger::throwable($throwable); - return null; + throw $throwable; } }else{ return $obj; diff --git a/src/Event.php b/src/Event.php index 12d6a82..4159040 100644 --- a/src/Event.php +++ b/src/Event.php @@ -8,9 +8,6 @@ namespace EasySwoole\Component; - -use EasySwoole\Trigger\Trigger; - class Event extends Container { function set($key, $item) @@ -22,16 +19,17 @@ function set($key, $item) } } - public function hook($event,...$args) + /** + * @param $event + * @param mixed ...$args + * @return mixed|null + * @throws \Throwable + */ + public function hook($event, ...$args) { $call = $this->get($event); if(is_callable($call)){ - try{ - return call_user_func($call,...$args); - }catch (\Throwable $throwable){ - Trigger::throwable($throwable); - return null; - } + return call_user_func($call,...$args); }else{ return null; } diff --git a/src/MultiEvent.php b/src/MultiEvent.php index 86a0bf3..d260871 100644 --- a/src/MultiEvent.php +++ b/src/MultiEvent.php @@ -31,18 +31,19 @@ function add($key, $item) } } - public function hook($event,...$args):array + /** + * @param $event + * @param mixed ...$args + * @return array + * @throws \Throwable + */ + public function hook($event, ...$args):array { $res = []; $calls = $this->get($event); if(is_array($calls)){ foreach ($calls as $key => $call){ - try{ - $res[$key] = call_user_func($call,...$args); - }catch (\Throwable $throwable){ - Trigger::throwable($throwable); - $res[$key] = null; - } + $res[$key] = call_user_func($call,...$args); } } return $res; diff --git a/src/Pool/PoolManager.php b/src/Pool/PoolManager.php index eeb383c..1064461 100644 --- a/src/Pool/PoolManager.php +++ b/src/Pool/PoolManager.php @@ -10,7 +10,6 @@ use EasySwoole\Component\Singleton; -use EasySwoole\Trigger\Trigger; class PoolManager { @@ -18,18 +17,21 @@ class PoolManager private $pool = []; - function register(string $className,$maxNum = 20):bool + /** + * @param string $className + * @param int $maxNum + * @return bool + * @throws \Throwable + */ + function register(string $className, $maxNum = 20):bool { - try{ - $ref = new \ReflectionClass($className); - if($ref->isSubclassOf(AbstractPool::class)){ - $this->pool[$this->generateKey($className)] = new $className($maxNum); - return true; - } - }catch (\Throwable $throwable){ - Trigger::throwable($throwable); + $ref = new \ReflectionClass($className); + if($ref->isSubclassOf(AbstractPool::class)){ + $this->pool[$this->generateKey($className)] = new $className($maxNum); + return true; + }else{ + return false; } - return false; } function getPool(string $className):?AbstractPool