added a Controller:getUser() shortcut to recover the current user
This commit is contained in:
parent
b66eb4db57
commit
181332b4d4
@ -165,6 +165,24 @@ class Controller extends ContainerAware
|
||||
return $this->container->get('doctrine');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user from the Security Context
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \LogicException If SecurityBundle is not available
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
if (!$this->container->has('security.context')) {
|
||||
throw new \LogicException('The SecurityBundle is not installed in your application.');
|
||||
}
|
||||
|
||||
$token = $this->container->get('security.context')->getToken();
|
||||
|
||||
return null === $token ?: $token->getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the service id is defined.
|
||||
*
|
||||
|
Reference in New Issue
Block a user