X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fregistration%2FVersionChecker.php;h=a5d1fa1fcf6bc77072512711d0f361680556ced6;hb=dcb26aa2dbf360fec1382a95161eaf0420bc60ad;hp=586729d057f02ae53457769dca7a0ad2ea4beccf;hpb=329f0cfb6c243b366973f8e7360aac18ef924e69;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/registration/VersionChecker.php b/includes/registration/VersionChecker.php index 586729d057..a5d1fa1fcf 100644 --- a/includes/registration/VersionChecker.php +++ b/includes/registration/VersionChecker.php @@ -45,6 +45,16 @@ class VersionChecker { */ private $phpExtensions = []; + /** + * @var bool[] List of provided abilities + */ + private $abilities = []; + + /** + * @var string[] List of provided ability errors + */ + private $abilityErrors = []; + /** * @var array Loaded extensions */ @@ -59,12 +69,19 @@ 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, array $phpExtensions ) { + 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; } /** @@ -121,7 +138,8 @@ class VersionChecker { * 'MediaWiki' => '>= 1.25.0', * 'platform': { * 'php': '>= 7.0.0', - * 'ext-foo': '*' + * 'ext-foo': '*', + * 'ability-bar': true * }, * 'extensions' => { * 'FooBaz' => '>= 1.25.0' @@ -193,6 +211,37 @@ class VersionChecker { '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 .