Final Class yii\httpclient\MockTransport
Inheritance | yii\httpclient\MockTransport » yii\httpclient\Transport » yii\base\Component |
---|---|
Source Code | https://github.com/yiisoft/yii2-httpclient/blob/master/src/MockTransport.php |
Public Methods
Method | Description | Defined By |
---|---|---|
appendResponse() | yii\httpclient\MockTransport | |
batchSend() | Performs multiple HTTP requests. | yii\httpclient\Transport |
flushRequests() | yii\httpclient\MockTransport | |
send() | Performs given request. | yii\httpclient\MockTransport |
Method Details
public void appendResponse ( yii\httpclient\Response $response ) | ||
$response | yii\httpclient\Response |
public function appendResponse(Response $response)
{
$this->responses[] = $response;
}
Defined in: yii\httpclient\Transport::batchSend()
Performs multiple HTTP requests.
Particular transport may benefit from this method, allowing sending requests in parallel. This method accepts an array of the yii\httpclient\Request objects and returns an array of the yii\httpclient\Response objects. Keys of the response array correspond the ones from request array.
public yii\httpclient\Response[] batchSend ( array $requests ) | ||
$requests | yii\httpclient\Request[] |
Requests to perform. |
return | yii\httpclient\Response[] |
Responses list. |
---|---|---|
throws | yii\httpclient\Exception |
public function batchSend(array $requests)
{
$responses = [];
foreach ($requests as $key => $request) {
$responses[$key] = $this->send($request);
}
return $responses;
}
public yii\httpclient\Request[] flushRequests ( ) |
public function flushRequests()
{
$requests = $this->requests;
$this->requests = [];
return $requests;
}
Performs given request.
public yii\httpclient\Response send ( $request ) | ||
$request | yii\httpclient\Request |
Request to be sent. |
return | yii\httpclient\Response |
Response instance. |
---|---|---|
throws | yii\httpclient\Exception |
on failure. |
public function send($request)
{
if (empty($this->responses)) {
throw new Exception('No Response available');
}
$nextResponse = array_shift($this->responses);
if (null === $nextResponse->client) {
$nextResponse->client = $request->client;
}
$this->requests[] = $request;
return $nextResponse;
}