1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelPlus\Extension\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Foundation\Application; |
7
|
|
|
use LaravelPlus\Extension\Hooks\ApplicationHook; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Fumio Furukawa <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class AppContainerCommand extends Command |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The console command signature. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $signature = 'app:container'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command description. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $description = '[+] Lists object in application container'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Execute the console command. |
30
|
|
|
* |
31
|
|
|
* @return mixed |
32
|
|
|
*/ |
33
|
1 |
|
public function handle() |
34
|
|
|
{ |
35
|
1 |
|
$app = new ApplicationHook($this->laravel); |
36
|
|
|
|
37
|
1 |
|
$instances = $app->getInstances(); |
38
|
1 |
|
$objects = $app->getBindings(); |
39
|
1 |
|
$aliases = []; |
40
|
|
|
|
41
|
1 |
|
foreach ($app->getAliases() as $alias => $abstract) { |
42
|
|
|
$aliases[$abstract][] = $alias; |
43
|
1 |
|
} |
44
|
|
|
|
45
|
1 |
|
ksort($objects); |
46
|
|
|
|
47
|
1 |
|
foreach ($objects as $name => $instance) { |
48
|
1 |
|
$this->info($name.': '); |
49
|
|
|
|
50
|
1 |
|
if (is_array($instance)) { |
51
|
1 |
|
if ($instance['shared']) { |
52
|
1 |
|
$this->output(array_get($instances, $name)); |
53
|
1 |
|
} |
54
|
|
|
else { |
55
|
1 |
|
$this->output($instance['concrete']); |
56
|
|
|
} |
57
|
1 |
|
} |
58
|
|
|
else { |
59
|
|
|
$this->output($instance); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
if (isset($aliases[$name])) { |
63
|
|
|
foreach ($aliases[$name] as $value) { |
64
|
|
|
$this->line("\t[alias] \"$value\"\n"); |
65
|
|
|
} |
66
|
|
|
} |
67
|
1 |
|
} |
68
|
1 |
|
} |
69
|
|
|
|
70
|
1 |
|
private function output($instance) |
71
|
|
|
{ |
72
|
1 |
|
$line = "\t"; |
73
|
1 |
|
if (is_object($instance)) { |
74
|
1 |
|
$line .= 'object "'.get_class($instance).'"'; |
75
|
1 |
|
} elseif (is_string($instance)) { |
76
|
|
|
$line .= 'string "'.$instance.'"'; |
77
|
1 |
|
} elseif (is_bool($instance)) { |
78
|
|
|
$line .= 'bool '.$instance.''; |
79
|
1 |
|
} elseif (is_null($instance)) { |
80
|
1 |
|
$line .= 'null'; |
81
|
1 |
|
} else { |
82
|
|
|
$line .= '(unknown) '.$instance; |
83
|
|
|
} |
84
|
1 |
|
$line .= "\n"; |
85
|
|
|
|
86
|
1 |
|
$this->line($line); |
87
|
1 |
|
} |
88
|
|
|
} |
89
|
|
|
|