ChainServiceFactory.php 1.03 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
<?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)
    {
        $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);
Bertrand Gauthier's avatar
Bertrand Gauthier committed
32
            $chain->getEventManager()->attach('getIdentityRoles', array($provider, 'getIdentityRolesTrigger'), $priority);
33
34
35
36
37
        }
        
        return $chain;
    }
}