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]];
}