Skip to content

Commit

Permalink
[Feature] Added config option to exclude paths (#42)
Browse files Browse the repository at this point in the history
* Update telescope-toolbar.php

* Added ability to exclude from running on certain config paths

* Added default array for Toolbar config reference
  • Loading branch information
Braunson authored Jul 2, 2020
1 parent 7c27b94 commit 4a116e5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions config/telescope-toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion src/ToolbarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function boot(Toolbar $toolbar)

$this->registerRoutes();
$this->registerPublishing();

if (! $this->runningApprovedRequest()) {
return;
}

$this->registerResponseHandler($toolbar);
$this->registerDumpWatcher();
$this->loadViewsFrom(
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -129,4 +155,4 @@ public function register()

$this->app->singleton(Toolbar::class);
}
}
}

0 comments on commit 4a116e5

Please sign in to comment.