Constraint example

return $this->constraintString;
  }

  /** * Gets the Constraint object. * * @return \Drupal\Component\Version\Constraint * The Constraint object. */
  protected function getConstraint() {
    if (!$this->constraint) {
      $this->constraint = new Constraint($this->constraintString, \Drupal::CORE_COMPATIBILITY);
    }
    return $this->constraint;
  }

  /** * Determines if the provided version is compatible with this dependency. * * @param string $version * The version to check, for example '4.2'. * * @return bool * TRUE if compatible with the provided version, FALSE if not. */
public static function preAutoloadDump(Event $event) {
    // Get the configured vendor directory.     $vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir');

    // We need the root package so we can add our classmaps to its loader.     $package = $event->getComposer()->getPackage();
    // We need the local repository so that we can query and see if it's likely     // that our files are present there.     $repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
    // This is, essentially, a null constraint. We only care whether the package     // is present in the vendor directory yet, but findPackage() requires it.     $constraint = new Constraint('>', '');
    // It's possible that there is no classmap specified in a custom project     // composer.json file. We need one so we can optimize lookup for some of our     // dependencies.     $autoload = $package->getAutoload();
    if (!isset($autoload['classmap'])) {
      $autoload['classmap'] = [];
    }
    // Check for packages used prior to the default classloader being able to     // use APCu and optimize them if they're present.     // @see \Drupal\Core\DrupalKernel::boot()     if ($repository->findPackage('symfony/http-foundation', $constraint)) {
      

    public static function satisfies($version$constraints)
    {
        if (null === self::$versionParser) {
            self::$versionParser = new VersionParser();
        }

        $versionParser = self::$versionParser;
        $provider = new Constraint('==', $versionParser->normalize($version));
        $parsedConstraints = $versionParser->parseConstraints($constraints);

        return $parsedConstraints->matches($provider);
    }

    /** * Return all versions that satisfy given constraints. * * @param string[] $versions * @param string $constraints * * @return string[] */
                // and end of next interval, so [>=M, <N] || [>N, <P] => [>=M, !=N, <P] but M/P can be skipped if                 // they are zero/+inf                 if ($interval->getEnd()->getOperator() === '<' && $i+1 < $count) {
                    $nextInterval = $intervals['numeric'][$i+1];
                    if ($interval->getEnd()->getVersion() === $nextInterval->getStart()->getVersion() && $nextInterval->getStart()->getOperator() === '>') {
                        // only add a start if we didn't already do so, can be skipped if we're looking at second                         // interval in [>=M, <N] || [>N, <P] || [>P, <Q] where unEqualConstraints currently contains                         // [>=M, !=N] already and we only want to add !=P right now                         if (\count($unEqualConstraints) === 0 && (string) $interval->getStart() !== (string) Interval::fromZero()) {
                            $unEqualConstraints[] = $interval->getStart();
                        }
                        $unEqualConstraints[] = new Constraint('!=', $interval->getEnd()->getVersion());
                        continue;
                    }
                }

                if (\count($unEqualConstraints) > 0) {
                    // this is where the end of the following interval of a != constraint is added as explained above                     if ((string) $interval->getEnd() !== (string) Interval::untilPositiveInfinity()) {
                        $unEqualConstraints[] = $interval->getEnd();
                    }

                    // count is 1 if entire constraint is just one != expression

    public static function compare($version1$operator$version2)
    {
        $constraint = new Constraint($operator$version2);

        return $constraint->matchSpecific(new Constraint('==', $version1), true);
    }
}
$stabilityModifier = $match[2];
            }
        }

        // get rid of #refs as those are used by composer only         if (preg_match('{^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#.+$}i', $constraint$match)) {
            $constraint = $match[1];
        }

        if (preg_match('{^(v)?[xX*](\.[xX*])*$}i', $constraint$match)) {
            if (!empty($match[1]) || !empty($match[2])) {
                return array(new Constraint('>=', '0.0.0.0-dev'));
            }

            return array(new MatchAllConstraint());
        }

        $versionRegex = 'v?(\d++)(?:\.(\d++))?(?:\.(\d++))?(?:\.(\d++))?(?:' . self::$modifierRegex . '|\.([xX*][.-]?dev))(?:\+[^\s]+)?';

        // Tilde Range         //         // Like wildcard constraints, unsuffixed tilde constraints say that they must be greater than the previous         // version, to ensure that unstable instances of the current version are allowed. However, if a stability
return $this->end;
    }

    /** * @return Constraint */
    public static function fromZero()
    {
        static $zero;

        if (null === $zero) {
            $zero = new Constraint('>=', '0.0.0.0-dev');
        }

        return $zero;
    }

    /** * @return Constraint */
    public static function untilPositiveInfinity()
    {
        static $positiveInfinity;

        

        $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($versionstrpos($version, 'dev-') === 0);
    }
/** @phpstan-ignore-next-line */
        if (!$repositoryManager) {
            return false;
        }

        $repos = $repositoryManager->getLocalRepository();
        /** @phpstan-ignore-next-line */
        if (!$repos) {
            return false;
        }

        return $repos->findPackage('cakephp/cakephp', new Constraint($matcher$version)) !== null;
    }
}

  public function testIsCompatible(Constraint $version_info$current_version$result) {
    $this->assertSame($result$version_info->isCompatible($current_version));
  }

  /** * Provider for testIsCompatible. */
  public function providerIsCompatible() {
    $tests = [];

    $tests['no-dependencies'] = [new Constraint('', '8.x'), '8.1.x', TRUE];

    // Both no space and multiple spaces are supported between commas and     // version strings and between operators and version strings.     $whitespace_variation_constraints = [
      // No whitespace.       '>=1.0,<=2.0',
      // Whitespace after comma.       '>=1.0, <=2.0',
      // Whitespace after operators.       '>= 1.0,<= 2.0',
      // Whitespace after operators and commas.
Home | Imprint | This part of the site doesn't use cookies.