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

Di Debugger Bundle Laravel Package

cypresslab/di-debugger-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Add the bundle to your Laravel project via Composer (note: this is a Symfony2 bundle, but can be adapted for Laravel via Bridge or manually):

    composer require cypresslab/di-debugger-bundle
    

    Register the bundle in config/app.php under providers (if using Laravel 5.5+ with auto-discovery, this may not be needed).

  2. First Use Case Run the debug command to inspect your service container:

    php artisan di:debug
    

    This will output a structured overview of all registered services, their bindings, and dependencies.

  3. Where to Look First

    • Check the config/di_debugger.php (if auto-generated) for configuration options.
    • Review the vendor/cypresslab/di-debugger-bundle/README.md for Symfony-specific setup (adapt as needed for Laravel).
    • Use the --format flag to customize output (e.g., --format=json for machine-readable logs).

Implementation Patterns

Usage Patterns

  1. Dependency Inspection Use the bundle to validate service bindings before runtime:

    php artisan di:debug --service=App\Services\UserService
    

    This helps identify circular dependencies or missing services early.

  2. Integration with Laravel’s Service Container Manually trigger the debugger in custom commands or middleware:

    use Cypresslab\DiDebuggerBundle\Debugger\Debugger;
    
    public function handle()
    {
        $debugger = new Debugger($this->app->getContainer());
        $debugger->debug();
    }
    
  3. Workflow: Debugging a Failed Service

    • Run php artisan di:debug --service=FailedService.
    • Check for:
      • Missing interfaces/abstract classes.
      • Incorrect binding priorities (e.g., singleton vs instance).
      • Unresolvable constructor arguments.
  4. Automated Testing Integrate the debugger into CI pipelines to fail builds on misconfigured services:

    php artisan di:debug --fail-on-error
    

Integration Tips

  • Laravel-Specific Adaptations: Replace Symfony’s ContainerInterface with Laravel’s Illuminate\Container\Container in the debugger’s constructor. Example override:

    $debugger = new Debugger(app());
    
  • Custom Output Formats: Extend the bundle’s Debugger class to add Laravel-specific formats (e.g., TAP for testing frameworks):

    $debugger->setOutputFormat(new LaravelTapFormatter());
    
  • Excluding Services: Use the --exclude flag to ignore third-party services (e.g., vendor/*):

    php artisan di:debug --exclude="vendor/laravel/framework"
    

Gotchas and Tips

Pitfalls

  1. Symfony vs. Laravel Incompatibilities

    • The bundle assumes Symfony’s ContainerInterface. Laravel’s container extends Illuminate\Container\Container, which may cause:
      • Method signature mismatches (e.g., has() vs bound()).
      • Fix: Patch the debugger or use a wrapper class.
    • Example patch:
      // In a custom Debugger class:
      public function has($id)
      {
          return $this->container->bound($id);
      }
      
  2. Performance Overhead

    • Debugging the entire container can be slow for large applications.
    • Tip: Use --service to target specific services or limit scope with --exclude.
  3. False Positives

    • The bundle may flag Laravel’s internal services (e.g., Illuminate\Contracts\Console\Kernel) as "unresolvable" if not explicitly bound.
    • Tip: Whitelist core services in config:
      'ignored_services' => [
          'Illuminate\Contracts\Console\Kernel',
          'Illuminate\Contracts\Http\Kernel',
      ],
      
  4. Dynamic Bindings

    • Services bound dynamically (e.g., via app()->bindWhen()) may not appear in static output.
    • Tip: Run the debugger after all dynamic bindings are registered (e.g., in boot() methods).

Debugging Tips

  • Verbose Mode: Use --verbose to see raw container internals, including:

    php artisan di:debug --verbose --service=App\Services\*
    
  • JSON Output for Scripting: Pipe output to jq for programmatic analysis:

    php artisan di:debug --format=json | jq '.services["App\\Services\\UserService"]'
    
  • Extension Points: Override the Debugger class to add Laravel-specific checks:

    class LaravelDebugger extends \Cypresslab\DiDebuggerBundle\Debugger
    {
        public function checkForLaravelIssues()
        {
            if (!$this->container->bound('app')) {
                throw new \RuntimeException('Laravel container not initialized!');
            }
        }
    }
    

Configuration Quirks

  • Missing di_debugger.php: The bundle may not auto-generate a config file. Manually create it in config/:

    return [
        'format' => 'text',
        'ignored_services' => [],
        'fail_on_error' => false,
    ];
    
  • Case Sensitivity: Laravel’s container is case-insensitive for service IDs, but the debugger may not account for this. Normalize IDs in custom implementations:

    $id = strtolower($id); // Force lowercase for consistency
    
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