To get the route by name, use the following method:
$route = $router->getRoute('foo');To check the existence of a route by name, use the following method:
if ($router->hasRoute('foo')) {
// Some code...
}To get the requested route, use the following method:
use Sunrise\Http\Router\RouteInterface;
$route = $request->getAttribute(RouteInterface::class);To build the route, i.e., convert its syntax path to a URI path, use the following method:
$path = $router->buildRoute($route);To build a route with variables, use the following method:
// If the route is `/{foo}`, then the expected result is `/bar`.
$path = $router->buildRoute($route, ['foo' => 'bar']);To build the route in strict mode, use the following method:
// If the route is `/{foo<bar>}`, an error will occur
// because `baz` is an unexpected value for the route variable `foo`.
$path = $router->buildRoute($route, ['foo' => 'baz'], true);To run the route, use the following method:
$response = $router->runRoute($route, $request);