PHP code example of borsch / router
1. Go to this page and download the library: Download borsch/router library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
borsch / router example snippets
use Borsch\Router\UriTemplateRouter;
$router = new UriTemplateRouter();
$router->get(
'/hotels/{hotel}/bookings/{booking}',
function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
// Laminas\Diactoros\Response or any other PSR-7 implementation.
$response = new \Laminas\Diactoros\Response();
$response->getBody()->write('Welcome to the hotel page !');
return $response;
},
'route-name'
);
$server_request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals();
$route_result = $router->match($server_request);
// $route_result is an instance of RouteResultInterface.