1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gacela\Framework\Config\GacelaFileConfig; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\Config\GacelaConfigBuilder\SuffixTypesBuilder; |
8
|
|
|
|
9
|
|
|
final class GacelaConfigFile implements GacelaConfigFileInterface |
10
|
|
|
{ |
11
|
|
|
/** @var list<GacelaConfigItem> */ |
12
|
|
|
private array $configItems = []; |
13
|
|
|
|
14
|
|
|
/** @var array<class-string,class-string|callable|object> */ |
15
|
|
|
private array $bindings = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array{ |
19
|
|
|
* Facade:list<string>, |
20
|
|
|
* Factory:list<string>, |
21
|
|
|
* Config:list<string>, |
22
|
|
|
* DependencyProvider:list<string>, |
23
|
|
|
* } |
24
|
|
|
*/ |
25
|
|
|
private array $suffixTypes = SuffixTypesBuilder::DEFAULT_SUFFIX_TYPES; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param list<GacelaConfigItem> $configItems |
29
|
|
|
*/ |
30
|
65 |
|
public function setConfigItems(array $configItems): self |
31
|
|
|
{ |
32
|
65 |
|
$this->configItems = $configItems; |
|
|
|
|
33
|
|
|
|
34
|
65 |
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return list<GacelaConfigItem> |
39
|
|
|
*/ |
40
|
98 |
|
public function getConfigItems(): array |
41
|
|
|
{ |
42
|
98 |
|
return $this->configItems; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param array<class-string,class-string|callable|object> $bindings |
47
|
|
|
*/ |
48
|
64 |
|
public function setBindings(array $bindings): self |
49
|
|
|
{ |
50
|
64 |
|
$this->bindings = $bindings; |
51
|
|
|
|
52
|
64 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Map interfaces to concrete classes or callable (which will be resolved on runtime). |
57
|
|
|
* This is util to inject dependencies to Gacela services (such as Factories, for example) via their constructor. |
58
|
|
|
* |
59
|
|
|
* @return array<class-string,class-string|callable|object> |
60
|
|
|
*/ |
61
|
60 |
|
public function getBindings(): array |
62
|
|
|
{ |
63
|
60 |
|
return $this->bindings; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param array{ |
68
|
|
|
* Facade:list<string>, |
69
|
|
|
* Factory:list<string>, |
70
|
|
|
* Config:list<string>, |
71
|
|
|
* DependencyProvider:list<string>, |
72
|
|
|
* } $suffixTypes |
73
|
|
|
*/ |
74
|
64 |
|
public function setSuffixTypes(array $suffixTypes): self |
75
|
|
|
{ |
76
|
64 |
|
$this->suffixTypes = $suffixTypes; |
77
|
|
|
|
78
|
64 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @psalm-suppress ImplementedReturnTypeMismatch |
83
|
|
|
* |
84
|
|
|
* @return array{ |
85
|
|
|
* Facade:list<string>, |
86
|
|
|
* Factory:list<string>, |
87
|
|
|
* Config:list<string>, |
88
|
|
|
* DependencyProvider:list<string>, |
89
|
|
|
* } |
90
|
|
|
*/ |
91
|
60 |
|
public function getSuffixTypes(): array |
92
|
|
|
{ |
93
|
60 |
|
return $this->suffixTypes; |
94
|
|
|
} |
95
|
|
|
|
96
|
22 |
|
public function combine(GacelaConfigFileInterface $other): GacelaConfigFileInterface |
97
|
|
|
{ |
98
|
22 |
|
$new = clone $this; |
99
|
22 |
|
$new->configItems = array_merge($this->configItems, $other->getConfigItems()); |
|
|
|
|
100
|
22 |
|
$new->bindings = array_merge($this->bindings, $other->getBindings()); |
101
|
22 |
|
$new->suffixTypes = [ |
102
|
22 |
|
'Facade' => $this->filterList($other, 'Facade'), |
103
|
22 |
|
'Factory' => $this->filterList($other, 'Factory'), |
104
|
22 |
|
'Config' => $this->filterList($other, 'Config'), |
105
|
22 |
|
'DependencyProvider' => $this->filterList($other, 'DependencyProvider'), |
106
|
22 |
|
]; |
107
|
|
|
|
108
|
22 |
|
return $new; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return list<string> |
113
|
|
|
*/ |
114
|
22 |
|
private function filterList(GacelaConfigFileInterface $other, string $key): array |
115
|
|
|
{ |
116
|
22 |
|
$merged = array_merge($this->suffixTypes[$key], $other->getSuffixTypes()[$key]); // @phpstan-ignore-line |
117
|
22 |
|
$filtered = array_filter(array_unique($merged)); |
118
|
|
|
/** @var list<string> $values */ |
119
|
22 |
|
$values = array_values($filtered); |
120
|
|
|
|
121
|
22 |
|
return $values; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
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..