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

Composer installer plugin for Yii 2 extensions. Adds the yii2-extension package type, supports extension bootstrapping via extra.bootstrap, and provides post-create-project and post-install hooks for tasks like setting permissions and generating cookie validation keys.

View on GitHub
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor