Added interface for route handlers.
This commit is contained in:
parent
1172115e69
commit
2b8b31289d
5 changed files with 40 additions and 4 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
0.2308.220004
|
||||
0.2309.61148
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
10
src/Routing/IRouteHandler.php
Normal file
10
src/Routing/IRouteHandler.php
Normal 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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue