handcraftedinthealps/rest-routing-bundle
Symfony bundle that restores FOSRestBundle-style automatic REST route generation. Supports format options and method/name prefixing, and includes a command to dump/convert type: rest routes into standard Symfony routes for migration or opt-out.
@RouteResource, @Prefix, etc.).Key Fit for Laravel/PHP Ecosystem:
symfony/http-foundation).AnnotationReader and Routing components—common in Laravel’s service containers.FOS\RestBundle\Routing\ClassResourceInterface with the bundle’s equivalent.@RouteResource, @Prefix, etc.) to the new namespace.php artisan route:cache) may need adjustment if routes are dynamically generated.Illuminate\Container vs. Symfony’s DependencyInjection require explicit binding (e.g., via AppServiceProvider).Technical Risks:
RouteServiceProvider vs. Symfony’s AnnotationLoader.
Route::getRoutes() to merge routes post-load.ViewHandler) or only routing?Route facade and apiResource() helpers?symfony/routing, symfony/http-kernel) or migrating from FOSRestBundle.apiResource() + manual routes (less flexible for complex REST APIs).| Step | Action | Tools/Commands |
|---|---|---|
| 1 | Assess Dependency Graph | composer why-not handcraftedinthealps/rest-routing-bundle |
| 2 | Replace Annotations | Update use statements (see README diff example). |
| 3 | Update Config | Replace fos_rest.routing_loader with handcraftedinthealps_rest_routing. |
| 4 | Test Route Generation | php artisan route:list (Laravel) or bin/console debug:router (Symfony). |
| 5 | Opt-Out (If Needed) | bin/console fos:rest:routing:dump-symfony-routes → paste into routes/api.php. |
| 6 | Benchmark | Compare route load times with/without the bundle. |
Laravel-Specific Steps:
config/app.php under extra.bundles.AnnotationReader in AppServiceProvider to avoid conflicts:
public function register()
{
$this->app->singleton(\Symfony\Component\DependencyInjection\Loader\AnnotationReader::class);
}
| Component | Compatibility | Notes |
|---|---|---|
| Symfony 6/7/8 | ✅ Full | Tested in CI. |
| PHP 8.1–8.4 | ✅ Full | PHP 8.4 deprecations fixed in v1.1.2. |
| Laravel 9/10 | ⚠️ Partial | Requires Symfony components; may conflict with Laravel’s Route facade. |
| FOSRestBundle 3.0 | ✅ Drop-in | Identical config structure. |
| Doctrine Annotations | ✅ | Uses doctrine/annotations v1.4+. |
Breaking Changes:
FOS\RestBundle namespace imports allowed (must use HandcraftedInTheAlps\RestRoutingBundle).@Prefix("/api") are preserved but must match Symfony’s conventions./admin routes).route:list.dump-symfony-routes to convert to manual routes/api.php definitions.Rollback Plan:
routes/api.php or use Git to revert annotations.doctrine/annotations if Laravel’s version drifts.bin/console debug:router to inspect generated routes.EventDispatcher logs for route loading errors.Routing component docs.symfony-routing, laravel-symfony.route:cache will cache generated routes (mitigates overhead).AnnotationReader).opcache + Laravel’s route cache.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Annotation parsing errors | Routes fail to load → 500 errors. | Validate annotations with php artisan route:list. |
| Symfony DI conflicts | Laravel’s container rejects Symfony services. | Explicitly bind AnnotationReader in AppServiceProvider. |
| Route name collisions | Duplicate routes (e.g., /api/users from two controllers). |
Use @NamePrefix to scope routes. |
| PHP 8.4 deprecations | Nullable object warnings. | Upgrade to v1.1.2+. |
| Laravel cache corruption | route:cache fails |
How can I help you explore Laravel packages today?