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\VcsCode
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;
}