UsurpationFactory.php 1.12 KB
Newer Older
1
2
3
4
5
6
7
<?php

namespace UnicaenAuth\Authentication\Storage;

use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use Zend\Authentication\Storage\Session;
8
use Zend\Session\SessionManager;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use ZfcUser\Mapper\UserInterface as UserMapper;

class UsurpationFactory
{
    /**
     * @param ContainerInterface $container
     * @param string $requestedName
     * @param array|null $moduleOptions
     * @return Usurpation
     */
    public function __invoke(ContainerInterface $container, string $requestedName, array $moduleOptions = null)
    {
        /** @var UserMapper $mapper */
        $mapper = $container->get('zfcuser_user_mapper');

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

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

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

        return $storage;
    }
}