/** * {@inheritdoc} */ public function collect() { if (null === $this->auth) { return ['enabled' => false, 'authenticated' => false, 'user_class' => null, 'user' => '', 'roles' => []]; } try { $user = $this->auth->getUser(); } catch (\Exception $e) { $user = null; } if (null === $user) { return ['enabled' => true, 'authenticated' => false, 'user_class' => null, 'user' => '', 'roles' => []]; } return ['enabled' => true, 'authenticated' => $user->isAuthenticated(), 'user_class' => get_class($user), 'user' => $user->getUsername(), 'roles' => array_map(function ($role) { return $role->name; }, User::findRoles($user))]; }