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