File size: 2,558 Bytes
cf14c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

declare(strict_types=1);

namespace User\Infrastructure;

use Application;
use Easy\Container\Attributes\Inject;
use Override;
use Shared\Infrastructure\BootstrapperInterface;
use User\Domain\Repositories\UserRepositoryInterface;
use User\Infrastructure\Repositories\DoctrineOrm\UserRepository;
use User\Infrastructure\SSO\IdentityProviderFactory;
use User\Infrastructure\SSO\IdentityProviderFactoryInterface;
use User\Infrastructure\SSO\IdentityProviders\FacebookIdentityProvider;
use User\Infrastructure\SSO\IdentityProviders\GithubIdentityProvider;
use User\Infrastructure\SSO\IdentityProviders\GoogleIdentityProvider;
use User\Infrastructure\SSO\IdentityProviders\LinkedInIdentityProvider;

class UserModuleBootstrapper implements BootstrapperInterface
{
    public function __construct(
        private Application $app,
        private IdentityProviderFactory $factory,

        #[Inject('option.google.is_sso_enabled')]
        private bool $isGoogleSSOEnabled = false,

        #[Inject('option.facebook.is_sso_enabled')]
        private bool $isFacebookSSOEnabled = false,

        #[Inject('option.linkedin.is_sso_enabled')]
        private bool $isLinkedInSSOEnabled = false,

        #[Inject('option.github.is_sso_enabled')]
        private bool $isGithubSSOEnabled = false,
    ) {
    }

    #[Override]
    public function bootstrap(): void
    {
        // Register repository implementations
        $this->app->set(
            UserRepositoryInterface::class,
            UserRepository::class
        );

        $this->registerIdentityProviderFactory();
    }

    private function registerIdentityProviderFactory(): void
    {
        if ($this->isGoogleSSOEnabled) {
            $this->factory
                ->register(
                    'google',
                    GoogleIdentityProvider::class
                );
        }

        if ($this->isFacebookSSOEnabled) {
            $this->factory
                ->register(
                    'facebook',
                    FacebookIdentityProvider::class
                );
        }

        if ($this->isLinkedInSSOEnabled) {
            $this->factory->register(
                'linkedin',
                LinkedInIdentityProvider::class
            );
        }

        if ($this->isGithubSSOEnabled) {
            $this->factory->register(
                'github',
                GithubIdentityProvider::class
            );
        }

        $this->app->set(
            IdentityProviderFactoryInterface::class,
            $this->factory
        );
    }
}