Skip to content

Commit

Permalink
Add initial Gate collector
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Oct 29, 2015
1 parent 3cc1de3 commit 2e48b23
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
'files' => false, // Show the included files
'config' => false, // Display config settings
'auth' => false, // Display Laravel authentication status
'gate' => false, // Display Laravel Gate checks
'session' => true, // Display session data
),

Expand Down
37 changes: 37 additions & 0 deletions src/DataCollector/GateCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

use DebugBar\DataCollector\MessagesCollector;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\Auth\Authenticatable;

/**
* Collector for Laravel's Auth provider
*/
class GateCollector extends MessagesCollector
{
/**
* @param Gate $gate
*/
public function __construct(Gate $gate)
{
parent::__construct('gate');

if (method_exists($gate, 'after')) {
$gate->after([$this, 'addCheck']);
}
}

public function addCheck(Authenticatable $user, $ability, $result = null, $arguments = [])
{
$label = $result ? 'success' : 'error';

$this->addMessage([
'ability' => $ability,
'result' => $result,
'arguments' => $arguments,
'user' => $user ? $user->getAuthIdentifier() : null,
], $label, false);
}
}
9 changes: 9 additions & 0 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ function ($query, $bindings, $time, $connectionName) use ($db, $queryCollector)
}
}

if ($this->shouldCollect('gate', false)) {
try {
$gateCollector = $this->app->make(GateCollector::class);
$this->addCollector($gateCollector);
} catch (\Exception $e){
// No Gate collector
}
}

$renderer = $this->getJavascriptRenderer();
$renderer->setIncludeVendors($this->app['config']->get('debugbar.include_vendors', true));
$renderer->setBindAjaxHandlerToXHR($app['config']->get('debugbar.capture_ajax', true));
Expand Down

0 comments on commit 2e48b23

Please sign in to comment.