You are here

public function HttpServiceApiWrapperBase::httpConfigRequest in HTTP Client Manager 8.2

Executes an HTTP Config Request.

Parameters

string $request_name: The Http Config Request name.

int|bool $expire: The expire time, Cache::PERMANENT or FALSE if cache has not to be used.

array $tags: An array of cache tags to be used if $expire !== FALSE.

Return value

array The Response array.

Overrides HttpServiceApiWrapperInterface::httpConfigRequest

File

src/Plugin/HttpServiceApiWrapper/HttpServiceApiWrapperBase.php, line 125

Class

HttpServiceApiWrapperBase
Class HttpServiceApiWrapperBase.

Namespace

Drupal\http_client_manager\Plugin\HttpServiceApiWrapper

Code

public function httpConfigRequest($request_name, $expire = FALSE, array $tags = []) {
  $request = HttpConfigRequest::load($request_name);
  if (empty($request)) {
    $args = [
      '%name' => $request_name,
    ];
    $message = $this
      ->t('Undefined HTTP Config Request "%name"', $args);
    throw new \InvalidArgumentException($message);
  }
  if ($expire !== FALSE) {
    return $this
      ->getCachedHttpConfigRequest($request, $expire, $tags);
  }
  try {
    $data = $request
      ->execute()
      ->toArray();
  } catch (CommandException $e) {
    $this
      ->logError($e);
    $data = [];
  }
  return $data;
}