1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Framework\Bootstrap; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\Config\ConfigReaderInterface; |
8
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\ConfigBuilder; |
9
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\MappingInterfacesBuilder; |
10
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\SuffixTypesBuilder; |
11
|
|
|
|
12
|
|
|
final class GacelaConfig |
13
|
|
|
{ |
14
|
|
|
private ConfigBuilder $configBuilder; |
15
|
|
|
|
16
|
|
|
private SuffixTypesBuilder $suffixTypesBuilder; |
17
|
|
|
|
18
|
|
|
private MappingInterfacesBuilder $mappingInterfacesBuilder; |
19
|
|
|
|
20
|
|
|
/** @var array<string,mixed> */ |
21
|
|
|
private array $externalServices; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param array<string,mixed> $externalServices |
25
|
|
|
*/ |
26
|
14 |
|
public function __construct(array $externalServices = []) |
27
|
|
|
{ |
28
|
14 |
|
$this->externalServices = $externalServices; |
29
|
14 |
|
$this->configBuilder = new ConfigBuilder(); |
30
|
14 |
|
$this->suffixTypesBuilder = new SuffixTypesBuilder(); |
31
|
14 |
|
$this->mappingInterfacesBuilder = new MappingInterfacesBuilder(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $path define the path where Gacela will read all the config files |
36
|
|
|
* @param string $pathLocal define the path where Gacela will read the local config file |
37
|
|
|
* @param class-string<ConfigReaderInterface>|ConfigReaderInterface|null $reader Define the reader class which will read and parse the config files |
|
|
|
|
38
|
|
|
*/ |
39
|
5 |
|
public function addAppConfig(string $path, string $pathLocal = '', $reader = null): self |
40
|
|
|
{ |
41
|
5 |
|
$this->configBuilder->add($path, $pathLocal, $reader); |
42
|
|
|
|
43
|
5 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
public function addSuffixTypeFacade(string $suffix): self |
47
|
|
|
{ |
48
|
2 |
|
$this->suffixTypesBuilder->addFacade($suffix); |
49
|
|
|
|
50
|
2 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
public function addSuffixTypeFactory(string $suffix): self |
54
|
|
|
{ |
55
|
2 |
|
$this->suffixTypesBuilder->addFactory($suffix); |
56
|
|
|
|
57
|
2 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
public function addSuffixTypeConfig(string $suffix): self |
61
|
|
|
{ |
62
|
2 |
|
$this->suffixTypesBuilder->addConfig($suffix); |
63
|
|
|
|
64
|
2 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
3 |
|
public function addSuffixTypeDependencyProvider(string $suffix): self |
68
|
|
|
{ |
69
|
3 |
|
$this->suffixTypesBuilder->addDependencyProvider($suffix); |
70
|
|
|
|
71
|
3 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param class-string $key |
|
|
|
|
76
|
|
|
* @param class-string|object|callable $value |
77
|
|
|
*/ |
78
|
9 |
|
public function addMappingInterface(string $key, $value): self |
79
|
|
|
{ |
80
|
9 |
|
$this->mappingInterfacesBuilder->bind($key, $value); |
81
|
|
|
|
82
|
9 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return mixed |
87
|
|
|
*/ |
88
|
4 |
|
public function getExternalService(string $key) |
89
|
|
|
{ |
90
|
4 |
|
return $this->externalServices[$key]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param mixed $value |
95
|
|
|
*/ |
96
|
2 |
|
public function addExternalService(string $key, $value): self |
97
|
|
|
{ |
98
|
2 |
|
$this->externalServices[$key] = $value; |
99
|
|
|
|
100
|
2 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @internal |
105
|
|
|
* |
106
|
|
|
* @return array<string,mixed> |
107
|
|
|
*/ |
108
|
14 |
|
public function getExternalServices(): array |
109
|
|
|
{ |
110
|
14 |
|
return $this->externalServices; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @internal |
115
|
|
|
*/ |
116
|
14 |
|
public function getConfigBuilder(): ConfigBuilder |
117
|
|
|
{ |
118
|
14 |
|
return $this->configBuilder; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @internal |
123
|
|
|
*/ |
124
|
14 |
|
public function getSuffixTypesBuilder(): SuffixTypesBuilder |
125
|
|
|
{ |
126
|
14 |
|
return $this->suffixTypesBuilder; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @internal |
131
|
|
|
*/ |
132
|
14 |
|
public function getMappingInterfacesBuilder(): MappingInterfacesBuilder |
133
|
|
|
{ |
134
|
14 |
|
return $this->mappingInterfacesBuilder; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|