Esempio n. 1
0
 /**
  * Return the file contents.
  *
  * @param string $fileName
  * @throws \Exception
  * @return array(string, string) [$contentType, $content]
  */
 public function readFile($fileName)
 {
     $this->validateConnectionSettings();
     /** @var LocalGitRepoConnectionSettings $connectionSettings */
     $connectionSettings = $this->getConnectionSettings();
     $content = $this->gitArchiveFile($connectionSettings->getHostName(), $connectionSettings->getGroupName(), $connectionSettings->getRepoName(), $fileName, $connectionSettings->getNamedReference(), $connectionSettings->getGitExecutable());
     $contentType = FileUtils::getContentTypeFromFileName($fileName);
     return array($contentType, $content);
 }
Esempio n. 2
0
 /**
  * Return the file contents.
  *
  * @param string $fileName
  * @throws \Exception
  * @return array(string, string) [$contentType, $content]
  */
 public function readFile($fileName)
 {
     $this->validateConnectionSettings();
     /** @var LocalFileConnectionSettings $connectionSettings */
     $connectionSettings = $this->getConnectionSettings();
     $rootPath = $connectionSettings->getRootPath();
     $normalizedPath = FileUtils::normalizePath($fileName, true);
     $localFileName = $rootPath . DIRECTORY_SEPARATOR . $normalizedPath;
     if (!file_exists($localFileName)) {
         throw new \Exception($this->getFileNotFoundMessage($fileName));
     }
     $content = file_get_contents($fileName);
     $contentType = FileUtils::getContentTypeFromFileName($fileName);
     return array($contentType, $content);
 }
Esempio n. 3
0
 /**
  * Return the file contents.
  *
  * @param string $fileName
  * @throws \Exception
  * @return array(string, string) [$contentType, $content]
  */
 public function readFile($fileName)
 {
     $this->validateConnectionSettings();
     /** @var GitLabRepoConnectionSettings $connectionSettings */
     $connectionSettings = $this->getConnectionSettings();
     $remote = sprintf('git@%s:%s/%s.git', $connectionSettings->getHostName(), $connectionSettings->getGroupName(), $connectionSettings->getRepoName());
     $url = sprintf("%s/projects/%s/repository/blobs/%s?private_token=%s&filepath=%s", $connectionSettings->getUrl(), str_replace('.', '%2E', urlencode($remote)), $connectionSettings->getNamedReference(), $connectionSettings->getApiToken(), $fileName);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, "application/json");
     $content = curl_exec($ch);
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     if ($httpCode != 200) {
         throw new FileClientConnectionException(sprintf('Unable to fetch file "%s" from %s (%s) via GitLab API %s. Got response code %s.', $fileName, $remote, $connectionSettings->getNamedReference(), $connectionSettings->getUrl(), $httpCode));
     }
     $contentType = FileUtils::getContentTypeFromFileName($fileName);
     return array($contentType, $content);
 }