objects

Router

Holds the routes a view registers for its page, plus before and after hooks.

Matches the sub-path below the page URL.

$router Phlat\Router 9 methods
Properties (3)
$router->routes array
$router->before array
$router->after array
Show
  • after Registers a hook to run after the matched route's handler resolves, before the result is returned.
  • any Handles requests of any method matching $pattern.
  • before Registers a hook to run before route dispatch, once all router files (app, ancestors, this page) have loaded.
  • clearRoutes Discards registered routes; hooks (before/after) are kept.
  • delete Handles DELETE requests matching $pattern.
  • get Handles GET requests matching $pattern below the page URL: `$page->router->get('post/{slug}', fn($slug) => ...)`.
  • patch Handles PATCH requests matching $pattern.
  • post Handles POST requests matching $pattern.
  • put Handles PUT requests matching $pattern.

Methods

$router->after(callable $hook): void

Registers a hook to run after the matched route's handler resolves, before the result is returned.

Parameters (1)
$hook callable
phlat/src/Router.php:68

any

$router->any(string $pattern, callable $handler): void

Handles requests of any method matching $pattern.

Parameters (2)
$pattern string
$handler callable
phlat/src/Router.php:56
$router->before(callable $hook): void

Registers a hook to run before route dispatch, once all router files (app, ancestors, this page) have loaded.

Parameters (1)
$hook callable
phlat/src/Router.php:62
$router->clearRoutes(): void

Discards registered routes; hooks (before/after) are kept.

phlat/src/Router.php:74
$router->delete(string $pattern, callable $handler): void

Handles DELETE requests matching $pattern.

Parameters (2)
$pattern string
$handler callable
phlat/src/Router.php:50

get

$router->get(string $pattern, callable $handler): void

Handles GET requests matching $pattern below the page URL: `$page->router->get('post/{slug}', fn($slug) => ...)`.

Parameters (2)
$pattern string
$handler callable
phlat/src/Router.php:26
$router->patch(string $pattern, callable $handler): void

Handles PATCH requests matching $pattern.

Parameters (2)
$pattern string
$handler callable
phlat/src/Router.php:38
$router->post(string $pattern, callable $handler): void

Handles POST requests matching $pattern.

Parameters (2)
$pattern string
$handler callable
phlat/src/Router.php:32

put

$router->put(string $pattern, callable $handler): void

Handles PUT requests matching $pattern.

Parameters (2)
$pattern string
$handler callable
phlat/src/Router.php:44