44
55use  Illuminate \Console \Command ;
66use  QuixLabs \LaravelHookSystem \Facades \HookManager ;
7+ use  QuixLabs \LaravelHookSystem \Hook ;
78use  QuixLabs \LaravelHookSystem \Hooks \GetHooksTable ;
89use  QuixLabs \LaravelHookSystem \Utils \CommandTable ;
910
@@ -19,7 +20,27 @@ public function handle(): int
1920            $ this  ->components ->warn ('Hooks are actually cached! ' );
2021        }
2122
22-         $ rows  = [];
23+         $ hooks  = collect (HookManager::getHooks ())
24+             ->mapWithKeys (fn  (string |Hook   $ hook ) => [$ hook  => HookManager::getInterceptorsForHook ($ hook )])->toArray ();
25+         $ rows  = collect ($ hooks )->map (function  (array  $ interceptors , string  $ hookClass ) {
26+             $ callables  = collect ($ interceptors )
27+                 ->map (fn  (array  $ callables , int  $ priority ) => implode ('<br/> ' , array_map (
28+                     fn  (callable  $ callable ) => static ::_callableToString ($ callable ), $ callables )
29+                 ))->join ('<br/> ' );
30+ 
31+             $ priorities  = collect ($ interceptors )
32+                 ->map (fn  (array  $ callables , int  $ priority ) => implode ('<br/> ' , array_fill (0 , count ($ callables ), $ priority )))
33+                 ->join ('<br/> ' );
34+ 
35+             return  [
36+                 'Hook '  => $ hookClass ,
37+                 'Interceptors '  => $ callables ,
38+                 'Priority '  => $ priorities ,
39+                 'Fully Cacheable '  => HookManager::isFullyCacheable ($ hookClass ) ? 'YES '  : 'NO ' ,
40+                 'Fully Cached '  => HookManager::isFullyCached ($ hookClass ) ? 'YES '  : 'NO ' ,
41+             ];
42+         })->toArray ();
43+ 
2344        GetHooksTable::send ($ rows );
2445        if  (count ($ rows ) > 0 ) {
2546            $ this  ->output ->writeln (CommandTable::asString ($ rows ));
@@ -29,4 +50,23 @@ public function handle(): int
2950
3051        return  self ::SUCCESS ;
3152    }
53+ 
54+     public  static  function  _callableToString (callable  $ callable ): string 
55+     {
56+         if  (is_array ($ callable )) {
57+             $ class  = is_object ($ callable [0 ]) ? get_class ($ callable [0 ]) : $ callable [0 ];
58+             $ method  = $ callable [1 ];
59+         } elseif  (is_string ($ callable ) && str_contains ($ callable , ':: ' )) {
60+             [$ class , $ method ] = explode (':: ' , $ callable );
61+         } else  {
62+             $ class  = get_class ($ callable );
63+             $ method  = '__invoke ' ;
64+         }
65+ 
66+         $ reflection  = new  \ReflectionMethod ($ class , $ method );
67+         $ line  = $ reflection ->getStartLine ();
68+ 
69+         return  sprintf ('%s@%s:%d ' , $ class , $ method , $ line );
70+ 
71+     }
3272}
0 commit comments