1212use Symfony \Component \OptionsResolver \OptionsResolver ;
1313
1414/**
15- * Socket Http Client
15+ * Socket Http Client.
1616 *
1717 * Use stream and socket capabilities of the core of PHP to send HTTP requests
1818 *
@@ -24,20 +24,21 @@ class Client implements HttpClient
2424 use ResponseReader;
2525
2626 private $ config = [
27- 'remote_socket ' => null ,
28- 'timeout ' => null ,
29- 'stream_context_options ' => array () ,
30- 'stream_context_param ' => array () ,
31- 'ssl ' => null ,
32- 'write_buffer_size ' => 8192 ,
33- 'ssl_method ' => STREAM_CRYPTO_METHOD_TLS_CLIENT
27+ 'remote_socket ' => null ,
28+ 'timeout ' => null ,
29+ 'stream_context_options ' => [] ,
30+ 'stream_context_param ' => [] ,
31+ 'ssl ' => null ,
32+ 'write_buffer_size ' => 8192 ,
33+ 'ssl_method ' => STREAM_CRYPTO_METHOD_TLS_CLIENT ,
3434 ];
3535
3636 /**
3737 * Constructor.
3838 *
3939 * @param ResponseFactory $responseFactory Response factory for creating response
40- * @param array $config {
40+ * @param array $config {
41+ *
4142 * @var string $remote_socket Remote entrypoint (can be a tcp or unix domain address)
4243 * @var int $timeout Timeout before canceling request
4344 * @var array $stream_context_options Context options as defined in the PHP documentation
@@ -68,8 +69,8 @@ public function __construct(ResponseFactory $responseFactory = null, array $conf
6869 */
6970 public function sendRequest (RequestInterface $ request )
7071 {
71- $ remote = $ this ->config ['remote_socket ' ];
72- $ useSsl = $ this ->config ['ssl ' ];
72+ $ remote = $ this ->config ['remote_socket ' ];
73+ $ useSsl = $ this ->config ['ssl ' ];
7374
7475 if (!$ request ->hasHeader ('Connection ' )) {
7576 $ request = $ request ->withHeader ('Connection ' , 'close ' );
@@ -98,19 +99,19 @@ public function sendRequest(RequestInterface $request)
9899 }
99100
100101 /**
101- * Create the socket to write request and read response on it
102+ * Create the socket to write request and read response on it.
102103 *
103104 * @param RequestInterface $request Request for
104105 * @param string $remote Entrypoint for the connection
105- * @param boolean $useSsl Whether to use ssl or not
106+ * @param bool $useSsl Whether to use ssl or not
106107 *
107108 * @throws NetworkException When the connection fail
108109 *
109110 * @return resource Socket resource
110111 */
111112 protected function createSocket (RequestInterface $ request , $ remote , $ useSsl )
112113 {
113- $ errNo = null ;
114+ $ errNo = null ;
114115 $ errMsg = null ;
115116 $ socket = @stream_socket_client ($ remote , $ errNo , $ errMsg , floor ($ this ->config ['timeout ' ] / 1000 ), STREAM_CLIENT_CONNECT , $ this ->config ['stream_context ' ]);
116117
@@ -130,7 +131,7 @@ protected function createSocket(RequestInterface $request, $remote, $useSsl)
130131 }
131132
132133 /**
133- * Close the socket, used when having an error
134+ * Close the socket, used when having an error.
134135 *
135136 * @param resource $socket
136137 */
@@ -140,7 +141,7 @@ protected function closeSocket($socket)
140141 }
141142
142143 /**
143- * Return configuration for the socket client
144+ * Return configuration for the socket client.
144145 *
145146 * @param array $config Configuration from user
146147 *
@@ -165,7 +166,7 @@ protected function configure(array $config = [])
165166 }
166167
167168 /**
168- * Return remote socket from the request
169+ * Return remote socket from the request.
169170 *
170171 * @param RequestInterface $request
171172 *
@@ -175,13 +176,13 @@ protected function configure(array $config = [])
175176 */
176177 private function determineRemoteFromRequest (RequestInterface $ request )
177178 {
178- if ($ request ->getUri ()->getHost () == "" && !$ request ->hasHeader ('Host ' )) {
179- throw new NetworkException (" Cannot find connection endpoint for this request " , $ request );
179+ if ($ request ->getUri ()->getHost () == '' && !$ request ->hasHeader ('Host ' )) {
180+ throw new NetworkException (' Cannot find connection endpoint for this request ' , $ request );
180181 }
181182
182183 $ host = $ request ->getUri ()->getHost ();
183- $ port = $ request ->getUri ()->getPort () ?: ($ request ->getUri ()->getScheme () == " https " ? 443 : 80 );
184- $ endpoint = sprintf (" %s:%s " , $ host , $ port );
184+ $ port = $ request ->getUri ()->getPort () ?: ($ request ->getUri ()->getScheme () == ' https ' ? 443 : 80 );
185+ $ endpoint = sprintf (' %s:%s ' , $ host , $ port );
185186
186187 // If use the host header if present for the endpoint
187188 if (empty ($ host ) && $ request ->hasHeader ('Host ' )) {
0 commit comments