Skip to content

Commit bfdfbaf

Browse files
authored
Add config option to exclude paths from ViewCollector (#1327)
* Add views.exclude_paths config option * Pass through excludePaths to the ViewCollector * Exclude files matching paths from view collector * Use strpos for check
1 parent 615ce47 commit bfdfbaf

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

config/debugbar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
'views' => [
207207
'timeline' => false, // Add the views to the timeline (Experimental)
208208
'data' => false, //Note: Can slow down the application, because the data can be quite large..
209+
'exclude_paths' => [], // Add the paths which you don't want to appear in the views
209210
],
210211
'route' => [
211212
'label' => true, // show complete route on bar

src/DataCollector/ViewCollector.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ class ViewCollector extends TwigCollector
1010
{
1111
protected $templates = [];
1212
protected $collect_data;
13+
protected $exclude_paths;
1314

1415
/**
1516
* Create a ViewCollector
1617
*
1718
* @param bool $collectData Collects view data when tru
19+
* @param string[] $excludePaths Paths to exclude from collection
1820
*/
19-
public function __construct($collectData = true)
21+
public function __construct($collectData = true, $excludePaths = [])
2022
{
2123
$this->setDataFormatter(new SimpleFormatter());
2224
$this->collect_data = $collectData;
2325
$this->templates = [];
26+
$this->exclude_paths = $excludePaths;
2427
}
2528

2629
public function getName()
@@ -69,6 +72,12 @@ public function addView(View $view)
6972
$path = '';
7073
}
7174

75+
foreach ($this->exclude_paths as $excludePath) {
76+
if (strpos($path, $excludePath) !== false) {
77+
return;
78+
}
79+
}
80+
7281
if (!$this->collect_data) {
7382
$params = array_keys($view->getData());
7483
} else {

src/LaravelDebugbar.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ function () use ($debugbar, $startTime) {
205205
if ($this->shouldCollect('views', true) && isset($this->app['events'])) {
206206
try {
207207
$collectData = $this->app['config']->get('debugbar.options.views.data', true);
208-
$this->addCollector(new ViewCollector($collectData));
208+
$excludePaths = $this->app['config']->get('debugbar.options.views.exclude_paths', []);
209+
$this->addCollector(new ViewCollector($collectData, $excludePaths));
209210
$this->app['events']->listen(
210211
'composing:*',
211212
function ($view, $data = []) use ($debugbar) {

0 commit comments

Comments
 (0)