Download the PHP package fatjon-lleshi/antares-router without Composer
On this page you can find all versions of the php package fatjon-lleshi/antares-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fatjon-lleshi/antares-router
More information about fatjon-lleshi/antares-router
Files in fatjon-lleshi/antares-router
Package antares-router
Short Description Lightweight attribute-based router for PHP 8.2+
License MIT
Homepage https://github.com/johnlesis/antares-router
Informations about the package antares-router
antares-router
Lightweight attribute-based router for PHP 8.2+. Built on top of nikic/fast-route. Can be used standalone or as part of the Antares framework.
Installation
Standalone Usage
Example Project Structure
Defining Routes
Define routes directly on controller methods using PHP attributes:
Registering Routes
Create a routes.php file that registers all your controllers:
Bootstrapping
In public/index.php, create the router, load the routes file, and dispatch the request:
Route Parameters
Parameters in the path are extracted and returned as an array:
Custom Status Codes
Pass a status code as the second argument to any route attribute. Defaults to 200:
Array Config
Register routes from a plain array if you prefer config-based routing instead of attributes:
YAML Config
Register routes from a YAML file. Requires symfony/yaml:
Route Caching
Cache compiled routes for production to avoid reflection overhead on every request:
Error Handling
match() throws a RuntimeException when a route is not found or the method is not allowed:
Available Attributes
| Attribute | HTTP Method |
|---|---|
#[Get] |
GET |
#[Post] |
POST |
#[Put] |
PUT |
#[Patch] |
PATCH |
#[Delete] |
DELETE |
Requirements
- PHP 8.2+
- nikic/fast-route ^1.3
License
MIT