PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Settings / Settings.php
matomo / app / core / Settings Last commit date
FieldConfig 2 years ago Measurable 2 years ago Plugin 2 years ago Storage 2 years ago FieldConfig.php 2 years ago Setting.php 2 years ago Settings.php 2 years ago
Settings.php
110 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Settings;
11
12 /**
13 * Base class of all settings providers.
14 *
15 * @api
16 */
17 abstract class Settings
18 {
19 /**
20 * An array containing all available settings: Array ( [setting-name] => [setting] )
21 *
22 * @var Setting[]
23 */
24 private $settings = array();
25 protected $pluginName;
26 /**
27 * By default the plugin name is shown in the UI when managing plugin settings. However, you can overwrite
28 * the displayed title by specifying a title.
29 * @var string
30 */
31 protected $title = '';
32 public function __construct()
33 {
34 if (!isset($this->pluginName)) {
35 $classname = get_class($this);
36 $parts = explode('\\', $classname);
37 if (count($parts) >= 3) {
38 $this->pluginName = $parts[2];
39 } else {
40 throw new \Exception(sprintf('Plugin Settings must have a plugin name specified in %s, could not detect plugin name', $classname));
41 }
42 }
43 }
44 public function getTitle()
45 {
46 if (!empty($this->title)) {
47 return $this->title;
48 }
49 return $this->pluginName;
50 }
51 /**
52 * @ignore
53 */
54 public function getPluginName()
55 {
56 return $this->pluginName;
57 }
58 /**
59 * @ignore
60 * @return Setting
61 */
62 public function getSetting($name)
63 {
64 if (array_key_exists($name, $this->settings)) {
65 return $this->settings[$name];
66 }
67 }
68 /**
69 * Implemented by descendants. This method should define plugin settings (via the
70 * {@link addSetting()}) method and set the introduction text (via the
71 * {@link setIntroduction()}).
72 */
73 protected abstract function init();
74 /**
75 * Returns the settings that can be displayed for the current user.
76 *
77 * @return Setting[]
78 */
79 public function getSettingsWritableByCurrentUser()
80 {
81 return array_filter($this->settings, function (\Piwik\Settings\Setting $setting) {
82 return $setting->isWritableByCurrentUser();
83 });
84 }
85 /**
86 * Adds a new setting to the settings container.
87 *
88 * @param Setting $setting
89 * @throws \Exception If there is a setting with the same name that already exists.
90 * If the name contains non-alphanumeric characters.
91 */
92 public function addSetting(\Piwik\Settings\Setting $setting)
93 {
94 $name = $setting->getName();
95 if (isset($this->settings[$name])) {
96 throw new \Exception(sprintf('A setting with name "%s" does already exist for plugin "%s"', $name, $this->pluginName));
97 }
98 $this->settings[$name] = $setting;
99 }
100 /**
101 * Saves (persists) the current setting values in the database.
102 */
103 public function save()
104 {
105 foreach ($this->settings as $setting) {
106 $setting->save();
107 }
108 }
109 }
110