| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Bavix\Prof; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Bavix\Prof\Middleware\ProfileLogMiddleware; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Bavix\Prof\Middleware\TerminateMiddleware; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Bavix\Prof\Services\ProfileLogService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Support\ServiceProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Contracts\Http\Kernel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class ProfileLogServiceProvider extends ServiceProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     public function boot(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         if (!$this->app->runningInConsole()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |             return; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         if (function_exists('config_path')) { | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |             $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |                 dirname(__DIR__) . '/config/config.php' => config_path('prof.php'), | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             ], 'laravel-prof-config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function register(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->mergeConfigFrom(\dirname(__DIR__) . '/config/config.php', 'prof'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->app->singleton(ProfileLogMiddleware::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->app->singleton(ProfileLogService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |          * @var \Illuminate\Foundation\Http\Kernel $kernel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         if (!$this->app->shouldSkipMiddleware() && $this->handlingApprovedRequest()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             $kernel = $this->app[Kernel::class]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             $kernel->appendMiddlewareToGroup('web', ProfileLogMiddleware::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             $kernel->appendMiddlewareToGroup('api', ProfileLogMiddleware::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             $kernel->pushMiddleware(TerminateMiddleware::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @see https://github.com/laravel/telescope/blob/3.x/src/Telescope.php#L187-L198 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     protected function handlingApprovedRequest(): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return !$this->app->runningInConsole() && !$this->app['request']->is( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 \array_merge([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     \config('telescope.path', 'telescope') . '*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                     'telescope-api*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                     'vendor/telescope*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                     'horizon*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                     'vendor/horizon*', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 ], \config('telescope.ignore_paths', [])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |  |