Routing
PathHandler provides several neat improvements for standard Mezzio routing registration routine.
Route path prefixes
You can easily add common path prefix for a group of handlers via router factory configuration:
It is useful for prefixes that do not affect handler behaviour, for example API version number.
Route path declaration
Each handler should have at least one path declaration. Each path declaration may have default values for parameters that will be available after matching and unique name to simplify URI generation. You may declare several paths for single handler. Corresponding routes will be registered in the order they appear in annotations or based on their priority. Check Articus\PathHandler\PhpAttribute\Route
for details.
Path pattern syntax depends on router you choose. Default one is Articus\PathHandler\Router\FastRoute
based on FastRoute. You can switch to your favourite router implementation via router factory configuration:
Route HTTP method declaration
Each handler should have at least one class method with HTTP method declaration. There are "shortcuts" for GET, POST, PUT, PATCH and DELETE. Any other HTTP method can be declared with generic Articus\PathHandler\PhpAttribute\HttpMethod
PHP attribute. Class method may have several HTTP method declarations. You may even create two handlers with same path but mark their class methods to handle different HTTP methods.