/** * Include the constraint of root dependency version in the constraint * of installed package. * * @param PackageInterface $package The installed package * @param Link $link The link contained installed constraint * * @return Link The link with root and installed version constraint */ private function includeRootConstraint(PackageInterface $package, Link $link) { if (isset($this->requires[$package->getName()])) { /* @var Link $rLink */ $rLink = $this->requires[$package->getName()]; $useConjunctive = FilterUtil::checkExtraOption($this->package, 'asset-optimize-with-conjunctive'); $constraint = new MultiConstraint(array($rLink->getConstraint(), $link->getConstraint()), $useConjunctive); $link = new Link($rLink->getSource(), $rLink->getTarget(), $constraint, 'installed', $constraint->getPrettyString()); } return $link; }
/** * Parses as constraint string into LinkConstraint objects. * * @param string $constraints * * @return ConstraintInterface */ public function parseConstraints($constraints) { $prettyConstraint = $constraints; if (preg_match('{^([^,\\s]*?)@(' . implode('|', self::$stabilities) . ')$}i', $constraints, $match)) { $constraints = empty($match[1]) ? '*' : $match[1]; } if (preg_match('{^(dev-[^,\\s@]+?|[^,\\s@]+?\\.x-dev)#.+$}i', $constraints, $match)) { $constraints = $match[1]; } $orConstraints = preg_split('{\\s*\\|\\|?\\s*}', trim($constraints)); $orGroups = array(); foreach ($orConstraints as $constraints) { $andConstraints = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $constraints); if (count($andConstraints) > 1) { $constraintObjects = array(); foreach ($andConstraints as $constraint) { foreach ($this->parseConstraint($constraint) as $parsedConstraint) { $constraintObjects[] = $parsedConstraint; } } } else { $constraintObjects = $this->parseConstraint($andConstraints[0]); } if (1 === count($constraintObjects)) { $constraint = $constraintObjects[0]; } else { $constraint = new MultiConstraint($constraintObjects); } $orGroups[] = $constraint; } if (1 === count($orGroups)) { $constraint = $orGroups[0]; } else { $constraint = new MultiConstraint($orGroups, false); } $constraint->setPrettyString($prettyConstraint); return $constraint; }
/** * Parses a constraint string into MultiConstraint and/or Constraint objects. * * @param string $constraints * * @return ConstraintInterface */ public function parseConstraints($constraints) { $prettyConstraint = $constraints; if (preg_match('{^([^,\\s]*?)@(' . implode('|', self::$stabilities) . ')$}i', $constraints, $match)) { $constraints = empty($match[1]) ? '*' : $match[1]; } if (preg_match('{^(dev-[^,\\s@]+?|[^,\\s@]+?\\.x-dev)#.+$}i', $constraints, $match)) { $constraints = $match[1]; } $orConstraints = preg_split('{\\s*\\|\\|?\\s*}', trim($constraints)); $orGroups = array(); foreach ($orConstraints as $constraints) { $andConstraints = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $constraints); if (count($andConstraints) > 1) { $constraintObjects = array(); foreach ($andConstraints as $constraint) { foreach ($this->parseConstraint($constraint) as $parsedConstraint) { $constraintObjects[] = $parsedConstraint; } } } else { $constraintObjects = $this->parseConstraint($andConstraints[0]); } if (1 === count($constraintObjects)) { $constraint = $constraintObjects[0]; } else { $constraint = new MultiConstraint($constraintObjects); } $orGroups[] = $constraint; } if (1 === count($orGroups)) { $constraint = $orGroups[0]; } elseif (2 === count($orGroups) && $orGroups[0] instanceof MultiConstraint && $orGroups[1] instanceof MultiConstraint && ($a = (string) $orGroups[0]) && substr($a, 0, 3) === '[>=' && false !== ($posA = strpos($a, '<', 4)) && ($b = (string) $orGroups[1]) && substr($b, 0, 3) === '[>=' && false !== ($posB = strpos($b, '<', 4)) && substr($a, $posA + 2, -1) === substr($b, 4, $posB - 5)) { $constraint = new MultiConstraint(array(new Constraint('>=', substr($a, 4, $posA - 5)), new Constraint('<', substr($b, $posB + 2, -1)))); } else { $constraint = new MultiConstraint($orGroups, false); } $constraint->setPrettyString($prettyConstraint); return $constraint; }