ion-bazan/laravel-container-debug

Lists available services in Laravel IoC Container. Works with Laravel 5.4-11.x

Fund package maintenance!
IonBazan

v1.5.0 2024-04-14 14:51 UTC

This package is auto-updated.

Last update: 2024-12-24 04:22:17 UTC


README

Laravel 5.4|6|7|8|9|10|11 Latest version GitHub Workflow Status PHP version Codecov Mutation testing badge Downloads License

Symfony-inspired package to list available services in Laravel IoC Container. Works with Laravel 5.4-11.x.

Example output

+--------------------------------------------------------------+-------------------------------------------------------------+--------+-------+
| Service ID                                                   | Class                                                       | Shared | Alias |
+--------------------------------------------------------------+-------------------------------------------------------------+--------+-------+
| IonBazan\Laravel\ContainerDebug\Tests\IContainerContractStub | IonBazan\Laravel\ContainerDebug\Tests\ContainerConcreteStub | No     | No    |
| IonBazan\Laravel\ContainerDebug\Tests\SingletonService       | IonBazan\Laravel\ContainerDebug\Tests\SingletonService      | Yes    | No    |
| alias.b                                                      | alias for "service.b"                                       | No     | Yes   |
| alias.c                                                      | alias for "service.c"                                       | No     | Yes   |
| service.a                                                    | IonBazan\Laravel\ContainerDebug\Tests\ServiceStubA          | No     | No    |
| service.b                                                    | IonBazan\Laravel\ContainerDebug\Tests\ServiceStubB          | No     | No    |
| service.c                                                    | IonBazan\Laravel\ContainerDebug\Tests\ServiceStubC          | No     | No    |
| service.d                                                    | N/A                                                         | No     | No    |
| simple.value.array                                           | <array> [10,20]                                             | No     | No    |
| simple.value.int                                             | <integer> 10                                                | No     | No    |
| simple.value.string                                          | <string> test                                               | No     | No    |
+--------------------------------------------------------------+-------------------------------------------------------------+--------+-------+

Installation

composer require --dev ion-bazan/laravel-container-debug

Thanks to Laravel's Package Auto-Discovery, you don't need to register the ServiceProvider.

Laravel without auto-discovery

If you don't use auto-discovery, add the Service Provider to the providers array in your config/app.php:

\IonBazan\Laravel\ContainerDebug\ServiceProvider::class,

Lumen

For Lumen, register the Service Provider in your bootstrap/app.php:

$app->register(\IonBazan\Laravel\ContainerDebug\ServiceProvider::class);

Usage

TL;DR: php artisan container:debug --help

Usage is pretty straightforward:

  • to list all services: php artisan container:debug
  • to check specific service: php artisan container:debug MyFooService
  • to list all tags with tagged services: php artisan container:debug --tags
  • to list all services with tag: php artisan container:debug --tag=foo

The command does it best to find the service you want by stripping slashes in service names and looking for any occurrences of given name in service names. For example, to display service.foo service information, simply use php artisan container:debug foo. If there are more services with the similar name, a prompt will be shown to choose the one you are looking for.

To get the class name of the service, it must be initialized. To check how much time it took for each service, you may use --profile option.