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