From 4b15596d377368e36bfda6b7323dedb100da76ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 27 Jul 2021 16:18:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/Worker/ServerWorker.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Server/Worker/ServerWorker.php b/Server/Worker/ServerWorker.php index 2fad98de..0e9a8fda 100644 --- a/Server/Worker/ServerWorker.php +++ b/Server/Worker/ServerWorker.php @@ -4,11 +4,13 @@ namespace Server\Worker; use Annotation\Annotation; use Exception; +use ReflectionException; use Server\Constant; use Snowflake\Abstracts\Config; use Snowflake\Core\Help; use Snowflake\Event; use Snowflake\Exception\ConfigException; +use Snowflake\Exception\NotFindClassException; use Snowflake\Runtime; use Snowflake\Snowflake; use Swoole\Server; @@ -37,7 +39,32 @@ class ServerWorker extends \Server\Abstracts\Server $this->runEvent(Constant::WORKER_START, null, [$server, $workerId]); $this->workerInitExecutor($server, $annotation, $workerId); - $annotation->runtime(APP_PATH . 'app'); + $this->interpretDirectory($annotation); + } + + + /** + * @param $annotation + * @throws ReflectionException + * @throws NotFindClassException + */ + private function interpretDirectory($annotation) + { + $fileLists = $annotation->runtime(APP_PATH . 'app'); + + $di = Snowflake::getDi(); + foreach ($fileLists as $class) { + $instance = $di->get($class); + $methods = $di->getMethodAttribute($class); + foreach ($methods as $method => $attribute) { + if (empty($attribute)) { + continue; + } + foreach ($attribute as $item) { + $item->execute($instance, $method); + } + } + } }