forked from barryvdh/laravel-debugbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request barryvdh#456 from plapinski/fixes
[5.2] Add support for multi auth
- Loading branch information
Showing
2 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters