Ejemplo n.º 1
0
 public function testSendsToNonStreaming()
 {
     $a = $b = null;
     $m1 = new MockHandler([function ($v) use(&$a) {
         $a = $v;
     }]);
     $m2 = new MockHandler([function ($v) use(&$b) {
         $b = $v;
     }]);
     $h = Proxy::wrapStreaming($m1, $m2);
     $h(new Request('GET', 'http://foo.com'), ['stream' => true]);
     $this->assertNull($a);
     $this->assertNotNull($b);
 }
Ejemplo n.º 2
0
/**
 * Chooses and creates a default handler to use based on the environment.
 *
 * The returned handler is not wrapped by any default middlewares.
 *
 * @throws \RuntimeException if no viable Handler is available.
 * @return callable Returns the best handler for the given system.
 */
function choose_handler()
{
    $handler = null;
    if (function_exists('curl_multi_exec') && function_exists('curl_exec')) {
        $handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler());
    } elseif (function_exists('curl_exec')) {
        $handler = new CurlHandler();
    } elseif (function_exists('curl_multi_exec')) {
        $handler = new CurlMultiHandler();
    }
    if (ini_get('allow_url_fopen')) {
        $handler = $handler ? Proxy::wrapStreaming($handler, new StreamHandler()) : new StreamHandler();
    } elseif (!$handler) {
        throw new \RuntimeException('GuzzleHttp requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
    }
    return $handler;
}