Skip to content

Instantly share code, notes, and snippets.

@REBELinBLUE
Created May 31, 2020 12:59
Show Gist options
  • Save REBELinBLUE/f40061c4cefdd418f0272c761d4cb527 to your computer and use it in GitHub Desktop.
Save REBELinBLUE/f40061c4cefdd418f0272c761d4cb527 to your computer and use it in GitHub Desktop.
<?php
namespace REBELinBLUE\Deployer\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\Application;
use Illuminate\Contracts\Container\Container;
class DebugContainer extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'debug:container';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Displays current bindings in the container';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$container = $this->getApplication()->getLaravel();
$bindings = $container->getBindings();
$this->output->note(count($bindings) . ' bindings found');
$rows = [];
foreach (array_keys($bindings) as $key) {
try {
$className = get_class($container->make($key));
} catch (\Throwable $e) {
$className = '??';
}
$rows[] = [
$key,
$className,
$container->isShared($key) ? 'Yes' : 'No',
];
}
sort($rows);
$this->table(['Key', 'Class', 'Shared'], $rows);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment