PHP code example of borschphp / router
1. Go to this page and download the library: Download borschphp/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/ */
borschphp / router example snippets
$router = new \Borsch\Router\FastRouteRouter();
$router->addRoute(new \Borsch\Router\Route(
['GET'],
'/articles/{id:\d+}[/{slug}]',
new ArticleHandler(), // Instance of RequestHandlerInterface
'articles.id.title'
));
$server_request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals();
// $route_result is an instance of RouteResultInterface
$route_result = $router->match($server_request);
// $route is an instance of RouteInterface (or false if no match)
$route = $route_result->getMatchedRoute();
if (!$route) {
return new \Laminas\Diactoros\Response('Not Found', 404);
}
// $response is an instance of ResponseInterface
$response = $route->getHandler()->handle($server_request);
// Send the response back to the client or other...