Waypoint

Lightweight PSR-15 PHP Router with Attribute Routing, Prefix-Trie Matching & Middleware Pipeline.

CI codecov PHPStan Level 9 Latest Stable Version PHP Version License

Get Started Русский View on GitHub


What is Waypoint?

Waypoint is a modern, lightweight PSR-15 compatible PHP router for PHP 8.4+. It combines attribute-based routing, a fast prefix-trie matching engine, and a PSR-15 middleware pipeline into a single, elegant package.

Key Highlights

  • PSR-15 compliant — implements RequestHandlerInterface, works with any PSR-7 / PSR-15 stack
  • Attribute-based routing — declare routes with PHP 8 #[Route] attributes directly on controllers
  • Fast prefix-trie matching — static segments resolved via O(1) hash-map lookups; dynamic segments tested only when necessary
  • Middleware pipeline — global and per-route PSR-15 middleware with FIFO execution
  • Route groups — shared path prefixes and middleware for related routes
  • Route caching — compile routes to a PHP file for OPcache-friendly production loading
  • Automatic dependency injection — route parameters, ServerRequestInterface, and container services injected into controller methods
  • URL generation — reverse routing from named routes and parameters
  • Route diagnostics — detect duplicate paths, duplicate names, and shadowed routes
  • Priority-based matching — control which route wins when patterns overlap

Quick Example

use AsceticSoft\Waypoint\Router;
use Nyholm\Psr7\ServerRequest;

$router = new Router($container); // any PSR-11 container

$router->get('/hello/{name}', function (string $name) use ($responseFactory) {
    $response = $responseFactory->createResponse();
    $response->getBody()->write("Hello, {$name}!");
    return $response;
});

$request  = new ServerRequest('GET', '/hello/world');
$response = $router->handle($request);

That’s it. A few lines to get a fully working router with parameter injection. No XML, no YAML, no boilerplate.


Why Waypoint?

Feature Waypoint Other routers
PSR-15 RequestHandlerInterface Yes Not always
PHP 8 #[Route] attributes Yes Some
Prefix-trie O(1) matching Yes Linear scan
Per-route middleware Yes Some
Route caching (OPcache) Yes Some
Auto dependency injection Yes Rare
Route diagnostics Yes No
Minimal dependencies PSR packages only Often many
PHPStan Level 9 Yes Varies

Requirements

  • PHP >= 8.4
  • ext-mbstring

Installation

composer require ascetic-soft/waypoint

Documentation

Getting Started

Installation, quick start, and basic usage in 5 minutes.

Routing

Route registration, parameters, groups, and attribute-based routing.

Middleware

Global and per-route PSR-15 middleware pipeline.

Advanced

Dependency injection, URL generation, route caching, and diagnostics.

API Reference

Complete reference for all public classes and methods.

Internals

Algorithms, data structures, and diagrams of the internal architecture.