改名
This commit is contained in:
@@ -8,9 +8,6 @@ namespace HttpServer\Route\Dispatch;
|
||||
use Closure;
|
||||
use HttpServer\Controller;
|
||||
use HttpServer\Http\Context;
|
||||
use ReflectionException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class Dispatch
|
||||
@@ -27,10 +24,7 @@ class Dispatch
|
||||
|
||||
/**
|
||||
* @param $handler
|
||||
* @param $request
|
||||
* @return static
|
||||
* @throws NotFindClassException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public static function create($handler): static
|
||||
{
|
||||
@@ -39,7 +33,6 @@ class Dispatch
|
||||
if ($handler instanceof Closure) {
|
||||
$class->bind();
|
||||
}
|
||||
$class->bindParam();
|
||||
return $class;
|
||||
}
|
||||
|
||||
@@ -60,39 +53,11 @@ class Dispatch
|
||||
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*
|
||||
*/
|
||||
protected function bind()
|
||||
{
|
||||
$class = $this->bindRequest(Snowflake::createObject(Controller::class));
|
||||
$this->handler = Closure::bind($this->handler, $class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $controller
|
||||
* @return mixed
|
||||
*/
|
||||
protected function bindRequest($controller): mixed
|
||||
{
|
||||
$controller->request = Context::getContext('request');
|
||||
$controller->headers = $controller->request?->headers;
|
||||
$controller->input = $controller->request?->params;
|
||||
return $controller;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 参数绑定
|
||||
*/
|
||||
protected function bindParam()
|
||||
{
|
||||
if ($this->handler instanceof Closure) {
|
||||
return;
|
||||
}
|
||||
$controller = $this->handler[0];
|
||||
$this->bindRequest($controller);
|
||||
$this->handler = Closure::bind($this->handler, new Controller());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user