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

namespace UnicaenAuth\Provider\Role;

5
use BjyAuthorize\Exception\InvalidArgumentException;
6
use Interop\Container\ContainerInterface;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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}
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
22
23
24
25
26
27
        return $this->__invoke($serviceLocator, '?');
    }

    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $config = $container->get('BjyAuthorize\Config');
28
29
30
31
32
33

        if (! isset($config['role_providers']['UnicaenAuth\Provider\Role\Config'])) {
            throw new InvalidArgumentException(
                'Config for "UnicaenAuth\Provider\Role\Config" not set'
            );
        }
34

35
        $providerConfig = $config['role_providers']['UnicaenAuth\Provider\Role\Config'];
36

37
        /* @var $mapper \UnicaenApp\Mapper\Ldap\Group */
38
        $mapper = $container->get('ldap_group_mapper');
39
40
41
42
43
44

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

        return $service;
    }
}