PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
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 / Plugin / Dependency.php
matomo / app / core / Plugin Last commit date
ConsoleCommand 2 months ago Dimension 2 months ago API.php 8 months ago AggregatedMetric.php 2 years ago ArchivedMetric.php 2 weeks ago Archiver.php 2 months ago Categories.php 2 years ago ComponentFactory.php 2 weeks ago ComputedMetric.php 1 year ago ConsoleCommand.php 2 months ago Controller.php 2 months ago ControllerAdmin.php 2 weeks ago Dependency.php 2 months ago LogTablesProvider.php 2 weeks ago Manager.php 2 weeks ago Menu.php 2 weeks ago MetadataLoader.php 2 weeks ago Metric.php 2 months ago PluginException.php 1 year ago ProcessedMetric.php 4 months ago ReleaseChannels.php 4 months ago Report.php 2 months ago ReportsProvider.php 2 years ago RequestProcessors.php 5 months ago Segment.php 4 months ago SettingsProvider.php 2 weeks ago Tasks.php 2 months ago ThemeStyles.php 2 weeks ago ViewDataTable.php 2 weeks ago Visualization.php 2 weeks ago WidgetsProvider.php 4 months ago
Dependency.php
154 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\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 class Dependency
16 {
17 private $piwikVersion;
18 private $phpVersion;
19 public function __construct()
20 {
21 $this->setPiwikVersion(Version::VERSION);
22 $this->setPhpVersion(\PHP_MAJOR_VERSION . '.' . \PHP_MINOR_VERSION . '.' . \PHP_RELEASE_VERSION);
23 }
24 public function setEnvironment(Environment $environment)
25 {
26 $this->setPiwikVersion($environment->getPiwikVersion());
27 $this->setPhpVersion($environment->getPhpVersion());
28 }
29 public function getMissingDependencies($requires)
30 {
31 $missingRequirements = array();
32 if (empty($requires)) {
33 return $missingRequirements;
34 }
35 foreach ($requires as $name => $requiredVersion) {
36 $currentVersion = $this->getCurrentVersion($name);
37 if (in_array(strtolower($name), ['piwik', 'matomo'])) {
38 $requiredVersion = $this->markPluginsWithoutUpperBoundMatomoRequirementAsIncompatible($requiredVersion);
39 }
40 $missingVersions = $this->getMissingVersions($currentVersion, $requiredVersion);
41 if (!empty($missingVersions)) {
42 $missingRequirements[] = array('requirement' => $name, 'actualVersion' => $currentVersion, 'requiredVersion' => $requiredVersion, 'causedBy' => implode(', ', $missingVersions));
43 }
44 }
45 return $missingRequirements;
46 }
47 public function getMissingVersions($currentVersion, $requiredVersion)
48 {
49 $currentVersion = trim($currentVersion ?? '');
50 $missingVersions = array();
51 if (empty($currentVersion)) {
52 if (!empty($requiredVersion)) {
53 $missingVersions[] = (string) $requiredVersion;
54 }
55 return $missingVersions;
56 }
57 $requiredVersion = $this->makeVersionBackwardsCompatibleIfNoComparisonDefined($requiredVersion);
58 $version = new VersionParser();
59 $constraintsExisting = $version->parseConstraints($currentVersion);
60 $requiredVersions = explode(',', (string) $requiredVersion);
61 foreach ($requiredVersions as $required) {
62 $required = trim($required);
63 if (empty($required)) {
64 continue;
65 }
66 $required = $this->makeVersionBackwardsCompatibleIfNoComparisonDefined($required);
67 $constraintRequired = $version->parseConstraints($required);
68 if (!$constraintRequired->matches($constraintsExisting)) {
69 $missingVersions[] = $required;
70 }
71 }
72 return $missingVersions;
73 }
74 /**
75 * Upon Matomo 4 we require a lower and upper version bound for Matomo to be set in plugin.json
76 * If that is not the case we assume the plugin not to be compatible with Matomo 4
77 *
78 * @param string $requiredVersion
79 * @return string
80 */
81 private function markPluginsWithoutUpperBoundMatomoRequirementAsIncompatible($requiredVersion)
82 {
83 if (strpos($requiredVersion, ',') !== \false) {
84 return $requiredVersion;
85 }
86 $minVersion = str_replace(array('>', '=', '<', '!', '~', '^'), '', $requiredVersion);
87 if (preg_match("/^\\<=?\\d/", $requiredVersion)) {
88 $upperLimit = '>=' . $minVersion[0] . '.0.0-b1,' . $requiredVersion;
89 } elseif (!empty($minVersion) && is_numeric($minVersion[0])) {
90 $upperLimit = $requiredVersion . ',<' . ($minVersion[0] + 1) . '.0.0-b1';
91 } else {
92 $upperLimit = '>=4.0.0-b1,<5.0.0-b1';
93 }
94 return $upperLimit;
95 }
96 private function makeVersionBackwardsCompatibleIfNoComparisonDefined($version)
97 {
98 if (!empty($version) && preg_match('/^(\\d+)\\.(\\d+)/', $version)) {
99 // TODO: we should remove this from piwik 3. To stay BC we add >= if no >= is defined yet
100 $version = '>=' . $version;
101 }
102 return $version;
103 }
104 public function setPiwikVersion($piwikVersion)
105 {
106 $this->piwikVersion = $piwikVersion;
107 }
108 public function setPhpVersion($phpVersion)
109 {
110 $this->phpVersion = $phpVersion;
111 }
112 public function hasDependencyToDisabledPlugin($requires)
113 {
114 if (empty($requires)) {
115 return \false;
116 }
117 foreach ($requires as $name => $requiredVersion) {
118 $nameLower = strtolower($name);
119 $isPluginRequire = !in_array($nameLower, array('piwik', 'php', 'matomo'));
120 if ($isPluginRequire) {
121 // we do not check version, only whether it's activated. Everything that is not piwik or php is assumed
122 // a plugin so far.
123 if (!PluginManager::getInstance()->isPluginActivated($name)) {
124 return \true;
125 }
126 }
127 }
128 return \false;
129 }
130 private function getCurrentVersion($name)
131 {
132 switch (strtolower($name)) {
133 case 'matomo':
134 case 'piwik':
135 return $this->piwikVersion;
136 case 'php':
137 return $this->phpVersion;
138 default:
139 try {
140 $pluginNames = PluginManager::getAllPluginsNames();
141 if (!in_array($name, $pluginNames) || !PluginManager::getInstance()->isPluginLoaded($name)) {
142 return '';
143 }
144 $plugin = PluginManager::getInstance()->loadPlugin(ucfirst($name));
145 if (!empty($plugin)) {
146 return $plugin->getVersion();
147 }
148 } catch (\Exception $e) {
149 }
150 }
151 return '';
152 }
153 }
154