Monorepo\Build::loadPackages PHP Метод

loadPackages() публичный Метод

public loadPackages ( $rootDirectory )
    public function loadPackages($rootDirectory)
    {
        $finder = new Finder();
        $finder->in($rootDirectory)->exclude('vendor')->ignoreVCS(true)->name('monorepo.json');
        $packages = array();
        foreach ($finder as $file) {
            $monorepoJson = $this->loadMonorepoJson($file->getContents(), $file->getPath());
            if ($monorepoJson === NULL) {
                throw new \RuntimeException("Invalid " . $file->getRelativePath() . '/monorepo.json file.');
            }
            $monorepoJson['path'] = $file->getRelativePath();
            if (!isset($monorepoJson['autoload'])) {
                $monorepoJson['autoload'] = array();
            }
            if (!isset($monorepoJson['autoload-dev'])) {
                $monorepoJson['autoload-dev'] = array();
            }
            if (!isset($monorepoJson['deps'])) {
                $monorepoJson['deps'] = array();
            }
            if (!isset($monorepoJson['deps-dev'])) {
                $monorepoJson['deps-dev'] = array();
            }
            $packages[$file->getRelativePath()] = $monorepoJson;
        }
        $installedJsonFile = $rootDirectory . '/vendor/composer/installed.json';
        if (file_exists($installedJsonFile)) {
            $installed = json_decode(file_get_contents($installedJsonFile), true);
            if ($installed === NULL) {
                throw new \RuntimeException("Invalid installed.json file at " . dirname($installedJsonFile));
            }
            foreach ($installed as $composerJson) {
                $name = $composerJson['name'];
                $monorepoedComposerJson = array('path' => 'vendor/' . $name, 'autoload' => array(), 'deps' => array(), 'bin' => array());
                if (isset($composerJson['autoload'])) {
                    $monorepoedComposerJson['autoload'] = $composerJson['autoload'];
                }
                if (isset($composerJson['autoload-dev'])) {
                    $monorepoedComposerJson['autoload'] = array_merge_recursive($monorepoedComposerJson['autoload'], $composerJson['autoload-dev']);
                }
                if (isset($composerJson['require'])) {
                    foreach ($composerJson['require'] as $packageName => $_) {
                        $monorepoedComposerJson['deps'][] = 'vendor/' . $packageName;
                    }
                }
                if (isset($composerJson['bin'])) {
                    foreach ($composerJson['bin'] as $binary) {
                        $binary = 'vendor/' . $composerJson['name'] . '/' . $binary;
                        if (!in_array($binary, $monorepoedComposerJson['bin'])) {
                            $monorepoedComposerJson['bin'][] = $binary;
                        }
                    }
                }
                $packages['vendor/' . strtolower($name)] = $monorepoedComposerJson;
                if (isset($composerJson['provide'])) {
                    foreach ($composerJson['provide'] as $provideName => $_) {
                        $packages['vendor/' . $provideName] = $monorepoedComposerJson;
                    }
                }
                if (isset($composerJson['replace'])) {
                    foreach ($composerJson['replace'] as $replaceName => $_) {
                        $packages['vendor/' . $replaceName] = $monorepoedComposerJson;
                    }
                }
            }
        }
        return $packages;
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $range = $input->getArgument('range') ?: (isset($_SERVER['TRAVIS_COMMIT_RANGE']) ? $_SERVER['TRAVIS_COMMIT_RANGE'] : '');
     if (!$range) {
         throw new \RuntimeException("No git range given via argument or TRAVIS_COMMIT_RANGE environment variable.");
     }
     exec('git diff --name-only ' . escapeshellarg($range), $result);
     $build = new Build(new ConsoleIO($input, $output, $this->getHelperSet()));
     $this->packages = $build->loadPackages(getcwd());
     $changePackageName = rtrim($input->getArgument('package'), '/');
     $this->calculateDependencies($changePackageName);
     if ($output->isVerbose()) {
         $output->writeln('Checking for changes in the following directories:');
         foreach ($this->checkPaths as $checkPath) {
             $output->writeln('- ' . $checkPath);
         }
         $output->writeln(sprintf('Iterating the changed files in git commit range %s', $range));
     }
     $found = false;
     foreach ($result as $changedFile) {
         if ($output->isVerbose()) {
             $output->writeln(sprintf("- %s", $changedFile));
         }
         foreach ($this->checkPaths as $checkPath) {
             if (strpos(trim($changedFile), $checkPath) !== false) {
                 if ($output->isVerbose()) {
                     $output->writeln(sprintf('  Matches check path %s', $checkPath));
                 }
                 $found = true;
             }
         }
     }
     exit($found ? 0 : 1);
 }
All Usage Examples Of Monorepo\Build::loadPackages