diff --git a/HttpServer/Events/OnClose.php b/HttpServer/Events/OnClose.php index 2b171bac..e2973dad 100644 --- a/HttpServer/Events/OnClose.php +++ b/HttpServer/Events/OnClose.php @@ -5,7 +5,7 @@ namespace HttpServer\Events; use HttpServer\Abstracts\Callback; -use HttpServer\Route\Annotation\Annotation; +use HttpServer\Route\Annotation\Http; use HttpServer\Route\Annotation\Tcp; use HttpServer\Route\Annotation\Websocket; use HttpServer\Route\Annotation\Websocket as AWebsocket; @@ -62,13 +62,13 @@ class OnClose extends Callback if (!$server->isEstablished($fd)) { return [null, null]; } - $manager = Snowflake::app()->annotation->get('websocket'); + $manager = Snowflake::app()->annotation->websocket; $name = $manager->getName(AWebsocket::CLOSE); } else if ($server instanceof HServer) { - $manager = Snowflake::app()->annotation->get('http'); - $name = $manager->getName(Annotation::CLOSE); + $manager = Snowflake::app()->annotation->http; + $name = $manager->getName(Http::CLOSE); } else { - $manager = Snowflake::app()->annotation->get('tcp'); + $manager = Snowflake::app()->annotation->tcp; $name = $manager->getName(Tcp::CLOSE); } return [$manager, $name]; diff --git a/HttpServer/Events/OnHandshake.php b/HttpServer/Events/OnHandshake.php index 2eccce74..397ae711 100644 --- a/HttpServer/Events/OnHandshake.php +++ b/HttpServer/Events/OnHandshake.php @@ -79,8 +79,7 @@ class OnHandshake extends Callback try { $this->resolveParse($request, $response); - /** @var AWebsocket $manager */ - $manager = Snowflake::app()->annotation->get('websocket'); + $manager = Snowflake::app()->annotation->websocket; $name = $manager->getName(AWebsocket::HANDSHAKE); if (!$manager->has($name)) { return $this->disconnect($response); diff --git a/HttpServer/Events/OnMessage.php b/HttpServer/Events/OnMessage.php index 42922548..6d290e07 100644 --- a/HttpServer/Events/OnMessage.php +++ b/HttpServer/Events/OnMessage.php @@ -36,8 +36,7 @@ class OnMessage extends Callback $frame->data = json_decode($frame->data, true); } - /** @var AWebsocket $manager */ - $manager = Snowflake::app()->annotation->get('websocket'); + $manager = Snowflake::app()->annotation->websocket; if (!isset($frame->data['route'])) { throw new \Exception('Fromat errr.'); } diff --git a/HttpServer/Route/Annotation/Annotation.php b/HttpServer/Route/Annotation/Http.php similarity index 98% rename from HttpServer/Route/Annotation/Annotation.php rename to HttpServer/Route/Annotation/Http.php index da6e8419..0ca37821 100644 --- a/HttpServer/Route/Annotation/Annotation.php +++ b/HttpServer/Route/Annotation/Http.php @@ -10,13 +10,13 @@ use HttpServer\IInterface\Limits; use HttpServer\Route\Node; use ReflectionClass; use ReflectionException; -use Snowflake\Abstracts\BaseAnnotation; +use Snowflake\Annotation\Annotation; use Snowflake\Snowflake; /** * Class Annotation */ -class Annotation extends \Snowflake\Annotation\Annotation +class Http extends Annotation { const HTTP_EVENT = 'http:event:'; diff --git a/HttpServer/Route/Annotation/Tcp.php b/HttpServer/Route/Annotation/Tcp.php index 095ce342..de4a273a 100644 --- a/HttpServer/Route/Annotation/Tcp.php +++ b/HttpServer/Route/Annotation/Tcp.php @@ -22,13 +22,6 @@ class Tcp extends Annotation private string $Message = 'required|not empty'; - - private string $Handshake; - - - private string $Close; - - /** * @param $controller * @param $methodName diff --git a/HttpServer/Route/Node.php b/HttpServer/Route/Node.php index b571a96e..8e3677be 100644 --- a/HttpServer/Route/Node.php +++ b/HttpServer/Route/Node.php @@ -9,7 +9,7 @@ use Closure; use HttpServer\Http\Request; use Exception; use HttpServer\Application; -use HttpServer\Route\Annotation\Annotation; +use HttpServer\Route\Annotation\Http; use Snowflake\Core\JSON; use Snowflake\Event; use Snowflake\Snowflake; @@ -208,9 +208,8 @@ class Node extends Application throw new Exception('method ' . $action . ' not exists at ' . $controller . '.'); } - /** @var Annotation $annotation */ - $annotation = Snowflake::app()->annotation->get('http'); - if (!empty($annotations = $annotation->getAnnotation(Annotation::class))) { + $annotation = Snowflake::app()->annotation->http; + if (!empty($annotations = $annotation->getAnnotation(Http::class))) { $annotation->read($this, $reflect, $action, $annotations); } return [$reflect->newInstance(), $action]; diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 266f3fa1..d90d269d 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -10,7 +10,7 @@ use HttpServer\Http\Context; use HttpServer\Http\Request; use HttpServer\IInterface\RouterInterface; use HttpServer\Application; -use HttpServer\Route\Annotation\Annotation; +use HttpServer\Route\Annotation\Http; use Snowflake\Abstracts\Config; use Snowflake\Core\JSON; use Snowflake\Exception\ComponentException; @@ -580,11 +580,10 @@ class Router extends Application implements RouterInterface { $prefix = APP_PATH . 'app/Http/'; - /** @var Annotation $annotation */ + /** @var Http $annotation */ $annotation = Snowflake::app()->annotation; - $annotation->register('http', Annotation::class); - $annotation = $annotation->get('http'); + $annotation = $annotation->http; $annotation->registration_notes($prefix . 'Interceptor', 'App\Http\Interceptor'); $annotation->registration_notes($prefix . 'Limits', 'App\Http\Limits'); $annotation->registration_notes($prefix . 'Middleware', 'App\Http\Middleware'); diff --git a/HttpServer/Server.php b/HttpServer/Server.php index 09a93c9c..beee9252 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -8,7 +8,7 @@ use HttpServer\Events\OnConnect; use HttpServer\Events\OnPacket; use HttpServer\Events\OnReceive; use HttpServer\Events\OnRequest; -use HttpServer\Route\Annotation\Annotation; +use HttpServer\Route\Annotation\Http as AnnotationHttp; use HttpServer\Route\Annotation\Tcp; use HttpServer\Service\Http; use HttpServer\Service\Receive; @@ -85,11 +85,6 @@ class Server extends Application */ public function initCore(array $configs) { - $annotation = Snowflake::app()->annotation; - $annotation->register('tcp', Tcp::class); - $annotation->register('http', Annotation::class); - $annotation->register('websocket', AWebsocket::class); - $this->enableCoroutine((bool)Config::get('settings.enable_coroutine')); $this->orders($configs); @@ -443,8 +438,7 @@ class Server extends Application { $event = Snowflake::app()->getEvent(); $event->on(Event::SERVER_WORKER_START, function () { - /** @var AWebsocket $websocket */ - $websocket = Snowflake::app()->annotation->get('websocket'); + $websocket = Snowflake::app()->annotation->websocket; $websocket->registration_notes(APP_PATH . 'app/Websocket', 'App\\Websocket'); }); } diff --git a/System/Annotation/Annotation.php b/System/Annotation/Annotation.php index 01ede8d4..bce54f41 100644 --- a/System/Annotation/Annotation.php +++ b/System/Annotation/Annotation.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Snowflake\Annotation; use Exception; +use HttpServer\Route\Annotation\Http; +use HttpServer\Route\Annotation\Tcp; use HttpServer\Route\Annotation\Websocket; use ReflectionClass; use ReflectionException; @@ -11,12 +13,13 @@ use ReflectionMethod; use Snowflake\Abstracts\BaseAnnotation; use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; -use validator\RequiredValidator; -use validator\RequiredValidator as NotEmptyValidator; /** * Class Annotation * @package Snowflake\Snowflake\Annotation + * @property Http $http + * @property Websocket $websocket + * @property Tcp $tcp */ class Annotation extends BaseAnnotation { @@ -34,7 +37,11 @@ class Annotation extends BaseAnnotation protected array $params = []; - private array $_classMap = []; + private array $_classMap = [ + 'http' => Http::class, + 'tcp' => Tcp::class, + 'websocket' => Websocket::class + ]; /** * @param $name