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

Symfony Bundle Dependencies Laravel Package

mmoreram/symfony-bundle-dependencies

Symfony bundle to manage inter-bundle dependencies and load order. Define requirements between bundles and let the resolver ensure needed bundles are enabled and initialized first, helping avoid missing services and configuration issues in complex apps.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require mmoreram/symfony-bundle-dependencies
    

    Add the bundle to your config/bundles.php (Symfony) or config/app.php (Laravel via Symfony bridge):

    return [
        // ...
        Mmoreram\BundleDependenciesBundle\MmoreramBundleDependenciesBundle::class => ['all' => true],
    ];
    
  2. First Use Case: Define a dependency between two bundles in config/packages/mmoreram_bundle_dependencies.yaml:

    dependencies:
        Acme\Bundle1: [Acme\Bundle2]
    

    This ensures Bundle2 loads before Bundle1.

  3. Verify: Run php bin/console debug:container (Symfony) or check Laravel service container for bundle order.


Implementation Patterns

Workflows

  1. Bundle Ordering: Use config/packages/mmoreram_bundle_dependencies.yaml to enforce load order:

    dependencies:
        App\Bundle\Admin: [App\Bundle\Auth, App\Bundle\Security]
    
    • Ensures Auth and Security bundles are initialized before Admin.
  2. Conditional Dependencies: Leverage Symfony’s environment-aware configuration:

    dependencies:
        App\Bundle\Stripe: [App\Bundle\Payment]
        _env: [dev, staging]  # Only enforce in dev/staging
    
  3. Dynamic Dependencies (PHP): Override the dependency resolver in a custom compiler pass (Symfony):

    use Mmoreram\BundleDependenciesBundle\Dependency\DependencyResolverInterface;
    
    public function process(ContainerBuilder $container)
    {
        $resolver = $container->getDefinition('mmoreram_bundle_dependencies.resolver');
        $resolver->addMethodCall('addDynamicDependency', [
            'App\Bundle\Dynamic', ['App\Bundle\Config']
        ]);
    }
    
  4. Laravel Integration: Use the Symfony bridge to integrate with Laravel’s service provider ordering:

    // In a Laravel service provider
    $this->app->register(Mmoreram\BundleDependenciesBundle\MmoreramBundleDependenciesBundle::class);
    

Integration Tips

  • Composer Scripts: Add a post-autoload script to validate dependencies:
    {
        "scripts": {
            "post-autoload-cmd": [
                "@php bin/console mmoreram:bundle-dependencies:validate"
            ]
        }
    }
    
  • CI/CD: Fail builds if dependencies are violated:
    php bin/console mmoreram:bundle-dependencies:validate --fail
    

Gotchas and Tips

Pitfalls

  1. Circular Dependencies: The package detects and throws exceptions for circular dependencies. Example:

    dependencies:
        App\Bundle\A: [App\Bundle\B]
        App\Bundle\B: [App\Bundle\A]  # Throws: Circular dependency detected!
    
    • Fix: Refactor bundles to remove mutual dependencies or use interfaces.
  2. Lazy-Loaded Bundles: If bundles are lazy-loaded (e.g., via loadFromDirectory), dependencies may not be enforced until the bundle is explicitly loaded.

    • Fix: Use prepend: true in config/bundles.php for critical bundles.
  3. Namespace Conflicts: Ensure bundle namespaces in dependencies match the actual class names (e.g., Acme\Bundle1\Bundle vs. Acme\Bundle1).

  4. Symfony Flex Autoconfigure: If using Symfony Flex, the package may not auto-register. Manually add it to config/bundles.php.

Debugging

  • Validate Dependencies:

    php bin/console mmoreram:bundle-dependencies:validate --verbose
    

    Outputs a graph of dependencies and potential issues.

  • Check Load Order:

    php bin/console debug:container --parameter=kernel.bundles
    

    Verify the order matches expectations.

Tips

  1. Visualize Dependencies: Use Graphviz to visualize bundle relationships:

    php bin/console mmoreram:bundle-dependencies:graph > dependencies.dot
    dot -Tpng dependencies.dot -o dependencies.png
    
  2. Environment-Specific Rules: Override dependencies per environment:

    # config/packages/dev/mmoreram_bundle_dependencies.yaml
    dependencies:
        App\Bundle\DebugToolbar: [App\Bundle\Profiler]
    
  3. Extend the Resolver: Create a custom resolver for complex logic:

    namespace App\Dependency;
    
    use Mmoreram\BundleDependenciesBundle\Dependency\DependencyResolverInterface;
    
    class CustomResolver implements DependencyResolverInterface
    {
        public function resolve(array $dependencies): array
        {
            // Custom logic (e.g., skip optional bundles)
            return $dependencies;
        }
    }
    

    Register it in config/packages/mmoreram_bundle_dependencies.yaml:

    resolver_class: App\Dependency\CustomResolver
    
  4. Laravel Service Providers: For Laravel, treat bundles as service providers and order them in AppServiceProvider:

    public function register()
    {
        $this->app->register(\App\Providers\AuthServiceProvider::class);
        $this->app->register(\App\Providers\AdminServiceProvider::class);
        // Dependencies enforced via provider order
    }
    
  5. Performance: Cache the dependency graph in production:

    # config/packages/prod/mmoreram_bundle_dependencies.yaml
    cache_graph: true
    
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.
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
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope