DbFactory.php 1.15 KB
Newer Older
1
2
3
4
5
<?php

namespace UnicaenAuth\Authentication\Storage;

use Interop\Container\ContainerInterface;
6
7
8
use UnicaenAuth\Authentication\Adapter\Db as DbAdapter;
use UnicaenAuth\Options\ModuleOptions;
use Zend\Authentication\Storage\Session;
9
use Zend\Session\SessionManager;
10
11
use ZfcUser\Mapper\UserInterface as UserMapper;

12
class DbFactory
13
{
14
15
16
17
18
19
20
    /**
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param array|null $moduleOptions
     * @return Db
     */
    public function __invoke(ContainerInterface $container, string $requestedName, array $moduleOptions = null)
21
22
23
24
    {
        /** @var UserMapper $mapper */
        $mapper = $container->get('zfcuser_user_mapper');

25
26
27
        /** @var ModuleOptions $moduleOptions */
        $moduleOptions = $container->get('unicaen-auth_module_options');

28
29
30
        /** @var SessionManager $sessionManager */
        $sessionManager = $container->get(SessionManager::class);

31
        $storage = new Db();
32
        $storage->setStorage(new Session(DbAdapter::class, null, $sessionManager));
33
        $storage->setMapper($mapper);
34
        $storage->setModuleOptions($moduleOptions);
35
36
37
38

        return $storage;
    }
}