This commit is contained in:
2020-11-17 16:45:08 +08:00
parent d4ffa8c848
commit be04bf2e35
9 changed files with 27 additions and 37 deletions
+5 -5
View File
@@ -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];
+1 -2
View File
@@ -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);
+1 -2
View File
@@ -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.');
}
@@ -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:';
-7
View File
@@ -22,13 +22,6 @@ class Tcp extends Annotation
private string $Message = 'required|not empty';
private string $Handshake;
private string $Close;
/**
* @param $controller
* @param $methodName
+3 -4
View File
@@ -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];
+3 -4
View File
@@ -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');
+2 -8
View File
@@ -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');
});
}