DbAdapterFactory.php 944 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

namespace UnicaenAuth\Authentication\Adapter;

use Interop\Container\ContainerInterface;
use UnicaenAuth\Options\ModuleOptions;
use Zend\Authentication\Storage\Session;
use Zend\EventManager\EventManagerAwareInterface;

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)
    {
        /** @var ModuleOptions $moduleOptions */
        $moduleOptions = $container->get('unicaen-auth_module_options');

        $adapter = new Db();
        $adapter->setStorage(new Session(Db::class));

        $substitut = $moduleOptions->getDb()['type'] ?? null;
        if ($substitut !== null) {
            $adapter->setType($substitut);
        }

        return $adapter;
    }
}