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