PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.1.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.1.2
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 / vendor / composer / semver / src / Semver.php
matomo / app / vendor / composer / semver / src Last commit date
Constraint 6 years ago Comparator.php 6 years ago Semver.php 6 years ago VersionParser.php 6 years ago
Semver.php
128 lines
1 <?php
2
3 /*
4 * This file is part of composer/semver.
5 *
6 * (c) Composer <https://github.com/composer>
7 *
8 * For the full copyright and license information, please view
9 * the LICENSE file that was distributed with this source code.
10 */
11
12 namespace Composer\Semver;
13
14 use Composer\Semver\Constraint\Constraint;
15
16 class Semver
17 {
18 const SORT_ASC = 1;
19 const SORT_DESC = -1;
20
21 /** @var VersionParser */
22 private static $versionParser;
23
24 /**
25 * Determine if given version satisfies given constraints.
26 *
27 * @param string $version
28 * @param string $constraints
29 *
30 * @return bool
31 */
32 public static function satisfies($version, $constraints)
33 {
34 if (null === self::$versionParser) {
35 self::$versionParser = new VersionParser();
36 }
37
38 $versionParser = self::$versionParser;
39 $provider = new Constraint('==', $versionParser->normalize($version));
40 $constraints = $versionParser->parseConstraints($constraints);
41
42 return $constraints->matches($provider);
43 }
44
45 /**
46 * Return all versions that satisfy given constraints.
47 *
48 * @param array $versions
49 * @param string $constraints
50 *
51 * @return array
52 */
53 public static function satisfiedBy(array $versions, $constraints)
54 {
55 $versions = array_filter($versions, function ($version) use ($constraints) {
56 return Semver::satisfies($version, $constraints);
57 });
58
59 return array_values($versions);
60 }
61
62 /**
63 * Sort given array of versions.
64 *
65 * @param array $versions
66 *
67 * @return array
68 */
69 public static function sort(array $versions)
70 {
71 return self::usort($versions, self::SORT_ASC);
72 }
73
74 /**
75 * Sort given array of versions in reverse.
76 *
77 * @param array $versions
78 *
79 * @return array
80 */
81 public static function rsort(array $versions)
82 {
83 return self::usort($versions, self::SORT_DESC);
84 }
85
86 /**
87 * @param array $versions
88 * @param int $direction
89 *
90 * @return array
91 */
92 private static function usort(array $versions, $direction)
93 {
94 if (null === self::$versionParser) {
95 self::$versionParser = new VersionParser();
96 }
97
98 $versionParser = self::$versionParser;
99 $normalized = array();
100
101 // Normalize outside of usort() scope for minor performance increase.
102 // Creates an array of arrays: [[normalized, key], ...]
103 foreach ($versions as $key => $version) {
104 $normalized[] = array($versionParser->normalize($version), $key);
105 }
106
107 usort($normalized, function (array $left, array $right) use ($direction) {
108 if ($left[0] === $right[0]) {
109 return 0;
110 }
111
112 if (Comparator::lessThan($left[0], $right[0])) {
113 return -$direction;
114 }
115
116 return $direction;
117 });
118
119 // Recreate input array, using the original indexes which are now in sorted order.
120 $sorted = array();
121 foreach ($normalized as $item) {
122 $sorted[] = $versions[$item[1]];
123 }
124
125 return $sorted;
126 }
127 }
128