diff --git a/HttpServer/Route/Node.php b/HttpServer/Route/Node.php index 23911d3a..63a99873 100644 --- a/HttpServer/Route/Node.php +++ b/HttpServer/Route/Node.php @@ -35,7 +35,7 @@ class Node extends HttpService public string $method = ''; /** @var Node[] $childes */ - public array $childes = []; + public static array $childes = []; public array $group = []; @@ -429,12 +429,12 @@ class Node extends HttpService { $field = (string)$field; /** @var Node $oLod */ - $oLod = $this->childes[$field] ?? null; + $oLod = static::$childes[$field] ?? null; if (!empty($oLod)) { $node = $oLod; } - $this->childes[$field] = $node; - return $this->childes[$field]; + static::$childes[$field] = $node; + return static::$childes[$field]; } @@ -445,19 +445,19 @@ class Node extends HttpService */ public function findNode(string $search): ?Node { - if (empty($this->childes)) { + if (empty(static::$childes)) { return null; } - if (isset($this->childes[$search])) { - return $this->childes[$search]; + if (isset(static::$childes[$search])) { + return static::$childes[$search]; } $_searchMatch = '/<(\w+)?:(.+)?>/'; - foreach ($this->childes as $key => $val) { + foreach (static::$childes as $key => $val) { if (preg_match($_searchMatch, (string)$key, $match)) { Input()->addGetParam($match[1] ?? '--', $search); - return $this->childes[$key]; + return static::$childes[$key]; } } return null; diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 276fff19..d0731435 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -27,7 +27,7 @@ defined('ROUTER_HASH') or define('ROUTER_HASH', 2); class Router extends HttpService implements RouterInterface { /** @var Node[] $nodes */ - public array $nodes = []; + public static array $nodes = []; public array $groupTacks = []; public ?string $dir = 'App\\Http\\Controllers'; @@ -104,8 +104,8 @@ class Router extends HttpService implements RouterInterface public function addRoute($path, $handler, $method = 'any'): ?Node { $method = strtolower($method); - if (!isset($this->nodes[$method])) { - $this->nodes[$method] = []; + if (!isset(static::$nodes[$method])) { + static::$nodes[$method] = []; } if ($handler instanceof Closure) { @@ -130,9 +130,9 @@ class Router extends HttpService implements RouterInterface { $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); - $parent = $this->nodes[$method][$first] ?? null; + $parent = static::$nodes[$method][$first] ?? null; if (empty($parent)) { - $this->nodes[$method][$first] = $parent = $this->NodeInstance('/', 0, $method); + static::$nodes[$method][$first] = $parent = $this->NodeInstance('/', 0, $method); } if ($first !== '/') { @@ -298,7 +298,6 @@ class Router extends HttpService implements RouterInterface public function NodeInstance($value, $index = 0, $method = 'get'): Node { $node = new Node(); - $node->childes = []; $node->path = $value; $node->index = $index; $node->method = $method; @@ -421,10 +420,10 @@ class Router extends HttpService implements RouterInterface public function tree_search(?array $explode, $method): ?Node { if (empty($explode)) { - return $this->nodes[$method]['/'] ?? null; + return static::$nodes[$method]['/'] ?? null; } $first = array_shift($explode); - if (!($parent = $this->nodes[$method][$first] ?? null)) { + if (!($parent = static::$nodes[$method][$first] ?? null)) { return null; } if (empty($explode)) { @@ -471,7 +470,7 @@ class Router extends HttpService implements RouterInterface public function each(): array { $paths = []; - foreach ($this->nodes as $node) { + foreach (static::$nodes as $node) { /** @var Node[] $node */ foreach ($node as $path => $_node) { $paths[] = strtoupper($_node->method) . ' : ' . $path; @@ -521,10 +520,10 @@ class Router extends HttpService implements RouterInterface $method = $request->getMethod(); $uri = $request->headers->get('request_uri', '/'); - if (!isset($this->nodes[$method])) { + if (!isset(static::$nodes[$method])) { return null; } - $methods = $this->nodes[$method]; + $methods = static::$nodes[$method]; if (isset($methods[$uri])) { return $methods[$uri]; } @@ -542,10 +541,10 @@ class Router extends HttpService implements RouterInterface */ public function search($uri, $method): Node|null { - if (!isset($this->nodes[$method])) { + if (!isset(static::$nodes[$method])) { return null; } - $methods = $this->nodes[$method]; + $methods = static::$nodes[$method]; if (isset($methods[$uri])) { return $methods[$uri]; } @@ -560,13 +559,13 @@ class Router extends HttpService implements RouterInterface private function search_options($request): ?Node { $method = $request->getMethod(); - if (!isset($this->nodes[$method])) { + if (!isset(static::$nodes[$method])) { return null; } - if (!isset($this->nodes[$method]['*'])) { + if (!isset(static::$nodes[$method]['*'])) { return null; } - return $this->nodes[$method]['*']; + return static::$nodes[$method]['*']; }