bernardosecades/laravel-debug-container
Installation:
composer require bernardosecades/laravel-debug-container
Register the provider in bootstrap/app.php under APP_ENV === 'development':
$app->register(\BernardoSecades\Laravel\DebugContainer\DebugContainerServiceProvider::class);
First Use Case: Run the debug command to inspect registered services:
php artisan debug:container
This outputs a structured list of all services in the container, including bindings, aliases, and singleton status.
debug:container output to identify:
bootstrap/app.php to confirm the provider is conditionally loaded (e.g., only in development).Debugging Dependency Injection:
debug:container to verify if a service is registered before troubleshooting App\Services\MyService::class resolution failures.bind()/singleton() calls.Workflows:
debug:container in staging to ensure no unexpected services are registered (e.g., debug-only bindings).Integration Tips:
debug:container --prefix="App\Services").php artisan debug:container to a custom script in your pipeline to fail builds if critical services are missing.# Debug a missing service
php artisan debug:container | grep -i "AuthService"
# Verify singleton status
php artisan debug:container --singletons-only
Performance Overhead:
debug:container in production (provider is env-gated, but double-check).Output Parsing:
grep/awk for specific data (e.g., php artisan debug:container | grep "App\\").Dynamic Bindings:
afterResolving()) may not appear in the output. Run the command after the app boots fully.Missing Services:
boot() method (bindings in register() are container-wide, but boot() bindings are context-specific).config/app.php under providers.Singleton Confusion:
--singletons-only to confirm if a service is a singleton. Non-singletons may resolve differently across requests.Customize Output:
Override the command class (\BernardoSecades\Laravel\DebugContainer\Commands\DebugContainerCommand) to:
Add Metadata:
Extend the container’s getBindings() logic to include custom tags:
// In a service provider
$this->app->bind('MyService', function () {
return new MyService();
})->withMetadata(['tag' => 'auth']);
Then modify the command to display metadata.
Integration with Laravel IDE Helper:
Use the output to generate/update ide-helper models for better autocompletion.
APP_ENV=development is set when testing locally (the provider won’t register otherwise).How can I help you explore Laravel packages today?