PrivilegeServiceFactory.php 1 KB
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\Privilege;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
7
8
9
10
11
12
13
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class PrivilegeServiceFactory 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']['privilege_entity_class'])) {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
22
23
//            throw new InvalidArgumentException("La classe de l'entité privilège n'a pas été trouvée dans la config");
            $config['unicaen-auth']['privilege_entity_class'] = Privilege::class;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
24
25
26
27
28
29
30
31
        }

        $service = new PrivilegeService();
        $service->setPrivilegeEntityClass($config['unicaen-auth']['privilege_entity_class']);

        return $service;
    }
}