You are here

protected function HttpClient::initFileLoader in HTTP Client Manager 8.2

Set File Loader.

1 call to HttpClient::initFileLoader()
HttpClient::getFileLoader in src/HttpClient.php
Get File Loader.

File

src/HttpClient.php, line 294

Class

HttpClient
The http client.

Namespace

Drupal\http_client_manager

Code

protected function initFileLoader() {
  $source = $this
    ->getApiSourceInfo();
  $locator = $this
    ->getFileLocator();
  switch ($source['extension']) {
    case 'json':
      $loader = new JsonLoader($locator);
      break;
    case 'yml':
      $loader = new YamlLoader($locator);
      break;
    case 'php':
      $loader = new PhpLoader($locator);
      break;
    default:
      $allowed_extensions = [
        'json',
        'yml',
        'php',
      ];
      $message = sprintf('Invalid HTTP Services Api source provided: "%s". ', $source['filename']);
      $message .= sprintf('File extension must be one of %s.', implode(', ', $allowed_extensions));
      throw new \RuntimeException($message);
  }
  $this->fileLoader = $loader;
}