Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Locker.php

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\Package

Code

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;
}
RSS feed
Powered by Drupal