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 / Storage / Factory.php
matomo / app / core / Settings / Storage Last commit date
Backend 1 month ago Factory.php 3 months ago LegacyUserSettingsMigration.php 1 month ago Storage.php 1 year ago UserScopedSettingsAccessManager.php 1 month ago
Factory.php
122 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\Storage;
10
11 use Piwik\Settings\Storage\Backend\BackendInterface;
12 use Piwik\SettingsServer;
13 /**
14 * Factory to create an instance of a storage. The storage can be created with different backends depending on the need.
15 */
16 class Factory
17 {
18 // cache prevents multiple loading of storage
19 private $cache = array();
20 /**
21 * Get a storage instance for plugin settings.
22 *
23 * The storage will hold values that belong to the given plugin name and user login. Be aware that instances
24 * for a specific plugin and login will be cached during one request for better performance.
25 *
26 * @param string $pluginName
27 * @param string $userLogin Use an empty string if settings should be not for a specific login
28 * @return Storage
29 */
30 public function getPluginStorage($pluginName, $userLogin)
31 {
32 $id = $pluginName . '#' . $userLogin;
33 if (!isset($this->cache[$id])) {
34 $backend = new \Piwik\Settings\Storage\Backend\PluginSettingsTable($pluginName, $userLogin);
35 $this->cache[$id] = $this->makeStorage($backend);
36 }
37 return $this->cache[$id];
38 }
39 /**
40 * @param string $section
41 * @return mixed
42 */
43 public function getConfigStorage($section)
44 {
45 $id = 'config' . $section;
46 if (!isset($this->cache[$id])) {
47 $backend = new \Piwik\Settings\Storage\Backend\Config($section);
48 $this->cache[$id] = $this->makeStorage($backend);
49 }
50 return $this->cache[$id];
51 }
52 /**
53 * Get a storage instance for measurable settings.
54 *
55 * The storage will hold values that belong to the given idSite and plugin name. Be aware that a storage instance
56 * for a specific site and plugin will be cached during one request for better performance.
57 *
58 * @param int $idSite If idSite is empty it will use a backend that never actually persists any value. Pass
59 * $idSite = 0 to create a storage for a site that is about to be created.
60 * @param string $pluginName
61 * @return Storage
62 */
63 public function getMeasurableSettingsStorage($idSite, $pluginName)
64 {
65 $id = 'measurableSettings' . (int) $idSite . '#' . $pluginName;
66 if (empty($idSite)) {
67 return $this->getNonPersistentStorage($id . '#nonpersistent');
68 }
69 if (!isset($this->cache[$id])) {
70 $backend = new \Piwik\Settings\Storage\Backend\MeasurableSettingsTable($idSite, $pluginName);
71 $this->cache[$id] = $this->makeStorage($backend);
72 }
73 return $this->cache[$id];
74 }
75 /**
76 * Get a storage instance for settings that will be saved in the "site" table.
77 *
78 * The storage will hold values that belong to the given idSite. Be aware that a storage instance for a specific
79 * site will be cached during one request for better performance.
80 *
81 * @param int $idSite If idSite is empty it will use a backend that never actually persists any value. Pass
82 * $idSite = 0 to create a storage for a site that is about to be created.
83 *
84 * @param int $idSite
85 * @return Storage
86 */
87 public function getSitesTable($idSite)
88 {
89 $id = 'sitesTable#' . $idSite;
90 if (empty($idSite)) {
91 return $this->getNonPersistentStorage($id . '#nonpersistent');
92 }
93 if (!isset($this->cache[$id])) {
94 $backend = new \Piwik\Settings\Storage\Backend\SitesTable($idSite);
95 $this->cache[$id] = $this->makeStorage($backend);
96 }
97 return $this->cache[$id];
98 }
99 /**
100 * Get a storage with a backend that will never persist or load any value.
101 *
102 * @param string $key
103 * @return Storage
104 */
105 public function getNonPersistentStorage($key)
106 {
107 return new \Piwik\Settings\Storage\Storage(new \Piwik\Settings\Storage\Backend\NullBackend($key));
108 }
109 /**
110 * Makes a new storage object based on a custom backend interface.
111 *
112 * @return Storage
113 */
114 public function makeStorage(BackendInterface $backend)
115 {
116 if (SettingsServer::isTrackerApiRequest()) {
117 $backend = new \Piwik\Settings\Storage\Backend\Cache($backend);
118 }
119 return new \Piwik\Settings\Storage\Storage($backend);
120 }
121 }
122