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