| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Settings; |
|
|
| |
| |
| |
| |
| |
| abstract class Settings |
| { |
| |
| |
| |
| |
| |
| private $settings = array(); |
|
|
| protected $pluginName; |
|
|
| |
| |
| |
| |
| |
| protected $title = ''; |
|
|
| public function __construct() |
| { |
| if (!isset($this->pluginName)) { |
| $classname = get_class($this); |
| $parts = explode('\\', $classname); |
|
|
| if (count($parts) >= 3) { |
| $this->pluginName = $parts[2]; |
| } else { |
| throw new \Exception(sprintf('Plugin Settings must have a plugin name specified in %s, could not detect plugin name', $classname)); |
| } |
| } |
| } |
|
|
| public function getTitle() |
| { |
| if (!empty($this->title)) { |
| return $this->title; |
| } |
|
|
| return $this->pluginName; |
| } |
|
|
| |
| |
| |
| public function getPluginName() |
| { |
| return $this->pluginName; |
| } |
|
|
| |
| |
| |
| |
| public function getSetting($name) |
| { |
| if (array_key_exists($name, $this->settings)) { |
| return $this->settings[$name]; |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| |
| |
| abstract protected function init(); |
|
|
| |
| |
| |
| |
| |
| public function getSettingsWritableByCurrentUser() |
| { |
| return array_filter($this->settings, function (Setting $setting) { |
| return $setting->isWritableByCurrentUser(); |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function addSetting(Setting $setting) |
| { |
| $name = $setting->getName(); |
|
|
| if (isset($this->settings[$name])) { |
| throw new \Exception(sprintf('A setting with name "%s" does already exist for plugin "%s"', $name, $this->pluginName)); |
| } |
|
|
| $this->settings[$name] = $setting; |
| } |
|
|
| |
| |
| |
| public function save() |
| { |
| foreach ($this->settings as $setting) { |
| $setting->save(); |
| } |
| } |
| } |
|
|