vendor/guzzlehttp/guzzle/src/Handler/Proxy.php line 28

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