Commit 87dc8570 authored by Fabien Potencier's avatar Fabien Potencier

made it easier to get the user from the app

parent 1b5f29d3
......@@ -23,7 +23,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
trait SecurityTrait
{
/**
* Gets a user from the Security Context.
* Gets a user from the Security context.
*
* @return mixed
*
......@@ -31,15 +31,7 @@ trait SecurityTrait
*/
public function user()
{
if (null === $token = $this['security.token_storage']->getToken()) {
return;
}
if (!is_object($user = $token->getUser())) {
return;
}
return $user;
return $this['user'];
}
/**
......
......@@ -101,6 +101,18 @@ class SecurityServiceProvider implements ServiceProviderInterface
});
}
$app['user'] = function ($app) {
if (null === $token = $app['security.token_storage']->getToken()) {
return;
}
if (!is_object($user = $token->getUser())) {
return;
}
return $user;
};
$app['security.authentication_manager'] = $app->share(function ($app) {
$manager = new AuthenticationProviderManager($app['security.authentication_providers']);
$manager->setEventDispatcher($app['dispatcher']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment