PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
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 / CompilingMatcher.php
matomo / app / vendor / composer / semver / src Last commit date
Constraint 1 year ago Comparator.php 1 year ago CompilingMatcher.php 1 year ago Interval.php 1 year ago Intervals.php 1 year ago Semver.php 7 months ago VersionParser.php 1 year ago
CompilingMatcher.php
95 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 use Composer\Semver\Constraint\ConstraintInterface;
16
17 /**
18 * Helper class to evaluate constraint by compiling and reusing the code to evaluate
19 */
20 class CompilingMatcher
21 {
22 /**
23 * @var array
24 * @phpstan-var array<string, callable>
25 */
26 private static $compiledCheckerCache = array();
27 /**
28 * @var array
29 * @phpstan-var array<string, bool>
30 */
31 private static $resultCache = array();
32
33 /** @var bool */
34 private static $enabled;
35
36 /**
37 * @phpstan-var array<Constraint::OP_*, Constraint::STR_OP_*>
38 */
39 private static $transOpInt = array(
40 Constraint::OP_EQ => Constraint::STR_OP_EQ,
41 Constraint::OP_LT => Constraint::STR_OP_LT,
42 Constraint::OP_LE => Constraint::STR_OP_LE,
43 Constraint::OP_GT => Constraint::STR_OP_GT,
44 Constraint::OP_GE => Constraint::STR_OP_GE,
45 Constraint::OP_NE => Constraint::STR_OP_NE,
46 );
47
48 /**
49 * Clears the memoization cache once you are done
50 *
51 * @return void
52 */
53 public static function clear()
54 {
55 self::$resultCache = array();
56 self::$compiledCheckerCache = array();
57 }
58
59 /**
60 * Evaluates the expression: $constraint match $operator $version
61 *
62 * @param ConstraintInterface $constraint
63 * @param int $operator
64 * @phpstan-param Constraint::OP_* $operator
65 * @param string $version
66 *
67 * @return bool
68 */
69 public static function match(ConstraintInterface $constraint, $operator, $version)
70 {
71 $resultCacheKey = $operator.$constraint.';'.$version;
72
73 if (isset(self::$resultCache[$resultCacheKey])) {
74 return self::$resultCache[$resultCacheKey];
75 }
76
77 if (self::$enabled === null) {
78 self::$enabled = !\in_array('eval', explode(',', (string) ini_get('disable_functions')), true);
79 }
80 if (!self::$enabled) {
81 return self::$resultCache[$resultCacheKey] = $constraint->matches(new Constraint(self::$transOpInt[$operator], $version));
82 }
83
84 $cacheKey = $operator.$constraint;
85 if (!isset(self::$compiledCheckerCache[$cacheKey])) {
86 $code = $constraint->compile($operator);
87 self::$compiledCheckerCache[$cacheKey] = $function = eval('return function($v, $b){return '.$code.';};');
88 } else {
89 $function = self::$compiledCheckerCache[$cacheKey];
90 }
91
92 return self::$resultCache[$resultCacheKey] = $function($version, strpos($version, 'dev-') === 0);
93 }
94 }
95