function Locker::getPackageTime
Returns the packages's datetime for its source reference.
Parameters
PackageInterface $package The package to scan.:
Return value
string|null The formatted datetime or null if none was found.
1 call to Locker::getPackageTime()
- Locker::lockPackages in vendor/
composer/ composer/ src/ Composer/ Package/ Locker.php - @phpstan-return list<array<string, mixed>>
File
-
vendor/
composer/ composer/ src/ Composer/ Package/ Locker.php, line 537
Class
- Locker
- Reads/writes project lockfile (composer.lock).
Namespace
Composer\PackageCode
private function getPackageTime(PackageInterface $package) : ?string {
if (!function_exists('proc_open')) {
return null;
}
$path = $this->installationManager
->getInstallPath($package);
if ($path === null) {
return null;
}
$path = realpath($path);
$sourceType = $package->getSourceType();
$datetime = null;
if ($path && in_array($sourceType, [
'git',
'hg',
])) {
$sourceRef = $package->getSourceReference() ?: $package->getDistReference();
switch ($sourceType) {
case 'git':
GitUtil::cleanEnv();
$command = array_merge([
'git',
'log',
'-n1',
'--pretty=%ct',
(string) $sourceRef,
], GitUtil::getNoShowSignatureFlags($this->process));
if (0 === $this->process
->execute($command, $output, $path) && Preg::isMatch('{^\\s*\\d+\\s*$}', $output)) {
$datetime = new \DateTime('@' . trim($output), new \DateTimeZone('UTC'));
}
break;
case 'hg':
if (0 === $this->process
->execute([
'hg',
'log',
'--template',
'{date|hgdate}',
'-r',
(string) $sourceRef,
], $output, $path) && Preg::isMatch('{^\\s*(\\d+)\\s*}', $output, $match)) {
$datetime = new \DateTime('@' . $match[1], new \DateTimeZone('UTC'));
}
break;
}
}
return $datetime ? $datetime->format(DATE_RFC3339) : null;
}