Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
LamiasConfigAggregatorConfig | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__invoke | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | /** |
6 | * This file is part of php-fast-forward/config. |
7 | * |
8 | * This source file is subject to the license bundled |
9 | * with this source code in the file LICENSE. |
10 | * |
11 | * @link https://github.com/php-fast-forward/config |
12 | * @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
13 | * @license https://opensource.org/licenses/MIT MIT License |
14 | */ |
15 | |
16 | namespace FastForward\Config; |
17 | |
18 | use Laminas\ConfigAggregator\ConfigAggregator; |
19 | |
20 | /** |
21 | * Class LamiasConfigAggregatorConfig. |
22 | * |
23 | * Integrates Laminas\ConfigAggregator for collecting configuration data from multiple providers. |
24 | * This class MUST support optional caching of the merged configuration using a defined file path. |
25 | * It SHALL return an ArrayConfig with the aggregated data upon invocation. |
26 | */ |
27 | class LamiasConfigAggregatorConfig implements ConfigInterface |
28 | { |
29 | use LazyLoadConfigTrait; |
30 | |
31 | /** |
32 | * Constructs the configuration aggregator. |
33 | * |
34 | * This constructor SHALL accept a set of configuration providers and an optional cache file path. |
35 | * Providers MUST be iterable and yield valid configuration arrays. |
36 | * |
37 | * @param iterable $providers the configuration providers for aggregation |
38 | * @param null|string $cachedConfigFile the optional path to a cached config file |
39 | */ |
40 | public function __construct( |
41 | private iterable $providers, |
42 | private ?string $cachedConfigFile = null, |
43 | ) {} |
44 | |
45 | /** |
46 | * Aggregates configuration from the provided sources and returns a unified configuration object. |
47 | * |
48 | * If a cached config file is provided and exists, it SHALL be used to hydrate the result. |
49 | * Otherwise, all providers SHALL be executed to merge configurations. |
50 | * |
51 | * @return ConfigInterface the resulting configuration object as an ArrayConfig instance |
52 | */ |
53 | public function __invoke(): ConfigInterface |
54 | { |
55 | $configAggregator = new ConfigAggregator( |
56 | $this->providers, |
57 | $this->cachedConfigFile, |
58 | ); |
59 | |
60 | return new ArrayConfig(config: $configAggregator->getMergedConfig()); |
61 | } |
62 | } |