yiisoft/yii2-composer
Yii2 Composer plugin that streamlines installing and updating Yii2 apps and extensions. It manages vendor assets, runs post-install/update tasks, and helps automate configuration so Yii2 projects integrate smoothly with Composer workflows.
Installation Add the package to your Laravel project via Composer:
composer require yiisoft/yii2-composer --dev
This package is primarily a Yii 2 Composer plugin, not a standalone Laravel package. Use it to manage Yii 2 dependencies in a Laravel project (e.g., for hybrid Yii/Laravel apps or legacy integration).
First Use Case
yiisoft/yii2, yiisoft/yii2-bootstrap) into Laravel, this plugin ensures proper autoloading and dependency resolution.composer require yiisoft/yii2:^2.0.0
composer.json includes the Yii 2 autoloader:
"autoload": {
"psr-4": {
"App\\": "app/",
"yiisoft\\yii2\\": "vendor/yiisoft/yii2"
}
}
Where to Look First
composer.json merges Yii 2 and Laravel autoloading correctly. Use composer dump-autoload after installation.Hybrid Yii/Laravel Projects
Yii2\ to avoid conflicts:
// app/Providers/Yii2ServiceProvider.php
use yii\base\Application as YiiApp;
class Yii2ServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton('yiisoft.yii2', fn() => new YiiApp(config('yiisoft')));
}
}
$yiiAuth = $this->app->make('yiisoft.yii2')->getAuthManager();
Dependency Management
composer require --dev yiisoft/yii2-debug:^2.0 yiisoft/yii2-gii:^2.0
composer.json:
"extra": {
"yiisoft/yii2": {
"aliases": {
"@yiisoft/yii2": "vendor/yiisoft/yii2"
}
}
}
Asset Pipeline
AssetManager in Laravel views:
use yii\web\AssetBundle;
$asset = new AssetBundle(['sourcePath' => resource_path('yiisoft/assets')]);
$asset->register($this);
config/ with Laravel’s config/yiisoft.php:
// config/yiisoft.php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => env('YII_DB_DSN'),
],
],
];
Yii::$app->on('yiisoft\yii2\Event::EVENT_NAME', function() {
event(new LaravelEvent());
});
Autoload Conflicts
composer.json:
"autoload": {
"psr-0": {
"yiisoft\\": "vendor/yiisoft/"
}
}
composer dump-autoload --optimize if classes aren’t found.Dependency Hell
composer why-not to check constraints:
composer why-not yiisoft/yii2:^2.0
"yiisoft/yii2": "2.0.38"
Service Provider Collisions
Application may override Laravel’s App class.composer.json:
"extra": {
"yiisoft/yii2": {
"namespace": "Yii2\\"
}
}
composer show -v yiisoft/yii2
Yii::debug('Event triggered', __METHOD__);
config_cache to debug merged configs:
php artisan config:clear && php artisan config:cache
"scripts": {
"post-install-cmd": [
"@yii2-composer post-install",
"php artisan optimize"
]
}
Route::get('yiisoft/{path}', function($path) {
return Yii::$app->runAction($path);
});
$this->app->instance('yiisoft.yii2', Mockery::mock('yii\base\Application'));
How can I help you explore Laravel packages today?