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