Skip to content

Commit 5379747

Browse files
author
=
committed
[5.2] Add support for multi auth
Change new auth collector name to MultiAuthCollector change the way of checking Laravel version
1 parent 80633a2 commit 5379747

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
@@ -5,6 +5,7 @@
55
use Barryvdh\Debugbar\DataCollector\FilesCollector;
66
use Barryvdh\Debugbar\DataCollector\LaravelCollector;
77
use Barryvdh\Debugbar\DataCollector\LogsCollector;
8+
use Barryvdh\Debugbar\DataCollector\MultiAuthCollector;
89
use Barryvdh\Debugbar\DataCollector\QueryCollector;
910
use Barryvdh\Debugbar\DataCollector\SessionCollector;
1011
use Barryvdh\Debugbar\DataCollector\SymfonyRequestCollector;
@@ -354,7 +355,14 @@ function ($query, $bindings = null, $time = null, $connectionName = null) use ($
354355

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

0 commit comments

Comments
 (0)