File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11up :
22 docker compose up
33down :
4- docker compose down -v
4+ docker compose down
55php :
66 docker exec -it hyperf-sqlcommenter-app bash
77check :
Original file line number Diff line number Diff line change @@ -75,15 +75,19 @@ private function appendSqlComments(string $query, string $dbDriver): string
7575 }
7676
7777 if ($ this ->switchManager ->isEnable ('controller ' ) || $ this ->switchManager ->isEnable ('action ' )) {
78+ /** @var null|Dispatched $dispatched */
7879 $ dispatched = $ request ->getAttribute (Dispatched::class);
79- $ parts = Utils::extractCallback ($ dispatched ->handler ->callback );
8080
81- if ($ this ->switchManager ->isEnable ('controller ' )) {
82- $ comments ['controller ' ] = $ parts [0 ];
83- }
81+ if ($ dispatched && $ dispatched ->isFound ()) {
82+ $ parts = Utils::extractCallback ($ dispatched ->handler ?->callback);
83+
84+ if ($ this ->switchManager ->isEnable ('controller ' )) {
85+ $ comments ['controller ' ] = $ parts [0 ];
86+ }
8487
85- if ($ this ->switchManager ->isEnable ('action ' )) {
86- $ comments ['action ' ] = $ parts [1 ];
88+ if ($ this ->switchManager ->isEnable ('action ' )) {
89+ $ comments ['action ' ] = $ parts [1 ];
90+ }
8791 }
8892 }
8993 }
Original file line number Diff line number Diff line change @@ -47,16 +47,22 @@ public static function extractCallback(mixed $callback): array
4747 switch (gettype ($ callback )) {
4848 case 'string ' :
4949 $ parts = explode ('@ ' , $ callback );
50- $ method = $ parts [1 ] ?? '' ;
50+ $ method = $ parts [1 ] ?? '__invoke ' ;
5151
5252 $ controllerNameParts = explode ('\\' , $ parts [0 ]);
5353 $ controllerName = end ($ controllerNameParts );
5454
5555 return [$ controllerName , $ method ];
5656 case 'array ' :
57- return [basename ($ callback [0 ], '.php ' ), $ callback [1 ]];
57+ $ method = $ callback [1 ] ?? '__invoke ' ;
58+
59+ $ controllerNameParts = explode ('\\' , $ callback [0 ]);
60+ $ controllerName = end ($ controllerNameParts );
61+ $ controllerName = str_replace ('.php ' , '' , $ controllerName );
62+
63+ return [$ controllerName , $ method ];
5864 default :
59- return ['' , '' ];
65+ return ['' , 'callable ' ];
6066 }
6167 }
6268
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ public function testProcess(): void
6464 ->with (Dispatched::class)
6565 ->willReturn (new Dispatched ([
6666 Dispatcher::FOUND ,
67- new Handler ([ ' app/ Controller/ IndexController.php ' , ' index '] , '' ),
67+ new Handler (' App\ Controller\ IndexController@ index ' , '' ),
6868 [],
6969 ]));
7070
You can’t perform that action at this time.
0 commit comments