Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DependencyChecker.php
Go to the documentation of this file.
1 <?php
7 
8 use Composer\Console\Application;
10 use Symfony\Component\Console\Input\ArrayInput;
11 use Symfony\Component\Console\Output\BufferedOutput;
12 
17 {
21  private $composerApp;
22 
26  private $directoryList;
27 
34  public function __construct(Application $composerApp, DirectoryList $directoryList)
35  {
36  $this->composerApp = $composerApp;
37  $this->directoryList = $directoryList;
38  }
39 
50  public function checkDependencies(array $packages, $excludeSelf = false)
51  {
52  $this->composerApp->setAutoExit(false);
53  $dependencies = [];
54  foreach ($packages as $package) {
55  $buffer = new BufferedOutput();
56  $this->composerApp->resetComposer();
57  $this->composerApp->run(
58  new ArrayInput(
59  ['command' => 'depends', '--working-dir' => $this->directoryList->getRoot(), 'package' => $package]
60  ),
61  $buffer
62  );
63  $dependingPackages = $this->parseComposerOutput($buffer->fetch());
64  if ($excludeSelf === true) {
65  $dependingPackages = array_values(array_diff($dependingPackages, $packages));
66  }
67  $dependencies[$package] = $dependingPackages;
68  }
69  return $dependencies;
70  }
71 
78  private function parseComposerOutput($output)
79  {
80  $rawLines = explode(PHP_EOL, $output);
81  $packages = [];
82  foreach ($rawLines as $rawLine) {
83  $parts = explode(' ', $rawLine);
84  if (count(explode('/', $parts[0])) == 2) {
85  if (strpos($parts[0], 'magento/project-') === false) {
86  $packages[] = $parts[0];
87  }
88  }
89  }
90  return $packages;
91  }
92 }
checkDependencies(array $packages, $excludeSelf=false)
__construct(Application $composerApp, DirectoryList $directoryList)