ConfigGetterTrait.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Settings\Interfaces\Traits\Getters; |
| 10 | |
| 11 | use Piwik\Config; |
| 12 | use Piwik\Settings\Interfaces\ConfigSettingInterface; |
| 13 | /** |
| 14 | * @template T of mixed |
| 15 | * |
| 16 | * @phpstan-require-implements ConfigSettingInterface |
| 17 | */ |
| 18 | trait ConfigGetterTrait |
| 19 | { |
| 20 | /** |
| 21 | * @return T|null |
| 22 | */ |
| 23 | public static function getConfigValue(?int $idSite = null) |
| 24 | { |
| 25 | $configKey = self::getConfigSection(); |
| 26 | if ($idSite !== null) { |
| 27 | $configKey .= '_' . $idSite; |
| 28 | } |
| 29 | $config = Config::getInstance()->{$configKey}; |
| 30 | if (is_null($config) || !array_key_exists(self::getConfigSettingName(), $config)) { |
| 31 | return null; |
| 32 | } |
| 33 | return $config[self::getConfigSettingName()]; |
| 34 | } |
| 35 | protected static abstract function getConfigSection() : string; |
| 36 | protected static abstract function getConfigSettingName() : string; |
| 37 | /** |
| 38 | * @deprecated Will be removed in 6.0 in favour of making getConfigSettingName public |
| 39 | */ |
| 40 | public static function getConfigSettingShortName() : string |
| 41 | { |
| 42 | return self::getConfigSettingName(); |
| 43 | } |
| 44 | } |
| 45 |