改名
This commit is contained in:
@@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
|
|
||||||
namespace HttpServer\Route\Dispatch;
|
|
||||||
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use HttpServer\Controller;
|
|
||||||
use HttpServer\Http\Context;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Dispatch
|
|
||||||
* @package HttpServer\Route\Dispatch
|
|
||||||
*/
|
|
||||||
class Dispatch
|
|
||||||
{
|
|
||||||
|
|
||||||
/** @var Closure|array */
|
|
||||||
protected array|Closure $handler;
|
|
||||||
|
|
||||||
protected mixed $request;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $handler
|
|
||||||
* @return static
|
|
||||||
*/
|
|
||||||
public static function create($handler): static
|
|
||||||
{
|
|
||||||
$class = new static();
|
|
||||||
$class->handler = $handler;
|
|
||||||
if ($handler instanceof Closure) {
|
|
||||||
$class->bind();
|
|
||||||
}
|
|
||||||
return $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
* 执行函数
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
public function dispatch(): mixed
|
|
||||||
{
|
|
||||||
$dispatchParam = Context::getContext('dispatch-param');
|
|
||||||
if (empty($dispatchParam)) {
|
|
||||||
$dispatchParam = [\request()];
|
|
||||||
}
|
|
||||||
return \aop($this->handler, $dispatchParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected function bind()
|
|
||||||
{
|
|
||||||
$this->handler = Closure::bind($this->handler, new Controller());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,6 @@ use HttpServer\Controller;
|
|||||||
use HttpServer\Http\Context;
|
use HttpServer\Http\Context;
|
||||||
use HttpServer\Http\Request;
|
use HttpServer\Http\Request;
|
||||||
use HttpServer\HttpFilter;
|
use HttpServer\HttpFilter;
|
||||||
use HttpServer\Route\Dispatch\Dispatch;
|
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Snowflake\Core\Json;
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
@@ -127,7 +126,11 @@ class Node extends HttpService
|
|||||||
public function createDispatch(): Closure
|
public function createDispatch(): Closure
|
||||||
{
|
{
|
||||||
return function () {
|
return function () {
|
||||||
return Dispatch::create($this->handler)->dispatch();
|
$dispatchParam = Context::getContext('dispatch-param');
|
||||||
|
if (empty($dispatchParam)) {
|
||||||
|
$dispatchParam = [\request()];
|
||||||
|
}
|
||||||
|
return \aop($this->handler, $dispatchParam);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user