22
33namespace Statamic \Console \Commands ;
44
5- use Illuminate \Console \Command ;
5+ use Illuminate \Foundation \Console \AboutCommand ;
6+ use Illuminate \Support \Composer ;
67use Statamic \Console \RunsInPlease ;
8+ use Symfony \Component \Console \Attribute \AsCommand ;
79
8- class SupportDetails extends Command
10+ #[AsCommand(name: 'statamic:support:details ' )]
11+ class SupportDetails extends AboutCommand
912{
1013 use RunsInPlease;
1114
12- protected $ signature = 'statamic:support:details ' ;
15+ /**
16+ * @var string
17+ */
18+ protected $ signature = 'statamic:support:details
19+ {--only= : The section to display}
20+ {--json : Output the information as JSON} ' ;
21+
22+ /**
23+ * @var string
24+ */
1325 protected $ description = 'Outputs details helpful for support requests ' ;
1426
27+ public function __construct (Composer $ composer )
28+ {
29+ parent ::__construct ($ composer );
30+ }
31+
1532 public function handle ()
1633 {
1734 $ this ->replaceView ();
1835
1936 try {
20- $ this -> call ( ' about ' );
37+ return parent :: handle ( );
2138 } finally {
2239 $ this ->restoreView ();
2340 }
41+ }
42+
43+ /**
44+ * @param \Illuminate\Support\Collection $data
45+ */
46+ protected function displayDetail ($ data ): void
47+ {
48+ $ data ->each (function ($ data , $ section ) {
49+ $ this ->newLine ();
50+
51+ $ this ->components ->twoColumnDetail (' <fg=green;options=bold> ' .$ section .'</> ' );
2452
25- return static ::SUCCESS ;
53+ $ data ->pipe (fn ($ data ) => $ section !== 'Environment ' ? $ data ->sort () : $ data )
54+ ->reject (fn ($ detail ) => $ this ->shouldExcludeSupportDetail ($ detail [0 ]))
55+ ->each (function ($ detail ) {
56+ [$ label , $ value ] = $ detail ;
57+
58+ $ this ->components ->twoColumnDetail ($ label , value ($ value , false ));
59+ });
60+ });
61+ }
62+
63+ /**
64+ * @param \Illuminate\Support\Collection $data
65+ */
66+ protected function displayJson ($ data ): void
67+ {
68+ $ data = $ data ->map (fn ($ sectionData ) => $ sectionData
69+ ->reject (fn ($ detail ) => $ this ->shouldExcludeSupportDetail ($ detail [0 ]))
70+ ->values ());
71+
72+ parent ::displayJson ($ data );
73+ }
74+
75+ private function shouldExcludeSupportDetail (string $ label ): bool
76+ {
77+ return in_array ($ label , ['Application Name ' , 'URL ' ], true );
2678 }
2779
28- private function replaceView ()
80+ private function replaceView (): void
2981 {
3082 $ view = <<<'EOT'
3183<div class="flex">
@@ -38,14 +90,14 @@ private function replaceView()
3890 app ('files ' )->put ($ dir .'/two-column-detail.php ' , $ view );
3991 }
4092
41- private function restoreView ()
93+ private function restoreView (): void
4294 {
4395 $ dir = $ this ->viewDir ();
4496 app ('files ' )->delete ($ dir .'/two-column-detail.php ' );
4597 app ('files ' )->move ($ dir .'/two-column-detail.php.bak ' , $ dir .'/two-column-detail.php ' );
4698 }
4799
48- private function viewDir ()
100+ private function viewDir (): string
49101 {
50102 return base_path ('vendor/laravel/framework/src/Illuminate/Console/resources/views/components ' );
51103 }
0 commit comments