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

Breadcrumb

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

function SelfUpdateCommand::fetchKeys

Throws

\Exception

1 call to SelfUpdateCommand::fetchKeys()
SelfUpdateCommand::execute in vendor/composer/composer/src/Composer/Command/SelfUpdateCommand.php

File

vendor/composer/composer/src/Composer/Command/SelfUpdateCommand.php, line 367

Class

SelfUpdateCommand
@author Igor Wiedler <igor@wiedler.ch> @author Kevin Ran <kran@adobe.com> @author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Command

Code

protected function fetchKeys(IOInterface $io, Config $config) : void {
    if (!$io->isInteractive()) {
        throw new \RuntimeException('Public keys can not be fetched in non-interactive mode, please run Composer interactively');
    }
    $io->write('Open <info>https://composer.github.io/pubkeys.html</info> to find the latest keys');
    $validator = static function ($value) : string {
        $value = (string) $value;
        if (!Preg::isMatch('{^-----BEGIN PUBLIC KEY-----$}', trim($value))) {
            throw new \UnexpectedValueException('Invalid input');
        }
        return trim($value) . "\n";
    };
    $devKey = '';
    while (!Preg::isMatch('{(-----BEGIN PUBLIC KEY-----.+?-----END PUBLIC KEY-----)}s', $devKey, $match)) {
        $devKey = $io->askAndValidate('Enter Dev / Snapshot Public Key (including lines with -----): ', $validator);
        while ($line = $io->ask('', '')) {
            $devKey .= trim($line) . "\n";
            if (trim($line) === '-----END PUBLIC KEY-----') {
                break;
            }
        }
    }
    file_put_contents($keyPath = $config->get('home') . '/keys.dev.pub', $match[0]);
    $io->write('Stored key with fingerprint: ' . Keys::fingerprint($keyPath));
    $tagsKey = '';
    while (!Preg::isMatch('{(-----BEGIN PUBLIC KEY-----.+?-----END PUBLIC KEY-----)}s', $tagsKey, $match)) {
        $tagsKey = $io->askAndValidate('Enter Tags Public Key (including lines with -----): ', $validator);
        while ($line = $io->ask('', '')) {
            $tagsKey .= trim($line) . "\n";
            if (trim($line) === '-----END PUBLIC KEY-----') {
                break;
            }
        }
    }
    file_put_contents($keyPath = $config->get('home') . '/keys.tags.pub', $match[0]);
    $io->write('Stored key with fingerprint: ' . Keys::fingerprint($keyPath));
    $io->write('Public keys stored in ' . $config->get('home'));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal