1 | <?php |
||
15 | class StreamSocketProvider implements ProviderInterface |
||
16 | { |
||
17 | |||
18 | const DEFAULT_TIMEOUT_SECONDS = 15; |
||
19 | const DEFAULT_PORT = 443; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $hostname; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | private $port; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | private $timeout; |
||
35 | |||
36 | /** |
||
37 | * @var boolean |
||
38 | */ |
||
39 | private $verifyPeerName; |
||
40 | |||
41 | /** |
||
42 | * @var array maps partial error messages to exception types |
||
43 | */ |
||
44 | private static $errorExceptionMap = [ |
||
45 | // Check for name resolution errors |
||
46 | 'getaddrinfo failed' => NameResolutionException::class, |
||
47 | // Check for unknown SSL protocol (usually means no SSL is configured on the endpoint) |
||
48 | 'GET_SERVER_HELLO:unknown protocol' => CertificateNotFoundException::class, |
||
49 | // Check for domain mismatches |
||
50 | 'did not match expected' => DomainMismatchException::class, |
||
51 | // Check for connection timeouts |
||
52 | 'timed out' => ConnectionTimeoutException::class, |
||
53 | ]; |
||
54 | |||
55 | |||
56 | /** |
||
57 | * StreamSocketProvider constructor. |
||
58 | * |
||
59 | * @param string $hostname |
||
60 | * @param int $port (optional) |
||
61 | * @param int $timeout (optional) |
||
62 | * @param boolean $verifyPeerName (optional) |
||
63 | */ |
||
64 | public function __construct( |
||
75 | |||
76 | |||
77 | /** |
||
78 | * @inheritdoc |
||
79 | */ |
||
80 | public function getRawCertificate() |
||
108 | |||
109 | |||
110 | /** |
||
111 | * @return resource |
||
112 | */ |
||
113 | private function getStreamContext() |
||
123 | |||
124 | |||
125 | /** |
||
126 | * @return string |
||
127 | */ |
||
128 | private function getRequestUrl() |
||
132 | |||
133 | } |
||
134 |