改名
This commit is contained in:
@@ -93,9 +93,6 @@ class Router extends HttpService implements RouterInterface
|
|||||||
*/
|
*/
|
||||||
public function addRoute($path, $handler, string $method = 'any'): ?Node
|
public function addRoute($path, $handler, string $method = 'any'): ?Node
|
||||||
{
|
{
|
||||||
if (!isset($this->nodes[$method])) {
|
|
||||||
$this->nodes[$method] = [];
|
|
||||||
}
|
|
||||||
if ($handler instanceof Closure) {
|
if ($handler instanceof Closure) {
|
||||||
$handler = Closure::bind($handler, di(Controller::class));
|
$handler = Closure::bind($handler, di(Controller::class));
|
||||||
}
|
}
|
||||||
@@ -130,15 +127,17 @@ class Router extends HttpService implements RouterInterface
|
|||||||
private function tree($path, $handler, string $method = 'any'): Node
|
private function tree($path, $handler, string $method = 'any'): Node
|
||||||
{
|
{
|
||||||
$explode = $this->split($path);
|
$explode = $this->split($path);
|
||||||
if (!isset($this->nodes['/'])) {
|
$start = array_shift($explode);
|
||||||
$this->nodes['/'] = $this->NodeInstance('/', 0, $method);
|
$parent = $this->nodes[$start] ?? null;
|
||||||
}
|
if (is_null($parent)) {
|
||||||
$parent = $this->nodes['/'];
|
$parent = $this->nodes[$start] = $this->NodeInstance($start, 0, $method);
|
||||||
if (!empty($explode)) {
|
|
||||||
$parent = $this->bindNode($parent, $explode, $method);
|
|
||||||
}
|
}
|
||||||
|
if (empty($explode)) {
|
||||||
return $parent->setHandler($handler, $method, $path);
|
return $parent->setHandler($handler, $method, $path);
|
||||||
}
|
}
|
||||||
|
return $this->bindNode($parent, $explode, $method)
|
||||||
|
->setHandler($handler, $method, $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -396,10 +395,13 @@ class Router extends HttpService implements RouterInterface
|
|||||||
*/
|
*/
|
||||||
public function tree_search(?array $explode): ?Node
|
public function tree_search(?array $explode): ?Node
|
||||||
{
|
{
|
||||||
if (!isset($this->nodes['/'])) {
|
if (empty($this->nodes)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$parent = $this->nodes[array_shift($explode)];
|
||||||
|
if (!($parent instanceof Node)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$parent = $this->nodes['/'];
|
|
||||||
while ($value = array_shift($explode)) {
|
while ($value = array_shift($explode)) {
|
||||||
$node = $parent->findNode($value);
|
$node = $parent->findNode($value);
|
||||||
if (!$node) {
|
if (!$node) {
|
||||||
@@ -418,13 +420,13 @@ class Router extends HttpService implements RouterInterface
|
|||||||
{
|
{
|
||||||
$path = $this->addPrefix() . '/' . ltrim($path, '/');
|
$path = $this->addPrefix() . '/' . ltrim($path, '/');
|
||||||
if ($path === '/') {
|
if ($path === '/') {
|
||||||
return [];
|
return ['/'];
|
||||||
}
|
}
|
||||||
$filter = array_filter(explode('/', $path));
|
$filter = array_filter(explode('/', $path));
|
||||||
if (!empty($filter)) {
|
if (!empty($filter)) {
|
||||||
return $filter;
|
return $filter;
|
||||||
}
|
}
|
||||||
return [];
|
return ['/'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class Uri implements UriInterface
|
|||||||
public function getExplode(): array
|
public function getExplode(): array
|
||||||
{
|
{
|
||||||
if ($this->path == '/' || $this->path == '') {
|
if ($this->path == '/' || $this->path == '') {
|
||||||
return [''];
|
return ['/'];
|
||||||
}
|
}
|
||||||
if (empty($this->_explode)) {
|
if (empty($this->_explode)) {
|
||||||
$this->_explode = array_filter(explode('/', $this->path));
|
$this->_explode = array_filter(explode('/', $this->path));
|
||||||
|
|||||||
Reference in New Issue
Block a user