From 290286e1a9eb6fd5b58c637ddca89e70cdece94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 2 Aug 2021 18:29:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Route/Node.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/HttpServer/Route/Node.php b/HttpServer/Route/Node.php index e66f649a..b8c82445 100644 --- a/HttpServer/Route/Node.php +++ b/HttpServer/Route/Node.php @@ -11,7 +11,6 @@ use Exception; use HttpServer\Abstracts\HttpService; use HttpServer\Http\Request; use JetBrains\PhpStorm\Pure; -use ReflectionClass; use ReflectionException; use Snowflake\Aop; use Snowflake\Core\Json; @@ -85,11 +84,7 @@ class Node extends HttpService public function bindHandler($handler): static { if (is_string($handler) && str_contains($handler, '@')) { - list($controller, $action) = explode('@', $handler); - if (!class_exists($controller) && !empty($this->namespace)) { - $controller = implode('\\', $this->namespace) . '\\' . $controller; - } - $this->handler = [Snowflake::getDi()->get($controller), $action]; + $this->handler = $this->splitHandler($handler); } else if ($handler != null && !is_callable($handler, true)) { $this->_error = 'Controller is con\'t exec.'; } else { @@ -100,6 +95,22 @@ class Node extends HttpService } + /** + * @param string $handler + * @return array + * @throws NotFindClassException + * @throws ReflectionException + */ + private function splitHandler(string $handler): array + { + list($controller, $action) = explode('@', $handler); + if (!class_exists($controller) && !empty($this->namespace)) { + $controller = implode('\\', $this->namespace) . '\\' . $controller; + } + return [Snowflake::getDi()->get($controller), $action]; + } + + /** * @throws NotFindClassException * @throws ReflectionException