DbAdapterFactory.php 1.08 KB
Newer Older
1
2
3
4
5
6
<?php

namespace UnicaenAuth\Authentication\Adapter;

use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
7
use Laminas\Authentication\Storage\Session;
8
use ZfcUser\Mapper\UserInterface as UserMapperInterface;
9
10
11
12
13

class DbAdapterFactory
{
    /**
     * @param ContainerInterface $container
14
     * @return Db
15
     */
16
    public function __invoke(ContainerInterface $container): Db
17
    {
18
19
        /** @var UserMapperInterface $userMapper */
        $userMapper = $container->get('zfcuser_user_mapper');
20
21
22

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

25
26
27
28
29
30
        $options = array_merge(
            $container->get('zfcuser_module_options')->toArray(),
            $container->get('unicaen-auth_module_options')->toArray());
        $moduleOptions = new ModuleOptions($options);
        $adapter->setModuleOptions($moduleOptions);

31
32
33
34
35
36
37
38
        $substitut = $moduleOptions->getDb()['type'] ?? null;
        if ($substitut !== null) {
            $adapter->setType($substitut);
        }

        return $adapter;
    }
}