AuthControllerFactory.php 1.72 KB
Newer Older
1
2
3
4
<?php

namespace UnicaenAuth\Controller;

5
use Interop\Container\ContainerInterface;
6
use UnicaenAuth\Form\LoginForm;
7
use UnicaenAuth\Options\ModuleOptions;
8
9
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\User as UserService;
10
use UnicaenAuth\Service\UserContext;
11
use ZfcUser\Controller\RedirectCallback;
12
13
14
15

class AuthControllerFactory
{
    /**
16
     * @param ContainerInterface $container
17
18
     * @return AuthController
     */
19
    public function __invoke(ContainerInterface $container): AuthController
20
21
    {
        /** @var ShibService $shibService */
22
        $shibService = $container->get(ShibService::class);
23
24

        /* @var $userService UserService */
25
        $userService = $container->get('unicaen-auth_user_service');
26

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

30
31
32
33
34
35
        /** @var ModuleOptions $moduleOptions */
        $moduleOptions = $container->get('unicaen-auth_module_options');

        /* @var RedirectCallback $redirectCallback */
        $redirectCallback = $container->get('zfcuser_redirect_callback');

36
37
38
        $controller = new AuthController();
        $controller->setShibService($shibService);
        $controller->setUserService($userService);
39
        $controller->setServiceUserContext($userContextService);
40
41
42
        $controller->setModuleOptions($moduleOptions);
        $controller->setRedirectCallback($redirectCallback);

43
44
45
46
47
48
        $authTypesConfig = $moduleOptions->getEnabledAuthTypes();
        foreach ($authTypesConfig as $type => $config) {
            /** @var LoginForm $loginForm */
            $loginForm = $container->get($config['form']);
            $controller->addLoginForm($loginForm);
        }
49

50
51
52
        return $controller;
    }
}