You are here

protected function SolrConnectorPluginBase::restRequest in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()
  2. 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()
  3. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::restRequest()

Sends a REST request to the Solr server endpoint and returns the result.

Parameters

string $handler: The handler used for the API query.

string $method: The HTTP request method.

string $command_json: The command to send encoded as JSON.

\Solarium\Core\Client\Endpoint|null $endpoint:

Return value

array The decoded response.

Throws

\Drupal\search_api_solr\SearchApiSolrException

4 calls to SolrConnectorPluginBase::restRequest()
SolrConnectorPluginBase::coreRestGet in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST GET request to the Solr core and returns the result.
SolrConnectorPluginBase::coreRestPost in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST POST request to the Solr core and returns the result.
SolrConnectorPluginBase::serverRestGet in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST GET request to the Solr server and returns the result.
SolrConnectorPluginBase::serverRestPost in src/SolrConnector/SolrConnectorPluginBase.php
Sends a REST POST request to the Solr server and returns the result.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 741

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

protected function restRequest($handler, $method = Request::METHOD_GET, $command_json = '', ?Endpoint $endpoint = NULL) {
  $this
    ->connect();
  $query = $this->solr
    ->createApi([
    'handler' => $handler,
    'accept' => 'application/json',
    'contenttype' => 'application/json',
    'method' => $method,
    'rawdata' => Request::METHOD_POST == $method ? $command_json : NULL,
  ]);
  $response = $this
    ->execute($query, $endpoint);
  $output = $response
    ->getData();

  // \Drupal::logger('search_api_solr')->info(print_r($output, true));.
  if (!empty($output['errors'])) {
    throw new SearchApiSolrException('Error trying to send a REST request.' . "\nError message(s):" . print_r($output['errors'], TRUE));
  }
  return $output;
}