1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Providers; |
4
|
|
|
|
5
|
|
|
use App\Src\UseCases\Domain\Ports\InvitationRepository; |
6
|
|
|
use App\Src\UseCases\Domain\Ports\OrganizationRepository; |
7
|
|
|
use App\Src\UseCases\Domain\Ports\UserRepository; |
8
|
|
|
use App\Src\UseCases\Infra\Gateway\Auth\AuthGateway; |
9
|
|
|
use App\Src\UseCases\Infra\Gateway\Auth\InMemoryAuthGateway; |
10
|
|
|
use App\Src\UseCases\Infra\Gateway\Auth\SessionAuthGateway; |
11
|
|
|
use App\Src\UseCases\Infra\Gateway\Auth\SocialiteGateway; |
12
|
|
|
use App\Src\UseCases\Infra\Gateway\FileStorage; |
13
|
|
|
use App\Src\UseCases\Infra\Gateway\InMemory\InMemorySocialiteGateway; |
14
|
|
|
use App\Src\UseCases\Infra\Gateway\InMemoryFileStorage; |
15
|
|
|
use App\Src\UseCases\Infra\Gateway\InMemoryPictureHandler; |
16
|
|
|
use App\Src\UseCases\Infra\Gateway\PictureHandler; |
17
|
|
|
use App\Src\UseCases\Infra\Gateway\Real\FsFileStorage; |
18
|
|
|
use App\Src\UseCases\Infra\Gateway\Real\RealSocialiteGateway; |
19
|
|
|
use App\Src\UseCases\Infra\Gateway\StoragePictureHandler; |
20
|
|
|
use App\Src\UseCases\Infra\InMemory\InMemoryInvitationRepository; |
21
|
|
|
use App\Src\UseCases\Infra\InMemory\InMemoryOrganizationRepository; |
22
|
|
|
use App\Src\UseCases\Infra\InMemory\InMemoryUserRepository; |
23
|
|
|
use App\Src\UseCases\Infra\Sql\InvitationRepositorySql; |
24
|
|
|
use App\Src\UseCases\Infra\Sql\SqlOrganizationRepository; |
25
|
|
|
use App\Src\UseCases\Infra\Sql\UserRepositorySql; |
26
|
|
|
use App\Src\Utils\Hash\HashGen; |
27
|
|
|
use App\Src\Utils\Hash\HashGenReal; |
28
|
|
|
use App\Src\Utils\Hash\InMemoryHashGen; |
29
|
|
|
use Illuminate\Support\ServiceProvider; |
30
|
|
|
|
31
|
|
|
class AppServiceProvider extends ServiceProvider |
32
|
|
|
{ |
33
|
|
|
public function register() |
34
|
|
|
{ |
35
|
|
|
$this->registerHelpers(); |
36
|
|
|
|
37
|
|
|
if(config('app.env') === 'testing'){ |
38
|
|
|
$this->tuBinding(); |
39
|
|
|
} |
40
|
|
|
if(config('app.env') === 'testing-ti'){ |
41
|
|
|
$this->tiBinding(); |
42
|
|
|
} |
43
|
|
|
if(config('app.env') === 'local' || config('app.env') === 'production'){ |
44
|
|
|
$this->prodBinding(); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function boot() |
49
|
|
|
{ |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function registerHelpers(): void |
53
|
|
|
{ |
54
|
|
|
foreach (glob(app_path() . '/Src/Utils/Helpers/*.php') as $filename) { |
55
|
|
|
require_once($filename); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function prodBinding(): void |
60
|
|
|
{ |
61
|
|
|
$this->app->singleton(OrganizationRepository::class, SqlOrganizationRepository::class); |
62
|
|
|
$this->app->singleton(InvitationRepository::class, InvitationRepositorySql::class); |
63
|
|
|
$this->app->singleton(PictureHandler::class, StoragePictureHandler::class); |
64
|
|
|
$this->app->singleton(UserRepository::class, UserRepositorySql::class); |
65
|
|
|
$this->app->singleton(AuthGateway::class, SessionAuthGateway::class); |
66
|
|
|
$this->app->singleton(FileStorage::class, FsFileStorage::class); |
67
|
|
|
$this->app->singleton(SocialiteGateway::class, RealSocialiteGateway::class); |
68
|
|
|
$this->app->singleton(HashGen::class, HashGenReal::class); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function tuBinding(): void |
72
|
|
|
{ |
73
|
|
|
$this->app->singleton(OrganizationRepository::class, InMemoryOrganizationRepository::class); |
74
|
|
|
$this->app->singleton(PictureHandler::class, InMemoryPictureHandler::class); |
75
|
|
|
$this->app->singleton(UserRepository::class, InMemoryUserRepository::class); |
76
|
|
|
$this->app->singleton(FileStorage::class, InMemoryFileStorage::class); |
77
|
|
|
$this->app->singleton(AuthGateway::class, InMemoryAuthGateway::class); |
78
|
|
|
$this->app->singleton(SocialiteGateway::class, InMemorySocialiteGateway::class); |
79
|
|
|
$this->app->singleton(HashGen::class, InMemoryHashGen::class); |
80
|
|
|
$this->app->singleton(InvitationRepository::class, InMemoryInvitationRepository::class); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function tiBinding(): void |
84
|
|
|
{ |
85
|
|
|
$this->app->singleton(OrganizationRepository::class, SqlOrganizationRepository::class); |
86
|
|
|
$this->app->singleton(InvitationRepository::class, InMemoryInvitationRepository::class); |
87
|
|
|
$this->app->singleton(PictureHandler::class, InMemoryPictureHandler::class); |
88
|
|
|
$this->app->singleton(UserRepository::class, InMemoryUserRepository::class); |
89
|
|
|
$this->app->singleton(AuthGateway::class, InMemoryAuthGateway::class); |
90
|
|
|
$this->app->singleton(FileStorage::class, InMemoryFileStorage::class); |
91
|
|
|
$this->app->singleton(HashGen::class, InMemoryHashGen::class); |
92
|
|
|
$this->app->singleton(SocialiteGateway::class, InMemorySocialiteGateway::class); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|