From c02526bfbf95a18310fb271310f404669fe0ce6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 2 Sep 2020 14:26:57 +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 --- http-server/Route/Dispatch/Dispatch.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/http-server/Route/Dispatch/Dispatch.php b/http-server/Route/Dispatch/Dispatch.php index d4654085..b222c1f7 100644 --- a/http-server/Route/Dispatch/Dispatch.php +++ b/http-server/Route/Dispatch/Dispatch.php @@ -52,7 +52,21 @@ class Dispatch */ protected function bind() { - $this->handler = \Closure::bind($this->handler, new Controller()); + $class = $this->bindRequest(new Controller()); + $this->handler = \Closure::bind($this->handler, $class); + } + + + /** + * @param $controller + * @return mixed + */ + protected function bindRequest($controller) + { + $controller->request = Context::getContext('request'); + $controller->headers = $controller->request->headers; + $controller->input = $controller->request->params; + return $controller; } @@ -65,9 +79,7 @@ class Dispatch return; } $controller = $this->handler[0]; - $controller->request = Context::getContext('request'); - $controller->headers = $controller->request->headers; - $controller->input = $controller->request->params; + $this->bindRequest($controller); } }