23 use Composer\Semver\VersionParser;
24 use Composer\Semver\Constraint\Constraint;
79 $this->versionParser =
new VersionParser();
94 $this->loaded = $credits;
106 $this->coreVersion =
new Constraint(
111 }
catch ( UnexpectedValueException $e ) {
124 $this->phpVersion =
new Constraint(
158 foreach ( $extDependencies as $extension => $dependencies ) {
159 foreach ( $dependencies as $dependencyType => $values ) {
160 switch ( $dependencyType ) {
167 if ( $mwError !==
false ) {
170 "{$extension} is not compatible with the current MediaWiki "
171 .
"core (version {$this->coreVersion->getPrettyString()}), "
172 .
"it requires: $values."
174 'type' =>
'incompatible-core',
179 foreach ( $values as $dependency => $constraint ) {
180 if ( $dependency ===
'php' ) {
187 if ( $phpError !==
false ) {
190 "{$extension} is not compatible with the current PHP "
191 .
"version {$this->phpVersion->getPrettyString()}), "
192 .
"it requires: $constraint."
194 'type' =>
'incompatible-php',
197 } elseif ( substr( $dependency, 0, 4 ) ===
'ext-' ) {
199 $phpExtension = substr( $dependency, 4 );
200 if ( $constraint !==
'*' ) {
201 throw new UnexpectedValueException(
'Version constraints for '
202 .
'PHP extensions are not supported in ' . $extension );
204 if ( !in_array( $phpExtension, $this->phpExtensions,
true ) ) {
207 "{$extension} requires {$phpExtension} PHP extension "
210 'type' =>
'missing-phpExtension',
211 'missing' => $phpExtension,
214 } elseif ( substr( $dependency, 0, 8 ) ===
'ability-' ) {
216 $ability = substr( $dependency, 8 );
217 if ( !isset( $this->abilities[$ability] ) ) {
218 throw new UnexpectedValueException(
'Dependency type '
219 . $dependency .
' unknown in ' . $extension );
221 if ( !is_bool( $constraint ) ) {
222 throw new UnexpectedValueException(
'Only booleans are '
223 .
'allowed to to indicate the presence of abilities '
224 .
'in ' . $extension );
227 if ( $constraint ===
true &&
228 $this->abilities[$ability] !==
true
232 if ( isset( $this->abilityErrors[$ability] ) ) {
233 $customMessage =
': ' . $this->abilityErrors[$ability];
238 "{$extension} requires \"{$ability}\" ability"
241 'type' =>
'missing-ability',
242 'missing' => $ability,
247 throw new UnexpectedValueException(
'Dependency type ' . $dependency .
248 ' unknown in ' . $extension );
254 foreach ( $values as $dependency => $constraint ) {
256 $dependency, $constraint, $extension, $dependencyType
258 if ( $extError !==
false ) {
259 $errors[] = $extError;
264 throw new UnexpectedValueException(
'Dependency type ' . $dependencyType .
265 ' unknown in ' . $extension );
283 if ( $version ===
false ) {
289 if ( $this->versionParser->parseConstraints( $constraint )
290 ->matches( $version ) ) {
310 if ( !isset( $this->loaded[$dependencyName] ) ) {
312 'msg' =>
"{$checkedExt} requires {$dependencyName} to be installed.",
313 'type' =>
"missing-$type",
314 'missing' => $dependencyName,
317 if ( $constraint ===
'*' ) {
322 if ( !isset( $this->loaded[$dependencyName][
'version'] ) ) {
323 $msg =
"{$dependencyName} does not expose its version, but {$checkedExt}"
324 .
" requires: {$constraint}.";
327 'type' =>
"incompatible-$type",
328 'incompatible' => $checkedExt,
333 $installedVersion =
new Constraint(
335 $this->versionParser->normalize( $this->loaded[$dependencyName][
'version'] )
337 }
catch ( UnexpectedValueException $e ) {
341 'msg' =>
"$dependencyName does not have a valid version string.",
342 'type' =>
'invalid-version',
347 !$this->versionParser->parseConstraints( $constraint )->matches( $installedVersion )
349 $msg =
"{$checkedExt} is not compatible with the current "
350 .
"installed version of {$dependencyName} "
351 .
"({$this->loaded[$dependencyName]['version']}), "
352 .
"it requires: " . $constraint .
'.';
355 'type' =>
"incompatible-$type",
356 'incompatible' => $checkedExt,