改名
This commit is contained in:
@@ -42,6 +42,8 @@ class Router extends Application implements RouterInterface
|
|||||||
|
|
||||||
public $useTree = false;
|
public $useTree = false;
|
||||||
|
|
||||||
|
private $reading = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Closure $middleware
|
* @param Closure $middleware
|
||||||
@@ -474,6 +476,9 @@ class Router extends Application implements RouterInterface
|
|||||||
public function dispatch()
|
public function dispatch()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
if ($this->reading) {
|
||||||
|
return send(self::NOT_FOUND, 404);
|
||||||
|
}
|
||||||
/** @var Node $node */
|
/** @var Node $node */
|
||||||
if (!($node = $this->find_path(\request()))) {
|
if (!($node = $this->find_path(\request()))) {
|
||||||
$response = send(self::NOT_FOUND, 404);
|
$response = send(self::NOT_FOUND, 404);
|
||||||
@@ -485,12 +490,14 @@ class Router extends Application implements RouterInterface
|
|||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$response = send($this->exception($exception), 200);
|
$response = send($this->exception($exception), 200);
|
||||||
} finally {
|
} finally {
|
||||||
if (!($node instanceof Node) || !$node->hasAfter()) {
|
if (!isset($node) || !($node instanceof Node)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($node->hasAfter()) {
|
||||||
$node->afterDispatch($response ?? null);
|
$node->afterDispatch($response ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -595,6 +602,7 @@ class Router extends Application implements RouterInterface
|
|||||||
private function loadRouteDir($path)
|
private function loadRouteDir($path)
|
||||||
{
|
{
|
||||||
$files = glob($path . '/*');
|
$files = glob($path . '/*');
|
||||||
|
$this->reading = true;
|
||||||
for ($i = 0; $i < count($files); $i++) {
|
for ($i = 0; $i < count($files); $i++) {
|
||||||
if (is_dir($files[$i])) {
|
if (is_dir($files[$i])) {
|
||||||
$this->loadRouteDir($files[$i]);
|
$this->loadRouteDir($files[$i]);
|
||||||
@@ -602,6 +610,7 @@ class Router extends Application implements RouterInterface
|
|||||||
$this->loadRouterFile($files[$i]);
|
$this->loadRouterFile($files[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->reading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user