DbAdapterFactory.php 1.33 KB
Newer Older
1
2
3
4
5
6
7
8
<?php

namespace UnicaenAuth\Authentication\Adapter;

use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use Zend\Authentication\Storage\Session;
use Zend\EventManager\EventManagerAwareInterface;
9
use ZfcUser\Mapper\UserInterface as UserMapperInterface;
10
11
12
13
14
15
16
17
18
19
20

class DbAdapterFactory
{
    /**
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param array|null $options
     * @return mixed|Cas|Db|Ldap|EventManagerAwareInterface
     */
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null)
    {
21
22
        /** @var UserMapperInterface $userMapper */
        $userMapper = $container->get('zfcuser_user_mapper');
23
24
25

        $adapter = new Db();
        $adapter->setStorage(new Session(Db::class));
26
        $adapter->setMapper($userMapper);
27

28
29
30
31
32
        $options = array_merge(
            $container->get('zfcuser_module_options')->toArray(),
            $container->get('unicaen-auth_module_options')->toArray());
        $moduleOptions = new ModuleOptions($options);
        $adapter->setModuleOptions($moduleOptions);
33
        $adapter->setOptions($moduleOptions);
34

35
36
37
38
39
40
41
42
        $substitut = $moduleOptions->getDb()['type'] ?? null;
        if ($substitut !== null) {
            $adapter->setType($substitut);
        }

        return $adapter;
    }
}