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 / Plugin / Dependency.php
matomo / app / core / Plugin Last commit date
Dimension 6 years ago API.php 6 years ago AggregatedMetric.php 6 years ago ArchivedMetric.php 6 years ago Archiver.php 6 years ago Categories.php 6 years ago ComponentFactory.php 6 years ago ComputedMetric.php 6 years ago ConsoleCommand.php 6 years ago Controller.php 6 years ago ControllerAdmin.php 6 years ago Dependency.php 6 years ago LogTablesProvider.php 6 years ago Manager.php 6 years ago Menu.php 6 years ago MetadataLoader.php 6 years ago Metric.php 6 years ago PluginException.php 6 years ago ProcessedMetric.php 6 years ago ReleaseChannels.php 6 years ago Report.php 6 years ago ReportsProvider.php 6 years ago RequestProcessors.php 6 years ago Segment.php 6 years ago SettingsProvider.php 6 years ago Tasks.php 6 years ago ThemeStyles.php 6 years ago ViewDataTable.php 6 years ago Visualization.php 6 years ago WidgetsProvider.php 6 years ago
Dependency.php
171 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 namespace Piwik\Plugin;
10
11 use Composer\Semver\VersionParser;
12 use Piwik\Plugin\Manager as PluginManager;
13 use Piwik\Plugins\Marketplace\Environment;
14 use Piwik\Version;
15
16 /**
17 *
18 */
19 class Dependency
20 {
21 private $piwikVersion;
22 private $phpVersion;
23
24 public function __construct()
25 {
26 $this->setPiwikVersion(Version::VERSION);
27 $this->setPhpVersion(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION);
28 }
29
30 public function setEnvironment(Environment $environment)
31 {
32 $this->setPiwikVersion($environment->getPiwikVersion());
33 $this->setPhpVersion($environment->getPhpVersion());
34 }
35
36 public function getMissingDependencies($requires)
37 {
38 $missingRequirements = array();
39
40 if (empty($requires)) {
41 return $missingRequirements;
42 }
43
44 foreach ($requires as $name => $requiredVersion) {
45 $currentVersion = $this->getCurrentVersion($name);
46 $missingVersions = $this->getMissingVersions($currentVersion, $requiredVersion);
47
48 if (!empty($missingVersions)) {
49 $missingRequirements[] = array(
50 'requirement' => $name,
51 'actualVersion' => $currentVersion,
52 'requiredVersion' => $requiredVersion,
53 'causedBy' => implode(', ', $missingVersions)
54 );
55 }
56 }
57
58 return $missingRequirements;
59 }
60
61 public function getMissingVersions($currentVersion, $requiredVersion)
62 {
63 $currentVersion = trim($currentVersion);
64
65 $missingVersions = array();
66
67 if (empty($currentVersion)) {
68 if (!empty($requiredVersion)) {
69 $missingVersions[] = (string) $requiredVersion;
70 }
71
72 return $missingVersions;
73 }
74
75 $requiredVersion = $this->makeVersionBackwardsCompatibleIfNoComparisonDefined($requiredVersion);
76
77 $version = new VersionParser();
78 $constraintsExisting = $version->parseConstraints($currentVersion);
79
80 $requiredVersions = explode(',', (string) $requiredVersion);
81
82 foreach ($requiredVersions as $required) {
83 $required = trim($required);
84
85 if (empty($required)) {
86 continue;
87 }
88
89 $required = $this->makeVersionBackwardsCompatibleIfNoComparisonDefined($required);
90 $constraintRequired = $version->parseConstraints($required);
91
92 if (!$constraintRequired->matches($constraintsExisting)) {
93 $missingVersions[] = $required;
94 }
95 }
96
97 return $missingVersions;
98 }
99
100 private function makeVersionBackwardsCompatibleIfNoComparisonDefined($version)
101 {
102 if (!empty($version) && preg_match('/^(\d+)\.(\d+)/', $version)) {
103 // TODO: we should remove this from piwik 3. To stay BC we add >= if no >= is defined yet
104 $version = '>=' . $version;
105 }
106
107 return $version;
108 }
109
110 public function setPiwikVersion($piwikVersion)
111 {
112 $this->piwikVersion = $piwikVersion;
113 }
114
115 public function setPhpVersion($phpVersion)
116 {
117 $this->phpVersion = $phpVersion;
118 }
119
120 public function hasDependencyToDisabledPlugin($requires)
121 {
122 if (empty($requires)) {
123 return false;
124 }
125
126 foreach ($requires as $name => $requiredVersion) {
127 $nameLower = strtolower($name);
128 $isPluginRequire = !in_array($nameLower, array('piwik', 'php', 'matomo'));
129 if ($isPluginRequire) {
130 // we do not check version, only whether it's activated. Everything that is not piwik or php is assumed
131 // a plugin so far.
132 if (!PluginManager::getInstance()->isPluginActivated($name)) {
133 return true;
134 }
135 }
136 }
137
138 return false;
139 }
140
141 private function getCurrentVersion($name)
142 {
143 switch (strtolower($name)) {
144 case 'matomo':
145 case 'piwik':
146 return $this->piwikVersion;
147 case 'php':
148 return $this->phpVersion;
149 default:
150 try {
151 $pluginNames = PluginManager::getAllPluginsNames();
152
153 if (!in_array($name, $pluginNames) || !PluginManager::getInstance()->isPluginLoaded($name)) {
154 return '';
155 }
156
157 $plugin = PluginManager::getInstance()->loadPlugin(ucfirst($name));
158
159 if (!empty($plugin)) {
160 return $plugin->getVersion();
161 }
162 } catch (\Exception $e) {
163 }
164 }
165
166 return '';
167 }
168
169
170 }
171