改名
This commit is contained in:
@@ -35,7 +35,7 @@ class Node extends HttpService
|
|||||||
public string $method = '';
|
public string $method = '';
|
||||||
|
|
||||||
/** @var Node[] $childes */
|
/** @var Node[] $childes */
|
||||||
public array $childes = [];
|
public static array $childes = [];
|
||||||
|
|
||||||
public array $group = [];
|
public array $group = [];
|
||||||
|
|
||||||
@@ -429,12 +429,12 @@ class Node extends HttpService
|
|||||||
{
|
{
|
||||||
$field = (string)$field;
|
$field = (string)$field;
|
||||||
/** @var Node $oLod */
|
/** @var Node $oLod */
|
||||||
$oLod = $this->childes[$field] ?? null;
|
$oLod = static::$childes[$field] ?? null;
|
||||||
if (!empty($oLod)) {
|
if (!empty($oLod)) {
|
||||||
$node = $oLod;
|
$node = $oLod;
|
||||||
}
|
}
|
||||||
$this->childes[$field] = $node;
|
static::$childes[$field] = $node;
|
||||||
return $this->childes[$field];
|
return static::$childes[$field];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -445,19 +445,19 @@ class Node extends HttpService
|
|||||||
*/
|
*/
|
||||||
public function findNode(string $search): ?Node
|
public function findNode(string $search): ?Node
|
||||||
{
|
{
|
||||||
if (empty($this->childes)) {
|
if (empty(static::$childes)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->childes[$search])) {
|
if (isset(static::$childes[$search])) {
|
||||||
return $this->childes[$search];
|
return static::$childes[$search];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_searchMatch = '/<(\w+)?:(.+)?>/';
|
$_searchMatch = '/<(\w+)?:(.+)?>/';
|
||||||
foreach ($this->childes as $key => $val) {
|
foreach (static::$childes as $key => $val) {
|
||||||
if (preg_match($_searchMatch, (string)$key, $match)) {
|
if (preg_match($_searchMatch, (string)$key, $match)) {
|
||||||
Input()->addGetParam($match[1] ?? '--', $search);
|
Input()->addGetParam($match[1] ?? '--', $search);
|
||||||
return $this->childes[$key];
|
return static::$childes[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+17
-18
@@ -27,7 +27,7 @@ defined('ROUTER_HASH') or define('ROUTER_HASH', 2);
|
|||||||
class Router extends HttpService implements RouterInterface
|
class Router extends HttpService implements RouterInterface
|
||||||
{
|
{
|
||||||
/** @var Node[] $nodes */
|
/** @var Node[] $nodes */
|
||||||
public array $nodes = [];
|
public static array $nodes = [];
|
||||||
public array $groupTacks = [];
|
public array $groupTacks = [];
|
||||||
public ?string $dir = 'App\\Http\\Controllers';
|
public ?string $dir = 'App\\Http\\Controllers';
|
||||||
|
|
||||||
@@ -104,8 +104,8 @@ class Router extends HttpService implements RouterInterface
|
|||||||
public function addRoute($path, $handler, $method = 'any'): ?Node
|
public function addRoute($path, $handler, $method = 'any'): ?Node
|
||||||
{
|
{
|
||||||
$method = strtolower($method);
|
$method = strtolower($method);
|
||||||
if (!isset($this->nodes[$method])) {
|
if (!isset(static::$nodes[$method])) {
|
||||||
$this->nodes[$method] = [];
|
static::$nodes[$method] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($handler instanceof Closure) {
|
if ($handler instanceof Closure) {
|
||||||
@@ -130,9 +130,9 @@ class Router extends HttpService implements RouterInterface
|
|||||||
{
|
{
|
||||||
$path = $this->resolve($path);
|
$path = $this->resolve($path);
|
||||||
|
|
||||||
$this->nodes[$method][$path] = $this->NodeInstance($path, 0, $method);
|
static::$nodes[$method][$path] = $this->NodeInstance($path, 0, $method);
|
||||||
|
|
||||||
return $this->nodes[$method][$path]->bindHandler($handler);
|
return static::$nodes[$method][$path]->bindHandler($handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -164,9 +164,9 @@ class Router extends HttpService implements RouterInterface
|
|||||||
{
|
{
|
||||||
list($first, $explode) = $this->split($path);
|
list($first, $explode) = $this->split($path);
|
||||||
|
|
||||||
$parent = $this->nodes[$method][$first] ?? null;
|
$parent = static::$nodes[$method][$first] ?? null;
|
||||||
if (empty($parent)) {
|
if (empty($parent)) {
|
||||||
$this->nodes[$method][$first] = $parent = $this->NodeInstance('/', 0, $method);
|
static::$nodes[$method][$first] = $parent = $this->NodeInstance('/', 0, $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($first !== '/') {
|
if ($first !== '/') {
|
||||||
@@ -298,7 +298,6 @@ class Router extends HttpService implements RouterInterface
|
|||||||
public function NodeInstance($value, $index = 0, $method = 'get'): Node
|
public function NodeInstance($value, $index = 0, $method = 'get'): Node
|
||||||
{
|
{
|
||||||
$node = new Node();
|
$node = new Node();
|
||||||
$node->childes = [];
|
|
||||||
$node->path = $value;
|
$node->path = $value;
|
||||||
$node->index = $index;
|
$node->index = $index;
|
||||||
$node->method = $method;
|
$node->method = $method;
|
||||||
@@ -421,10 +420,10 @@ class Router extends HttpService implements RouterInterface
|
|||||||
public function tree_search(?array $explode, $method): ?Node
|
public function tree_search(?array $explode, $method): ?Node
|
||||||
{
|
{
|
||||||
if (empty($explode)) {
|
if (empty($explode)) {
|
||||||
return $this->nodes[$method]['/'] ?? null;
|
return static::$nodes[$method]['/'] ?? null;
|
||||||
}
|
}
|
||||||
$first = array_shift($explode);
|
$first = array_shift($explode);
|
||||||
if (!($parent = $this->nodes[$method][$first] ?? null)) {
|
if (!($parent = static::$nodes[$method][$first] ?? null)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (empty($explode)) {
|
if (empty($explode)) {
|
||||||
@@ -471,7 +470,7 @@ class Router extends HttpService implements RouterInterface
|
|||||||
public function each(): array
|
public function each(): array
|
||||||
{
|
{
|
||||||
$paths = [];
|
$paths = [];
|
||||||
foreach ($this->nodes as $node) {
|
foreach (static::$nodes as $node) {
|
||||||
/** @var Node[] $node */
|
/** @var Node[] $node */
|
||||||
foreach ($node as $path => $_node) {
|
foreach ($node as $path => $_node) {
|
||||||
$paths[] = strtoupper($_node->method) . ' : ' . $path;
|
$paths[] = strtoupper($_node->method) . ' : ' . $path;
|
||||||
@@ -521,10 +520,10 @@ class Router extends HttpService implements RouterInterface
|
|||||||
$method = $request->getMethod();
|
$method = $request->getMethod();
|
||||||
$uri = $request->headers->get('request_uri', '/');
|
$uri = $request->headers->get('request_uri', '/');
|
||||||
|
|
||||||
if (!isset($this->nodes[$method])) {
|
if (!isset(static::$nodes[$method])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$methods = $this->nodes[$method];
|
$methods = static::$nodes[$method];
|
||||||
if (isset($methods[$uri])) {
|
if (isset($methods[$uri])) {
|
||||||
return $methods[$uri];
|
return $methods[$uri];
|
||||||
}
|
}
|
||||||
@@ -542,10 +541,10 @@ class Router extends HttpService implements RouterInterface
|
|||||||
*/
|
*/
|
||||||
public function search($uri, $method): Node|null
|
public function search($uri, $method): Node|null
|
||||||
{
|
{
|
||||||
if (!isset($this->nodes[$method])) {
|
if (!isset(static::$nodes[$method])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$methods = $this->nodes[$method];
|
$methods = static::$nodes[$method];
|
||||||
if (isset($methods[$uri])) {
|
if (isset($methods[$uri])) {
|
||||||
return $methods[$uri];
|
return $methods[$uri];
|
||||||
}
|
}
|
||||||
@@ -560,13 +559,13 @@ class Router extends HttpService implements RouterInterface
|
|||||||
private function search_options($request): ?Node
|
private function search_options($request): ?Node
|
||||||
{
|
{
|
||||||
$method = $request->getMethod();
|
$method = $request->getMethod();
|
||||||
if (!isset($this->nodes[$method])) {
|
if (!isset(static::$nodes[$method])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!isset($this->nodes[$method]['*'])) {
|
if (!isset(static::$nodes[$method]['*'])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $this->nodes[$method]['*'];
|
return static::$nodes[$method]['*'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user