ChainServiceFactory.php 1.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace UnicaenAuth\Provider\Identity;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * Description of CcainIdentityProviderServiceFactory
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class ChainServiceFactory implements FactoryInterface
{
    /**
     * Create service
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @return mixed
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
//        $config = $serviceLocator->get('BjyAuthorize\Config');
//        
//        if (!isset($config['identity_provider']) ||
//            'UnicaenAuth\Provider\Identity\Chain' !== $config['identity_provider']) {
//            throw new InvalidArgumentException(
//                'Config for "UnicaenAuth\Provider\Identity\Chain" not set'
//            );
//        }
//        $providers = (array) $config['identity_provider']['UnicaenAuth\Provider\Identity\Chain'];
        
        $providers = array(
            200 => 'UnicaenAuth\Provider\Identity\Db',
            100 => 'UnicaenAuth\Provider\Identity\Ldap',
        );
        
        $chain = new Chain();
        $chain->setServiceLocator($serviceLocator);
        
        foreach ($providers as $priority => $name) {
            $provider = $serviceLocator->get($name);
            $chain->getEventManager()->attach('getIdentityRoles', array($provider, 'getIdentityRoles'), $priority);
        }
        
        return $chain;
    }
}