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

Breadcrumb

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

function GitHubDriver::getFileContent

@inheritDoc

Overrides VcsDriverInterface::getFileContent

File

vendor/composer/composer/src/Composer/Repository/Vcs/GitHubDriver.php, line 299

Class

GitHubDriver
@author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Repository\Vcs

Code

public function getFileContent(string $file, string $identifier) : ?string {
    if ($this->gitDriver) {
        return $this->gitDriver
            ->getFileContent($file, $identifier);
    }
    $resource = $this->getApiUrl() . '/repos/' . $this->owner . '/' . $this->repository . '/contents/' . $file . '?ref=' . urlencode($identifier);
    $resource = $this->getContents($resource)
        ->decodeJson();
    // The GitHub contents API only returns files up to 1MB as base64 encoded files
    // larger files either need be fetched with a raw accept header or by using the git blob endpoint
    if ((!isset($resource['content']) || $resource['content'] === '') && $resource['encoding'] === 'none' && isset($resource['git_url'])) {
        $resource = $this->getContents($resource['git_url'])
            ->decodeJson();
    }
    if (!isset($resource['content']) || $resource['encoding'] !== 'base64' || false === ($content = base64_decode($resource['content']))) {
        throw new \RuntimeException('Could not retrieve ' . $file . ' for ' . $identifier);
    }
    return $content;
}
RSS feed
Powered by Drupal