Skip to content

Commit 931972c

Browse files
committed
Added option to disable Soap SSL certificate check.
1 parent e31ebfa commit 931972c

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"license": "MIT",
1919
"require": {
2020
"php": ">=7.1",
21+
"ext-soap": "*",
2122
"guzzlehttp/guzzle": "^6.3"
2223
},
2324
"require-dev": {

Diff for: src/EPrint/Api.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,19 @@ class Api
4444
public function __construct(array $config)
4545
{
4646
$this->config = array_replace_recursive([
47-
'login' => null,
48-
'password' => null,
49-
'cache' => true,
50-
'debug' => false,
51-
'test' => false,
47+
'login' => null,
48+
'password' => null,
49+
'cache' => true,
50+
'debug' => false,
51+
'test' => false,
52+
'ssl_check' => true,
5253
], $config);
5354
}
5455

5556
/**
5657
* Calls the method with parameters.
5758
*
58-
* @param string $name The method name
59+
* @param string $name The method name
5960
* @param array $parameters The parameters
6061
*
6162
* @return mixed
@@ -105,7 +106,8 @@ private function getClient(): Client
105106
$this->config['password'],
106107
$this->config['cache'],
107108
$this->config['debug'],
108-
$this->config['test']
109+
$this->config['test'],
110+
$this->config['ssl_check']
109111
);
110112
}
111-
}
113+
}

Diff for: src/EPrint/Client.php

+26-12
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,26 @@ class Client extends \Soapclient
4747
* @param bool $cache
4848
* @param bool $debug
4949
* @param bool $test
50+
* @param bool $sslCheck
5051
*/
5152
public function __construct(
5253
string $login,
5354
string $password,
5455
bool $cache = false,
5556
bool $debug = false,
56-
bool $test = false
57+
bool $test = false,
58+
bool $sslCheck = true
5759
) {
58-
$this->login = $login;
60+
$this->login = $login;
5961
$this->password = $password;
60-
$this->debug = $debug;
61-
62-
parent::__construct($test ? static::TEST_WSDL : static::PROD_WSDL, [
63-
'cache_wsdl' => $cache ? WSDL_CACHE_BOTH : WSDL_CACHE_NONE,
64-
'trace' => $debug ? 1 : 0,
65-
'soap_version' => SOAP_1_2,
66-
'compression' => true,
67-
'classmap' => [
62+
$this->debug = $debug;
63+
64+
$options = [
65+
'cache_wsdl' => $cache ? WSDL_CACHE_BOTH : WSDL_CACHE_NONE,
66+
'trace' => $debug ? 1 : 0,
67+
'soap_version' => SOAP_1_2,
68+
'compression' => true,
69+
'classmap' => [
6870
'Address' => Model\Address::class,
6971
'ArrayOfLabel' => Model\ArrayOfLabel::class,
7072
'ArrayOfShipment' => Model\ArrayOfShipment::class,
@@ -86,7 +88,19 @@ public function __construct(
8688
'GetLabelResponse' => Response\GetLabelResponse::class,
8789
'GetShipmentResponse' => Response\GetShipmentResponse::class,
8890
],
89-
]);
91+
];
92+
93+
if (!$sslCheck) {
94+
$options['stream_context'] = stream_context_create([
95+
'ssl' => [
96+
'verify_peer' => false,
97+
'verify_peer_name' => false,
98+
'allow_self_signed' => true,
99+
],
100+
]);
101+
}
102+
103+
parent::__construct($test ? static::TEST_WSDL : static::PROD_WSDL, $options);
90104
}
91105

92106
/**
@@ -106,7 +120,7 @@ public function call(string $method, array $arguments): ResponseInterface
106120
$exception = new ClientException($e->getMessage(), $e->getCode(), $e);
107121

108122
if ($this->debug) {
109-
$exception->request = ClientException::formatXml($this->__getLastRequest());
123+
$exception->request = ClientException::formatXml($this->__getLastRequest());
110124
$exception->response = ClientException::formatXml($this->__getLastResponse());
111125
}
112126

0 commit comments

Comments
 (0)