/**
  * @param string $key AWS IAM User Key
  * @param string $secret AWS IAM User Secret
  * @param string $region AWS Region
  * @param array $multiParams Parameters to pass to CURL
  * @param array $singleParams Parmaters to pass to CURL
  *
  * @return ClientBuilder
  */
 public function setAwsHandler($key, $secret, $region = 'us-east-1', $multiParams = [], $singleParams = [])
 {
     $future = null;
     if (extension_loaded('curl')) {
         $config = array_merge(['mh' => curl_multi_init()], $multiParams);
         if (function_exists('curl_reset')) {
             $default = new CurlHandler($singleParams);
             $future = new CurlMultiHandler($config);
         } else {
             $default = new CurlMultiHandler($config);
         }
     } else {
         throw new \RuntimeException('Elasticsearch-PHP requires cURL, or a custom HTTP handler.');
     }
     $curlHandler = $future ? Middleware::wrapFuture($default, $future) : $default;
     $awsSignedHandler = function (array $request) use($curlHandler, $region, $key, $secret) {
         $signer = new SignatureV4('es', $region);
         $credentials = new Credentials($key, $secret);
         $psr7Request = new Request($request['http_method'], $request['uri'], $request['headers'], $request['body']);
         $signedRequest = $signer->signRequest($psr7Request, $credentials);
         $request['headers'] = $signedRequest->getHeaders();
         return $curlHandler($request);
     };
     $this->setHandler($awsSignedHandler);
     return $this;
 }
Exemple #2
0
 public function testStreamingCallsStreamingHandler()
 {
     $calledA = false;
     $a = function (array $req) use(&$calledA) {
         $calledA = true;
     };
     $calledB = false;
     $b = function (array $req) use(&$calledB) {
         $calledB = true;
     };
     $s = Middleware::wrapStreaming($a, $b);
     $s(['client' => ['stream' => true]]);
     $this->assertFalse($calledA);
     $this->assertTrue($calledB);
 }
 /**
  * @param array $singleParams
  * @param array $multiParams
  * @throws \RuntimeException
  * @return callable
  */
 public static function defaultHandler($multiParams = [], $singleParams = [])
 {
     $future = null;
     if (extension_loaded('curl')) {
         $config = array_merge(['mh' => curl_multi_init()], $multiParams);
         if (function_exists('curl_reset')) {
             $default = new CurlHandler($singleParams);
             $future = new CurlMultiHandler($config);
         } else {
             $default = new CurlMultiHandler($config);
         }
     } else {
         throw new \RuntimeException('Elasticsearch-PHP requires cURL, or a custom HTTP handler.');
     }
     return $future ? Middleware::wrapFuture($default, $future) : $default;
 }
Exemple #4
0
 /**
  * Create a default handler to use based on the environment
  *
  * @throws \RuntimeException if no viable Handler is available.
  */
 public static function getDefaultHandler()
 {
     $default = $future = $streaming = null;
     if (extension_loaded('curl')) {
         $config = array('select_timeout' => getenv('GUZZLE_CURL_SELECT_TIMEOUT') ?: 1);
         if ($maxHandles = getenv('GUZZLE_CURL_MAX_HANDLES')) {
             $config['max_handles'] = $maxHandles;
         }
         $future = new CurlMultiHandler($config);
         if (function_exists('curl_reset')) {
             $default = new CurlHandler();
         }
     }
     if (ini_get('allow_url_fopen')) {
         $streaming = new StreamHandler();
     }
     if (!($default = $default ?: $future ?: $streaming)) {
         throw new \RuntimeException('Guzzle requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
     }
     $handler = $default;
     if ($streaming && $streaming !== $default) {
         $handler = Middleware::wrapStreaming($default, $streaming);
     }
     if ($future) {
         $handler = Middleware::wrapFuture($handler, $future);
     }
     return $handler;
 }
Exemple #5
0
 /**
  * Create a default handler to use based on the environment
  *
  * @throws \RuntimeException if no viable Handler is available.
  */
 public static function getDefaultHandler()
 {
     $default = $future = null;
     if (extension_loaded('curl')) {
         $config = ['select_timeout' => getenv('GUZZLE_CURL_SELECT_TIMEOUT') ?: 1];
         if ($maxHandles = getenv('GUZZLE_CURL_MAX_HANDLES')) {
             $config['max_handles'] = $maxHandles;
         }
         if (function_exists('curl_reset')) {
             $default = new CurlHandler();
             $future = new CurlMultiHandler($config);
         } else {
             $default = new CurlMultiHandler($config);
         }
     }
     if (ini_get('allow_url_fopen')) {
         $default = !$default ? new StreamHandler() : Middleware::wrapStreaming($default, new StreamHandler());
     } elseif (!$default) {
         throw new \RuntimeException('Guzzle requires cURL, the ' . 'allow_url_fopen ini setting, or a custom HTTP handler.');
     }
     return $future ? Middleware::wrapFuture($default, $future) : $default;
 }