Skip to content

Commit d9949ff

Browse files
committed
Add auth to request collector
1 parent 8dea06b commit d9949ff

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Barryvdh/Debugbar/DataCollector/SymfonyRequestCollector.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use DebugBar\DataCollector\Renderable;
77
use DebugBar\DataCollector\DataCollector;
88
use Symfony\Component\HttpFoundation\Response;
9+
use Illuminate\Auth\AuthManager;
10+
use Illuminate\Support\Contracts\ArrayableInterface;
911

1012
/**
1113
*
@@ -29,15 +31,16 @@ class SymfonyRequestCollector extends DataCollector implements DataCollectorInte
2931
* @param \Symfony\Component\HttpFoundation\Request $request
3032
* @param \Symfony\Component\HttpFoundation\Request $response
3133
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
34+
* @param \Illuminate\Auth\AuthManager $auth
3235
*/
33-
public function __construct($request, $response, $session)
36+
public function __construct($request, $response, $session, AuthManager $auth = null)
3437
{
3538
$this->request = $request;
3639
$this->response = $response;
3740
$this->session = $session;
41+
$this->auth = $auth;
3842
}
3943

40-
4144
/**
4245
* {@inheritDoc}
4346
*/
@@ -65,6 +68,16 @@ public function getWidgets()
6568
*/
6669
public function collect()
6770
{
71+
$user = null;
72+
if($this->auth){
73+
$user = $this->auth->user();
74+
if(is_null($user)){
75+
$user = 'Guest';
76+
}elseif($user instanceof ArrayableInterface){
77+
$user = $user->toArray();
78+
}
79+
}
80+
6881
$request = $this->request;
6982
$response = $this->response;
7083

@@ -85,6 +98,7 @@ public function collect()
8598
$statusCode = $response->getStatusCode();
8699

87100
$data = array(
101+
'auth' => $user ?: '?',
88102
'format' => $request->getRequestFormat(),
89103
'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html',
90104
'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '',

0 commit comments

Comments
 (0)