This commit is contained in:
2020-10-29 18:17:25 +08:00
parent 6839b64be8
commit 53ae43b79b
198 changed files with 708 additions and 850 deletions
+8 -7
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Annotation;
@@ -25,25 +26,25 @@ class Annotation extends \Snowflake\Annotation\Annotation
* @var string
* @Interceptor(LoginInterceptor)
*/
private $Interceptor = 'required|not empty';
private string $Interceptor = 'required|not empty';
/**
* @var string
*/
private $Limits = 'required|not empty';
private string $Limits = 'required|not empty';
private $Method = 'post';
private string $Method = 'post';
private $Middleware = '';
private string $Middleware = '';
private $After = '';
private string $After = '';
protected $_annotations = [];
protected array $_annotations = [];
/**
@@ -53,7 +54,7 @@ class Annotation extends \Snowflake\Annotation\Annotation
* @param $annotations
* @throws ReflectionException
*/
public function read($node, $reflect, $method, $annotations)
public function read(Node $node, ReflectionClass $reflect, $method, $annotations)
{
$method = $reflect->getMethod($method);
+4 -3
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Annotation;
@@ -19,13 +20,13 @@ class Tcp extends Annotation
const RECEIVE = 'Receive';
const CLOSE = 'Close';
private $Message = 'required|not empty';
private string $Message = 'required|not empty';
private $Handshake;
private string $Handshake;
private $Close;
private string $Close;
/**
+4 -3
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Annotation;
@@ -16,13 +17,13 @@ class Websocket extends Annotation
const HANDSHAKE = 'Handshake';
const CLOSE = 'Close';
private $Message = 'required|not empty';
private string $Message = 'required|not empty';
private $Handshake;
private string $Handshake;
private $Close;
private string $Close;
/**
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route;
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route;
+9 -5
View File
@@ -1,11 +1,14 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Dispatch;
use Closure;
use HttpServer\Controller;
use HttpServer\Http\Context;
use HttpServer\Http\Request;
use Snowflake\Snowflake;
/**
@@ -15,9 +18,10 @@ use Snowflake\Snowflake;
class Dispatch
{
protected $handler;
/** @var Closure|array */
protected Closure|array $handler;
protected $request;
protected Request $request;
/**
* @param $handler
@@ -29,7 +33,7 @@ class Dispatch
$class = new static();
$class->handler = $handler;
$class->request = $request;
if ($handler instanceof \Closure) {
if ($handler instanceof Closure) {
$class->bind();
}
$class->bindParam();
@@ -53,7 +57,7 @@ class Dispatch
protected function bind()
{
$class = $this->bindRequest(new Controller());
$this->handler = \Closure::bind($this->handler, $class);
$this->handler = Closure::bind($this->handler, $class);
}
@@ -75,7 +79,7 @@ class Dispatch
*/
protected function bindParam()
{
if ($this->handler instanceof \Closure) {
if ($this->handler instanceof Closure) {
return;
}
$controller = $this->handler[0];
+3 -2
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route;
@@ -21,10 +22,10 @@ class Filter extends Application
{
/** @var Filter\Filter[] */
private $_filters = [];
private array $_filters = [];
/** @var array */
public $grant = [];
public array $grant = [];
/**
* @param array $value
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Filter;
+3 -2
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Filter;
@@ -15,9 +16,9 @@ use validator\Validator;
abstract class Filter extends Application
{
public $rules = [];
public array $rules = [];
public $params = [];
public array $params = [];
abstract public function check();
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Filter;
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Filter;
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route\Filter;
+2 -1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route;
@@ -16,7 +17,7 @@ class Handler extends Application
{
/** @var Router */
protected $router;
protected Router $router;
/**
* Listen constructor.
+2 -1
View File
@@ -5,6 +5,7 @@
* Date: 2019-03-20
* Time: 02:17
*/
declare(strict_types=1);
// declare(strict_types=1);
@@ -21,7 +22,7 @@ class Middleware
{
/** @var array */
private $middleWares = [];
private array $middleWares = [];
/**
* @param $call
+23 -22
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route;
@@ -21,37 +22,37 @@ use Swoole\Coroutine;
class Node extends Application
{
public $path;
public $index = 0;
public $method;
public string $path = '';
public int $index = 0;
public string $method = '';
/** @var Node[] $childes */
public $childes = [];
public array $childes = [];
public $group = [];
public array $group = [];
private $_error = '';
private string $_error = '';
public $rules = [];
public $handler;
public $htmlSuffix = '.html';
public $enableHtmlSuffix = false;
public $namespace = [];
public $middleware = [];
public $callback = [];
public array $rules = [];
public ?Closure $handler;
public string $htmlSuffix = '.html';
public bool $enableHtmlSuffix = false;
public array $namespace = [];
public array $middleware = [];
public array $callback = [];
private $_alias = '';
private string $_alias = '';
private $_interceptors = [];
private $_after = [];
private $_limits = [];
private array $_interceptors = [];
private array $_after = [];
private array $_limits = [];
/**
* @param $handler
* @return Node
* @throws
*/
public function bindHandler($handler)
public function bindHandler(Closure|array $handler)
{
if ($handler instanceof Closure) {
$this->handler = $handler;
@@ -221,7 +222,7 @@ class Node extends Application
* @param Closure|array|string $handler
* @throws Exception
*/
public function addInterceptor($handler)
public function addInterceptor(Closure|string|array $handler)
{
$this->_interceptors[] = $handler;
@@ -232,7 +233,7 @@ class Node extends Application
* @param Closure|array|string $handler
* @throws Exception
*/
public function addAfter($handler)
public function addAfter(Closure|string|array $handler)
{
$this->_after[] = $handler;
}
@@ -242,7 +243,7 @@ class Node extends Application
* @param Closure|array|string $handler
* @throws Exception
*/
public function addLimits($handler)
public function addLimits(Closure|string|array $handler)
{
$this->_limits[] = $handler;
@@ -374,7 +375,7 @@ class Node extends Application
* @param string|\Closure $class
* @throws Exception
*/
public function addMiddleware($class)
public function addMiddleware(Closure|string $class)
{
if (!is_callable($class, true)) {
return;
+3 -3
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route;
@@ -14,7 +14,7 @@ class Reduce
/**
* @param $last
* @param $middleWares
* @return mixed|null
* @return array
*/
public static function reduce($last, $middleWares)
{
@@ -31,7 +31,7 @@ class Reduce
return array_reduce(array_reverse($middleWares), function ($stack, $pipe) {
return function ($request, $passable) use ($stack, $pipe) {
if ($pipe instanceof After) {
return $pipe->onHandler($request, $passable, $stack);
return $pipe->onHandler($request, $passable);
} else {
return $pipe($request, $passable, $stack);
}
+8 -8
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace HttpServer\Route;
@@ -28,21 +28,21 @@ defined('ROUTER_HASH') or define('ROUTER_HASH', 2);
class Router extends Application implements RouterInterface
{
/** @var Node[] $nodes */
public $nodes = [];
public $groupTacks = [];
public $dir = 'App\\Http\\Controllers';
public array $nodes = [];
public array $groupTacks = [];
public ?string $dir = 'App\\Http\\Controllers';
const NOT_FOUND = 'Page not found or method not allowed.';
/** @var string[] */
public $methods = ['get', 'post', 'options', 'put', 'delete', 'receive'];
public array $methods = ['get', 'post', 'options', 'put', 'delete', 'receive'];
public $middleware = null;
public Closure|null $middleware = null;
public $useTree = false;
public bool $useTree = false;
private $reading = false;
private bool $reading = false;
/**