RoleServiceFactory.php 860 Bytes
Newer Older
Bertrand Gauthier's avatar
Bertrand Gauthier committed
1
2
3
4
<?php

namespace UnicaenAuth\Service;

5
use Interop\Container\ContainerInterface;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
6
use UnicaenAuth\Entity\Db\Role;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
7
8
9
10
11
12
13
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class RoleServiceFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
14
15
16
17
18
19
        return $this->__invoke($serviceLocator, '?');
    }

    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $config = $container->get('Config');
Bertrand Gauthier's avatar
Bertrand Gauthier committed
20

Bertrand Gauthier's avatar
Bertrand Gauthier committed
21
        if (! isset($config['unicaen-auth']['role_entity_class'])) {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
22
            $config['unicaen-auth']['role_entity_class'] = Role::class;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
23
24
25
26
27
28
29
30
        }

        $service = new RoleService();
        $service->setRoleEntityClass($config['unicaen-auth']['role_entity_class']);

        return $service;
    }
}