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

Multibundle Laravel Package

ashleydawson/multibundle

Group and register multiple dependent Symfony2 bundles as a single logical unit. Extend AbstractMultiBundle to declare required bundles, then call registerInto() in AppKernel to add the bundle and its dependencies in one step.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require ashleydawson/multibundle
    

    Add to config/app.php under providers (Laravel 5.x):

    'providers' => [
        // ...
        Ashleydawson\Multibundle\MultibundleServiceProvider::class,
    ],
    
  2. Basic Registration In a service provider (e.g., AppServiceProvider):

    use Ashleydawson\Multibundle\MultibundleManager;
    
    public function boot(MultibundleManager $manager)
    {
        $manager->register('my_bundle', function () {
            return new \MyBundle\MyBundle();
        });
    }
    
  3. First Use Case Load bundles dynamically in bootstrap/app.php (Laravel 8+):

    $app->register(\Ashleydawson\Multibundle\MultibundleServiceProvider::class);
    $app->make(\Ashleydawson\Multibundle\MultibundleManager::class)->load();
    

Implementation Patterns

Dynamic Bundle Loading

Workflow:

  1. Define bundles in config/multibundle.php:
    'bundles' => [
        'my_bundle' => [
            'class' => \MyBundle\MyBundle::class,
            'enabled' => env('MY_BUNDLE_ENABLED', false),
        ],
    ],
    
  2. Load conditionally in AppServiceProvider:
    public function register()
    {
        $manager = $this->app->make(MultibundleManager::class);
        $manager->load('my_bundle'); // Load single bundle
        // OR
        $manager->load(); // Load all enabled bundles
    }
    

Integration with Laravel’s Kernel

Override App\Http\Kernel to conditionally register bundles:

protected function registerBundles()
{
    $manager = app(MultibundleManager::class);
    $manager->load(['my_bundle', 'another_bundle']);
}

Dependency Injection

Inject MultibundleManager into controllers/services:

public function __construct(MultibundleManager $manager)
{
    $this->bundles = $manager->getLoadedBundles();
}

Gotchas and Tips

Pitfalls

  1. Circular Dependencies Avoid registering bundles that depend on each other. Use lazy loading:

    $manager->registerLazy('bundle_a', function () {
        return new \BundleA();
    });
    
  2. Namespace Collisions Ensure bundle namespaces are unique. Prefix with your vendor name (e.g., Vendor\BundleName).

  3. Configuration Overrides If bundles define their own config, merge them manually:

    $manager->load('bundle')->getConfig()->merge([
        'key' => 'override_value',
    ]);
    

Debugging

  • Check Loaded Bundles Dump loaded bundles in tinker:

    php artisan tinker
    >>> \Ashleydawson\Multibundle\Facades\Multibundle::getLoadedBundles();
    
  • Enable Debug Mode Set debug: true in config/multibundle.php to log bundle registration.

Extension Points

  1. Custom Bundle Resolvers Extend Ashleydawson\Multibundle\BundleResolverInterface for custom logic (e.g., database-backed bundles).

  2. Event Listeners Listen for bundle.registered and bundle.loaded events:

    $manager->register('bundle')->addListener('bundle.registered', function ($bundle) {
        // Post-registration logic
    });
    
  3. Environment-Specific Bundles Use env() in bundle registration:

    $manager->register('bundle', function () {
        return env('APP_ENV') === 'local' ? new \LocalBundle() : new \ProdBundle();
    });
    
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours