From 4a116e53d666c43cc35658be5b7f5ffd421b9e54 Mon Sep 17 00:00:00 2001 From: Braunson Yager Date: Thu, 2 Jul 2020 13:00:49 -0400 Subject: [PATCH] [Feature] Added config option to exclude paths (#42) * Update telescope-toolbar.php * Added ability to exclude from running on certain config paths * Added default array for Toolbar config reference --- config/telescope-toolbar.php | 12 ++++++++++++ src/ToolbarServiceProvider.php | 28 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/config/telescope-toolbar.php b/config/telescope-toolbar.php index 1f0f49b..e59de99 100644 --- a/config/telescope-toolbar.php +++ b/config/telescope-toolbar.php @@ -63,6 +63,18 @@ */ 'excluded_ajax_paths' => '^/_tt|^/_debugbar|^/horizon', + /* + |-------------------------------------------------------------------------- + | Ignored Paths + |-------------------------------------------------------------------------- + | + | This is a list of paths the toolbar will not run on. + | + */ + 'ignore_paths' => [ + // + ], + /* |-------------------------------------------------------------------------- | Store Redirects in Session diff --git a/src/ToolbarServiceProvider.php b/src/ToolbarServiceProvider.php index 5fae408..2d239d1 100644 --- a/src/ToolbarServiceProvider.php +++ b/src/ToolbarServiceProvider.php @@ -24,6 +24,11 @@ public function boot(Toolbar $toolbar) $this->registerRoutes(); $this->registerPublishing(); + + if (! $this->runningApprovedRequest()) { + return; + } + $this->registerResponseHandler($toolbar); $this->registerDumpWatcher(); $this->loadViewsFrom( @@ -89,6 +94,27 @@ private function registerPublishing() } } + /** + * Determine if the application is handling an approved request. + * + * @param \Illuminate\Foundation\Application $app + * @return bool + */ + private function runningApprovedRequest() + { + return ! $this->app->runningInConsole() && ! $this->app['request']->is( + array_merge([ + config('telescope.path').'*', + 'telescope-api*', + 'vendor/telescope*', + 'horizon*', + 'vendor/horizon*', + ], + config('telescope.ignore_paths', []), + config('telescope-toolbar.ignore_paths', [])) + ); + } + /** * Listen to the RequestHandled event to prepare the Response. * @@ -129,4 +155,4 @@ public function register() $this->app->singleton(Toolbar::class); } -} \ No newline at end of file +}