1515
1616use CodeIgniter \CLI \AbstractCommand ;
1717use CodeIgniter \CLI \Attributes \Command ;
18- use CodeIgniter \CLI \CLI ;
1918use CodeIgniter \CLI \Input \Argument ;
19+ use CodeIgniter \CLI \Output ;
20+ use CodeIgniter \CLI \Table ;
2021use CodeIgniter \Commands \Utilities \Routes \FilterCollector ;
2122
2223/**
@@ -53,19 +54,20 @@ protected function execute(array $arguments, array $options): int
5354 $ filterCollector = new FilterCollector ();
5455
5556 $ filters = $ filterCollector ->get ($ method , $ route );
57+ $ output = $ this ->getOutput ();
5658
5759 // PageNotFoundException
5860 if ($ filters ['before ' ] === ['<unknown> ' ]) {
59- CLI :: error (sprintf (
61+ $ output -> error (sprintf (
6062 "Can't find a route: %s " ,
61- CLI :: color (sprintf ('"%s %s" ' , strtoupper ($ method ), $ route ), 'black ' , 'light_gray ' ),
63+ $ output -> color (sprintf ('"%s %s" ' , strtoupper ($ method ), $ route ), 'black ' , 'light_gray ' ),
6264 ));
6365
6466 return EXIT_ERROR ;
6567 }
6668
67- $ this ->showTable ($ filterCollector , $ filters , $ method , $ route );
68- $ this ->showFilterClasses ($ filterCollector , $ method , $ route );
69+ $ this ->showTable ($ output , $ filterCollector , $ filters , $ method , $ route );
70+ $ this ->showFilterClasses ($ output , $ filterCollector , $ method , $ route );
6971
7072 return EXIT_SUCCESS ;
7173 }
@@ -74,12 +76,13 @@ protected function execute(array $arguments, array $options): int
7476 * @param array{before: list<string>, after: list<string>} $filters
7577 */
7678 private function showTable (
79+ Output $ output ,
7780 FilterCollector $ filterCollector ,
7881 array $ filters ,
7982 string $ method ,
8083 string $ route ,
8184 ): void {
82- $ merged = $ this ->mergeFilters ($ filterCollector ->getRequiredFilters (), $ filters );
85+ $ merged = $ this ->mergeFilters ($ output , $ filterCollector ->getRequiredFilters (), $ filters );
8386
8487 $ thead = ['Method ' , 'Route ' , 'Before Filters ' , 'After Filters ' ];
8588 $ tbody = [
@@ -91,27 +94,29 @@ private function showTable(
9194 ],
9295 ];
9396
94- CLI :: table ( $ tbody , $ thead );
97+ $ output -> write (( new Table ( $ tbody , $ thead))-> render () );
9598 }
9699
97100 private function showFilterClasses (
101+ Output $ output ,
98102 FilterCollector $ filterCollector ,
99103 string $ method ,
100104 string $ route ,
101105 ): void {
102106 $ merged = $ this ->mergeFilters (
107+ $ output ,
103108 $ filterCollector ->getRequiredFilterClasses (),
104109 $ filterCollector ->getClasses ($ method , $ route ),
105110 );
106111
107112 $ lastPosition = array_key_last ($ merged );
108113
109114 foreach ($ merged as $ position => $ classes ) {
110- CLI :: write (sprintf ('%s Filter Classes: ' , ucfirst ($ position )), 'cyan ' );
111- CLI :: write (implode (' → ' , $ classes ));
115+ $ output -> write (sprintf ('%s Filter Classes: ' , ucfirst ($ position )), 'cyan ' );
116+ $ output -> write (implode (' → ' , $ classes ));
112117
113118 if ($ position !== $ lastPosition ) {
114- CLI :: newLine ();
119+ $ output -> newLine ();
115120 }
116121 }
117122 }
@@ -125,11 +130,11 @@ private function showFilterClasses(
125130 *
126131 * @return array{before: list<string>, after: list<string>}
127132 */
128- private function mergeFilters (array $ required , array $ filters ): array
133+ private function mergeFilters (Output $ output , array $ required , array $ filters ): array
129134 {
130135 return [
131- 'before ' => array_merge ($ this ->highlight ($ required ['before ' ]), $ filters ['before ' ]),
132- 'after ' => array_merge ($ filters ['after ' ], $ this ->highlight ($ required ['after ' ])),
136+ 'before ' => array_merge ($ this ->highlight ($ output , $ required ['before ' ]), $ filters ['before ' ]),
137+ 'after ' => array_merge ($ filters ['after ' ], $ this ->highlight ($ output , $ required ['after ' ])),
133138 ];
134139 }
135140
@@ -140,8 +145,8 @@ private function mergeFilters(array $required, array $filters): array
140145 *
141146 * @return list<string>
142147 */
143- private function highlight (array $ items ): array
148+ private function highlight (Output $ output , array $ items ): array
144149 {
145- return array_map (static fn (string $ item ): string => CLI :: color ($ item , 'yellow ' ), $ items );
150+ return array_map (static fn (string $ item ): string => $ output -> color ($ item , 'yellow ' ), $ items );
146151 }
147152}
0 commit comments