/** * Run 'composer remove' * * @param array $packages * @return void */ public function remove(array $packages) { $this->composerApp->resetComposer(); $this->composerApp->setAutoExit(false); $vendor = (include $this->directoryList->getPath(DirectoryList::CONFIG) . '/vendor_path.php'); $this->composerApp->run(new ArrayInput(['command' => 'remove', 'packages' => $packages, '--working-dir' => $this->directoryList->getRoot() . '/' . $vendor . '/..'])); }
/** * Checks dependencies to package(s), returns array of dependencies in the format of * 'package A' => [array of package names depending on package A] * If $excludeSelf is set to true, items in $packages will be excluded in all * "array of package names depending on package A" * * @param string[] $packages * @param bool $excludeSelf * @return string[] */ public function checkDependencies(array $packages, $excludeSelf = false) { $this->composerApp->setAutoExit(false); $dependencies = []; foreach ($packages as $package) { $buffer = new BufferedOutput(); $this->composerApp->resetComposer(); $this->composerApp->run(new ArrayInput(['command' => 'depends', '--working-dir' => $this->directoryList->getRoot(), 'package' => $package]), $buffer); $dependingPackages = $this->parseComposerOutput($buffer->fetch()); if ($excludeSelf === true) { $dependingPackages = array_values(array_diff($dependingPackages, $packages)); } $dependencies[$package] = $dependingPackages; } return $dependencies; }
/** * Runs composer command * * @param array $commandParams * @param string|null $workingDir * @return bool * @throws \RuntimeException */ public function runComposerCommand(array $commandParams, $workingDir = null) { $this->consoleApplication->resetComposer(); if ($workingDir) { $commandParams[self::COMPOSER_WORKING_DIR] = $workingDir; } else { $commandParams[self::COMPOSER_WORKING_DIR] = dirname($this->composerJson); } $input = $this->consoleArrayInputFactory->create($commandParams); $exitCode = $this->consoleApplication->run($input, $this->consoleOutput); if ($exitCode) { throw new \RuntimeException(sprintf('Command "%s" failed: %s', $commandParams['command'], $this->consoleOutput->fetch())); } return $this->consoleOutput->fetch(); }
/** * Resets all Composer references in the application. * * @param ComposerApplication $application */ private function resetComposers(ComposerApplication $application) { $application->resetComposer(); foreach ($this->getApplication()->all() as $command) { if ($command instanceof BaseCommand) { $command->resetComposer(); } } }