From 405724ec3f9f9f2fb318c5a1d9db175e1b99c382 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 11 Sep 2023 20:08:15 +0000 Subject: [PATCH] Removed router merging. --- VERSION | 2 +- src/Http/HttpFx.php | 12 +----------- src/Routing/IRouter.php | 10 +--------- src/Routing/RouteInfo.php | 18 +----------------- src/Routing/Router.php | 18 ++++-------------- tests/RouterTest.php | 7 +------ 6 files changed, 9 insertions(+), 58 deletions(-) diff --git a/VERSION b/VERSION index e037e50..bbc05bc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2309.111944 +0.2309.112008 diff --git a/src/Http/HttpFx.php b/src/Http/HttpFx.php index ff3d222..6310ffd 100644 --- a/src/Http/HttpFx.php +++ b/src/Http/HttpFx.php @@ -1,7 +1,7 @@ router->use($path, $handler); } - /** - * Merges another router with this one with possibility of changing its root. - * - * @param string $path Base path to use. - * @param Router $router Router object to inherit from. - */ - public function merge(string $path, Router $router): void { - $this->router->merge($path, $router); - } - /** * Adds a new route. * diff --git a/src/Routing/IRouter.php b/src/Routing/IRouter.php index 3f98e04..c9323c7 100644 --- a/src/Routing/IRouter.php +++ b/src/Routing/IRouter.php @@ -1,7 +1,7 @@ children = array_merge($this->children, $route->children); - $this->methods = array_merge($this->methods, $route->methods); - $this->middlewares = array_merge($this->middlewares, $route->middlewares); - if($this->dynamicChild === null) - $this->dynamicChild = $route->dynamicChild; - return; - } - - $this->getChild($path, $next)->mergeRoute($next, $route); - } - /** * @internal */ diff --git a/src/Routing/Router.php b/src/Routing/Router.php index da91848..9ca7549 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -1,7 +1,7 @@ route->resolve($method, trim($path, '/'), $args); + return $this->route->resolve($method, $path, $args); } /** @@ -43,17 +43,7 @@ class Router implements IRouter { * @param callable $handler Middleware function. */ public function use(string $path, callable $handler): void { - $this->route->addMiddleware(trim($path, '/'), $handler); - } - - /** - * Merges another router with this one with possibility of changing its root. - * - * @param string $path Base path to use. - * @param Router $router Router object to inherit from. - */ - public function merge(string $path, Router $router): void { - $this->route->mergeRoute(trim($path, '/'), $router->route); + $this->route->addMiddleware($path, $handler); } /** @@ -67,7 +57,7 @@ class Router implements IRouter { if(empty($method)) throw new InvalidArgumentException('$method may not be empty.'); - $this->route->addMethod($method, trim($path, '/'), $handler); + $this->route->addMethod($method, $path, $handler); } /** diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 3e047f3..f88f3fb 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -1,7 +1,7 @@ assertEquals(['meow', 'rules page'], $router2->resolve('GET', '/rules')->runAll()); - - $router1->merge('/info', $router2); - - $this->assertEquals(['warioware', 'meow', 'rules page'], $router1->resolve('GET', '/info/rules')->runAll()); - $this->assertEquals(['meow', 'numeric test'], $router2->resolve('GET', '/25252')->runAll()); $router3 = new Router;