jms/object-routing
jms/object-routing is a PHP library for routing based on object state rather than URLs. Define routes and generate targets by evaluating objects and their metadata, enabling flexible navigation and link generation in domain-driven apps.
User, Product) rather than static strings. This reduces coupling between controllers and routes, improving maintainability in large applications.GET /users/{id} → GET /users/123). However, may introduce complexity for non-RESTful or highly conventional routing schemes.Route::get('/home', 'HomeController')).RouteServiceProvider or middleware).User@id=1 vs. Product@id=1).ObjectRouter for Eloquent models).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Deprecated PHP | High | Fork or polyfill for PHP 8.x (e.g., str_contains → str_contains()). |
| No Laravel Support | Medium | Wrap in a Laravel service provider/facade. |
| Route Conflict Risk | Medium | Implement priority rules or middleware validation. |
| Testing Complexity | Medium | Use Laravel’s Route::assertGenerated() or custom assertions. |
| Performance | Low | Minimal overhead; cache route mappings if needed. |
User@id=1 vs. Product@id=1) be resolved?array_merge behavior, deprecated functions).Http::fake() or PestPHP for route assertions.User resource).| Component | Compatibility Notes |
|---|---|
| Laravel Router | Works but requires manual registration (no built-in integration). |
| Eloquent | Needs adapter layer (e.g., custom ObjectRouter for Eloquent models). |
| Doctrine | Native support (original use case). |
| PHP 8.x | May require polyfills for deprecated functions (e.g., str_contains). |
| Route Caching | Object-based routes bypass Laravel’s cache; may need custom caching logic. |
RouteServiceProvider.User).Product, Order).Route::get('/users/{id}')).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Route Conflict | 404/500 errors for ambiguous paths. | Implement priority rules or middleware validation. |
| Object Not Found | Broken links or 404s. | Add middleware to validate objects. |
| PHP Version Incompatibility | Runtime errors. | Use polyfills or fork the package. |
| Route Caching Issues | Stale routes in production. | Implement custom caching layer. |
| ORM Mismatch | Routes fail for Eloquent models. | Create adapter layer for Eloquent. |
How can I help you explore Laravel packages today?