From caa58018c161c5ac4e23ad3dc65e3600955af66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 1 Sep 2020 03:38:27 +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/Middleware.php | 2 +- http-server/Route/Router.php | 37 +++++++++++++++++++++----------- http-server/config.php | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/http-server/Route/Middleware.php b/http-server/Route/Middleware.php index 9f745cb3..b037cfab 100644 --- a/http-server/Route/Middleware.php +++ b/http-server/Route/Middleware.php @@ -70,7 +70,7 @@ class Middleware return $middleWares; } foreach ($node->getInterceptor() as $item) { - $middleWares[] = $item; + $middleWares[] = $item[0]; } return $middleWares; } diff --git a/http-server/Route/Router.php b/http-server/Route/Router.php index c1586a28..8263e3ce 100644 --- a/http-server/Route/Router.php +++ b/http-server/Route/Router.php @@ -481,7 +481,6 @@ class Router extends Application implements RouterInterface $annotation->registration_notes($prefix . 'Interceptor', 'App\Http\Interceptor'); $annotation->registration_notes($prefix . 'Limits', 'App\Http\Limits'); - $router = $this; $this->loadRouteDir(APP_PATH . '/routes'); } @@ -494,19 +493,31 @@ class Router extends Application implements RouterInterface { $files = glob($path . '/*'); for ($i = 0; $i < count($files); $i++) { - try { - if (is_dir($files[$i])) { - $this->loadRouteDir($files[$i]); - } else { - include_once "{$files[$i]}"; - } - } catch (Exception $exception) { - $this->error($exception->getMessage()); - } finally { - if (isset($exception)) { - unset($exception); - } + if (is_dir($files[$i])) { + $this->loadRouteDir($files[$i]); + } else { + $this->loadRouterFile($files[$i]); } } } + + + /** + * @param $files + * @throws Exception + */ + private function loadRouterFile($files) + { + try { + $router = $this; + include_once "{$files}"; + } catch (Exception $exception) { + $this->error($exception->getMessage()); + } finally { + if (isset($exception)) { + unset($exception); + } + } + } + } diff --git a/http-server/config.php b/http-server/config.php index 0a06fe8b..04a003a0 100644 --- a/http-server/config.php +++ b/http-server/config.php @@ -22,7 +22,7 @@ return [ 'events' => [ Event::SERVER_WORKER_START => function () { $router = Snowflake::get()->router; - $router->loader(); + $router->loadRouterSetting(); }, ] ],