BackendInterface.php
1 year ago
BaseSettingsTable.php
2 years ago
Cache.php
2 years ago
Config.php
2 years ago
MeasurableSettingsTable.php
6 months ago
NullBackend.php
2 years ago
PluginSettingsTable.php
1 month ago
SitesTable.php
1 month ago
Config.php
64 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\Settings\Storage\Backend; |
| 10 | |
| 11 | /** |
| 12 | * Backend for an existing site. Stores all settings in the "site" database table. |
| 13 | */ |
| 14 | class Config implements \Piwik\Settings\Storage\Backend\BackendInterface |
| 15 | { |
| 16 | private $section; |
| 17 | public function __construct($section) |
| 18 | { |
| 19 | if (empty($section)) { |
| 20 | throw new \Exception('No section given for config section backend'); |
| 21 | } |
| 22 | $this->section = $section; |
| 23 | } |
| 24 | /** |
| 25 | * @inheritdoc |
| 26 | */ |
| 27 | public function getStorageId() |
| 28 | { |
| 29 | return 'Config_' . $this->section; |
| 30 | } |
| 31 | private function getConfig() |
| 32 | { |
| 33 | return \Piwik\Config::getInstance(); |
| 34 | } |
| 35 | /** |
| 36 | * Saves (persists) the current setting values in the database. |
| 37 | */ |
| 38 | public function save($values) |
| 39 | { |
| 40 | $section = $this->load(); |
| 41 | foreach ($values as $key => $value) { |
| 42 | $section[$key] = $value; |
| 43 | } |
| 44 | $config = $this->getConfig(); |
| 45 | $config->{$this->section} = $section; |
| 46 | $config->forceSave(); |
| 47 | } |
| 48 | public function load() |
| 49 | { |
| 50 | $config = $this->getConfig(); |
| 51 | $section = $config->{$this->section}; |
| 52 | $values = array(); |
| 53 | // remove reference |
| 54 | foreach ($section as $key => $value) { |
| 55 | $values[$key] = $value; |
| 56 | } |
| 57 | return $values; |
| 58 | } |
| 59 | public function delete() |
| 60 | { |
| 61 | $this->getConfig()->{$this->section} = array(); |
| 62 | } |
| 63 | } |
| 64 |