ChainServiceFactory.php 1.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
namespace UnicaenAuth\Authentication\Storage;

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

/**
 * Description of ChainAuthenticationStorageServiceFactory
 *
 * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
 */
class ChainServiceFactory implements FactoryInterface
{
    /**
     * Create service
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @return mixed
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
22
        $storages = [
23
24
            200 => 'UnicaenAuth\Authentication\Storage\Ldap',
            100 => 'UnicaenAuth\Authentication\Storage\Db',
25
26
        ];

27
        $chain = new Chain();
28

29
30
        foreach ($storages as $priority => $name) {
            $storage = $serviceLocator->get($name);
31
32
33
            $chain->getEventManager()->attach('read', [$storage, 'read'], $priority);
            $chain->getEventManager()->attach('write', [$storage, 'write'], $priority);
            $chain->getEventManager()->attach('clear', [$storage, 'clear'], $priority);
34
        }
35

36
37
38
        return $chain;
    }
}