Pros:
@Inject, @Service, @Param) for services, parameters, and tags.services.php/config/di.xml by externalizing DI logic to annotations, improving developer ergonomics and code readability.symfony/di or laravel/framework).Cons:
Illuminate\Container) is service-provider-first, not annotation-driven. This bundle is Symfony-centric and may require adapters or workarounds for Laravel.ContainerBuilder under the hood, which Laravel abstracts away.jms/di-extra-bundle's core classes, bypassing the Symfony bundle layer.ReflectionClass) and manually registering services in ServiceProvider::register().Container extension to support annotations (high effort, low maintainability).services.php boilerplate, or is there a legacy Symfony codebase to migrate?#Injectable) or macroable containers achieve the same with lower risk?php-di/php-di (annotation support) or symfony/dependency-injection (modern)?| Component | Fit Level | Notes |
|---|---|---|
| Laravel 10+ | ❌ Poor | No native support; annotations conflict with Laravel’s DI philosophy. |
| Symfony 5/6 | ✅ Good | Designed for Symfony; works with ContainerBuilder. |
| Lumen | ⚠️ Medium | Possible with Symfony bridge, but outdated. |
| Plain PHP | ✅ Good | Core DI logic can be used standalone (without Symfony bundle). |
| Legacy Apps | ✅ Good | Useful for migrating Symfony2-style annotations to modern DI. |
Assess Scope:
services.php, bind() calls) to identify annotation migration candidates.Laravel-Specific Workarounds:
ServiceProvider:
// app/Providers/AppServiceProvider.php
public function register()
{
$services = AnnotationParser::parseServices(app_path('Services'));
foreach ($services as $service) {
$this->app->singleton($service['id'], $service['class']);
}
}
doctrine/annotations or phpDocumentor/reflection to parse annotations.#[Injectable]
class MyService {}
laravel/framework’s native attribute support.Symfony/Lumen Path:
composer require jms/di-extra-bundle
config/bundles.php (Symfony) or manually bootstrap (Lumen).services.xml/services.yml to annotations incrementally.Fallback Plan:
bind()/singleton().php-di/php-di (annotation support via AnnotationReader).| Feature | Compatibility | Notes |
|---|---|---|
| PHP 8.1+ | ❌ No | Deprecated ReflectionProperty::getDefaultValue() behavior. |
| Laravel 10+ | ❌ No | No attribute/annotation integration. |
| Symfony 6+ | ⚠️ Partial | Some DI XML features deprecated; may need polyfills. |
| PSR-11 Container | ✅ Yes | Core DI logic adheres to PSR-11. |
| Tagged Services | ✅ Yes | Works if Symfony’s ContainerBuilder is available. |
Phase 1: Proof of Concept (2-4 weeks)
Phase 2: Incremental Migration (4-8 weeks)
phpstan rules).Phase 3: Full Adoption (8+ weeks)
bind() calls with annotations (if justified).Phase 4: Maintenance Plan
services.php bloat: Easier to manage as codebase grows.@Inject working?").jms/di-extra-bundle’s lifecycle (last release in 2018).bind()).How can I help you explore Laravel packages today?