Commit | Line | Data |
---|---|---|
44d399bc S |
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\Service; | |
11 | ||
12 | use Interop\Container\ContainerInterface; | |
13 | use Zend\Authentication\AuthenticationService; | |
14 | use Zend\Mvc\Controller\Plugin\Identity; | |
15 | use Zend\ServiceManager\FactoryInterface; | |
16 | use Zend\ServiceManager\ServiceLocatorInterface; | |
17 | ||
18 | class IdentityFactory implements FactoryInterface | |
19 | { | |
20 | /** | |
21 | * {@inheritDoc} | |
22 | * | |
23 | * @return Identity | |
24 | */ | |
25 | public function __invoke(ContainerInterface $container, $name, array $options = null) | |
26 | { | |
27 | $helper = new Identity(); | |
28 | if ($container->has(AuthenticationService::class)) { | |
29 | $helper->setAuthenticationService($container->get(AuthenticationService::class)); | |
30 | } | |
31 | return $helper; | |
32 | } | |
33 | ||
34 | /** | |
35 | * Create and return Identity instance | |
36 | * | |
37 | * For use with zend-servicemanager v2; proxies to __invoke(). | |
38 | * | |
39 | * @param ServiceLocatorInterface $container | |
40 | * @return Identity | |
41 | */ | |
42 | public function createService(ServiceLocatorInterface $container) | |
43 | { | |
44 | // Retrieve the parent container when under zend-servicemanager v2 | |
45 | if (! method_exists($container, 'configure')) { | |
46 | $container = $container->getServiceLocator() ?: $container; | |
47 | } | |
48 | ||
49 | return $this($container, Identity::class); | |
50 | } | |
51 | } |