diff --git a/Annotation/Loader.php b/Annotation/Loader.php index c090f019..9adef56a 100644 --- a/Annotation/Loader.php +++ b/Annotation/Loader.php @@ -206,32 +206,37 @@ class Loader extends BaseObject /** * @param string $path + * @throws Exception */ public function loadByDirectory(string $path) { - foreach ($this->_fileMap as $fileName => $className) { - if (!str_starts_with($fileName, $path)) { - continue; - } - if (!isset($this->_classes[$className])) { - continue; - } - - $annotations = $this->_classes[$className]; - if (isset($annotations['target']) && !empty($annotations['target'])) { - foreach ($annotations['target'] as $value) { - $value->execute([$annotations['handler']]); + try { + foreach ($this->_fileMap as $fileName => $className) { + if (!str_starts_with($fileName, $path)) { + continue; + } + if (!isset($this->_classes[$className])) { + continue; } - } - foreach ($annotations['methods'] as $name => $attribute) { - foreach ($attribute as $value) { - if (!($value instanceof \Annotation\Attribute)) { - continue; + $annotations = $this->_classes[$className]; + if (isset($annotations['target']) && !empty($annotations['target'])) { + foreach ($annotations['target'] as $value) { + $value->execute([$annotations['handler']]); + } + } + + foreach ($annotations['methods'] as $name => $attribute) { + foreach ($attribute as $value) { + if (!($value instanceof \Annotation\Attribute)) { + continue; + } + $value->execute([$annotations['handler'], $name]); } - $value->execute([$annotations['handler'], $name]); } } + } catch (Throwable $exception) { + $this->addError($exception, 'throwable'); } } diff --git a/Database/DatabasesProviders.php b/Database/DatabasesProviders.php index cce97215..2d5e192b 100644 --- a/Database/DatabasesProviders.php +++ b/Database/DatabasesProviders.php @@ -35,19 +35,6 @@ class DatabasesProviders extends Providers $event = Snowflake::app()->getEvent(); $event->on(Event::SERVER_WORKER_START, [$this, 'createPool']); - - - $event->on(Event::SERVER_WORKER_START, [$this, 'scanModel']); - $event->on(Event::SERVER_TASK_START, [$this, 'scanModel']); - } - - - /** - * @throws ComponentException - */ - public function scanModel() - { - annotation()->instanceDirectoryFiles(MODEL_PATH); } diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 30f8201d..aa8f6737 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -527,7 +527,6 @@ class Router extends HttpService implements RouterInterface /** * @param $exception * @return mixed - * @throws ComponentException * @throws Exception */ private function exception($exception): mixed diff --git a/HttpServer/Server.php b/HttpServer/Server.php index bfab3eb7..8b2ce3f8 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -493,14 +493,11 @@ class Server extends HttpService { $event = Snowflake::app()->getEvent(); $event->on(Event::SERVER_WORKER_START, function () { - try { - router()->loadRouterSetting(); + $system = Snowflake::app(); - $annotation = Snowflake::app()->getAttributes(); - $annotation->instanceDirectoryFiles(APP_PATH); - } catch (\Throwable $exception) { - $this->addError($exception, 'throwable'); - } + $system->getRouter()->loadRouterSetting(); + + $system->getAnnotation()->instanceDirectoryFiles(APP_PATH); }); } diff --git a/System/Abstracts/BaseApplication.php b/System/Abstracts/BaseApplication.php index cc45a847..b704d8b4 100644 --- a/System/Abstracts/BaseApplication.php +++ b/System/Abstracts/BaseApplication.php @@ -34,7 +34,6 @@ use Snowflake\Channel; use Snowflake\Di\Service; use Snowflake\Error\ErrorHandler; use Snowflake\Error\Logger; -use Snowflake\Exception\ComponentException; use Snowflake\Exception\InitException; use Snowflake\Exception\NotFindClassException; use Snowflake\Jwt\Jwt; @@ -437,6 +436,16 @@ abstract class BaseApplication extends Service } + /** + * @return SAnnotation + * @throws Exception + */ + public function getAnnotation(): SAnnotation + { + return $this->get('annotation'); + } + + /** * @return Async * @throws Exception @@ -482,7 +491,7 @@ abstract class BaseApplication extends Service 'request' => ['class' => Request::class], 'config' => ['class' => Config::class], 'logger' => ['class' => Logger::class], - 'attributes' => ['class' => SAnnotation::class], + 'annotation' => ['class' => SAnnotation::class], 'router' => ['class' => Router::class], 'redis' => ['class' => Redis::class], 'aop' => ['class' => Aop::class], diff --git a/System/Abstracts/TraitApplication.php b/System/Abstracts/TraitApplication.php index d6a1feba..c9ec165c 100644 --- a/System/Abstracts/TraitApplication.php +++ b/System/Abstracts/TraitApplication.php @@ -41,7 +41,7 @@ use Rpc\Producer as RPCProducer; * @property Connection $connections * @property Logger $logger * @property Jwt $jwt - * @property SAnnotation $attributes + * @property SAnnotation $annotation * @property Http2 $http2 * @property BaseGoto $goto * @property Producer $kafka diff --git a/System/Snowflake.php b/System/Snowflake.php index 2b742165..d6ceafbf 100644 --- a/System/Snowflake.php +++ b/System/Snowflake.php @@ -120,7 +120,7 @@ class Snowflake */ public static function getAnnotation(): Annotation { - return static::app()->getAttributes(); + return static::app()->getAnnotation(); }