Cheetah
HttpClientsFactory.php
Go to the documentation of this file.
1 <?php
24 namespace Facebook\HttpClients;
25 
26 use GuzzleHttp\Client;
27 use InvalidArgumentException;
28 use Exception;
29 
31 {
32  private function __construct()
33  {
34  // a factory constructor should never be invoked
35  }
36 
47  public static function createHttpClient($handler)
48  {
49  if (!$handler) {
50  return self::detectDefaultClient();
51  }
52 
53  if ($handler instanceof FacebookHttpClientInterface) {
54  return $handler;
55  }
56 
57  if ('stream' === $handler) {
58  return new FacebookStreamHttpClient();
59  }
60  if ('curl' === $handler) {
61  if (!extension_loaded('curl')) {
62  throw new Exception('The cURL extension must be loaded in order to use the "curl" handler.');
63  }
64 
65  return new FacebookCurlHttpClient();
66  }
67 
68  if ('guzzle' === $handler && !class_exists('GuzzleHttp\Client')) {
69  throw new Exception('The Guzzle HTTP client must be included in order to use the "guzzle" handler.');
70  }
71 
72  if ($handler instanceof Client) {
73  return new FacebookGuzzleHttpClient($handler);
74  }
75  if ('guzzle' === $handler) {
76  return new FacebookGuzzleHttpClient();
77  }
78 
79  throw new InvalidArgumentException('The http client handler must be set to "curl", "stream", "guzzle", be an instance of GuzzleHttp\Client or an instance of Facebook\HttpClients\FacebookHttpClientInterface');
80  }
81 
87  private static function detectDefaultClient()
88  {
89  if (extension_loaded('curl')) {
90  return new FacebookCurlHttpClient();
91  }
92 
93  if (class_exists('GuzzleHttp\Client')) {
94  return new FacebookGuzzleHttpClient();
95  }
96 
97  return new FacebookStreamHttpClient();
98  }
99 }
Facebook\HttpClients\FacebookCurlHttpClient
Definition: FacebookCurlHttpClient.php:35
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
php
Facebook\HttpClients\FacebookGuzzleHttpClient
Definition: FacebookGuzzleHttpClient.php:35
Facebook\HttpClients\HttpClientsFactory
Definition: HttpClientsFactory.php:31
Facebook\HttpClients\FacebookHttpClientInterface
Definition: FacebookHttpClientInterface.php:32
Facebook\HttpClients\FacebookStreamHttpClient
Definition: FacebookStreamHttpClient.php:30
Facebook\HttpClients
Definition: FacebookCurl.php:24
Facebook\HttpClients\HttpClientsFactory\createHttpClient
static createHttpClient($handler)
Definition: HttpClientsFactory.php:47