This commit is contained in:
2021-09-18 10:54:46 +08:00
parent 0b172ed567
commit 5f4af41551
+4 -14
View File
@@ -8,8 +8,6 @@ use Closure;
use Exception; use Exception;
use Http\Abstracts\HttpService; use Http\Abstracts\HttpService;
use Http\Controller; use Http\Controller;
use Http\Handler\Abstracts\HandlerManager;
use Http\Handler\Handler;
use Http\IInterface\MiddlewareInterface; use Http\IInterface\MiddlewareInterface;
use Http\IInterface\RouterInterface; use Http\IInterface\RouterInterface;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
@@ -106,14 +104,10 @@ class Router extends HttpService implements RouterInterface
$handler = Closure::bind($handler, di(Controller::class)); $handler = Closure::bind($handler, di(Controller::class));
} }
$path = $this->addPrefix() . '/' . ltrim($path, '/');
if (is_string($handler)) { $di = Kiri::getDi()->get(\Http\Handler\Router::class);
$handler = explode('@', $handler); $di->addRoute($method, $path, $handler);
$handler[0] = $this->namespace . '\\' . $handler[0];
}
HandlerManager::add($path, $method, new Handler($path, $handler));
return null; return null;
return $this->tree($path, $handler, $method); return $this->tree($path, $handler, $method);
@@ -402,12 +396,8 @@ class Router extends HttpService implements RouterInterface
*/ */
public static function group(array $config, callable $callback) public static function group(array $config, callable $callback)
{ {
$router = Kiri::getDi()->get(Router::class); $di = Kiri::getDi()->get(\Http\Handler\Router::class);
$router->groupTacks[] = $config; $di->group($config, $callback);
call_user_func($callback);
array_pop($router->groupTacks);
} }
/** /**