condense interace

This commit is contained in:
Sky Johnson 2025-04-14 13:16:34 -05:00
parent a05ff9e55c
commit a8b0f2a410
3 changed files with 10 additions and 19 deletions

View File

@ -1,7 +1,7 @@
{
"name": "sharkk/router",
"description": "A simple node-based router.",
"version": "1.2.4",
"version": "1.2.5",
"type": "library",
"license": "MIT",
"autoload": {

View File

@ -2,7 +2,7 @@
namespace Sharkk\Router;
class SegmentRouter implements RouterInterface
class Router
{
private array $routes = [];
@ -13,7 +13,7 @@ class SegmentRouter implements RouterInterface
* Example:
* `$r->add('GET', '/posts/:id', function($id) { echo "Viewing post $id"; });`
*/
public function add(string $method, string $route, callable $handler): RouterInterface
public function add(string $method, string $route, callable $handler): Router
{
// Expand the route into segments and make dynamic segments into a common placeholder
$segments = array_map(function($segment) {
@ -84,7 +84,7 @@ class SegmentRouter implements RouterInterface
/**
* Clear all routes from the router.
*/
public function clear(): RouterInterface
public function clear(): Router
{
$this->routes = [];
return $this;
@ -101,7 +101,7 @@ class SegmentRouter implements RouterInterface
/**
* Register a GET route.
*/
public function get(string $route, callable $handler): RouterInterface
public function get(string $route, callable $handler): Router
{
return $this->add('GET', $route, $handler);
}
@ -109,7 +109,7 @@ class SegmentRouter implements RouterInterface
/**
* Register a POST route.
*/
public function post(string $route, callable $handler): RouterInterface
public function post(string $route, callable $handler): Router
{
return $this->add('POST', $route, $handler);
}
@ -117,7 +117,7 @@ class SegmentRouter implements RouterInterface
/**
* Register a PUT route.
*/
public function put(string $route, callable $handler): RouterInterface
public function put(string $route, callable $handler): Router
{
return $this->add('PUT', $route, $handler);
}
@ -125,7 +125,7 @@ class SegmentRouter implements RouterInterface
/**
* Register a PATCH route.
*/
public function patch(string $route, callable $handler): RouterInterface
public function patch(string $route, callable $handler): Router
{
return $this->add('PATCH', $route, $handler);
}
@ -133,7 +133,7 @@ class SegmentRouter implements RouterInterface
/**
* Register a DELETE route.
*/
public function delete(string $route, callable $handler): RouterInterface
public function delete(string $route, callable $handler): Router
{
return $this->add('DELETE', $route, $handler);
}
@ -141,7 +141,7 @@ class SegmentRouter implements RouterInterface
/**
* Register a HEAD route.
*/
public function head(string $route, callable $handler): RouterInterface
public function head(string $route, callable $handler): Router
{
return $this->add('HEAD', $route, $handler);
}

View File

@ -1,9 +0,0 @@
<?php
namespace Sharkk\Router;
interface RouterInterface
{
public function add(string $method, string $route, callable $handler): RouterInterface;
public function lookup(string $method, string $uri): array;
}