Added interface for route handlers.

This commit is contained in:
flash 2023-09-06 11:49:54 +00:00
parent 1172115e69
commit 2b8b31289d
5 changed files with 40 additions and 4 deletions

View file

@ -1 +1 @@
0.2308.220004
0.2309.61148

View file

@ -1,7 +1,7 @@
<?php
// HttpFx.php
// Created: 2022-02-15
// Updated: 2023-01-06
// Updated: 2023-09-06
namespace Index\Http;
@ -17,6 +17,7 @@ use Index\Http\Content\JsonContent;
use Index\Http\Content\StreamContent;
use Index\Http\Content\StringContent;
use Index\Routing\IRouter;
use Index\Routing\IRouteHandler;
use Index\Routing\Router;
use Index\Routing\RoutePathNotFoundException;
use Index\Routing\RouteMethodNotSupportedException;
@ -286,4 +287,13 @@ class HttpFx implements IRouter {
public function options(string $path, callable $handler): void {
$this->router->add('options', $path, $handler);
}
/**
* Registers routes in an IRouteHandler implementation.
*
* @param IRouteHandler $handler Routes handler.
*/
public function register(IRouteHandler $handler): void {
$handler->registerRoutes($this->router);
}
}

View file

@ -0,0 +1,10 @@
<?php
// IRouteHandler.php
// Created: 2023-09-06
// Updated: 2023-09-06
namespace Index\Routing;
interface IRouteHandler {
public function registerRoutes(IRouter $router): void;
}

View file

@ -1,7 +1,7 @@
<?php
// IRouter.php
// Created: 2023-01-06
// Updated: 2023-01-06
// Updated: 2023-09-06
namespace Index\Routing;
@ -78,4 +78,11 @@ interface IRouter {
* @param callable $handler Request handler.
*/
public function options(string $path, callable $handler): void;
/**
* Registers routes in an IRouteHandler implementation.
*
* @param IRouteHandler $handler Routes handler.
*/
public function register(IRouteHandler $handler): void;
}

View file

@ -1,7 +1,7 @@
<?php
// Router.php
// Created: 2022-01-18
// Updated: 2023-01-06
// Updated: 2023-09-06
namespace Index\Routing;
@ -129,4 +129,13 @@ class Router implements IRouter {
public function options(string $path, callable $handler): void {
$this->add('options', $path, $handler);
}
/**
* Registers routes in an IRouteHandler implementation.
*
* @param IRouteHandler $handler Routes handler.
*/
public function register(IRouteHandler $handler): void {
$handler->registerRoutes($this);
}
}