改名
This commit is contained in:
@@ -9,7 +9,6 @@ use Exception;
|
|||||||
use HttpServer\Http\Request;
|
use HttpServer\Http\Request;
|
||||||
use HttpServer\Route\Router;
|
use HttpServer\Route\Router;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Snowflake\Exception\ConfigException;
|
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ use Snowflake\Snowflake;
|
|||||||
* @param string $protocol
|
* @param string $protocol
|
||||||
* @param int $port
|
* @param int $port
|
||||||
*/
|
*/
|
||||||
#[Pure] public function __construct(public string $cmd, public string $protocol, public int $port)
|
#[Pure] public function __construct(public string $cmd, public string $protocol = self::PROTOCOL_SERIALIZE, public int $port = 443)
|
||||||
{
|
{
|
||||||
$this->uri = 'rpc/p' . $this->port . '/' . ltrim($this->cmd, '/');
|
$this->uri = 'rpc/p' . $this->port . '/' . ltrim($this->cmd, '/');
|
||||||
}
|
}
|
||||||
@@ -41,7 +40,6 @@ use Snowflake\Snowflake;
|
|||||||
/**
|
/**
|
||||||
* @param array $handler
|
* @param array $handler
|
||||||
* @return Router
|
* @return Router
|
||||||
* @throws ConfigException
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function execute(array $handler): Router
|
public function execute(array $handler): Router
|
||||||
@@ -49,7 +47,8 @@ use Snowflake\Snowflake;
|
|||||||
// TODO: Implement setHandler() method.
|
// TODO: Implement setHandler() method.
|
||||||
$router = Snowflake::app()->getRouter();
|
$router = Snowflake::app()->getRouter();
|
||||||
|
|
||||||
$router->addRoute($this->uri, $handler, Request::HTTP_CMD);
|
$router->addRoute($this->uri, $handler, Request::HTTP_CMD)
|
||||||
|
->setDataType($this->protocol);
|
||||||
|
|
||||||
return $router;
|
return $router;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,17 @@ namespace HttpServer\Route;
|
|||||||
|
|
||||||
|
|
||||||
use Annotation\Route\Middleware;
|
use Annotation\Route\Middleware;
|
||||||
|
use Annotation\Route\RpcProducer;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Exception;
|
||||||
use HttpServer\Abstracts\HttpService;
|
use HttpServer\Abstracts\HttpService;
|
||||||
use HttpServer\Controller;
|
use HttpServer\Controller;
|
||||||
use HttpServer\Http\Request;
|
use HttpServer\Http\Request;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
use HttpServer\HttpFilter;
|
use HttpServer\HttpFilter;
|
||||||
use HttpServer\IInterface\After;
|
|
||||||
use HttpServer\IInterface\Interceptor;
|
|
||||||
use HttpServer\IInterface\Limits;
|
|
||||||
use HttpServer\Route\Dispatch\Dispatch;
|
use HttpServer\Route\Dispatch\Dispatch;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Snowflake\Core\Json;
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Event;
|
|
||||||
use Snowflake\Exception\ComponentException;
|
|
||||||
use Snowflake\Exception\NotFindClassException;
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
@@ -48,6 +43,9 @@ class Node extends HttpService
|
|||||||
|
|
||||||
public array $rules = [];
|
public array $rules = [];
|
||||||
|
|
||||||
|
|
||||||
|
private string $_dataType = '';
|
||||||
|
|
||||||
/** @var ?Closure|?array */
|
/** @var ?Closure|?array */
|
||||||
public Closure|array|null $handler;
|
public Closure|array|null $handler;
|
||||||
public string $htmlSuffix = '.html';
|
public string $htmlSuffix = '.html';
|
||||||
@@ -64,6 +62,32 @@ class Node extends HttpService
|
|||||||
private array $_after = [];
|
private array $_after = [];
|
||||||
private array $_limits = [];
|
private array $_limits = [];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $dataType
|
||||||
|
*/
|
||||||
|
public function setDataType(string $dataType)
|
||||||
|
{
|
||||||
|
$this->_dataType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $data
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function unpack(string $data): mixed
|
||||||
|
{
|
||||||
|
if ($this->_dataType == RpcProducer::PROTOCOL_JSON) {
|
||||||
|
return json_decode($data, true);
|
||||||
|
}
|
||||||
|
if ($this->_dataType == RpcProducer::PROTOCOL_SERIALIZE) {
|
||||||
|
return unserialize($data);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $handler
|
* @param $handler
|
||||||
* @return Node
|
* @return Node
|
||||||
|
|||||||
Reference in New Issue
Block a user