1 | <?php |
||
19 | class HttpAdapterFactory |
||
20 | { |
||
21 | const BUZZ = 'buzz'; |
||
22 | const CAKE = 'cake'; |
||
23 | const CURL = 'curl'; |
||
24 | const FILE_GET_CONTENTS = 'file_get_contents'; |
||
25 | const FOPEN = 'fopen'; |
||
26 | const GUZZLE3 = 'guzzle3'; |
||
27 | const GUZZLE4 = 'guzzle4'; |
||
28 | const GUZZLE5 = 'guzzle5'; |
||
29 | const GUZZLE6 = 'guzzle6'; |
||
30 | const HTTPFUL = 'httpful'; |
||
31 | const PECL_HTTP = 'pecl_http'; |
||
32 | const REACT = 'react'; |
||
33 | const REQUESTS = 'requests'; |
||
34 | const SOCKET = 'socket'; |
||
35 | const ZEND1 = 'zend1'; |
||
36 | const ZEND2 = 'zend2'; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private static $adapters = [ |
||
42 | self::GUZZLE6 => [ |
||
43 | 'adapter' => 'Ivory\HttpAdapter\Guzzle6HttpAdapter', |
||
44 | 'client' => 'GuzzleHttp\Handler\CurlHandler', |
||
45 | ], |
||
46 | self::GUZZLE5 => [ |
||
47 | 'adapter' => 'Ivory\HttpAdapter\Guzzle5HttpAdapter', |
||
48 | 'client' => 'GuzzleHttp\Ring\Client\CurlHandler', |
||
49 | ], |
||
50 | self::GUZZLE4 => [ |
||
51 | 'adapter' => 'Ivory\HttpAdapter\Guzzle4HttpAdapter', |
||
52 | 'client' => 'GuzzleHttp\Adapter\Curl\CurlAdapter', |
||
53 | ], |
||
54 | self::GUZZLE3 => [ |
||
55 | 'adapter' => 'Ivory\HttpAdapter\Guzzle3HttpAdapter', |
||
56 | 'client' => 'Guzzle\Http\Client', |
||
57 | ], |
||
58 | self::ZEND2 => [ |
||
59 | 'adapter' => 'Ivory\HttpAdapter\Zend2HttpAdapter', |
||
60 | 'client' => 'Zend\Http\Client', |
||
61 | ], |
||
62 | self::ZEND1 => [ |
||
63 | 'adapter' => 'Ivory\HttpAdapter\Zend1HttpAdapter', |
||
64 | 'client' => 'Zend_Http_Client', |
||
65 | ], |
||
66 | self::BUZZ => [ |
||
67 | 'adapter' => 'Ivory\HttpAdapter\BuzzHttpAdapter', |
||
68 | 'client' => 'Buzz\Browser', |
||
69 | ], |
||
70 | self::REQUESTS => [ |
||
71 | 'adapter' => 'Ivory\HttpAdapter\RequestsHttpAdapter', |
||
72 | 'client' => '\Requests', |
||
73 | ], |
||
74 | self::REACT => [ |
||
75 | 'adapter' => 'Ivory\HttpAdapter\ReactHttpAdapter', |
||
76 | 'client' => 'React\HttpClient\Request', |
||
77 | ], |
||
78 | self::HTTPFUL => [ |
||
79 | 'adapter' => 'Ivory\HttpAdapter\HttpfulHttpAdapter', |
||
80 | 'client' => 'Httpful\Request', |
||
81 | ], |
||
82 | self::PECL_HTTP => [ |
||
83 | 'adapter' => 'Ivory\HttpAdapter\PeclHttpAdapter', |
||
84 | 'client' => 'http\Client', |
||
85 | ], |
||
86 | self::CAKE => [ |
||
87 | 'adapter' => 'Ivory\HttpAdapter\CakeHttpAdapter', |
||
88 | 'client' => 'Cake\Network\Http\Client', |
||
89 | ], |
||
90 | self::CURL => [ |
||
91 | 'adapter' => 'Ivory\HttpAdapter\CurlHttpAdapter', |
||
92 | 'client' => 'curl_init', |
||
93 | ], |
||
94 | self::FOPEN => [ |
||
95 | 'adapter' => 'Ivory\HttpAdapter\FopenHttpAdapter', |
||
96 | 'client' => 'allow_url_fopen', |
||
97 | ], |
||
98 | self::FILE_GET_CONTENTS => [ |
||
99 | 'adapter' => 'Ivory\HttpAdapter\FileGetContentsHttpAdapter', |
||
100 | 'client' => 'allow_url_fopen', |
||
101 | ], |
||
102 | self::SOCKET => [ |
||
103 | 'adapter' => 'Ivory\HttpAdapter\SocketHttpAdapter', |
||
104 | 'client' => 'stream_socket_client', |
||
105 | ], |
||
106 | ]; |
||
107 | |||
108 | /** |
||
109 | * @param string $name |
||
110 | * @param string $class |
||
111 | * @param string|null $client |
||
112 | * |
||
113 | * @throws HttpAdapterException |
||
114 | */ |
||
115 | 45 | public static function register($name, $class, $client = null) |
|
130 | |||
131 | /** |
||
132 | * @param string $name |
||
133 | */ |
||
134 | 45 | public static function unregister($name) |
|
138 | |||
139 | /** |
||
140 | * @param string $name |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | 444 | public static function capable($name) |
|
152 | |||
153 | /** |
||
154 | * @param string $name |
||
155 | * |
||
156 | * @throws HttpAdapterException |
||
157 | * |
||
158 | * @return HttpAdapterInterface |
||
159 | */ |
||
160 | 305 | public static function create($name) |
|
172 | |||
173 | /** |
||
174 | * @param string|array $preferred |
||
175 | * |
||
176 | * @throws HttpAdapterException |
||
177 | * |
||
178 | * @return HttpAdapterInterface |
||
179 | */ |
||
180 | 157 | public static function guess($preferred = []) |
|
200 | } |
||
201 |