composerApp = $composerApp; $this->directoryList = $directoryList; } /** * 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; } /** * Parse output from running composer remove command into an array of depending packages * * @param string $output * @return string[] */ private function parseComposerOutput($output) { $rawLines = explode(PHP_EOL, $output); $packages = []; foreach ($rawLines as $rawLine) { $parts = explode(' ', $rawLine); if (count(explode('/', $parts[0])) == 2) { if (strpos($parts[0], 'magento/project-') === false) { $packages[] = $parts[0]; } } } return $packages; } }