PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
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 6 years ago Measurable 6 years ago Plugin 6 years ago Storage 6 years ago FieldConfig.php 6 years ago Setting.php 6 years ago Settings.php 6 years ago
Settings.php
124 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\Settings;
10
11 /**
12 * Base class of all settings providers.
13 *
14 * @api
15 */
16 abstract class Settings
17 {
18 /**
19 * An array containing all available settings: Array ( [setting-name] => [setting] )
20 *
21 * @var Setting[]
22 */
23 private $settings = array();
24
25 protected $pluginName;
26
27 /**
28 * By default the plugin name is shown in the UI when managing plugin settings. However, you can overwrite
29 * the displayed title by specifying a title.
30 * @var string
31 */
32 protected $title = '';
33
34 public function __construct()
35 {
36 if (!isset($this->pluginName)) {
37 $classname = get_class($this);
38 $parts = explode('\\', $classname);
39
40 if (count($parts) >= 3) {
41 $this->pluginName = $parts[2];
42 } else {
43 throw new \Exception(sprintf('Plugin Settings must have a plugin name specified in %s, could not detect plugin name', $classname));
44 }
45 }
46 }
47
48 public function getTitle()
49 {
50 if (!empty($this->title)) {
51 return $this->title;
52 }
53
54 return $this->pluginName;
55 }
56
57 /**
58 * @ignore
59 */
60 public function getPluginName()
61 {
62 return $this->pluginName;
63 }
64
65 /**
66 * @ignore
67 * @return Setting
68 */
69 public function getSetting($name)
70 {
71 if (array_key_exists($name, $this->settings)) {
72 return $this->settings[$name];
73 }
74 }
75
76 /**
77 * Implemented by descendants. This method should define plugin settings (via the
78 * {@link addSetting()}) method and set the introduction text (via the
79 * {@link setIntroduction()}).
80 */
81 abstract protected function init();
82
83 /**
84 * Returns the settings that can be displayed for the current user.
85 *
86 * @return Setting[]
87 */
88 public function getSettingsWritableByCurrentUser()
89 {
90 return array_filter($this->settings, function (Setting $setting) {
91 return $setting->isWritableByCurrentUser();
92 });
93 }
94
95 /**
96 * Adds a new setting to the settings container.
97 *
98 * @param Setting $setting
99 * @throws \Exception If there is a setting with the same name that already exists.
100 * If the name contains non-alphanumeric characters.
101 */
102 public function addSetting(Setting $setting)
103 {
104 $name = $setting->getName();
105
106 if (isset($this->settings[$name])) {
107 throw new \Exception(sprintf('A setting with name "%s" does already exist for plugin "%s"', $name, $this->pluginName));
108 }
109
110 $this->settings[$name] = $setting;
111 }
112
113 /**
114 * Saves (persists) the current setting values in the database.
115 */
116 public function save()
117 {
118 foreach ($this->settings as $setting) {
119 $setting->save();
120 }
121 }
122
123 }
124