class Router implements RequestHandlerInterface

Properties

static Router|null $instance

Methods

static Router
instance()

Get or create the singleton instance of the Router.

static 
start()

Start the router, build the dispatcher, and handle the request.

get(string $path, callable|string $handler)

Add a GET route.

post(string $path, callable|string $handler)

Add a POST route.

patch(string $path, callable|string $handler)

Add a PATCH route.

put(string $path, callable|string $handler)

Add a PUT route.

head(string $path, callable|string $handler)

Add a HEAD route.

delete(string $path, callable|string $handler)

Add a DELETE route.

Route
view(string $url, string $name, array $arguments = [])

Shortcut for a GET route that returns a view.

add(string|array $methods, string $path, callable|string $handler)

Add a route to the router.

static 
addCSRFException(string $exception)

Add a CSRF exception.

mixed
currentRoute()

Get the current route.

group(string $prefix, callable $callback)

Create a route group with a common prefix.

void
buildDispatcher()

Build the route dispatcher.

ResponseInterface
handle(ServerRequestInterface $request)

No description

__construct(array $parsed)

No description

Details

at line 40
static Router instance()

Get or create the singleton instance of the Router.

Return Value

Router

The singleton instance of the Router.

at line 50
static start()

Start the router, build the dispatcher, and handle the request.

at line 73
Route get(string $path, callable|string $handler)

Add a GET route.

Parameters

string $path

The route path.

callable|string $handler

The route handler.

Return Value

Route

The created route instance.

at line 84
Route post(string $path, callable|string $handler)

Add a POST route.

Parameters

string $path

The route path.

callable|string $handler

The route handler.

Return Value

Route

The created route instance.

at line 95
Route patch(string $path, callable|string $handler)

Add a PATCH route.

Parameters

string $path

The route path.

callable|string $handler

The route handler.

Return Value

Route

The created route instance.

at line 106
Route put(string $path, callable|string $handler)

Add a PUT route.

Parameters

string $path

The route path.

callable|string $handler

The route handler.

Return Value

Route

The created route instance.

at line 117
Route head(string $path, callable|string $handler)

Add a HEAD route.

Parameters

string $path

The route path.

callable|string $handler

The route handler.

Return Value

Route

The created route instance.

at line 128
Route delete(string $path, callable|string $handler)

Add a DELETE route.

Parameters

string $path

The route path.

callable|string $handler

The route handler.

Return Value

Route

The created route instance.

at line 140
Route view(string $url, string $name, array $arguments = [])

Shortcut for a GET route that returns a view.

Parameters

string $url

The URL of the route.

string $name

The name of the view.

array $arguments

Optional arguments to pass to the view.

Return Value

Route

The created route instance.

at line 154
Route add(string|array $methods, string $path, callable|string $handler)

Add a route to the router.

Parameters

string|array $methods

HTTP methods (e.g., GET, POST).

string $path

The route path.

callable|string $handler

The route handler.

Return Value

Route

The created route instance.

at line 169
static addCSRFException(string $exception)

Add a CSRF exception.

Parameters

string $exception

The exception to add.

at line 178
mixed currentRoute()

Get the current route.

Return Value

mixed

The current route.

at line 189
RouteGroup group(string $prefix, callable $callback)

Create a route group with a common prefix.

Parameters

string $prefix

The group prefix.

callable $callback

The callback to define group routes.

Return Value

RouteGroup

The created route group instance.

at line 208
void buildDispatcher()

Build the route dispatcher.

Return Value

void

at line 310
ResponseInterface handle(ServerRequestInterface $request)

No description

Parameters

ServerRequestInterface $request

Return Value

ResponseInterface

at line 303
__construct(array $parsed)

No description

Parameters

array $parsed