ConfigServiceFactory.php 1.14 KB
Newer Older
1
2
3
4
<?php

namespace UnicaenAuth\Provider\Role;

5
use BjyAuthorize\Exception\InvalidArgumentException;
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
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * Factory responsible of instantiating {@see \UnicaenAuth\Provider\Role\Config}
 *
 * @author Marco Pivetta <ocramius@gmail.com>
 */
class ConfigServiceFactory implements FactoryInterface
{
    /**
     * {@inheritDoc}
     *
     * @return \BjyAuthorize\Provider\Role\Config
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('BjyAuthorize\Config');

        if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\Config'])) {
            throw new InvalidArgumentException(
                'Config for "UnicaenAuth\Provider\Role\Config" not set'
            );
        }
        
        $providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\Config'];
        
        /* @var $mapper \UnicaenApp\Mapper\Ldap\Group */
        $mapper = $serviceLocator->get('ldap_group_mapper');

        $service = new Config($mapper, $providerConfig);

        return $service;
    }
}