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