MediaWiki master
LockFileChecker.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Composer;
22
23use Composer\Semver\Semver;
26
34 private ComposerJson $composerJson;
35 private ComposerLock $composerLock;
36
37 public function __construct( ComposerJson $composerJson, ComposerLock $composerLock ) {
38 $this->composerJson = $composerJson;
39 $this->composerLock = $composerLock;
40 }
41
45 public function check(): ?array {
46 $errors = [];
47 $requiredButOld = [];
48 $requiredButMissing = [];
49
50 $installed = $this->composerLock->getInstalledDependencies();
51 foreach ( $this->composerJson->getRequiredDependencies() as $name => $version ) {
52 // Not installed at all.
53 if ( !isset( $installed[$name] ) ) {
54 $requiredButMissing[] = [
55 'name' => $name,
56 'wantedVersion' => $version
57 ];
58 continue;
59 }
60
61 // Installed; need to check it's the right version
62 if ( !SemVer::satisfies( $installed[$name]['version'], $version ) ) {
63 $requiredButOld[] = [
64 'name' => $name,
65 'wantedVersion' => $version,
66 'suppliedVersion' => $installed[$name]['version']
67 ];
68 }
69
70 // We're happy; loop to the next dependency.
71 }
72
73 foreach ( $requiredButOld as [
74 "name" => $name,
75 "suppliedVersion" => $suppliedVersion,
76 "wantedVersion" => $wantedVersion
77 ] ) {
78 $errors[] = "$name: $suppliedVersion installed, $wantedVersion required.";
79 }
80
81 foreach ( $requiredButMissing as [
82 "name" => $name,
83 "wantedVersion" => $wantedVersion
84 ] ) {
85 $errors[] = "$name: not installed, $wantedVersion required.";
86 }
87
88 return $errors ?: null;
89 }
90}
Used to check whether composer-installed dependencies (no-dev) are up-to-date.
__construct(ComposerJson $composerJson, ComposerLock $composerLock)
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
Reads a composer.lock file and provides accessors to get its hash and what is installed.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...