fix travis build
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / Mvc / Controller / Plugin / Identity.php
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10 namespace Zend\Mvc\Controller\Plugin;
11
12 use Zend\Authentication\AuthenticationServiceInterface;
13 use Zend\Mvc\Exception;
14
15 /**
16 * Controller plugin to fetch the authenticated identity.
17 */
18 class Identity extends AbstractPlugin
19 {
20 /**
21 * @var AuthenticationServiceInterface
22 */
23 protected $authenticationService;
24
25 /**
26 * @return AuthenticationServiceInterface
27 */
28 public function getAuthenticationService()
29 {
30 return $this->authenticationService;
31 }
32
33 /**
34 * @param AuthenticationServiceInterface $authenticationService
35 */
36 public function setAuthenticationService(AuthenticationServiceInterface $authenticationService)
37 {
38 $this->authenticationService = $authenticationService;
39 }
40
41 /**
42 * Retrieve the current identity, if any.
43 *
44 * If none is present, returns null.
45 *
46 * @return mixed|null
47 * @throws Exception\RuntimeException
48 */
49 public function __invoke()
50 {
51 if (!$this->authenticationService instanceof AuthenticationServiceInterface) {
52 throw new Exception\RuntimeException('No AuthenticationServiceInterface instance provided');
53 }
54 if (!$this->authenticationService->hasIdentity()) {
55 return;
56 }
57 return $this->authenticationService->getIdentity();
58 }
59 }