3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mvc\Controller\Plugin
;
12 use Zend\Authentication\AuthenticationService
;
13 use Zend\Mvc\Exception
;
16 * Controller plugin to fetch the authenticated identity.
18 class Identity
extends AbstractPlugin
21 * @var AuthenticationService
23 protected $authenticationService;
26 * @return AuthenticationService
28 public function getAuthenticationService()
30 return $this->authenticationService
;
34 * @param AuthenticationService $authenticationService
36 public function setAuthenticationService(AuthenticationService
$authenticationService)
38 $this->authenticationService
= $authenticationService;
42 * Retrieve the current identity, if any.
44 * If none is present, returns null.
47 * @throws Exception\RuntimeException
49 public function __invoke()
51 if (!$this->authenticationService
instanceof AuthenticationService
) {
52 throw new Exception\
RuntimeException('No AuthenticationService instance provided');
54 if (!$this->authenticationService
->hasIdentity()) {
57 return $this->authenticationService
->getIdentity();