You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+153Lines changed: 153 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,159 @@ several routes including one with a variable.
81
81
If present, the extra element is merged into the parameters array
82
82
before it is passed to the routes closure.
83
83
84
+
## Attribute-Based Routing
85
+
86
+
Modern PHP 8+ attribute-based routing allows you to define routes directly on controller methods using PHP attributes, providing a modern alternative to YAML configuration files.
- **Co-location**: Routes live with controller logic
200
+
- **Type Safety**: IDE autocomplete and validation
201
+
- **Refactor-Friendly**: Routes update when controllers change
202
+
- **No Sync Issues**: Can't have orphaned routes
203
+
- **Modern Standard**: Used by Symfony, Laravel, ASP.NET, Spring Boot
204
+
- **Self-Documenting**: Route definition IS the documentation
205
+
206
+
### Performance
207
+
208
+
Route scanning uses PHP Reflection, which could be slow. For production:
209
+
210
+
1. Routes are scanned once during application initialization
211
+
2. The Router caches RouteMap objects in memory
212
+
3. No reflection happens during request handling
213
+
4. Future: Add route caching to file for zero-cost production routing
214
+
215
+
### Migration from YAML
216
+
217
+
**Before (YAML):**
218
+
```yaml
219
+
# routes.yaml
220
+
home:
221
+
method: GET
222
+
route: /
223
+
controller: App\Controllers\Home@index
224
+
```
225
+
226
+
**After (Attributes):**
227
+
```php
228
+
class Home
229
+
{
230
+
#[Get('/', name: 'home')]
231
+
public function index() { }
232
+
}
233
+
```
234
+
235
+
See `tests/unit/RouteScannerTest.php` for working examples of basic route definition, route groups with prefixes, filter composition, and multiple routes per method.
236
+
84
237
## Rate Limiting
85
238
86
239
The routing component includes a powerful rate limiting system with multiple storage backends and flexible configuration options.
0 commit comments