Total Complexity | 21 |
Total Lines | 170 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class SetupGacela extends AbstractSetupGacela |
||
13 | { |
||
14 | /** @var ?callable(ConfigBuilder):void */ |
||
15 | private $configFn = null; |
||
16 | |||
17 | /** @var ?callable(MappingInterfacesBuilder,array<string,mixed>):void */ |
||
18 | private $mappingInterfacesFn = null; |
||
19 | |||
20 | /** @var ?callable(SuffixTypesBuilder):void */ |
||
21 | private $suffixTypesFn = null; |
||
22 | |||
23 | /** @var array<string,class-string|object|callable> */ |
||
1 ignored issue
–
show
|
|||
24 | private array $externalServices = []; |
||
25 | |||
26 | private ?ConfigBuilder $configBuilder = null; |
||
27 | |||
28 | private ?SuffixTypesBuilder $suffixTypesBuilder = null; |
||
29 | |||
30 | private ?MappingInterfacesBuilder $mappingInterfacesBuilder = null; |
||
31 | |||
32 | private bool $resetCache = false; |
||
33 | |||
34 | /** |
||
35 | * @param Closure(GacelaConfig):void $setupGacelaFileFn |
||
36 | */ |
||
37 | 18 | public static function fromCallable(Closure $setupGacelaFileFn): self |
|
38 | { |
||
39 | 18 | $gacelaConfig = new GacelaConfig(); |
|
40 | 18 | $setupGacelaFileFn($gacelaConfig); |
|
41 | |||
42 | 18 | return self::fromGacelaConfig($gacelaConfig); |
|
43 | } |
||
44 | |||
45 | 31 | public static function fromGacelaConfig(GacelaConfig $gacelaConfig): self |
|
46 | { |
||
47 | 31 | $build = $gacelaConfig->build(); |
|
48 | |||
49 | 31 | return (new self()) |
|
50 | 31 | ->setConfigBuilder($build['config-builder']) |
|
51 | 31 | ->setSuffixTypesBuilder($build['suffix-types-builder']) |
|
52 | 31 | ->setMappingInterfacesBuilder($build['mapping-interfaces-builder']) |
|
53 | 31 | ->setExternalServices($build['external-services']) |
|
54 | 31 | ->setResetCache($build['reset-cache']); |
|
55 | } |
||
56 | |||
57 | 31 | public function setMappingInterfacesBuilder(MappingInterfacesBuilder $builder): self |
|
58 | { |
||
59 | 31 | $this->mappingInterfacesBuilder = $builder; |
|
60 | |||
61 | 31 | return $this; |
|
62 | } |
||
63 | |||
64 | 31 | public function setSuffixTypesBuilder(SuffixTypesBuilder $builder): self |
|
69 | } |
||
70 | |||
71 | 31 | public function setConfigBuilder(ConfigBuilder $builder): self |
|
72 | { |
||
73 | 31 | $this->configBuilder = $builder; |
|
74 | |||
75 | 31 | return $this; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param callable(ConfigBuilder):void $callable |
||
80 | */ |
||
81 | 3 | public function setConfigFn(callable $callable): self |
|
82 | { |
||
83 | 3 | $this->configFn = $callable; |
|
84 | |||
85 | 3 | return $this; |
|
86 | } |
||
87 | |||
88 | 49 | public function buildConfig(ConfigBuilder $configBuilder): ConfigBuilder |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param callable(MappingInterfacesBuilder,array<string,mixed>):void $callable |
||
101 | */ |
||
102 | 3 | public function setMappingInterfacesFn(callable $callable): self |
|
103 | { |
||
104 | 3 | $this->mappingInterfacesFn = $callable; |
|
105 | |||
106 | 3 | return $this; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * Define the mapping between interfaces and concretions, so Gacela services will auto-resolve them automatically. |
||
111 | * |
||
112 | * @param array<string,class-string|object|callable> $externalServices |
||
1 ignored issue
–
show
|
|||
113 | */ |
||
114 | 49 | public function buildMappingInterfaces( |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * @param callable(SuffixTypesBuilder):void $callable |
||
132 | */ |
||
133 | 6 | public function setSuffixTypesFn(callable $callable): self |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Allow overriding gacela resolvable types. |
||
142 | */ |
||
143 | 49 | public function buildSuffixTypes(SuffixTypesBuilder $suffixTypesBuilder): SuffixTypesBuilder |
|
144 | { |
||
145 | 49 | if ($this->suffixTypesBuilder) { |
|
146 | 31 | $suffixTypesBuilder = $this->suffixTypesBuilder; |
|
147 | } |
||
148 | |||
149 | 49 | $this->suffixTypesFn && ($this->suffixTypesFn)($suffixTypesBuilder); |
|
150 | |||
151 | 49 | return $suffixTypesBuilder; |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * @param array<string,class-string|object|callable> $array |
||
1 ignored issue
–
show
|
|||
156 | */ |
||
157 | 34 | public function setExternalServices(array $array): self |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * @return array<string,class-string|object|callable> |
||
1 ignored issue
–
show
|
|||
166 | */ |
||
167 | 13 | public function externalServices(): array |
|
170 | } |
||
171 | |||
172 | 31 | public function setResetCache(bool $flag): self |
|
177 | } |
||
178 | |||
179 | 34 | public function isResetCache(): bool |
|
184 |