httpClient = \Drupal::httpClient(); } /** * Returns the initialized authentication plugin. * * @return \Drupal\migrate_plus\AuthenticationPluginInterface * The authentication plugin. */ public function getAuthenticationPlugin() { if (!isset($this->authenticationPlugin)) { $this->authenticationPlugin = \Drupal::service('plugin.manager.migrate_plus.authentication')->createInstance($this->configuration['authentication']['plugin'], $this->configuration['authentication']); } return $this->authenticationPlugin; } /** * {@inheritdoc} */ public function setRequestHeaders(array $headers) { $this->headers = $headers; } /** * {@inheritdoc} */ public function getRequestHeaders() { return !empty($this->headers) ? $this->headers : []; } /** * {@inheritdoc} */ public function getResponse($url) { try { $options = ['headers' => $this->getRequestHeaders()]; if (!empty($this->configuration['authentication'])) { $options = array_merge($options, $this->getAuthenticationPlugin()->getAuthenticationOptions()); } $response = $this->httpClient->get($url, $options); if (empty($response)) { throw new MigrateException('No response at ' . $url . '.'); } } catch (RequestException $e) { throw new MigrateException('Error message: ' . $e->getMessage() . ' at ' . $url .'.'); } return $response; } /** * {@inheritdoc} */ public function getResponseContent($url) { $response = $this->getResponse($url); return $response->getBody(); } }