draw/dependency-injection
Add-ons for Symfony DependencyInjection to simplify integrating subcomponents into a main bundle. Provides Integration classes and traits to auto-register integrations, load enabled configuration, and prepend container configuration when components are installed.
symfony/dependency-injection or symfony/http-kernel). Laravel’s Service Container (Illuminate\Container\Container) is built on top of Symfony’s DI, so this package can integrate seamlessly with Laravel’s core DI mechanisms.IntegrationTrait, provideExtensionClasses()) promotes modular bundle integration, which aligns with Laravel’s service provider and package-based architecture. It could simplify the integration of third-party components or internal modules.config/ structure, reducing friction for teams familiar with Symfony’s DI configuration.ContainerBuilder, so the package’s core functionality (e.g., load(), prepend()) can be adapted with minimal effort. Key challenges:
register() and boot() methods in service providers map loosely to Symfony’s load() and prepend(). The package’s IntegrationTrait would need to be adapted to Laravel’s lifecycle (e.g., using ServiceProvider::register() for load() and boot() for prepend()).config() helper and mergeConfigFrom() would replace Symfony’s ConfigurationInterface. The package’s loadIntegrations() would need to parse Laravel’s config files (e.g., config/example_my_bundle.php) instead of YAML.spatie/laravel-package-tools) and modular service providers. Teams already using these patterns would see immediate value.ContainerBuilder and Extension interfaces, which Laravel abstracts away. Risks include:
prependIntegrations() modifies the container directly, which could conflict with Laravel’s container binding priorities or service provider sequencing.config/) differs from Symfony’s load() method. Misalignment could lead to configuration overrides or missing values.registerDefaultIntegrations() method dynamically instantiates classes, which could introduce runtime overhead if misused.IntegrationTrait be mapped to Laravel’s ServiceProvider lifecycle (e.g., register() vs. boot())?ConfigurationInterface be replaced with Laravel’s Arrayable or a custom config resolver?config/ files be parsed to enable/disable integrations (e.g., enabled: true in YAML)?registerDefaultIntegrations() pose security risks (e.g., arbitrary class loading)?php artisan config:cache)?Illuminate\Container\Container, which is Symfony DI-compatible.IntegrationTrait can be adapted to Laravel’s ServiceProvider class, with provideExtensionClasses() mapping to a getSubcomponentProviders() method.ConfigurationInterface with Laravel’s config() system or a custom IntegrationConfig class.symfony/http-kernel), the package can integrate natively. Otherwise, a lightweight adapter layer would bridge Symfony’s ContainerBuilder to Laravel’s container.spatie/laravel-permission with multiple modules).IntegrationTrait:
use Draw\Component\DependencyInjection\IntegrationTrait;
class MyPackageServiceProvider extends ServiceProvider
{
use IntegrationTrait; // Hypothetical adapter
public function register()
{
$this->registerDefaultIntegrations();
$this->loadIntegrations(config('my_package'), $this->app);
}
protected function provideExtensionClasses(): array
{
return [
MySubcomponentIntegration::class,
];
}
}
ContainerBuilder methods (e.g., prependIntegrations() → app->prependTo()).public function prependIntegrations(Container $container, string $bundleName): void
{
foreach ($this->integrations as $integration) {
if ($integration->isEnabled()) {
$container->prependTo($bundleName, $integration->getPrependBindings());
}
}
}
config/my_package.php:
return [
'my_component' => [
'enabled' => true,
'my_component_configuration' => true,
],
];
mergeConfigFrom() to load subcomponent configs dynamically.laravel/fortify, spatie/laravel-medialibrary). Use priority tags or service provider sequencing to mitigate.config/app.php:
'providers' => [
// ...
MyPackageServiceProvider::class,
MySubcomponentServiceProvider::class,
],
when() or needs() methods to resolve dependencies in the correct order.prependIntegrations(), ensure bindings are added before Laravel’s default bindings (e.g., using app->prependTo()).loadIntegrations() in register() (for eager loading) and prependIntegrations() in boot() (for late binding).replace or platform constraints to avoid version conflicts.composer.json:
"require": {
"symfony/dependency-injection": "^6.0",
"draw/dependency-injection": "^1.0"
},
"conflict": {
"symfony/dependency-injection": "The package requires Symfony DI v6+"
}
enabled: true) must be version-controlled to avoid runtime failures. Use Laravel’s config:publish to expose configs to users.ContainerBuilder API shiftsHow can I help you explore Laravel packages today?