This commit is contained in:
2021-09-07 15:44:12 +08:00
parent 181250be29
commit 57531e1899
+25 -18
View File
@@ -177,9 +177,10 @@ class Router extends HttpService implements RouterInterface
* @return void * @return void
* @throws * @throws
*/ */
public function socket($route, $handler): void public static function socket($route, $handler): void
{ {
$this->addRoute($route, $handler, 'SOCKET'); $router = Kiri::getDi()->get(Router::class);
$router->addRoute($route, $handler, 'SOCKET');
} }
@@ -189,9 +190,10 @@ class Router extends HttpService implements RouterInterface
* @return void * @return void
* @throws * @throws
*/ */
public function post($route, $handler): void public static function post($route, $handler): void
{ {
$this->addRoute($route, $handler, 'POST'); $router = Kiri::getDi()->get(Router::class);
$router->addRoute($route, $handler, 'POST');
} }
/** /**
@@ -200,9 +202,10 @@ class Router extends HttpService implements RouterInterface
* @return void * @return void
* @throws * @throws
*/ */
public function get($route, $handler): void public static function get($route, $handler): void
{ {
$this->addRoute($route, $handler, 'GET'); $router = Kiri::getDi()->get(Router::class);
$router->addRoute($route, $handler, 'GET');
} }
@@ -212,9 +215,10 @@ class Router extends HttpService implements RouterInterface
* @return void * @return void
* @throws * @throws
*/ */
public function options($route, $handler): void public static function options($route, $handler): void
{ {
$this->addRoute($route, $handler, 'OPTIONS'); $router = Kiri::getDi()->get(Router::class);
$router->addRoute($route, $handler, 'OPTIONS');
} }
@@ -223,10 +227,11 @@ class Router extends HttpService implements RouterInterface
* @param $handler * @param $handler
* @throws * @throws
*/ */
public function any($route, $handler): void public static function any($route, $handler): void
{ {
foreach ($this->methods as $method) { $router = Kiri::getDi()->get(Router::class);
$this->addRoute($route, $handler, $method); foreach ($router->methods as $method) {
$router->addRoute($route, $handler, $method);
} }
} }
@@ -236,9 +241,10 @@ class Router extends HttpService implements RouterInterface
* @return void * @return void
* @throws * @throws
*/ */
public function delete($route, $handler): void public static function delete($route, $handler): void
{ {
$this->addRoute($route, $handler, 'DELETE'); $router = Kiri::getDi()->get(Router::class);
$router->addRoute($route, $handler, 'DELETE');
} }
@@ -248,9 +254,10 @@ class Router extends HttpService implements RouterInterface
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function head($route, $handler): void public static function head($route, $handler): void
{ {
$this->addRoute($route, $handler, 'HEAD'); $router = Kiri::getDi()->get(Router::class);
$router->addRoute($route, $handler, 'HEAD');
} }
@@ -260,9 +267,10 @@ class Router extends HttpService implements RouterInterface
* @return void * @return void
* @throws * @throws
*/ */
public function put($route, $handler): void public static function put($route, $handler): void
{ {
$this->addRoute($route, $handler, 'PUT'); $router = Kiri::getDi()->get(Router::class);
$router->addRoute($route, $handler, 'PUT');
} }
/** /**
@@ -546,7 +554,6 @@ class Router extends HttpService implements RouterInterface
private function loadRouterFile($files) private function loadRouterFile($files)
{ {
try { try {
$router = $this;
include_once "$files"; include_once "$files";
} catch (Throwable $exception) { } catch (Throwable $exception) {
$this->addError($exception, 'throwable'); $this->addError($exception, 'throwable');