|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MallardDuck\DynamicEcho\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use MallardDuck\DynamicEcho\DynamicEchoService; |
|
9
|
|
|
|
|
10
|
|
|
class PrintChannels extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The name and signature of the console command. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $signature = 'dynamic-echo:channels {--F|full : Get the full channel report.}'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'An easy way to see what routes are discoverable by the DynamicEchoEvent services.'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create a new command instance. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Execute the console command. |
|
38
|
|
|
* |
|
39
|
|
|
* @param DynamicEchoService $dynamicEchoService |
|
40
|
|
|
* |
|
41
|
|
|
* @return int |
|
42
|
|
|
*/ |
|
43
|
|
|
public function handle(DynamicEchoService $dynamicEchoService): int |
|
44
|
|
|
{ |
|
45
|
|
|
$headers = ["Event Channel"]; |
|
46
|
|
|
/** |
|
47
|
|
|
* @var Collection |
|
48
|
|
|
*/ |
|
49
|
|
|
$channelMap = collect([[]]); |
|
50
|
|
|
if (!$this->option('full')) { |
|
51
|
|
|
$channelMap = $channelMap->merge($dynamicEchoService->getDiscoveredChannels()); |
|
52
|
|
|
$channelMap = $channelMap->map(static function ($val) { |
|
53
|
|
|
return [$val]; |
|
54
|
|
|
}); |
|
55
|
|
|
} else { |
|
56
|
|
|
$headers[] = 'Channel Type'; |
|
57
|
|
|
$headers[] = 'Auth Callback'; |
|
58
|
|
|
$headers[] = 'Events'; |
|
59
|
|
|
$channelMap = $channelMap->merge($dynamicEchoService->getExtendedChannelInfo()); |
|
60
|
|
|
|
|
61
|
|
|
$channelMap = $channelMap->map(static function ($val, $key) { |
|
62
|
|
|
$authReflection = new \ReflectionFunction($val['authCallback']); |
|
63
|
|
|
$callbackType = Str::afterLast($authReflection->getName(), "\\"); |
|
64
|
|
|
$args = array_map(static function ($val) { |
|
65
|
|
|
if (null !== $val->getType()) { |
|
66
|
|
|
return sprintf("%s %s", $val->getType()->getName(), $val->getName()); |
|
67
|
|
|
} |
|
68
|
|
|
return $val->getName(); |
|
69
|
|
|
}, $authReflection->getParameters()); |
|
70
|
|
|
|
|
71
|
|
|
return [ |
|
72
|
|
|
$key, |
|
73
|
|
|
$val['type'], |
|
74
|
|
|
sprintf("%s - %s", $callbackType, implode(", ", $args)), |
|
75
|
|
|
implode("," . PHP_EOL, $val['events']), |
|
76
|
|
|
]; |
|
77
|
|
|
}); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$this->table($headers, $channelMap->toArray()); |
|
81
|
|
|
return 0; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|