Download the PHP package waffle-commons/routing without Composer
On this page you can find all versions of the php package waffle-commons/routing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download waffle-commons/routing
More information about waffle-commons/routing
Files in waffle-commons/routing
Package routing
Short Description Attribute-driven routing for Waffle Commons: routes declared with #[Route] next to the controller, discovered at boot, and resolved through an AOT-compiled trie in O(depth).
License MIT
Informations about the package routing
Waffle Routing Component
Release:
0.1.0-beta6|CHANGELOG.md
Attribute-driven router. No YAML, no XML β routes live next to the controller code via the #[Route] attribute and are discovered by scanning the configured controller directory at boot time. The compiled route table is then cached.
π Beta-2 highlights β HTTP method correctness
- HTTP method filtering & route overloading.
#[Route(methods: ['GET', 'POST'])]constrains a route to specific verbs. Multiple controller actions may share one path provided their methods arrays don't intersect β e.g. aGETandPOSThandler for/articles. Method names are canonicalised (upper-case) and de-duplicated at discovery, so typos likemethods: ['get']are caught at boot, not at runtime. HEAD β GETfallback (RFC 7231 Β§4.3.2). A request with methodHEADmatches aGETroute automatically.OPTIONSauto-answer. WhenWaffle\Commons\Pipeline\CoreRoutingMiddlewareis wired with a PSR-17ResponseFactoryInterface, anOPTIONSrequest to a known path is answered with204 No Content+Allowheader β no controller dispatch required.- Deterministic
Allowheader. When raisingMethodNotAllowedException(HTTP405), the router merges declared methods, auto-augments withHEAD(ifGETis allowed) andOPTIONS, deduplicates, and alphabetically sorts the resulting list β e.g.Allow: GET, HEAD, OPTIONS, POST. The error renderer (waffle-commons/error-handler) copies this verbatim. #[Route]attribute relocation. The canonical attribute now lives atWaffle\Commons\Contracts\Routing\Attribute\Route(in thecontractspackage). The oldWaffle\Commons\Routing\Attribute\Routehas been removed βuse Waffle\Commons\Contracts\Routing\Attribute\Route;everywhere.- Worker-safe PCRE cache. PCRE patterns compiled from route templates are memoised in resident-worker memory and survive across requests for the worker's lifetime.
Beta-1 inheritance
- Priority routing & catch-all.
#[Route]takes anint $priority = 0. At boot the router sorts the compiled table by descending priority, so high-priority specific routes are tried before low-priority ones. Negative priorities (e.g.-1000) flag catch-all routes like/{path:.*}that should only match once every specific route has failed β the foundation for Strangler-Fig / API-gateway proxying. MatchedRouteDTO.matchRequest()returns a typedWaffle\Commons\Contracts\Routing\MatchedRoute(ornull) instead of a loose array.- Reflection cleanup. Discovery reads
#[Route]via nativeReflectionClass/ReflectionMethod::getAttributes()β the oldReflectionTraitwas removed in Beta-1.
π¦ Installation
π§± Surface
| Class | Role |
|---|---|
Waffle\Commons\Routing\Router |
RouterInterface implementation. Boots from a ContainerInterface, sorts the table by descending priority, and returns a ?MatchedRoute from matchRequest(). |
Waffle\Commons\Routing\RouteDiscoverer |
Walks the controller directory and builds a list<MatchedRoute> from each controller's #[Route] attributes. |
Waffle\Commons\Routing\ControllerFinder |
Filesystem traversal of *.php controller files. |
Waffle\Commons\Routing\RouteParser |
Builds a MatchedRoute from a Route attribute + native reflection metadata (ReflectionClass/ReflectionMethod). A method-level priority overrides the class-level default. |
Waffle\Commons\Contracts\Routing\Attribute\Route |
The #[Route(path, methods, name, arguments, priority)] attribute (defined in contracts). |
Waffle\Commons\Routing\Attribute\Argument |
The #[Argument(classType, paramName, required)] attribute for routes that auto-resolve container services. |
Waffle\Commons\Routing\Trait\RequestTrait |
Helpers for extracting routing data from a PSR-7 request (_controller, _route_params). |
π #[Route] attribute β exact signature
From Waffle\Commons\Contracts\Routing\Attribute\Route (the attribute lives in contracts, so every component reads the same definition):
Argument (from src/Attribute/Argument.php):
π Declaring routes on a controller
π Matching a request
null means no route matched β the kernel converts that into RouteNotFoundException (which the error handler renders as RFC 7807 404). Routes are evaluated in descending priority order, so a catch-all (priority: -1000) is only reached after every specific route has failed.
π HTTP method filtering
- Matching is case-insensitive; methods are upper-cased + de-duplicated at discovery.
- A
GETroute also answersHEAD(RFC 7231 Β§4.3.2). OPTIONSto a known path is auto-answered204+AllowwhenCoreRoutingMiddlewareis wired with a PSR-17 response factory.- A method mismatch throws
MethodNotAllowedException(405); itsAllowheader is merged across candidates, augmented (HEADifGET, alwaysOPTIONS), de-duplicated, and sorted β e.g.Allow: GET, HEAD, OPTIONS, POST.
π PHP 8.5 features used
#[Route],#[Argument]β PHP 8 attribute syntax with PHP 8.5 typed properties.finalclasses throughout.- Strongly-typed
MatchedRouteDTO return fromRouterInterface::matchRequest()(no loose arrays). - Native reflection (
ReflectionClass/ReflectionMethod::getAttributes()) to read#[Route]β the oldReflectionTraitwas removed in Beta-1.
π§ Architectural boundary (mago guard)
An active dependency perimeter is enforced on every CI run by vendor/bin/mago guard (bundled into composer mago; zero baselines). The rules live in mago.toml under [guard.perimeter] β a forbidden use statement fails the build, not a reviewer.
Production code under Waffle\Commons\Routing may depend only on:
Waffle\Commons\Routing\**β itselfWaffle\Commons\Contracts\**β the shared contracts package (where#[Route],MatchedRoute, andMethodNotAllowedExceptionnow live)Waffle\Commons\Utils\**β theClassParsercontroller-discovery helperPsr\**β PSR interfaces (PSR-7)@global+Psl\**β PHP core and the PHP Standard Library
Test code under WaffleTests\Commons\Routing is unrestricted (@all). Structural rules are guarded too: interfaces must be named *Interface, Exception\** classes must end in *Exception, and any Enum\** namespace may hold only enum declarations.
Contract-first, component-agnostic by construction: components compose through waffle-commons/contracts (plus the explicitly-permitted utils), never ad-hoc through one another.
π§ͺ Testing
π Documentation
Full guides live in the central DiΓ‘taxis documentation tree:
π License
MIT β see LICENSE.md.
All versions of routing with dependencies
waffle-commons/contracts Version self.version
waffle-commons/utils Version self.version
psr/http-message Version ^2.0