改名
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:';
|
||||
@@ -22,13 +22,6 @@ class Tcp extends Annotation
|
||||
|
||||
private string $Message = 'required|not empty';
|
||||
|
||||
|
||||
private string $Handshake;
|
||||
|
||||
|
||||
private string $Close;
|
||||
|
||||
|
||||
/**
|
||||
* @param $controller
|
||||
* @param $methodName
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user