function Locker::updateHash
Updates the lock file's hash in-place from a given composer.json's JsonFile
This does not reload or require any packages, and retains the filemtime of the lock file.
Use this only to update the lock file hash after updating a composer.json in ways that are guaranteed NOT to impact the dependency resolution.
This is a risky method, use carefully.
Parameters
(callable(array<string, mixed>): array<string, mixed>)|null $dataProcessor Receives the lock data and can process it before it gets written to disk:
File
-
vendor/
composer/ composer/ src/ Composer/ Package/ Locker.php, line 429
Class
- Locker
- Reads/writes project lockfile (composer.lock).
Namespace
Composer\PackageCode
public function updateHash(JsonFile $composerJson, ?callable $dataProcessor = null) : void {
$contents = file_get_contents($composerJson->getPath());
if (false === $contents) {
throw new \RuntimeException('Unable to read ' . $composerJson->getPath() . ' contents to update the lock file hash.');
}
$lockMtime = filemtime($this->lockFile
->getPath());
$lockData = $this->lockFile
->read();
$lockData['content-hash'] = Locker::getContentHash($contents);
if ($dataProcessor !== null) {
$lockData = $dataProcessor($lockData);
}
$this->lockFile
->write($this->fixupJsonDataType($lockData));
$this->lockDataCache = null;
$this->virtualFileWritten = false;
if (is_int($lockMtime)) {
@touch($this->lockFile
->getPath(), $lockMtime);
}
}