Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Yii2 Composer Laravel Package

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.

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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).

  2. First Use Case

    • If you’re integrating Yii 2 components (e.g., yiisoft/yii2, yiisoft/yii2-bootstrap) into Laravel, this plugin ensures proper autoloading and dependency resolution.
    • Example: Install a Yii 2 package while maintaining Laravel’s PSR-4 autoloading:
      composer require yiisoft/yii2:^2.0.0
      
    • Verify the composer.json includes the Yii 2 autoloader:
      "autoload": {
          "psr-4": {
              "App\\": "app/",
              "yiisoft\\yii2\\": "vendor/yiisoft/yii2"
          }
      }
      
  3. Where to Look First

    • Plugin Docs: Yii 2 Composer Plugin (check for Laravel-specific quirks).
    • Laravel Compatibility: Ensure your composer.json merges Yii 2 and Laravel autoloading correctly. Use composer dump-autoload after installation.

Implementation Patterns

Workflow Integration

  1. Hybrid Yii/Laravel Projects

    • Namespace Isolation: Prefix Yii 2 classes with 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')));
          }
      }
      
    • Service Container Bridging: Use Laravel’s container to instantiate Yii 2 components:
      $yiiAuth = $this->app->make('yiisoft.yii2')->getAuthManager();
      
  2. Dependency Management

    • Grouped Installations: Install Yii 2 dev dependencies separately:
      composer require --dev yiisoft/yii2-debug:^2.0 yiisoft/yii2-gii:^2.0
      
    • Aliasing: Override Yii 2 paths in composer.json:
      "extra": {
          "yiisoft/yii2": {
              "aliases": {
                  "@yiisoft/yii2": "vendor/yiisoft/yii2"
              }
          }
      }
      
  3. Asset Pipeline

    • Asset Bundles: Use Yii 2’s AssetManager in Laravel views:
      use yii\web\AssetBundle;
      $asset = new AssetBundle(['sourcePath' => resource_path('yiisoft/assets')]);
      $asset->register($this);
      

Common Patterns

  • Configuration Merging: Combine Yii 2’s config/ with Laravel’s config/yiisoft.php:
    // config/yiisoft.php
    return [
        'components' => [
            'db' => [
                'class' => 'yii\db\Connection',
                'dsn' => env('YII_DB_DSN'),
            ],
        ],
    ];
    
  • Event Handling: Bind Yii 2 events to Laravel’s event system:
    Yii::$app->on('yiisoft\yii2\Event::EVENT_NAME', function() {
        event(new LaravelEvent());
    });
    

Gotchas and Tips

Pitfalls

  1. Autoload Conflicts

    • Issue: Yii 2’s PSR-0 autoloading may clash with Laravel’s PSR-4.
    • Fix: Explicitly define Yii 2 namespaces in composer.json:
      "autoload": {
          "psr-0": {
              "yiisoft\\": "vendor/yiisoft/"
          }
      }
      
    • Debug: Run composer dump-autoload --optimize if classes aren’t found.
  2. Dependency Hell

    • Issue: Yii 2 packages may pull in PHP 5.6+ dependencies incompatible with Laravel’s PHP 8.x.
    • Fix: Use composer why-not to check constraints:
      composer why-not yiisoft/yii2:^2.0
      
    • Workaround: Pin versions strictly:
      "yiisoft/yii2": "2.0.38"
      
  3. Service Provider Collisions

    • Issue: Yii 2’s Application may override Laravel’s App class.
    • Fix: Rename Yii 2’s namespace in composer.json:
      "extra": {
          "yiisoft/yii2": {
              "namespace": "Yii2\\"
          }
      }
      

Debugging Tips

  • Class Not Found: Verify the autoloader with:
    composer show -v yiisoft/yii2
    
  • Event Firing: Check Yii 2’s event system logs:
    Yii::debug('Event triggered', __METHOD__);
    
  • Configuration Overrides: Use Laravel’s config_cache to debug merged configs:
    php artisan config:clear && php artisan config:cache
    

Extension Points

  1. Custom Composer Plugins Extend the Yii 2 plugin to add Laravel-specific scripts:
    "scripts": {
        "post-install-cmd": [
            "@yii2-composer post-install",
            "php artisan optimize"
        ]
    }
    
  2. Hybrid Routing Use Laravel’s router to proxy to Yii 2 controllers:
    Route::get('yiisoft/{path}', function($path) {
        return Yii::$app->runAction($path);
    });
    
  3. Testing Mock Yii 2 dependencies in Laravel tests:
    $this->app->instance('yiisoft.yii2', Mockery::mock('yii\base\Application'));
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests