public function execute() { global $IP; $lockLocation = "{$IP}/composer.lock"; $jsonLocation = "{$IP}/composer.json"; if (!file_exists($lockLocation)) { // Maybe they're using mediawiki/vendor? $lockLocation = "{$IP}/vendor/composer.lock"; if (!file_exists($lockLocation)) { $this->error('Could not find composer.lock file. Have you run "composer install"?', 1); } } $lock = new ComposerLock($lockLocation); $json = new ComposerJson($jsonLocation); // Check all the dependencies to see if any are old $found = false; $installed = $lock->getInstalledDependencies(); foreach ($json->getRequiredDependencies() as $name => $version) { if (isset($installed[$name])) { if ($installed[$name]['version'] !== $version) { $this->output("{$name}: {$installed[$name]['version']} installed, {$version} required.\n"); $found = true; } } else { $this->output("{$name}: not installed, {$version} required.\n"); $found = true; } } if ($found) { $this->error('Error: your composer.lock file is not up to date. ' . 'Run "composer update" to install newer dependencies', 1); } else { // We couldn't find any out-of-date dependencies, so assume everything is ok! $this->output("Your composer.lock file is up to date with current dependencies!\n"); } }
public function execute() { global $IP; $lockLocation = "{$IP}/composer.lock"; $jsonLocation = "{$IP}/composer.json"; if (!file_exists($lockLocation)) { // Maybe they're using mediawiki/vendor? $lockLocation = "{$IP}/vendor/composer.lock"; if (!file_exists($lockLocation)) { $this->error('Could not find composer.lock file. Have you run "composer install"?', 1); } } $lock = new ComposerLock($lockLocation); $json = new ComposerJson($jsonLocation); if ($lock->getHash() === $json->getHash()) { $this->output("Your composer.lock file is up to date with current dependencies!\n"); return; } // Out of date, lets figure out which dependencies are old $found = false; $installed = $lock->getInstalledDependencies(); foreach ($json->getRequiredDependencies() as $name => $version) { if (isset($installed[$name])) { if ($installed[$name]['version'] !== $version) { $this->output("{$name}: {$installed[$name]['version']} installed, {$version} required.\n"); $found = true; } } else { $this->output("{$name}: not installed, {$version} required.\n"); $found = true; } } if ($found) { $this->error('Error: your composer.lock file is not up to date, run "composer update" to install newer dependencies', 1); } else { // The hash is the entire composer.json file, so it can be updated without any of the dependencies changing // We couldn't find any out-of-date dependencies, so assume everything is ok! $this->output("Your composer.lock file is up to date with current dependencies!\n"); } }
protected function needsComposerAutoloader($path) { $path .= '/composer.json'; if (file_exists($path)) { // assume, that the composer.json file is in the root of the extension path $composerJson = new ComposerJson($path); // check, if there are some dependencies in the require section if ($composerJson->getRequiredDependencies()) { return true; } } return false; }
/** * @covers ComposerJson::getRequiredDependencies */ public function testGetRequiredDependencies() { $json = new ComposerJson($this->json); $this->assertArrayEquals(['cdb/cdb' => '1.0.0', 'cssjanus/cssjanus' => '1.1.1', 'leafo/lessphp' => '0.5.0', 'psr/log' => '1.0.0'], $json->getRequiredDependencies(), false, true); }