Created
May 31, 2020 12:59
-
-
Save REBELinBLUE/f40061c4cefdd418f0272c761d4cb527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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