yiisoft/di
PSR-11 compatible dependency injection container for PHP 8.1+. Supports autowiring plus constructor, method and property injection, aliasing, service providers, delegated/composite containers, circular reference detection, and state reset for long-running workers.
Illuminate/Container). Reduces friction in adoption.['class' => MyService::class, 'params' => [...]]), which may require adaptation for Laravel’s more fluent syntax (e.g., app()->bind()).AppServiceProvider or bind() methods can register Yii DI definitions. Example:
$container->set('my.service', ['class' => MyService::class, 'params' => [...]]);
ResolverInterface.config/cache and view/compiled systems if configured to serialize definitions.set(), get(), and offsetGet(), while Laravel’s container uses bind(), resolve(), etc. Aliasing or wrapper classes may be needed.bind('foo', fn() => new Bar())). Hybrid approaches (e.g., converting Yii configs to Laravel bindings) could introduce complexity.yiisoft/yii-di). Isolating to just yiisoft/di mitigates this but requires manual dependency management.telescope, horizon, or sail interact with Yii’s container?Illuminate/Container as a drop-in replacement for the underlying implementation.composer require yiisoft/di with no global namespace conflicts.MockApplication).// app/Providers/AppServiceProvider.php
public function register()
{
$yiisoftDi = new \Yiisoft\Di\Container();
$yiisoftDi->set('custom.service', ['class' => CustomService::class]);
// Register Yii container as a Laravel binding
$this->app->instance('yiisoft.di', $yiisoftDi);
$this->app->bind('custom.service', fn($app) => $app['yiisoft.di']->get('custom.service'));
}
Container class to delegate to Yii’s container:
class YiiContainer extends Illuminate\Container\Container
{
protected $yiisoftDi;
public function __construct(Yiisoft\Di\Container $yiisoftDi)
{
$this->yiisoftDi = $yiisoftDi;
}
public function bind($abstract, $concrete = null)
{
$this->yiisoftDi->set($abstract, $concrete);
}
public function resolve($abstract = null)
{
return $this->yiisoftDi->get($abstract);
}
}
bootstrap/app.php:
$app = new Application(
new Yiisoft\Di\Container(),
new YiiContainer($container)
);
Facade::getFacadeRoot()).bind() calls with Yii’s set() or adapt to closures.Illuminate/Contracts/Container will work if the underlying container is swapped.Psr\Container\ContainerInterface will work without changes.php artisan container:analyze (or custom scripts) to map Laravel’s bindings to Yii’s format.Config class for managing definitions, which could be adapted for Laravel’s config/di.php.config/cache to store definitions in memory.| Scenario | Risk | Mitigation | |
How can I help you explore Laravel packages today?