source: externals/php/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php@ cf345ee

Last change on this file since cf345ee was 01a620f, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago

Removed submodules for php externals and use composer to provide them and versioned them afterwards

  • Property mode set to 100644
File size: 1.7 KB
Line 
1<?php
2namespace GuzzleHttp\Handler;
3
4use Psr\Http\Message\RequestInterface;
5
6/**
7 * Provides basic proxies for handlers.
8 */
9class Proxy
10{
11 /**
12 * Sends synchronous requests to a specific handler while sending all other
13 * requests to another handler.
14 *
15 * @param callable $default Handler used for normal responses
16 * @param callable $sync Handler used for synchronous responses.
17 *
18 * @return callable Returns the composed handler.
19 */
20 public static function wrapSync(
21 callable $default,
22 callable $sync
23 ) {
24 return function (RequestInterface $request, array $options) use ($default, $sync) {
25 return empty($options['sync'])
26 ? $default($request, $options)
27 : $sync($request, $options);
28 };
29 }
30
31 /**
32 * Sends streaming requests to a streaming compatible handler while sending
33 * all other requests to a default handler.
34 *
35 * This, for example, could be useful for taking advantage of the
36 * performance benefits of curl while still supporting true streaming
37 * through the StreamHandler.
38 *
39 * @param callable $default Handler used for non-streaming responses
40 * @param callable $streaming Handler used for streaming responses
41 *
42 * @return callable Returns the composed handler.
43 */
44 public static function wrapStreaming(
45 callable $default,
46 callable $streaming
47 ) {
48 return function (RequestInterface $request, array $options) use ($default, $streaming) {
49 return empty($options['stream'])
50 ? $default($request, $options)
51 : $streaming($request, $options);
52 };
53 }
54}
Note: See TracBrowser for help on using the repository browser.