|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Infrastructure; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\Frontend\Factories\EnvironmentDependentConfigReaderFactory; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\Factories\EnvironmentSetup\DevelopmentEnvironmentSetup; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\Factories\EnvironmentSetup\EnvironmentSetup; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\Factories\EnvironmentSetup\EnvironmentSetupException; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\Factories\EnvironmentSetup\ProductionEnvironmentSetup; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
|
13
|
|
|
|
|
14
|
|
|
class EnvironmentBootstrapper { |
|
15
|
|
|
|
|
16
|
|
|
private const DEFAULT_ENVIRONMENT_SETUP_MAP = [ |
|
17
|
|
|
'dev' => DevelopmentEnvironmentSetup::class, |
|
18
|
|
|
// User Acceptance Testing should be as close to production as possible |
|
19
|
|
|
'uat' => ProductionEnvironmentSetup::class, |
|
20
|
|
|
'prod' => ProductionEnvironmentSetup::class |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
private string $environmentName; |
|
24
|
|
|
|
|
25
|
238 |
|
/** |
|
26
|
238 |
|
* @var array<string,class-string> |
|
|
|
|
|
|
27
|
238 |
|
*/ |
|
28
|
238 |
|
private array $environmentMap; |
|
29
|
|
|
|
|
30
|
234 |
|
public function __construct( string $environmentName, array $environmentMap = [] ) { |
|
31
|
234 |
|
$this->environmentName = $environmentName; |
|
32
|
234 |
|
$this->environmentMap = array_merge( self::DEFAULT_ENVIRONMENT_SETUP_MAP, $environmentMap ); |
|
33
|
234 |
|
} |
|
34
|
234 |
|
|
|
35
|
|
|
public function getEnvironmentSetupInstance(): EnvironmentSetup { |
|
36
|
234 |
|
if ( !isset( $this->environmentMap[$this->environmentName] ) ) { |
|
37
|
232 |
|
throw new EnvironmentSetupException( $this->environmentName ); |
|
38
|
|
|
} |
|
39
|
|
|
$class = $this->environmentMap[$this->environmentName]; |
|
40
|
234 |
|
return new $class; |
|
41
|
234 |
|
} |
|
42
|
3 |
|
|
|
43
|
|
|
public function newFunFunFactory(): FunFunFactory { |
|
44
|
234 |
|
$config = $this->getConfiguration(); |
|
45
|
|
|
$factory = new FunFunFactory( $config ); |
|
46
|
|
|
|
|
47
|
234 |
|
$this->getEnvironmentSetupInstance() |
|
48
|
234 |
|
->setEnvironmentDependentInstances( $factory ); |
|
49
|
|
|
|
|
50
|
234 |
|
return $factory; |
|
51
|
2 |
|
} |
|
52
|
|
|
|
|
53
|
234 |
|
protected function getConfiguration(): array { |
|
54
|
234 |
|
$configReader = ( new EnvironmentDependentConfigReaderFactory( $this->environmentName ) )->getConfigReader(); |
|
55
|
|
|
return $configReader->getConfig(); |
|
56
|
232 |
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|