Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CompilingMatcher.php

class CompilingMatcher

Helper class to evaluate constraint by compiling and reusing the code to evaluate

Hierarchy

  • class \Composer\Semver\CompilingMatcher

Expanded class hierarchy of CompilingMatcher

5 files declare their use of CompilingMatcher
ComposerRepository.php in vendor/composer/composer/src/Composer/Repository/ComposerRepository.php
DefaultPolicy.php in vendor/composer/composer/src/Composer/DependencyResolver/DefaultPolicy.php
Pool.php in vendor/composer/composer/src/Composer/DependencyResolver/Pool.php
PoolBuilder.php in vendor/composer/composer/src/Composer/DependencyResolver/PoolBuilder.php
PoolOptimizer.php in vendor/composer/composer/src/Composer/DependencyResolver/PoolOptimizer.php

File

vendor/composer/semver/src/CompilingMatcher.php, line 20

Namespace

Composer\Semver
View source
class CompilingMatcher {
    
    /**
     * @var array
     * @phpstan-var array<string, callable>
     */
    private static $compiledCheckerCache = array();
    
    /**
     * @var array
     * @phpstan-var array<string, bool>
     */
    private static $resultCache = array();
    
    /** @var bool */
    private static $enabled;
    
    /**
     * @phpstan-var array<Constraint::OP_*, Constraint::STR_OP_*>
     */
    private static $transOpInt = array(
        Constraint::OP_EQ => Constraint::STR_OP_EQ,
        Constraint::OP_LT => Constraint::STR_OP_LT,
        Constraint::OP_LE => Constraint::STR_OP_LE,
        Constraint::OP_GT => Constraint::STR_OP_GT,
        Constraint::OP_GE => Constraint::STR_OP_GE,
        Constraint::OP_NE => Constraint::STR_OP_NE,
    );
    
    /**
     * Clears the memoization cache once you are done
     *
     * @return void
     */
    public static function clear() {
        self::$resultCache = array();
        self::$compiledCheckerCache = array();
    }
    
    /**
     * Evaluates the expression: $constraint match $operator $version
     *
     * @param ConstraintInterface $constraint
     * @param int                 $operator
     * @phpstan-param Constraint::OP_*  $operator
     * @param string              $version
     *
     * @return bool
     */
    public static function match(ConstraintInterface $constraint, $operator, $version) {
        $resultCacheKey = $operator . $constraint . ';' . $version;
        if (isset(self::$resultCache[$resultCacheKey])) {
            return self::$resultCache[$resultCacheKey];
        }
        if (self::$enabled === null) {
            self::$enabled = !\in_array('eval', explode(',', (string) ini_get('disable_functions')), true);
        }
        if (!self::$enabled) {
            return self::$resultCache[$resultCacheKey] = $constraint->matches(new Constraint(self::$transOpInt[$operator], $version));
        }
        $cacheKey = $operator . $constraint;
        if (!isset(self::$compiledCheckerCache[$cacheKey])) {
            $code = $constraint->compile($operator);
            self::$compiledCheckerCache[$cacheKey] = $function = eval('return function($v, $b){return ' . $code . ';};');
        }
        else {
            $function = self::$compiledCheckerCache[$cacheKey];
        }
        return self::$resultCache[$resultCacheKey] = $function($version, strpos($version, 'dev-') === 0);
    }

}

Members

Title Sort descending Modifiers Object type Summary
CompilingMatcher::$compiledCheckerCache private static property @phpstan-var array&lt;string, callable&gt;
CompilingMatcher::$enabled private static property @var bool
CompilingMatcher::$resultCache private static property @phpstan-var array&lt;string, bool&gt;
CompilingMatcher::$transOpInt private static property @phpstan-var array&lt;Constraint::OP_*, Constraint::STR_OP_*&gt;
CompilingMatcher::clear public static function Clears the memoization cache once you are done
CompilingMatcher::match public static function Evaluates the expression: $constraint match $operator $version

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal