EnvironmentValidator.php
1 year ago
GlobalSettingsProvider.php
2 years ago
PluginList.php
1 month ago
GlobalSettingsProvider.php
98 lines
| 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\Application\Kernel; |
| 10 | |
| 11 | use Piwik\Config; |
| 12 | use Piwik\Config\IniFileChain; |
| 13 | /** |
| 14 | * Provides global settings. Global settings are organized in sections where |
| 15 | * each section contains a list of name => value pairs. Setting values can |
| 16 | * be primitive values or arrays of primitive values. |
| 17 | * |
| 18 | * Uses the config.ini.php, common.ini.php and global.ini.php files to provide global settings. |
| 19 | * |
| 20 | * At the moment a singleton instance of this class is used in order to get tests to pass. |
| 21 | */ |
| 22 | class GlobalSettingsProvider |
| 23 | { |
| 24 | /** |
| 25 | * @var IniFileChain |
| 26 | */ |
| 27 | protected $iniFileChain; |
| 28 | /** |
| 29 | * @var string |
| 30 | */ |
| 31 | protected $pathGlobal = null; |
| 32 | /** |
| 33 | * @var string |
| 34 | */ |
| 35 | protected $pathCommon = null; |
| 36 | /** |
| 37 | * @var string |
| 38 | */ |
| 39 | protected $pathLocal = null; |
| 40 | /** |
| 41 | * @param string|null $pathGlobal Path to the global.ini.php file. Or null to use the default. |
| 42 | * @param string|null $pathLocal Path to the config.ini.php file. Or null to use the default. |
| 43 | * @param string|null $pathCommon Path to the common.ini.php file. Or null to use the default. |
| 44 | */ |
| 45 | public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null) |
| 46 | { |
| 47 | $this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath(); |
| 48 | $this->pathCommon = $pathCommon ?: Config::getCommonConfigPath(); |
| 49 | $this->pathLocal = $pathLocal ?: Config::getLocalConfigPath(); |
| 50 | $this->iniFileChain = new IniFileChain(); |
| 51 | $this->reload(); |
| 52 | } |
| 53 | public function reload($pathGlobal = null, $pathLocal = null, $pathCommon = null) |
| 54 | { |
| 55 | $this->pathGlobal = $pathGlobal ?: $this->pathGlobal; |
| 56 | $this->pathCommon = $pathCommon ?: $this->pathCommon; |
| 57 | $this->pathLocal = $pathLocal ?: $this->pathLocal; |
| 58 | $this->iniFileChain->reload(array($this->pathGlobal, $this->pathCommon), $this->pathLocal); |
| 59 | } |
| 60 | /** |
| 61 | * Returns a settings section. |
| 62 | * |
| 63 | * @param string $name |
| 64 | * @return array |
| 65 | */ |
| 66 | public function &getSection($name) |
| 67 | { |
| 68 | $section =& $this->iniFileChain->get($name); |
| 69 | return $section; |
| 70 | } |
| 71 | /** |
| 72 | * Sets a settings section. |
| 73 | * |
| 74 | * @param string $name |
| 75 | * @param array $value |
| 76 | */ |
| 77 | public function setSection($name, $value) |
| 78 | { |
| 79 | $this->iniFileChain->set($name, $value); |
| 80 | } |
| 81 | public function getIniFileChain() |
| 82 | { |
| 83 | return $this->iniFileChain; |
| 84 | } |
| 85 | public function getPathGlobal() |
| 86 | { |
| 87 | return $this->pathGlobal; |
| 88 | } |
| 89 | public function getPathLocal() |
| 90 | { |
| 91 | return $this->pathLocal; |
| 92 | } |
| 93 | public function getPathCommon() |
| 94 | { |
| 95 | return $this->pathCommon; |
| 96 | } |
| 97 | } |
| 98 |