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 StreamContext |
||
38 | */ |
||
39 | private $streamContext; |
||
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 StreamContext|null $streamContext (optional) |
||
63 | */ |
||
64 | public function __construct( |
||
75 | |||
76 | |||
77 | /** |
||
78 | * @return StreamContext |
||
79 | */ |
||
80 | public function getStreamContext() |
||
84 | |||
85 | |||
86 | /** |
||
87 | * @param StreamContext $streamContext |
||
88 | */ |
||
89 | public function setStreamContext($streamContext) |
||
93 | |||
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | public function getRawCertificate() |
||
126 | |||
127 | |||
128 | /** |
||
129 | * @return string |
||
130 | */ |
||
131 | private function getRequestUrl() |
||
135 | |||
136 | } |
||
137 |