改名
This commit is contained in:
@@ -59,7 +59,11 @@ class HttpHeaders
|
|||||||
*/
|
*/
|
||||||
public function getRequestUri(): ?string
|
public function getRequestUri(): ?string
|
||||||
{
|
{
|
||||||
return $this->__handler__('request_uri');
|
$uri = $this->__handler__('request_uri', '/');
|
||||||
|
if (empty($uri)) {
|
||||||
|
return '/';
|
||||||
|
}
|
||||||
|
return $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace HttpServer\Route;
|
namespace HttpServer\Route;
|
||||||
|
|
||||||
use Annotation\Route\Route;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
use HttpServer\Abstracts\HttpService;
|
use HttpServer\Abstracts\HttpService;
|
||||||
@@ -481,32 +480,6 @@ class Router extends HttpService implements RouterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
* @throws
|
|
||||||
*/
|
|
||||||
public function dispatch(Request $request): void
|
|
||||||
{
|
|
||||||
$node = $this->find_path($request);
|
|
||||||
if (!($node instanceof Node)) {
|
|
||||||
$this->response->setFormat(Response::HTML);
|
|
||||||
$this->response->send('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>');
|
|
||||||
} else {
|
|
||||||
$this->response->send($node->dispatch(), 200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function pageNotFound()
|
|
||||||
{
|
|
||||||
$this->response->setFormat(Response::HTML);
|
|
||||||
$this->response->send('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $exception
|
* @param $exception
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -522,13 +495,13 @@ class Router extends HttpService implements RouterInterface
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Node|null 树干搜索
|
* @return Node|null 树干搜索
|
||||||
* 树干搜索
|
* 树干搜索
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function find_path(Request $request): ?Node
|
public function find_path(Request $request): ?Node
|
||||||
{
|
{
|
||||||
$method = $request->getMethod();
|
$method = $request->getMethod();
|
||||||
$uri = $request->headers->get('request_uri', '/');
|
|
||||||
|
|
||||||
$methods = static::$nodes[$method][$uri] ?? null;
|
$methods = static::$nodes[$method][\request()->getUri()] ?? null;
|
||||||
if (!is_null($methods)) {
|
if (!is_null($methods)) {
|
||||||
return $methods;
|
return $methods;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user