vendor/symfony/http-client/HttpClient.php line 30

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpClient;
  11. use Symfony\Contracts\HttpClient\HttpClientInterface;
  12. /**
  13.  * A factory to instantiate the best possible HTTP client for the runtime.
  14.  *
  15.  * @author Nicolas Grekas <[email protected]>
  16.  */
  17. final class HttpClient
  18. {
  19.     /**
  20.      * @param array $defaultOptions     Default request's options
  21.      * @param int   $maxHostConnections The maximum number of connections to a single host
  22.      * @param int   $maxPendingPushes   The maximum number of pushed responses to accept in the queue
  23.      *
  24.      * @see HttpClientInterface::OPTIONS_DEFAULTS for available options
  25.      */
  26.     public static function create(array $defaultOptions = [], int $maxHostConnections 6int $maxPendingPushes 50): HttpClientInterface
  27.     {
  28.         if (\extension_loaded('curl')) {
  29.             if ('\\' !== \DIRECTORY_SEPARATOR || ini_get('curl.cainfo') || ini_get('openssl.cafile') || ini_get('openssl.capath')) {
  30.                 return new CurlHttpClient($defaultOptions$maxHostConnections$maxPendingPushes);
  31.             }
  32.             @trigger_error('Configure the "curl.cainfo", "openssl.cafile" or "openssl.capath" php.ini setting to enable the CurlHttpClient'E_USER_WARNING);
  33.         }
  34.         return new NativeHttpClient($defaultOptions$maxHostConnections);
  35.     }
  36.     /**
  37.      * Creates a client that adds options (e.g. authentication headers) only when the request URL matches the provided base URI.
  38.      */
  39.     public static function createForBaseUri(string $baseUri, array $defaultOptions = [], int $maxHostConnections 6int $maxPendingPushes 50): HttpClientInterface
  40.     {
  41.         $client self::create([], $maxHostConnections$maxPendingPushes);
  42.         return ScopingHttpClient::forBaseUri($client$baseUri$defaultOptions);
  43.     }
  44. }