Skip to content

Commit 8c4ec00

Browse files
committed
getSoapClient declared as non-static. it aims to solve #15
1 parent 781fdeb commit 8c4ec00

File tree

4 files changed

+39
-43
lines changed

4 files changed

+39
-43
lines changed

src/AbstractSoapClientBase.php

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ abstract class AbstractSoapClientBase implements SoapClientInterface
88
* Soapclient called to communicate with the actual SOAP Service
99
* @var \SoapClient
1010
*/
11-
private static $soapClient;
11+
private $soapClient;
1212
/**
1313
* Contains Soap call result
1414
* @var mixed
@@ -24,35 +24,32 @@ abstract class AbstractSoapClientBase implements SoapClientInterface
2424
* @uses AbstractSoapClientBase::setLastError()
2525
* @uses AbstractSoapClientBase::initSoapClient()
2626
* @param array $wsdlOptions
27-
* @param bool $resetSoapClient allows to disable the SoapClient redefinition
2827
*/
29-
public function __construct(array $wsdlOptions = [], $resetSoapClient = true)
28+
public function __construct(array $wsdlOptions = [])
3029
{
3130
$this->setLastError([]);
3231
/**
3332
* Init soap Client
3433
* Set default values
3534
*/
36-
if ($resetSoapClient) {
37-
$this->initSoapClient($wsdlOptions);
38-
}
35+
$this->initSoapClient($wsdlOptions);
3936
}
4037
/**
41-
* Static method getting current SoapClient
38+
* Method getting current SoapClient
4239
* @return \SoapClient
4340
*/
44-
public static function getSoapClient()
41+
public function getSoapClient()
4542
{
46-
return self::$soapClient;
43+
return $this->soapClient;
4744
}
4845
/**
49-
* Static method setting current SoapClient
46+
* Method setting current SoapClient
5047
* @param \SoapClient $soapClient
5148
* @return \SoapClient
5249
*/
53-
public static function setSoapClient(\SoapClient $soapClient)
50+
public function setSoapClient(\SoapClient $soapClient)
5451
{
55-
return (self::$soapClient = $soapClient);
52+
return ($this->soapClient = $soapClient);
5653
}
5754
/**
5855
* Method initiating SoapClient
@@ -78,7 +75,7 @@ public function initSoapClient(array $options)
7875
$wsdlUrl = $wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)];
7976
unset($wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)]);
8077
$soapClientClassName = $this->getSoapClientClassName();
81-
static::setSoapClient(new $soapClientClassName($wsdlUrl, $wsdlOptions));
78+
$this->setSoapClient(new $soapClientClassName($wsdlUrl, $wsdlOptions));
8279
}
8380
}
8481
/**
@@ -167,8 +164,8 @@ public static function getDefaultWsdlOptions()
167164
*/
168165
public function setLocation($location)
169166
{
170-
if (static::getSoapClient() instanceof \SoapClient) {
171-
static::getSoapClient()->__setLocation($location);
167+
if ($this->getSoapClient() instanceof \SoapClient) {
168+
$this->getSoapClient()->__setLocation($location);
172169
}
173170
return $this;
174171
}
@@ -206,8 +203,8 @@ public function getLastResponse($asDomDocument = false)
206203
protected function getLastXml($method, $asDomDocument = false)
207204
{
208205
$xml = null;
209-
if (static::getSoapClient() instanceof \SoapClient) {
210-
$xml = static::getFormatedXml(static::getSoapClient()->$method(), $asDomDocument);
206+
if ($this->getSoapClient() instanceof \SoapClient) {
207+
$xml = static::getFormatedXml($this->getSoapClient()->$method(), $asDomDocument);
211208
}
212209
return $xml;
213210
}
@@ -244,7 +241,7 @@ public function getLastResponseHeaders($asArray = false)
244241
*/
245242
protected function getLastHeaders($method, $asArray)
246243
{
247-
$headers = static::getSoapClient() instanceof \SoapClient ? static::getSoapClient()->$method() : null;
244+
$headers = $this->getSoapClient() instanceof \SoapClient ? $this->getSoapClient()->$method() : null;
248245
if (is_string($headers) && $asArray) {
249246
return static::convertStringHeadersToArray($headers);
250247
}
@@ -293,21 +290,21 @@ public static function convertStringHeadersToArray($headers)
293290
*/
294291
public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false, $actor = null)
295292
{
296-
if (static::getSoapClient()) {
297-
$defaultHeaders = (isset(static::getSoapClient()->__default_headers) && is_array(static::getSoapClient()->__default_headers)) ? static::getSoapClient()->__default_headers : [];
293+
if ($this->getSoapClient()) {
294+
$defaultHeaders = (isset($this->getSoapClient()->__default_headers) && is_array($this->getSoapClient()->__default_headers)) ? $this->getSoapClient()->__default_headers : [];
298295
foreach ($defaultHeaders as $index => $soapHeader) {
299296
if ($soapHeader->name === $name) {
300297
unset($defaultHeaders[$index]);
301298
break;
302299
}
303300
}
304-
static::getSoapClient()->__setSoapheaders(null);
301+
$this->getSoapClient()->__setSoapheaders(null);
305302
if (!empty($actor)) {
306303
array_push($defaultHeaders, new \SoapHeader($nameSpace, $name, $data, $mustUnderstand, $actor));
307304
} else {
308305
array_push($defaultHeaders, new \SoapHeader($nameSpace, $name, $data, $mustUnderstand));
309306
}
310-
static::getSoapClient()->__setSoapheaders($defaultHeaders);
307+
$this->getSoapClient()->__setSoapheaders($defaultHeaders);
311308
}
312309
return $this;
313310
}
@@ -323,7 +320,7 @@ public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false,
323320
public function setHttpHeader($headerName, $headerValue)
324321
{
325322
$state = false;
326-
if (static::getSoapClient() && !empty($headerName)) {
323+
if ($this->getSoapClient() && !empty($headerName)) {
327324
$streamContext = $this->getStreamContext();
328325
if ($streamContext === null) {
329326
$options = [];
@@ -361,12 +358,12 @@ public function setHttpHeader($headerName, $headerValue)
361358
* Create context if it does not exist
362359
*/
363360
if ($streamContext === null) {
364-
$state = (static::getSoapClient()->_stream_context = stream_context_create($options)) ? true : false;
361+
$state = ($this->getSoapClient()->_stream_context = stream_context_create($options)) ? true : false;
365362
} else {
366363
/**
367364
* Set the new context http header option
368365
*/
369-
$state = stream_context_set_option(static::getSoapClient()->_stream_context, 'http', 'header', $options['http']['header']);
366+
$state = stream_context_set_option($this->getSoapClient()->_stream_context, 'http', 'header', $options['http']['header']);
370367
}
371368
}
372369
}
@@ -378,7 +375,7 @@ public function setHttpHeader($headerName, $headerValue)
378375
*/
379376
public function getStreamContext()
380377
{
381-
return (static::getSoapClient() && isset(static::getSoapClient()->_stream_context) && is_resource(static::getSoapClient()->_stream_context)) ? static::getSoapClient()->_stream_context : null;
378+
return ($this->getSoapClient() && isset($this->getSoapClient()->_stream_context) && is_resource($this->getSoapClient()->_stream_context)) ? $this->getSoapClient()->_stream_context : null;
382379
}
383380
/**
384381
* Returns current \SoapClient::_stream_context resource options or empty array

src/SoapClientInterface.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,13 @@ interface SoapClientInterface
142142
* @uses SoapClientInterface::setLastError()
143143
* @uses SoapClientInterface::initSoapClient()
144144
* @param array $wsdlOptions
145-
* @param bool $resetSoapClient allows to disable the SoapClient redefinition
146145
*/
147-
public function __construct(array $wsdlOptions = [], $resetSoapClient = true);
146+
public function __construct(array $wsdlOptions = []);
148147
/**
149-
* Static method getting current SoapClient
148+
* Method getting current SoapClient
150149
* @return \SoapClient
151150
*/
152-
public static function getSoapClient();
151+
public function getSoapClient();
153152
/**
154153
* Sets a SoapHeader to send
155154
* For more information, please read the online documentation on {@link http://www.php.net/manual/en/class.soapheader.php}

tests/SoapClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function getSoapClientClassName($soapClientClassName = null)
1313
/**
1414
* @return Client
1515
*/
16-
public static function getSoapClient()
16+
public function getSoapClient()
1717
{
1818
return parent::getSoapClient();
1919
}
@@ -23,7 +23,7 @@ public static function getSoapClient()
2323
public function search()
2424
{
2525
try {
26-
self::getSoapClient()->search();
26+
$this->getSoapClient()->search();
2727
} catch (\SoapFault $soapFault) {
2828
$this->setResult(null);
2929
$this->saveLastError(__METHOD__, $soapFault);

tests/SoapClientTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ public function testSetHeaders()
217217

218218
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
219219

220-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
220+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
221221

222222
$this->assertSame(array(
223223
'http' => array(
224224
'header' => 'X-Header-Name: X-Header-Value',
225225
),
226-
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
226+
), stream_context_get_options($soapClient->getSoapClient()->_stream_context));
227227
}
228228
/**
229229
*
@@ -238,14 +238,14 @@ public function testSetHeadersOnExistingHeaders()
238238
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
239239
$this->assertTrue($soapClient->setHttpHeader('X-Header-ID', 'X-Header-ID-Value'));
240240

241-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
241+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
242242

243243
$this->assertSame(array(
244244
'http' => array(
245245
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
246246
'X-Header-ID: X-Header-ID-Value',
247247
),
248-
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
248+
), stream_context_get_options($soapClient->getSoapClient()->_stream_context));
249249
}
250250
/**
251251
*
@@ -268,7 +268,7 @@ public function testSetHeadersOnExistingHttpsHeaders()
268268
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
269269
$this->assertTrue($soapClient->setHttpHeader('X-Header-ID', 'X-Header-ID-Value'));
270270

271-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
271+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
272272

273273
$this->assertSame(array(
274274
'https' => array(
@@ -280,7 +280,7 @@ public function testSetHeadersOnExistingHttpsHeaders()
280280
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
281281
'X-Header-ID: X-Header-ID-Value',
282282
),
283-
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
283+
), stream_context_get_options($soapClient->getSoapClient()->_stream_context));
284284
}
285285
/**
286286
*
@@ -303,7 +303,7 @@ public function testSetHeadersOnExistingHttpHeaders()
303303
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
304304
$this->assertTrue($soapClient->setHttpHeader('X-Header-ID', 'X-Header-ID-Value'));
305305

306-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
306+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
307307

308308
$this->assertSame(array(
309309
'http' => array(
@@ -313,7 +313,7 @@ public function testSetHeadersOnExistingHttpHeaders()
313313
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
314314
'X-Header-ID: X-Header-ID-Value',
315315
),
316-
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
316+
), stream_context_get_options($soapClient->getSoapClient()->_stream_context));
317317
}
318318
/**
319319
*
@@ -398,7 +398,7 @@ public function testSetSoapHeader()
398398

399399
$this->assertEquals(array(
400400
new \SoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false),
401-
), SoapClient::getSoapClient()->__default_headers);
401+
), $soapClient->getSoapClient()->__default_headers);
402402
}
403403
/**
404404
*
@@ -413,7 +413,7 @@ public function testSetSoapHeaderModified()
413413
$soapClient->setSoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false, null);
414414
$soapClient->setSoapHeader('urn:namespace', 'HeaderAuth', 'the-data-modified', false, null);
415415

416-
$this->assertEquals(new \SoapHeader('urn:namespace', 'HeaderAuth', 'the-data-modified', false), array_pop(SoapClient::getSoapClient()->__default_headers));
416+
$this->assertEquals(new \SoapHeader('urn:namespace', 'HeaderAuth', 'the-data-modified', false), array_pop($soapClient->getSoapClient()->__default_headers));
417417
}
418418
/**
419419
*
@@ -429,7 +429,7 @@ public function testSetSoapActor()
429429

430430
$this->assertEquals(array(
431431
new \SoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false, 'actor'),
432-
), SoapClient::getSoapClient()->__default_headers);
432+
), $soapClient->getSoapClient()->__default_headers);
433433
}
434434
/**
435435
* @return string[]

0 commit comments

Comments
 (0)