From 86880f8b1fbef3c591214a5dd77cda9386ce3af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 7 Sep 2021 11:44:12 +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 --- core/Abstracts/BaseApplication.php | 3 +-- function.php | 4 +--- http-helper/Route/Router.php | 4 ++-- http-server/Worker/OnWorkerStart.php | 2 +- note/Route/Route.php | 15 ++++++--------- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/core/Abstracts/BaseApplication.php b/core/Abstracts/BaseApplication.php index 9b79c1c2..605482b9 100644 --- a/core/Abstracts/BaseApplication.php +++ b/core/Abstracts/BaseApplication.php @@ -373,7 +373,7 @@ abstract class BaseApplication extends Component */ public function getRouter(): Router { - return $this->get('router'); + return Kiri::getDi()->get(Router::class); } @@ -467,7 +467,6 @@ abstract class BaseApplication extends Component 'config' => ['class' => Config::class], 'logger' => ['class' => Logger::class], 'annotation' => ['class' => SAnnotation::class], - 'router' => ['class' => Router::class], 'redis' => ['class' => Redis::class], 'databases' => ['class' => Connection::class], 'aop' => ['class' => AspectManager::class], diff --git a/function.php b/function.php index 7aedd126..81dfc90c 100644 --- a/function.php +++ b/function.php @@ -1006,7 +1006,7 @@ if (!function_exists('router')) { */ function router(): Router { - return Kiri::app()->getRouter(); + return Kiri::getDi()->get(Router::class); } } @@ -1018,8 +1018,6 @@ if (!function_exists('isService')) { /** * @param string $name * @return bool - * @throws NotFindClassException - * @throws ReflectionException */ function isService(string $name): bool { diff --git a/http-helper/Route/Router.php b/http-helper/Route/Router.php index 18f6851f..3648f2d0 100644 --- a/http-helper/Route/Router.php +++ b/http-helper/Route/Router.php @@ -76,7 +76,7 @@ class Router extends HttpService implements RouterInterface */ public static function getNamespace(): string { - $router = Kiri::app()->getRouter(); + $router = Kiri::getDi()->get(Router::class); return Config::get('http.namespace', $router->namespace); } @@ -96,7 +96,7 @@ class Router extends HttpService implements RouterInterface * @param $handler * @param string $method * @return ?Node - * @throws Exception + * @throws */ public function addRoute($path, $handler, string $method = 'any'): ?Node { diff --git a/http-server/Worker/OnWorkerStart.php b/http-server/Worker/OnWorkerStart.php index 10998413..34e22bb8 100644 --- a/http-server/Worker/OnWorkerStart.php +++ b/http-server/Worker/OnWorkerStart.php @@ -48,7 +48,7 @@ class OnWorkerStart implements EventDispatcherInterface $this->interpretDirectory($isWorker); if ($isWorker) { ServerManager::setEnv('environmental', Kiri::WORKER); - Kiri::getFactory()->getRouter()->_loader(); + Kiri::getDi()->get(Router::class)->_loader(); $this->setProcessName(sprintf('Worker[%d].%d', $event->server->worker_pid, $event->workerId)); } else { diff --git a/note/Route/Route.php b/note/Route/Route.php index 2ee316fb..2a349f15 100644 --- a/note/Route/Route.php +++ b/note/Route/Route.php @@ -23,18 +23,15 @@ use Kiri\Kiri; } - /** - * @param static $params - * @param mixed $class - * @param mixed|null $method - * @return Router - * @throws \Kiri\Exception\NotFindClassException - * @throws \ReflectionException - */ + /** + * @param mixed $class + * @param mixed|null $method + * @return Router + */ public function execute(mixed $class, mixed $method = null): Router { // TODO: Implement setHandler() method. - $router = Kiri::app()->getRouter(); + $router = Kiri::getDi()->get(Router::class); if (is_string($class)) { $class = di($class); }