Skip to content

Commit fa9ed25

Browse files
committed
Merge pull request barryvdh#456 from plapinski/fixes
[5.2] Add support for multi auth
2 parents fdfd7de + 5379747 commit fa9ed25

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace Barryvdh\Debugbar\DataCollector;
4+
5+
/**
6+
* Collector for Laravel's Auth provider
7+
*/
8+
class MultiAuthCollector extends AuthCollector
9+
{
10+
/** @var array $guards */
11+
protected $guards;
12+
13+
/**
14+
* @param \Illuminate\Auth\AuthManager $auth
15+
* @param array $guards
16+
*/
17+
public function __construct($auth, $guards)
18+
{
19+
parent::__construct($auth);
20+
$this->guards = $guards;
21+
}
22+
23+
24+
/**
25+
* @{inheritDoc}
26+
*/
27+
public function collect()
28+
{
29+
$data = [];
30+
$names = '';
31+
32+
foreach($this->guards as $guardName) {
33+
$user = $this->auth->guard($guardName)->user();
34+
$data['guards'][$guardName] = $this->getUserInformation($user);
35+
if(!is_null($user)) {
36+
$names .= $guardName . ": " . $data['guards'][$guardName]['name'] . ', ';
37+
}
38+
}
39+
40+
foreach ($data['guards'] as $key => $var) {
41+
if (!is_string($data['guards'][$key])) {
42+
$data['guards'][$key] = $this->formatVar($var);
43+
}
44+
}
45+
46+
$data['names'] = rtrim($names, ', ');
47+
48+
return $data;
49+
}
50+
51+
/**
52+
* @{inheritDoc}
53+
*/
54+
public function getWidgets()
55+
{
56+
$widgets = array(
57+
"auth" => array(
58+
"icon" => "lock",
59+
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
60+
"map" => "auth.guards",
61+
"default" => "{}"
62+
)
63+
);
64+
65+
if ($this->showName) {
66+
$widgets['auth.name'] = array(
67+
'icon' => 'user',
68+
'tooltip' => 'Auth status',
69+
'map' => 'auth.names',
70+
'default' => '',
71+
);
72+
}
73+
74+
return $widgets;
75+
}
76+
}

src/LaravelDebugbar.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Barryvdh\Debugbar\DataCollector\GateCollector;
77
use Barryvdh\Debugbar\DataCollector\LaravelCollector;
88
use Barryvdh\Debugbar\DataCollector\LogsCollector;
9+
use Barryvdh\Debugbar\DataCollector\MultiAuthCollector;
910
use Barryvdh\Debugbar\DataCollector\QueryCollector;
1011
use Barryvdh\Debugbar\DataCollector\SessionCollector;
1112
use Barryvdh\Debugbar\DataCollector\SymfonyRequestCollector;
@@ -355,7 +356,14 @@ function ($query, $bindings = null, $time = null, $connectionName = null) use ($
355356

356357
if ($this->shouldCollect('auth', false)) {
357358
try {
358-
$authCollector = new AuthCollector($app['auth']);
359+
if($this->checkVersion('5.2')) {
360+
// fix for compatibility with Laravel 5.2.*
361+
$guards = array_keys($this->app['config']->get('auth.guards'));
362+
$authCollector = new MultiAuthCollector($app['auth'], $guards);
363+
} else {
364+
$authCollector = new AuthCollector($app['auth']);
365+
}
366+
359367
$authCollector->setShowName(
360368
$this->app['config']->get('debugbar.options.auth.show_name')
361369
);

0 commit comments

Comments
 (0)