1. Go to this page and download the library: Download bermudaphp/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/ */
bermudaphp / router example snippets
use Bermuda\Router\Routes;
$routes = new Routes;
$router = Router::fromDnf($routes);
$routes->addRoute(
RouteRecord::get('home', '/hello/[name]', static function(string $name): void {
echo sprintf('Hello, %s!', $name)
})
);
$route = $router->match($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
if (!route) {
// route not found logics
}
call_user_func($route->handler, $route->params['name']);
$group = $routes->group(name: 'api', prifix: '/api'); // set routes group
$group->addRoute(RouteRecord::get('users.get, 'users/[?id]', GetUserHandler::class));
$group->addRoute(RouteRecord::post(user.create, 'users', CreateUserHandler::class));
$group->setMiddleware([GuardMiddleware::class]) // set middleware for all routes in group
$group->setTokens(['id' => '[a-zA-Z]']) // set tokens for all routes in group
$group = $routes->group('api') // get routes group from name