forked from yiisoft/yii2-httpclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transport.php
44 lines (40 loc) · 1.23 KB
/
Transport.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\httpclient;
use yii\base\Component;
/**
* Transport performs actual HTTP request sending.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
abstract class Transport extends Component
{
/**
* Performs given request.
* @param Request $request request to be sent.
* @return Response response instance.
* @throws Exception on failure.
*/
abstract public function send($request);
/**
* Performs multiple HTTP requests.
* Particular transport may benefit from this method, allowing sending requests in parallel.
* This method accepts an array of the [[Request]] objects and returns an array of the [[Response]] objects.
* Keys of the response array correspond the ones from request array.
* @param Request[] $requests requests to perform.
* @return Response[] responses list.
*/
public function batchSend(array $requests)
{
$responses = [];
foreach ($requests as $key => $request) {
$responses[$key] = $this->send($request);
}
return $responses;
}
}