From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- .../src/Merge/StabilityFlags.php | 181 +++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 vendor/wikimedia/composer-merge-plugin/src/Merge/StabilityFlags.php (limited to 'vendor/wikimedia/composer-merge-plugin/src/Merge/StabilityFlags.php') diff --git a/vendor/wikimedia/composer-merge-plugin/src/Merge/StabilityFlags.php b/vendor/wikimedia/composer-merge-plugin/src/Merge/StabilityFlags.php new file mode 100644 index 00000000..1c106e02 --- /dev/null +++ b/vendor/wikimedia/composer-merge-plugin/src/Merge/StabilityFlags.php @@ -0,0 +1,181 @@ + + */ +class StabilityFlags +{ + + /** + * @var array Current package name => stability mappings + */ + protected $stabilityFlags; + + /** + * @var int Current default minimum stability + */ + protected $minimumStability; + + /** + * @var string Regex to extract an explict stability flag (eg '@dev') + */ + protected $explicitStabilityRe; + + + /** + * @param array $stabilityFlags Current package name => stability mappings + * @param int $minimumStability Current default minimum stability + */ + public function __construct( + array $stabilityFlags = array(), + $minimumStability = BasePackage::STABILITY_STABLE + ) { + $this->stabilityFlags = $stabilityFlags; + $this->minimumStability = $this->getStabilityInt($minimumStability); + $this->explicitStabilityRe = '/^[^@]*?@(' . + implode('|', array_keys(BasePackage::$stabilities)) . + ')$/i'; + } + + /** + * Get the stability value for a given string. + * + * @param string $name Stability name + * @return int Stability value + */ + protected function getStabilityInt($name) + { + $name = VersionParser::normalizeStability($name); + return isset(BasePackage::$stabilities[$name]) ? + BasePackage::$stabilities[$name] : + BasePackage::STABILITY_STABLE; + } + + /** + * Extract and merge stability flags from the given collection of + * requires with another collection of stability flags. + * + * @param array $requires New package name => link mappings + * @return array Unified package name => stability mappings + */ + public function extractAll(array $requires) + { + $flags = array(); + + foreach ($requires as $name => $link) { + $name = strtolower($name); + $version = $link->getPrettyConstraint(); + + $stability = $this->getExplicitStability($version); + + if ($stability === null) { + $stability = $this->getParsedStability($version); + } + + $flags[$name] = max($stability, $this->getCurrentStability($name)); + } + + // Filter out null stability values + return array_filter($flags, function ($v) { + return $v !== null; + }); + } + + + /** + * Extract the most unstable explicit stability (eg '@dev') from a version + * specification. + * + * @param string $version + * @return int|null Stability or null if no explict stability found + */ + protected function getExplicitStability($version) + { + $found = null; + $constraints = $this->splitConstraints($version); + foreach ($constraints as $constraint) { + if (preg_match($this->explicitStabilityRe, $constraint, $match)) { + $stability = $this->getStabilityInt($match[1]); + $found = max($stability, $found); + } + } + return $found; + } + + + /** + * Split a version specification into a list of version constraints. + * + * @param string $version + * @return array + */ + protected function splitConstraints($version) + { + $found = array(); + $orConstraints = preg_split('/\s*\|\|?\s*/', trim($version)); + foreach ($orConstraints as $constraints) { + $andConstraints = preg_split( + '/(?< ,]) *(?getStabilityInt( + VersionParser::parseStability($version) + ); + + if ($stability === BasePackage::STABILITY_STABLE || + $this->minimumStability > $stability + ) { + // Ignore if 'stable' or more stable than the global + // minimum + $stability = null; + } + + return $stability; + } + + + /** + * Get the current stability of a given package. + * + * @param string $name + * @return int|null Stability of null if not set + */ + protected function getCurrentStability($name) + { + return isset($this->stabilityFlags[$name]) ? + $this->stabilityFlags[$name] : null; + } +} +// vim:sw=4:ts=4:sts=4:et: -- cgit v1.2.3-54-g00ecf