UsernameServiceFactory.php 1.16 KB
Newer Older
1
2
3
4
<?php

namespace UnicaenAuth\Provider\Role;

5
use Interop\Container\ContainerInterface;
6
7
8
9
10
11
12
13
14
15
16
17
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * Description of UsernameServiceFactory
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class UsernameServiceFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
18
19
20
21
22
23
        return $this->__invoke($serviceLocator, '?');
    }

    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $config = $container->get('BjyAuthorize\Config');
24
25

        if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\Username'])) {
26
            throw new \InvalidArgumentException(
27
28
29
30
31
                'Config for "UnicaenAuth\Provider\Role\Username" not set'
            );
        }

        $providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\Username'];
32
33
34

        $authService = $container->get('zfcuser_auth_service'); /* @var $authService \Zend\Authentication\AuthenticationService */

35
        return new Username($authService, $providerConfig);
36
37
    }
}