DbServiceFactory.php 1.39 KB
Newer Older
1
2
3
4
<?php

namespace UnicaenAuth\Provider\Identity;

5
use Interop\Container\ContainerInterface;
6
7
use UnicaenApp\Options\ModuleOptions;
use Zend\Ldap\Ldap;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * Db identity provider factory
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
 */
class DbServiceFactory implements FactoryInterface
{
    /**
     * {@inheritDoc}
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
23
24
25
26
27
28
        return $this->__invoke($serviceLocator, '?');
    }

    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $user             = $container->get('zfcuser_user_service');
29
30
        $identityProvider = new Db($user->getAuthService());

31
        $unicaenAppOptions = $container->get('unicaen-app_module_options');
32
33
34
35
        /* @var $unicaenAppOptions ModuleOptions */

        $ldap = new Ldap($unicaenAppOptions->getLdap()['connection']['default']['params']);
        $identityProvider->setLdap($ldap);
36

37
        $identityProvider->setServiceRole($container->get('UnicaenAuth\Service\Role'));
38

39
        $config            = $container->get('BjyAuthorize\Config');
40
41
42
43
44
45
        $identityProvider->setDefaultRole($config['default_role']);
        $identityProvider->setAuthenticatedRole($config['authenticated_role']);

        return $identityProvider;
    }
}