scratch – Blame information for rev 87
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | |||
3 | namespace GuzzleHttp\Adapter; |
||
4 | |||
5 | /** |
||
6 | * Sends streaming requests to a streaming compatible adapter while sending all |
||
7 | * other requests to a default adapter. |
||
8 | * |
||
9 | * This, for example, could be useful for taking advantage of the performance |
||
10 | * benefits of the CurlAdapter while still supporting true streaming through |
||
11 | * the StreamAdapter. |
||
12 | */ |
||
13 | class StreamingProxyAdapter implements AdapterInterface |
||
14 | { |
||
15 | private $defaultAdapter; |
||
16 | private $streamingAdapter; |
||
17 | |||
18 | /** |
||
19 | * @param AdapterInterface $defaultAdapter Adapter used for non-streaming responses |
||
20 | * @param AdapterInterface $streamingAdapter Adapter used for streaming responses |
||
21 | */ |
||
22 | public function __construct( |
||
23 | AdapterInterface $defaultAdapter, |
||
24 | AdapterInterface $streamingAdapter |
||
25 | ) { |
||
26 | $this->defaultAdapter = $defaultAdapter; |
||
27 | $this->streamingAdapter = $streamingAdapter; |
||
28 | } |
||
29 | |||
30 | public function send(TransactionInterface $transaction) |
||
31 | { |
||
32 | return $transaction->getRequest()->getConfig()['stream'] |
||
33 | ? $this->streamingAdapter->send($transaction) |
||
34 | : $this->defaultAdapter->send($transaction); |
||
35 | } |
||
36 | } |