PHPackages                             debuss-a/attribute-routing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. debuss-a/attribute-routing

ActiveLibrary[API Development](/categories/api)

debuss-a/attribute-routing
==========================

Framework-agnostic route loader that discovers routes from PHP attributes and returns router-ready RouteDefinition objects.

1.1.0(1mo ago)0141MITPHPPHP ^8.3

Since Apr 10Pushed 1mo agoCompare

[ Source](https://github.com/debuss/attribute-routing)[ Packagist](https://packagist.org/packages/debuss-a/attribute-routing)[ RSS](/packages/debuss-a-attribute-routing/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)DependenciesVersions (4)Used By (1)

Attribute Routing
=================

[](#attribute-routing)

A framework-agnostic PHP library that discovers and loads route definitions from PHP 8 attributes.
It scans your controller classes, reads `#[Controller]` / `#[ApiController]` and HTTP-method attributes, and returns plain `RouteDefinition` objects that you can feed into any router (FastRoute, Aura Router, Symfony Router, …).

---

Requirements
------------

[](#requirements)

- PHP **8.3+**

---

Installation
------------

[](#installation)

```
composer require debuss-a/attribute-routing
```

---

Concepts
--------

[](#concepts)

Class / AttributeTargetDescription`#[Controller(prefix: '')]`ClassMarks a class as a controller. An optional `prefix` is prepended to every route path defined in the class.`#[BaseController(prefix: '')]`ClassAlias of `#[Controller]`, dedicated to base controllers.`#[ApiController(prefix: '')]`ClassAlias of `#[Controller]`, dedicated to API controllers.`#[HttpGet(path, name?, priority?)]`MethodMaps the method to `GET` requests.`#[HttpPost(path, name?, priority?)]`MethodMaps the method to `POST` requests.`#[HttpPut(path, name?, priority?)]`MethodMaps the method to `PUT` requests.`#[HttpPatch(path, name?, priority?)]`MethodMaps the method to `PATCH` requests.`#[HttpDelete(path, name?, priority?)]`MethodMaps the method to `DELETE` requests.`#[HttpHead(path, name?, priority?)]`MethodMaps the method to `HEAD` requests.`#[HttpOptions(path, name?, priority?)]`MethodMaps the method to `OPTIONS` requests.`AttributeRouteLoader`—Scans a directory for controllers and returns `RouteDefinition[]`.`RouteDefinition`—Value object holding `methods`, `path`, `handler`, `name`, and `priority`.---

Usage
-----

[](#usage)

### 1. Annotate your controllers

[](#1-annotate-your-controllers)

```
