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
+23 -18
View File
@@ -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');
}
}
-13
View File
@@ -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);
}
-1
View File
@@ -527,7 +527,6 @@ class Router extends HttpService implements RouterInterface
/**
* @param $exception
* @return mixed
* @throws ComponentException
* @throws Exception
*/
private function exception($exception): mixed
+4 -7
View File
@@ -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);
});
}
+11 -2
View File
@@ -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],
+1 -1
View File
@@ -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
+1 -1
View File
@@ -120,7 +120,7 @@ class Snowflake
*/
public static function getAnnotation(): Annotation
{
return static::app()->getAttributes();
return static::app()->getAnnotation();
}