Composer\Satis\Builder\PackagesBuilder::dumpPackageIncludeJson PHP Method

dumpPackageIncludeJson() private method

Writes includes JSON Files.
private dumpPackageIncludeJson ( array $packages, string $includesUrl, string $hashAlgorithm = 'sha1' ) : array
$packages array List of packages to dump
$includesUrl string The includes url (optionally containing %hash%)
$hashAlgorithm string Hash algorithm {@see \hash()}
return array The object for includes key in packages.json
    private function dumpPackageIncludeJson(array $packages, $includesUrl, $hashAlgorithm = 'sha1')
    {
        $filename = str_replace('%hash%', 'prep', $includesUrl);
        $path = $tmpPath = $this->outputDir . '/' . ltrim($filename, '/');
        $repoJson = new JsonFile($path);
        $contents = $repoJson->encode(['packages' => $packages]) . "\n";
        $hash = hash($hashAlgorithm, $contents);
        if (strpos($includesUrl, '%hash%') !== false) {
            $this->writtenIncludeJsons[] = [$hash, $includesUrl];
            $filename = str_replace('%hash%', $hash, $includesUrl);
            if (file_exists($path = $this->outputDir . '/' . ltrim($filename, '/'))) {
                // When the file exists, we don't need to override it as we assume,
                // the contents satisfy the hash
                $path = null;
            }
        }
        if ($path) {
            $this->writeToFile($path, $contents);
            $this->output->writeln("<info>wrote packages to {$path}</info>");
        }
        return [$filename => [$hashAlgorithm => $hash]];
    }