public function TestRequestService::request in Entity Share 8.2
Performs a HTTP request. Wraps the Guzzle HTTP client.
Why wrap the Guzzle HTTP client? Because we want to be able to override this service during tests to emulate another website.
Parameters
\GuzzleHttp\Client $http_client: The HTTP client.
string $method: HTTP method.
string $url: URL to request.
Return value
\Psr\Http\Message\ResponseInterface The response.
Overrides RequestService::request
See also
\GuzzleHttp\ClientInterface::request()
File
- modules/
entity_share_client/ tests/ modules/ entity_share_client_request_test/ src/ Service/ TestRequestService.php, line 27
Class
- TestRequestService
- Class TestRequestService.
Namespace
Drupal\entity_share_client_request_test\ServiceCode
public function request(Client $http_client, $method, $url) {
// It it is a GET request store the result to be able to re-obtain the
// result to simulate another website.
if ($method == 'GET') {
if (!isset($this->responseMapping[$url])) {
$this->responseMapping[$url] = parent::request($http_client, $method, $url);
}
return $this->responseMapping[$url];
}
return parent::request($http_client, $method, $url);
}