Skip to content

Commit

Permalink
[5.2] Add support for multi auth
Browse files Browse the repository at this point in the history
Change new auth collector name to MultiAuthCollector

change the way of checking Laravel version
  • Loading branch information
plapinski committed Jan 30, 2016
1 parent 80633a2 commit 5379747
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
76 changes: 76 additions & 0 deletions src/DataCollector/MultiAuthCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

/**
* Collector for Laravel's Auth provider
*/
class MultiAuthCollector extends AuthCollector
{
/** @var array $guards */
protected $guards;

/**
* @param \Illuminate\Auth\AuthManager $auth
* @param array $guards
*/
public function __construct($auth, $guards)
{
parent::__construct($auth);
$this->guards = $guards;
}


/**
* @{inheritDoc}
*/
public function collect()
{
$data = [];
$names = '';

foreach($this->guards as $guardName) {
$user = $this->auth->guard($guardName)->user();
$data['guards'][$guardName] = $this->getUserInformation($user);
if(!is_null($user)) {
$names .= $guardName . ": " . $data['guards'][$guardName]['name'] . ', ';
}
}

foreach ($data['guards'] as $key => $var) {
if (!is_string($data['guards'][$key])) {
$data['guards'][$key] = $this->formatVar($var);
}
}

$data['names'] = rtrim($names, ', ');

return $data;
}

/**
* @{inheritDoc}
*/
public function getWidgets()
{
$widgets = array(
"auth" => array(
"icon" => "lock",
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
"map" => "auth.guards",
"default" => "{}"
)
);

if ($this->showName) {
$widgets['auth.name'] = array(
'icon' => 'user',
'tooltip' => 'Auth status',
'map' => 'auth.names',
'default' => '',
);
}

return $widgets;
}
}
10 changes: 9 additions & 1 deletion src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Barryvdh\Debugbar\DataCollector\FilesCollector;
use Barryvdh\Debugbar\DataCollector\LaravelCollector;
use Barryvdh\Debugbar\DataCollector\LogsCollector;
use Barryvdh\Debugbar\DataCollector\MultiAuthCollector;
use Barryvdh\Debugbar\DataCollector\QueryCollector;
use Barryvdh\Debugbar\DataCollector\SessionCollector;
use Barryvdh\Debugbar\DataCollector\SymfonyRequestCollector;
Expand Down Expand Up @@ -354,7 +355,14 @@ function ($query, $bindings = null, $time = null, $connectionName = null) use ($

if ($this->shouldCollect('auth', false)) {
try {
$authCollector = new AuthCollector($app['auth']);
if($this->checkVersion('5.2')) {
// fix for compatibility with Laravel 5.2.*
$guards = array_keys($this->app['config']->get('auth.guards'));
$authCollector = new MultiAuthCollector($app['auth'], $guards);
} else {
$authCollector = new AuthCollector($app['auth']);
}

$authCollector->setShowName(
$this->app['config']->get('debugbar.options.auth.show_name')
);
Expand Down

0 comments on commit 5379747

Please sign in to comment.