X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fregistration%2FVersionChecker.php;h=a5d1fa1fcf6bc77072512711d0f361680556ced6;hb=dcb26aa2dbf360fec1382a95161eaf0420bc60ad;hp=93b4a14301ef428c7e2a12019257b503d1be698a;hpb=9c0eeb1a2d985f77134385975bf611ddc2bb8c7b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/registration/VersionChecker.php b/includes/registration/VersionChecker.php index 93b4a14301..a5d1fa1fcf 100644 --- a/includes/registration/VersionChecker.php +++ b/includes/registration/VersionChecker.php @@ -40,6 +40,21 @@ class VersionChecker { */ private $phpVersion = false; + /** + * @var string[] List of installed PHP extensions + */ + private $phpExtensions = []; + + /** + * @var bool[] List of provided abilities + */ + private $abilities = []; + + /** + * @var string[] List of provided ability errors + */ + private $abilityErrors = []; + /** * @var array Loaded extensions */ @@ -52,11 +67,21 @@ class VersionChecker { /** * @param string $coreVersion Current version of core + * @param string $phpVersion Current PHP version + * @param string[] $phpExtensions List of installed PHP extensions + * @param bool[] $abilities List of provided abilities + * @param string[] $abilityErrors Error messages for the abilities */ - public function __construct( $coreVersion, $phpVersion ) { + public function __construct( + $coreVersion, $phpVersion, array $phpExtensions, + array $abilities = [], array $abilityErrors = [] + ) { $this->versionParser = new VersionParser(); $this->setCoreVersion( $coreVersion ); $this->setPhpVersion( $phpVersion ); + $this->phpExtensions = $phpExtensions; + $this->abilities = $abilities; + $this->abilityErrors = $abilityErrors; } /** @@ -112,7 +137,9 @@ class VersionChecker { * 'FooBar' => { * 'MediaWiki' => '>= 1.25.0', * 'platform': { - * 'php': '>= 7.0.0' + * 'php': '>= 7.0.0', + * 'ext-foo': '*', + * 'ability-bar': true * }, * 'extensions' => { * 'FooBaz' => '>= 1.25.0' @@ -151,6 +178,7 @@ class VersionChecker { case 'platform': foreach ( $values as $dependency => $constraint ) { if ( $dependency === 'php' ) { + // PHP version $phpError = $this->handleDependency( $this->phpVersion, $constraint, @@ -166,6 +194,54 @@ class VersionChecker { 'type' => 'incompatible-php', ]; } + } elseif ( substr( $dependency, 0, 4 ) === 'ext-' ) { + // PHP extensions + $phpExtension = substr( $dependency, 4 ); + if ( $constraint !== '*' ) { + throw new UnexpectedValueException( 'Version constraints for ' + . 'PHP extensions are not supported in ' . $extension ); + } + if ( !in_array( $phpExtension, $this->phpExtensions, true ) ) { + $errors[] = [ + 'msg' => + "{$extension} requires {$phpExtension} PHP extension " + . "to be installed." + , + 'type' => 'missing-phpExtension', + 'missing' => $phpExtension, + ]; + } + } elseif ( substr( $dependency, 0, 8 ) === 'ability-' ) { + // Other abilities the environment might provide. + $ability = substr( $dependency, 8 ); + if ( !isset( $this->abilities[$ability] ) ) { + throw new UnexpectedValueException( 'Dependency type ' + . $dependency . ' unknown in ' . $extension ); + } + if ( !is_bool( $constraint ) ) { + throw new UnexpectedValueException( 'Only booleans are ' + . 'allowed to to indicate the presence of abilities ' + . 'in ' . $extension ); + } + + if ( $constraint === true && + $this->abilities[$ability] !== true + ) { + // add custom error message for missing ability if specified + $customMessage = ''; + if ( isset( $this->abilityErrors[$ability] ) ) { + $customMessage = ': ' . $this->abilityErrors[$ability]; + } + + $errors[] = [ + 'msg' => + "{$extension} requires \"{$ability}\" ability" + . $customMessage + , + 'type' => 'missing-ability', + 'missing' => $ability, + ]; + } } else { // add other platform dependencies here throw new UnexpectedValueException( 'Dependency type ' . $dependency .