Skip to content

Commit

Permalink
Check for ignored urls
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Sep 18, 2017
1 parent 1189ebc commit fff9d07
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/Middleware/InjectDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class InjectDebugbar
*/
protected $debugbar;

/**
* The URIs that should be excluded.
*
* @var array
*/
protected $except = [];

/**
* Create a new middleware instance.
*
Expand All @@ -35,6 +42,7 @@ public function __construct(Container $container, LaravelDebugbar $debugbar)
{
$this->container = $container;
$this->debugbar = $debugbar;
$this->except = config('debugbar.except') ?: [];
}

/**
Expand All @@ -46,7 +54,7 @@ public function __construct(Container $container, LaravelDebugbar $debugbar)
*/
public function handle($request, Closure $next)
{
if (!$this->debugbar->isEnabled()) {
if (!$this->debugbar->isEnabled() || $this->inExceptArray($request)) {
return $next($request);
}

Expand Down Expand Up @@ -91,4 +99,25 @@ protected function handleException($passable, Exception $e)

return $handler->render($passable, $e);
}

/**
* Determine if the request has a URI that should be ignored.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function inExceptArray($request)
{
foreach ($this->except as $except) {
if ($except !== '/') {
$except = trim($except, '/');
}

if ($request->is($except)) {
return true;
}
}

return false;
}
}

0 comments on commit fff9d07

Please sign in to comment.