@@ -17,6 +17,11 @@ class Client
1717 'https ' => 443 ,
1818 );
1919
20+ /**
21+ * @var int
22+ */
23+ private $ port ;
24+
2025 /**
2126 * @var string
2227 */
@@ -27,6 +32,11 @@ class Client
2732 */
2833 private $ apikey ;
2934
35+ /**
36+ * @var boolean
37+ */
38+ private $ checkSslCertificate = false ;
39+
3040 /**
3141 * @param string $url
3242 * @param string $apikey
@@ -166,6 +176,53 @@ public function delete($path)
166176 return $ this ->runRequest ($ path , 'DELETE ' );
167177 }
168178
179+ /**
180+ * Turns on/off ssl certificate check
181+ * @param boolean $check
182+ */
183+ public function setCheckSslCertificate ($ check = false )
184+ {
185+ $ this ->checkSslCertificate = $ check ;
186+ }
187+
188+ /**
189+ * Set the port of the connection
190+ * @param int $port
191+ */
192+ public function setPort ($ port = null )
193+ {
194+ if (null !== $ port ) {
195+ $ this ->port = (int ) $ port ;
196+ }
197+ }
198+
199+ /**
200+ * Returns the port of the current connection,
201+ * if not set, it will try to guess the port
202+ * from the given $urlPath
203+ * @param string $urlPath the url called
204+ * @return int
205+ */
206+ public function getPort ($ urlPath = null )
207+ {
208+ if (null === $ urlPath ) {
209+ return $ this ->port ;
210+ }
211+ if (null !== $ this ->port ) {
212+ return $ this ->port ;
213+ }
214+ $ tmp = parse_url ($ urlPath );
215+
216+ if (isset ($ tmp ['port ' ])) {
217+ $ this ->setPort ($ tmp ['port ' ]);
218+
219+ return $ this ->port ;
220+ }
221+ $ this ->setPort (self ::$ defaultPorts [$ tmp ['scheme ' ]]);
222+
223+ return $ this ->port ;
224+ }
225+
169226 /**
170227 * @param string $path
171228 * @param string $method
@@ -175,13 +232,7 @@ public function delete($path)
175232 */
176233 private function runRequest ($ path , $ method = 'GET ' , $ data = '' )
177234 {
178- $ tmp = parse_url ($ this ->url .$ path );
179-
180- if (isset ($ tmp ['port ' ])) {
181- $ port = $ tmp ['port ' ];
182- } else {
183- $ port = self ::$ defaultPorts [$ tmp ['scheme ' ]];
184- }
235+ $ this ->getPort ($ this ->url .$ path );
185236
186237 $ curl = curl_init ();
187238 if (isset ($ this ->apikey )) {
@@ -192,11 +243,12 @@ private function runRequest($path, $method = 'GET', $data = '')
192243 curl_setopt ($ curl , CURLOPT_VERBOSE , 0 );
193244 curl_setopt ($ curl , CURLOPT_HEADER , 0 );
194245 curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , 1 );
195- curl_setopt ($ curl , CURLOPT_PORT , $ port );
196- if (80 !== $ port ) {
197- curl_setopt ($ curl , CURLOPT_SSL_VERIFYPEER , false );
246+ curl_setopt ($ curl , CURLOPT_PORT , $ this -> port );
247+ if (80 !== $ this -> port ) {
248+ curl_setopt ($ curl , CURLOPT_SSL_VERIFYPEER , $ this -> checkSslCertificate );
198249 }
199250
251+ $ tmp = parse_url ($ this ->url .$ path );
200252 if ('xml ' === substr ($ tmp ['path ' ], -3 )) {
201253 curl_setopt ($ curl , CURLOPT_HTTPHEADER , array (
202254 'Content-Type: text/xml ' ,
0 commit comments