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