Mercurial > hg > isophonics-drupal-site
comparison vendor/guzzlehttp/guzzle/src/Handler/Proxy.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 namespace GuzzleHttp\Handler; | |
3 | |
4 use GuzzleHttp\RequestOptions; | |
5 use Psr\Http\Message\RequestInterface; | |
6 | |
7 /** | |
8 * Provides basic proxies for handlers. | |
9 */ | |
10 class Proxy | |
11 { | |
12 /** | |
13 * Sends synchronous requests to a specific handler while sending all other | |
14 * requests to another handler. | |
15 * | |
16 * @param callable $default Handler used for normal responses | |
17 * @param callable $sync Handler used for synchronous responses. | |
18 * | |
19 * @return callable Returns the composed handler. | |
20 */ | |
21 public static function wrapSync( | |
22 callable $default, | |
23 callable $sync | |
24 ) { | |
25 return function (RequestInterface $request, array $options) use ($default, $sync) { | |
26 return empty($options[RequestOptions::SYNCHRONOUS]) | |
27 ? $default($request, $options) | |
28 : $sync($request, $options); | |
29 }; | |
30 } | |
31 | |
32 /** | |
33 * Sends streaming requests to a streaming compatible handler while sending | |
34 * all other requests to a default handler. | |
35 * | |
36 * This, for example, could be useful for taking advantage of the | |
37 * performance benefits of curl while still supporting true streaming | |
38 * through the StreamHandler. | |
39 * | |
40 * @param callable $default Handler used for non-streaming responses | |
41 * @param callable $streaming Handler used for streaming responses | |
42 * | |
43 * @return callable Returns the composed handler. | |
44 */ | |
45 public static function wrapStreaming( | |
46 callable $default, | |
47 callable $streaming | |
48 ) { | |
49 return function (RequestInterface $request, array $options) use ($default, $streaming) { | |
50 return empty($options['stream']) | |
51 ? $default($request, $options) | |
52 : $streaming($request, $options); | |
53 }; | |
54 } | |
55 } |