nsrosenqvist / soma-router
League Route for the SOMA framework
1.0.0
2020-06-09 12:57 UTC
Requires
- php: >=7.1.0
- laminas/laminas-diactoros: ^2.3
- laminas/laminas-httphandlerrunner: ^1.1
- league/route: ^4.3
This package is auto-updated.
Last update: 2024-12-09 22:56:17 UTC
README
Installation
composer require nsrosenqvist/soma-router
Usage
Register the service provider, preferably alias NSRosenqvist\Soma\Router\Facades\Router
to Router
, and then simply register your routes using the Facade. The API is found here.
The system event router.init
is a great place to register your routes.
namespace MyApp; use Soma\ServiceProvider; use Psr\Container\ContainerInterface; use Laminas\Diactoros\Response; class RouterProvider extends ServiceProvider { public function boot(ContainerInterface $c) { listen('router.init', function($router) use ($c) { // map a route $router->map('GET', '/', function (ServerRequestInterface $request) : ResponseInterface { $response = new Response; $response->getBody()->write('<h1>Hello, World!</h1>'); return $response; }); // or include a file with all route definitions include "path/to/routes.php"; }); } }
License
MIT