Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ConfigurationStorageSettingsResolver | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| resolve | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Resolves configuration storage settings from database values. |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2026-02-23 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Configuration\Storage; |
| 21 | |
| 22 | readonly class ConfigurationStorageSettingsResolver |
| 23 | { |
| 24 | private const string DEFAULT_REDIS_DSN = 'tcp://redis:6379?database=1'; |
| 25 | private const string DEFAULT_REDIS_PREFIX = 'pmf:config:'; |
| 26 | private const float DEFAULT_CONNECT_TIMEOUT = 1.0; |
| 27 | |
| 28 | public function __construct( |
| 29 | private DatabaseConfigurationStore $databaseConfigurationStore, |
| 30 | ) { |
| 31 | } |
| 32 | |
| 33 | public function resolve(): ConfigurationStorageSettings |
| 34 | { |
| 35 | $enabledValue = strtolower( |
| 36 | $this->databaseConfigurationStore->fetchValue('storage.useRedisForConfiguration') ?? 'false', |
| 37 | ); |
| 38 | $enabled = in_array($enabledValue, ['1', 'true', 'yes', 'on'], strict: true); |
| 39 | |
| 40 | $redisDsn = trim($this->databaseConfigurationStore->fetchValue('storage.redisDsn') ?? ''); |
| 41 | if ($redisDsn === '') { |
| 42 | $redisDsn = self::DEFAULT_REDIS_DSN; |
| 43 | } |
| 44 | |
| 45 | $redisPrefix = $this->databaseConfigurationStore->fetchValue('storage.redisPrefix') ?? ''; |
| 46 | if ($redisPrefix === '') { |
| 47 | $redisPrefix = self::DEFAULT_REDIS_PREFIX; |
| 48 | } |
| 49 | |
| 50 | $connectTimeout = (float) ($this->databaseConfigurationStore->fetchValue('storage.redisConnectTimeout') ?? ''); |
| 51 | if ($connectTimeout <= 0) { |
| 52 | $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT; |
| 53 | } |
| 54 | |
| 55 | return new ConfigurationStorageSettings($enabled, $redisDsn, $redisPrefix, $connectTimeout); |
| 56 | } |
| 57 | } |