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

Breadcrumb

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

function GitLabDriver::getFileContent

@inheritDoc

Overrides VcsDriverInterface::getFileContent

File

vendor/composer/composer/src/Composer/Repository/Vcs/GitLabDriver.php, line 192

Class

GitLabDriver
Driver for GitLab API, use the Git driver for local checkouts.

Namespace

Composer\Repository\Vcs

Code

public function getFileContent(string $file, string $identifier) : ?string {
    if ($this->gitDriver) {
        return $this->gitDriver
            ->getFileContent($file, $identifier);
    }
    // Convert the root identifier to a cacheable commit id
    if (!Preg::isMatch('{[a-f0-9]{40}}i', $identifier)) {
        $branches = $this->getBranches();
        if (isset($branches[$identifier])) {
            $identifier = $branches[$identifier];
        }
    }
    $resource = $this->getApiUrl() . '/repository/files/' . $this->urlEncodeAll($file) . '/raw?ref=' . $identifier;
    try {
        $content = $this->getContents($resource)
            ->getBody();
    } catch (TransportException $e) {
        if ($e->getCode() !== 404) {
            throw $e;
        }
        return null;
    }
    return $content;
}
RSS feed
Powered by Drupal