This commit is contained in:
2021-04-02 18:40:50 +08:00
parent 98986ffe9d
commit bdd9f4008f
7 changed files with 40 additions and 43 deletions
+5
View File
@@ -206,9 +206,11 @@ class Loader extends BaseObject
/** /**
* @param string $path * @param string $path
* @throws Exception
*/ */
public function loadByDirectory(string $path) public function loadByDirectory(string $path)
{ {
try {
foreach ($this->_fileMap as $fileName => $className) { foreach ($this->_fileMap as $fileName => $className) {
if (!str_starts_with($fileName, $path)) { if (!str_starts_with($fileName, $path)) {
continue; continue;
@@ -233,6 +235,9 @@ class Loader extends BaseObject
} }
} }
} }
} catch (Throwable $exception) {
$this->addError($exception, 'throwable');
}
} }
-13
View File
@@ -35,19 +35,6 @@ class DatabasesProviders extends Providers
$event = Snowflake::app()->getEvent(); $event = Snowflake::app()->getEvent();
$event->on(Event::SERVER_WORKER_START, [$this, 'createPool']); $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);
} }
-1
View File
@@ -527,7 +527,6 @@ class Router extends HttpService implements RouterInterface
/** /**
* @param $exception * @param $exception
* @return mixed * @return mixed
* @throws ComponentException
* @throws Exception * @throws Exception
*/ */
private function exception($exception): mixed private function exception($exception): mixed
+4 -7
View File
@@ -493,14 +493,11 @@ class Server extends HttpService
{ {
$event = Snowflake::app()->getEvent(); $event = Snowflake::app()->getEvent();
$event->on(Event::SERVER_WORKER_START, function () { $event->on(Event::SERVER_WORKER_START, function () {
try { $system = Snowflake::app();
router()->loadRouterSetting();
$annotation = Snowflake::app()->getAttributes(); $system->getRouter()->loadRouterSetting();
$annotation->instanceDirectoryFiles(APP_PATH);
} catch (\Throwable $exception) { $system->getAnnotation()->instanceDirectoryFiles(APP_PATH);
$this->addError($exception, 'throwable');
}
}); });
} }
+11 -2
View File
@@ -34,7 +34,6 @@ use Snowflake\Channel;
use Snowflake\Di\Service; use Snowflake\Di\Service;
use Snowflake\Error\ErrorHandler; use Snowflake\Error\ErrorHandler;
use Snowflake\Error\Logger; use Snowflake\Error\Logger;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\InitException; use Snowflake\Exception\InitException;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Jwt\Jwt; 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 * @return Async
* @throws Exception * @throws Exception
@@ -482,7 +491,7 @@ abstract class BaseApplication extends Service
'request' => ['class' => Request::class], 'request' => ['class' => Request::class],
'config' => ['class' => Config::class], 'config' => ['class' => Config::class],
'logger' => ['class' => Logger::class], 'logger' => ['class' => Logger::class],
'attributes' => ['class' => SAnnotation::class], 'annotation' => ['class' => SAnnotation::class],
'router' => ['class' => Router::class], 'router' => ['class' => Router::class],
'redis' => ['class' => Redis::class], 'redis' => ['class' => Redis::class],
'aop' => ['class' => Aop::class], 'aop' => ['class' => Aop::class],
+1 -1
View File
@@ -41,7 +41,7 @@ use Rpc\Producer as RPCProducer;
* @property Connection $connections * @property Connection $connections
* @property Logger $logger * @property Logger $logger
* @property Jwt $jwt * @property Jwt $jwt
* @property SAnnotation $attributes * @property SAnnotation $annotation
* @property Http2 $http2 * @property Http2 $http2
* @property BaseGoto $goto * @property BaseGoto $goto
* @property Producer $kafka * @property Producer $kafka
+1 -1
View File
@@ -120,7 +120,7 @@ class Snowflake
*/ */
public static function getAnnotation(): Annotation public static function getAnnotation(): Annotation
{ {
return static::app()->getAttributes(); return static::app()->getAnnotation();
} }