|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gacela\Framework\Config\GacelaFileConfig; |
|
6
|
|
|
|
|
7
|
|
|
use Gacela\Framework\Config\ConfigReader\PhpConfigReader; |
|
8
|
|
|
use Gacela\Framework\Config\ConfigReaderInterface; |
|
9
|
|
|
|
|
10
|
|
|
final class GacelaConfigFile |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var list<GacelaConfigItem> */ |
|
13
|
|
|
private array $configItems = []; |
|
14
|
|
|
|
|
15
|
|
|
/** @var array<class-string,class-string|callable> */ |
|
16
|
|
|
private array $mappingInterfaces = []; |
|
17
|
|
|
|
|
18
|
|
|
/** @var array<string,ConfigReaderInterface> */ |
|
19
|
|
|
private array $configReaders = []; |
|
20
|
|
|
|
|
21
|
|
|
/** @var list<string> Namespaces relative to a module */ |
|
22
|
|
|
private array $customServicesLocation = []; |
|
23
|
|
|
|
|
24
|
30 |
|
public static function withDefaults(): self |
|
25
|
|
|
{ |
|
26
|
30 |
|
return (new self()) |
|
27
|
30 |
|
->setConfigItems([GacelaConfigItem::withDefaults()]) |
|
28
|
30 |
|
->setConfigReaders(['php' => new PhpConfigReader()]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param list<GacelaConfigItem> $configItems |
|
33
|
|
|
*/ |
|
34
|
32 |
|
public function setConfigItems(array $configItems): self |
|
35
|
|
|
{ |
|
36
|
32 |
|
$this->configItems = $configItems; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
32 |
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return list<GacelaConfigItem> |
|
43
|
|
|
*/ |
|
44
|
32 |
|
public function getConfigItems(): array |
|
45
|
|
|
{ |
|
46
|
32 |
|
return $this->configItems; |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param array<string,ConfigReaderInterface> $configReaders |
|
51
|
|
|
*/ |
|
52
|
32 |
|
public function setConfigReaders(array $configReaders): self |
|
53
|
|
|
{ |
|
54
|
32 |
|
$this->configReaders = $configReaders; |
|
55
|
|
|
|
|
56
|
32 |
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return array<string,ConfigReaderInterface> |
|
61
|
|
|
*/ |
|
62
|
32 |
|
public function getConfigReaders(): array |
|
63
|
|
|
{ |
|
64
|
32 |
|
return $this->configReaders; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param array<class-string,class-string|callable> $mappingInterfaces |
|
69
|
|
|
*/ |
|
70
|
6 |
|
public function setMappingInterfaces(array $mappingInterfaces): self |
|
71
|
|
|
{ |
|
72
|
6 |
|
$this->mappingInterfaces = $mappingInterfaces; |
|
73
|
|
|
|
|
74
|
6 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Map interfaces to concrete classes or callable (which will be resolved on runtime). |
|
79
|
|
|
* This is util to inject dependencies to Gacela services (such as Factories, for example) via their constructor. |
|
80
|
|
|
* |
|
81
|
|
|
* @return mixed |
|
82
|
|
|
*/ |
|
83
|
2 |
|
public function getMappingInterface(string $key) |
|
84
|
|
|
{ |
|
85
|
2 |
|
return $this->mappingInterfaces[$key] ?? null; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param list<string> $customServicesLocation |
|
90
|
|
|
*/ |
|
91
|
3 |
|
public function setCustomServicesLocation(array $customServicesLocation): self |
|
92
|
|
|
{ |
|
93
|
3 |
|
$this->customServicesLocation = $customServicesLocation; |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
3 |
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return list<string> |
|
100
|
|
|
*/ |
|
101
|
18 |
|
public function getCustomServicesLocation(): array |
|
102
|
|
|
{ |
|
103
|
18 |
|
return $this->customServicesLocation; |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..