1. Go to this page and download the library: Download istok/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/ */
istok / router example snippets
use Istok\Router\Router;
use Istok\Router\Route;
use Istok\Router\Http\HttpTemplate;
use Istok\Router\Http\HttpRequest;
// define single router entry
$route = new Route(
// provide template interface
new HttpTemplate('/post/{id}/show', 'GET', '{user}.example.com'),
// provide handler
fn($id, $user) => print "User: $user, id: $id"
);
// setup router, add our single route
$router = new Router($route);
// special http-oriented implementation of Request interface
$request = new HttpRequest('/post/abc/show', 'GET', 'user1.example.com');
// match route to request
$result = $router->find($request);
// execute result,
// $result->arguments contains ['user' => 'user1', 'id' => 'abc']
($result->route->handler)(...$result->arguments); // User: user1, id: abc
$template = new HttpTemplate('/post/{url*}'),
$template = new HttpTemplate('/', host: '{subdomain*}.example.com'),
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.