Download the PHP package tandrezone/zroute without Composer
On this page you can find all versions of the php package tandrezone/zroute. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package zroute
zRoute
A simple, lightweight PHP routing system available as a Composer package.
Features
- Static routes –
/about,/contact,/api/v1/status - Dynamic routes –
/products/$product-slug,/users/$id,/users/{id}/posts/{postId} - Dual parameter syntax – legacy
$paramor curly-brace{param}(both fully supported) - Per-parameter regex constraints – e.g.
{id}constrained to[0-9]+ - Array-based route loading – define routes as plain PHP arrays via
loadFromArray()/loadFromFile() - Named routes – look up any registered route by its logical name
- Middleware pipeline – sequential PSR-like middleware execution before the handler
- Parameter validation – type-casting, required/optional checks, default values, structured arrays
- Config-driven paths – resolve paths from a config array at load time (
config[namespace.key]) - All common HTTP methods:
GET,POST,PUT,PATCH,DELETE, andany() - Fluent (chainable) API
- Customisable 404 (Not Found) and 405 (Method Not Allowed) handlers
- Path normalisation: trailing slashes, query strings, and dot-segments (
.,..) are handled automatically
Requirements
- PHP 8.0 or higher
Installation
Quick Start
Route Syntax
Dynamic segments start with $ (legacy) or are wrapped in { } (recommended for array definitions).
The parameter name may contain letters, digits, underscores _, and hyphens -.
| Pattern | Example URL | Extracted params |
|---|---|---|
/about |
/about |
[] |
/users/$id |
/users/42 |
['id' => '42'] |
/users/{id} |
/users/42 |
['id' => '42'] |
/products/$product-slug |
/products/red-sneakers |
['product-slug' => 'red-sneakers'] |
/users/{userId}/posts/{postId} |
/users/7/posts/99 |
['userId' => '7', 'postId' => '99'] |
Dynamic segments match one path segment only (they never cross a /).
Array-Based Route Loading
Define routes as a PHP array and load them all at once. This enables separation of route definitions from bootstrap code and is the recommended approach for Composer packages.
Route Definition Schema
Loading from an Array
Loading from a File
The file must return a PHP array of route definitions:
Config-Driven Paths
A path like config[namespace.key] is resolved against a $config array supplied at load time:
Middleware
Each middleware class must implement zRoute\Contracts\MiddlewareInterface:
Middleware declared first in the array wraps middleware declared later (standard onion model).
Parameter Validation
Route parameters are validated and type-cast automatically when a parameters block is present.
The validated, typed values are available on the Request object passed to the controller.
Supported types: string, integer, float, boolean, array.
A zRoute\Exceptions\ValidationException is thrown if validation fails. Catch it in your
error handler to return a structured HTTP 422 response.
Request Object
Controllers loaded via loadFromArray() / loadFromFile() receive a zRoute\Request instance:
API Reference
Registering routes (fluent API)
Array-based loading
Named routes
Error handlers
Dispatching
Full Example
See examples/index.php for the classic fluent API and
examples/routes.php for a complete array-definition example.
Web Server Configuration
Apache (.htaccess)
Nginx
Running the Tests
License
MIT