改名
This commit is contained in:
@@ -5,7 +5,7 @@ namespace HttpServer\Events;
|
|||||||
|
|
||||||
|
|
||||||
use HttpServer\Abstracts\Callback;
|
use HttpServer\Abstracts\Callback;
|
||||||
use HttpServer\Route\Annotation\Annotation;
|
use HttpServer\Route\Annotation\Http;
|
||||||
use HttpServer\Route\Annotation\Tcp;
|
use HttpServer\Route\Annotation\Tcp;
|
||||||
use HttpServer\Route\Annotation\Websocket;
|
use HttpServer\Route\Annotation\Websocket;
|
||||||
use HttpServer\Route\Annotation\Websocket as AWebsocket;
|
use HttpServer\Route\Annotation\Websocket as AWebsocket;
|
||||||
@@ -62,13 +62,13 @@ class OnClose extends Callback
|
|||||||
if (!$server->isEstablished($fd)) {
|
if (!$server->isEstablished($fd)) {
|
||||||
return [null, null];
|
return [null, null];
|
||||||
}
|
}
|
||||||
$manager = Snowflake::app()->annotation->get('websocket');
|
$manager = Snowflake::app()->annotation->websocket;
|
||||||
$name = $manager->getName(AWebsocket::CLOSE);
|
$name = $manager->getName(AWebsocket::CLOSE);
|
||||||
} else if ($server instanceof HServer) {
|
} else if ($server instanceof HServer) {
|
||||||
$manager = Snowflake::app()->annotation->get('http');
|
$manager = Snowflake::app()->annotation->http;
|
||||||
$name = $manager->getName(Annotation::CLOSE);
|
$name = $manager->getName(Http::CLOSE);
|
||||||
} else {
|
} else {
|
||||||
$manager = Snowflake::app()->annotation->get('tcp');
|
$manager = Snowflake::app()->annotation->tcp;
|
||||||
$name = $manager->getName(Tcp::CLOSE);
|
$name = $manager->getName(Tcp::CLOSE);
|
||||||
}
|
}
|
||||||
return [$manager, $name];
|
return [$manager, $name];
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ class OnHandshake extends Callback
|
|||||||
try {
|
try {
|
||||||
$this->resolveParse($request, $response);
|
$this->resolveParse($request, $response);
|
||||||
|
|
||||||
/** @var AWebsocket $manager */
|
$manager = Snowflake::app()->annotation->websocket;
|
||||||
$manager = Snowflake::app()->annotation->get('websocket');
|
|
||||||
$name = $manager->getName(AWebsocket::HANDSHAKE);
|
$name = $manager->getName(AWebsocket::HANDSHAKE);
|
||||||
if (!$manager->has($name)) {
|
if (!$manager->has($name)) {
|
||||||
return $this->disconnect($response);
|
return $this->disconnect($response);
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ class OnMessage extends Callback
|
|||||||
$frame->data = json_decode($frame->data, true);
|
$frame->data = json_decode($frame->data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var AWebsocket $manager */
|
$manager = Snowflake::app()->annotation->websocket;
|
||||||
$manager = Snowflake::app()->annotation->get('websocket');
|
|
||||||
if (!isset($frame->data['route'])) {
|
if (!isset($frame->data['route'])) {
|
||||||
throw new \Exception('Fromat errr.');
|
throw new \Exception('Fromat errr.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ use HttpServer\IInterface\Limits;
|
|||||||
use HttpServer\Route\Node;
|
use HttpServer\Route\Node;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Snowflake\Abstracts\BaseAnnotation;
|
use Snowflake\Annotation\Annotation;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Annotation
|
* Class Annotation
|
||||||
*/
|
*/
|
||||||
class Annotation extends \Snowflake\Annotation\Annotation
|
class Http extends Annotation
|
||||||
{
|
{
|
||||||
|
|
||||||
const HTTP_EVENT = 'http:event:';
|
const HTTP_EVENT = 'http:event:';
|
||||||
@@ -22,13 +22,6 @@ class Tcp extends Annotation
|
|||||||
|
|
||||||
private string $Message = 'required|not empty';
|
private string $Message = 'required|not empty';
|
||||||
|
|
||||||
|
|
||||||
private string $Handshake;
|
|
||||||
|
|
||||||
|
|
||||||
private string $Close;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $controller
|
* @param $controller
|
||||||
* @param $methodName
|
* @param $methodName
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use Closure;
|
|||||||
use HttpServer\Http\Request;
|
use HttpServer\Http\Request;
|
||||||
use Exception;
|
use Exception;
|
||||||
use HttpServer\Application;
|
use HttpServer\Application;
|
||||||
use HttpServer\Route\Annotation\Annotation;
|
use HttpServer\Route\Annotation\Http;
|
||||||
use Snowflake\Core\JSON;
|
use Snowflake\Core\JSON;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
@@ -208,9 +208,8 @@ class Node extends Application
|
|||||||
throw new Exception('method ' . $action . ' not exists at ' . $controller . '.');
|
throw new Exception('method ' . $action . ' not exists at ' . $controller . '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Annotation $annotation */
|
$annotation = Snowflake::app()->annotation->http;
|
||||||
$annotation = Snowflake::app()->annotation->get('http');
|
if (!empty($annotations = $annotation->getAnnotation(Http::class))) {
|
||||||
if (!empty($annotations = $annotation->getAnnotation(Annotation::class))) {
|
|
||||||
$annotation->read($this, $reflect, $action, $annotations);
|
$annotation->read($this, $reflect, $action, $annotations);
|
||||||
}
|
}
|
||||||
return [$reflect->newInstance(), $action];
|
return [$reflect->newInstance(), $action];
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use HttpServer\Http\Context;
|
|||||||
use HttpServer\Http\Request;
|
use HttpServer\Http\Request;
|
||||||
use HttpServer\IInterface\RouterInterface;
|
use HttpServer\IInterface\RouterInterface;
|
||||||
use HttpServer\Application;
|
use HttpServer\Application;
|
||||||
use HttpServer\Route\Annotation\Annotation;
|
use HttpServer\Route\Annotation\Http;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
use Snowflake\Core\JSON;
|
use Snowflake\Core\JSON;
|
||||||
use Snowflake\Exception\ComponentException;
|
use Snowflake\Exception\ComponentException;
|
||||||
@@ -580,11 +580,10 @@ class Router extends Application implements RouterInterface
|
|||||||
{
|
{
|
||||||
$prefix = APP_PATH . 'app/Http/';
|
$prefix = APP_PATH . 'app/Http/';
|
||||||
|
|
||||||
/** @var Annotation $annotation */
|
/** @var Http $annotation */
|
||||||
$annotation = Snowflake::app()->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 . 'Interceptor', 'App\Http\Interceptor');
|
||||||
$annotation->registration_notes($prefix . 'Limits', 'App\Http\Limits');
|
$annotation->registration_notes($prefix . 'Limits', 'App\Http\Limits');
|
||||||
$annotation->registration_notes($prefix . 'Middleware', 'App\Http\Middleware');
|
$annotation->registration_notes($prefix . 'Middleware', 'App\Http\Middleware');
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use HttpServer\Events\OnConnect;
|
|||||||
use HttpServer\Events\OnPacket;
|
use HttpServer\Events\OnPacket;
|
||||||
use HttpServer\Events\OnReceive;
|
use HttpServer\Events\OnReceive;
|
||||||
use HttpServer\Events\OnRequest;
|
use HttpServer\Events\OnRequest;
|
||||||
use HttpServer\Route\Annotation\Annotation;
|
use HttpServer\Route\Annotation\Http as AnnotationHttp;
|
||||||
use HttpServer\Route\Annotation\Tcp;
|
use HttpServer\Route\Annotation\Tcp;
|
||||||
use HttpServer\Service\Http;
|
use HttpServer\Service\Http;
|
||||||
use HttpServer\Service\Receive;
|
use HttpServer\Service\Receive;
|
||||||
@@ -85,11 +85,6 @@ class Server extends Application
|
|||||||
*/
|
*/
|
||||||
public function initCore(array $configs)
|
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->enableCoroutine((bool)Config::get('settings.enable_coroutine'));
|
||||||
|
|
||||||
$this->orders($configs);
|
$this->orders($configs);
|
||||||
@@ -443,8 +438,7 @@ class Server extends Application
|
|||||||
{
|
{
|
||||||
$event = Snowflake::app()->getEvent();
|
$event = Snowflake::app()->getEvent();
|
||||||
$event->on(Event::SERVER_WORKER_START, function () {
|
$event->on(Event::SERVER_WORKER_START, function () {
|
||||||
/** @var AWebsocket $websocket */
|
$websocket = Snowflake::app()->annotation->websocket;
|
||||||
$websocket = Snowflake::app()->annotation->get('websocket');
|
|
||||||
$websocket->registration_notes(APP_PATH . 'app/Websocket', 'App\\Websocket');
|
$websocket->registration_notes(APP_PATH . 'app/Websocket', 'App\\Websocket');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||||||
namespace Snowflake\Annotation;
|
namespace Snowflake\Annotation;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use HttpServer\Route\Annotation\Http;
|
||||||
|
use HttpServer\Route\Annotation\Tcp;
|
||||||
use HttpServer\Route\Annotation\Websocket;
|
use HttpServer\Route\Annotation\Websocket;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
@@ -11,12 +13,13 @@ use ReflectionMethod;
|
|||||||
use Snowflake\Abstracts\BaseAnnotation;
|
use Snowflake\Abstracts\BaseAnnotation;
|
||||||
use Snowflake\Exception\NotFindClassException;
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
use validator\RequiredValidator;
|
|
||||||
use validator\RequiredValidator as NotEmptyValidator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Annotation
|
* Class Annotation
|
||||||
* @package Snowflake\Snowflake\Annotation
|
* @package Snowflake\Snowflake\Annotation
|
||||||
|
* @property Http $http
|
||||||
|
* @property Websocket $websocket
|
||||||
|
* @property Tcp $tcp
|
||||||
*/
|
*/
|
||||||
class Annotation extends BaseAnnotation
|
class Annotation extends BaseAnnotation
|
||||||
{
|
{
|
||||||
@@ -34,7 +37,11 @@ class Annotation extends BaseAnnotation
|
|||||||
protected array $params = [];
|
protected array $params = [];
|
||||||
|
|
||||||
|
|
||||||
private array $_classMap = [];
|
private array $_classMap = [
|
||||||
|
'http' => Http::class,
|
||||||
|
'tcp' => Tcp::class,
|
||||||
|
'websocket' => Websocket::class
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
|
|||||||
Reference in New Issue
Block a user