Skip to content

Commit 99d8c73

Browse files
committed
Merge branch 'release/2.0.0'
2 parents e5f56ff + 479ba1f commit 99d8c73

File tree

9 files changed

+99
-46
lines changed

9 files changed

+99
-46
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ matrix:
99
- php: 5.6
1010
- php: 7.0
1111
- php: 7.1
12+
- php: 7.2
1213

1314
before_install:
1415
- composer self-update

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 2.0.0 - 2018-04-17
4+
- Issue #15 - AbstractSoapClientBase should not define static SoapClient instance
5+
36
## 1.0.11
47
- Issue #19 - WSDL_CACHE_WSDL does not work!
58
- Merged pull request #20 - Fix WSDL_CACHE_WSDL not working

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
[![Latest Stable Version](https://poser.pugx.org/wsdltophp/packagebase/version.png)](https://packagist.org/packages/wsdltophp/packagebase)
66
[![Total Downloads](https://poser.pugx.org/wsdltophp/packagebase/downloads)](https://packagist.org/packages/wsdltophp/packagebase)
77
[![Build Status](https://api.travis-ci.org/WsdlToPhp/PackageBase.svg)](https://travis-ci.org/WsdlToPhp/PackageBase)
8-
[![PHP 7 ready](http://php7ready.timesplinter.ch/WsdlToPhp/PackageBase/badge.svg)](https://travis-ci.org/WsdlToPhp/PackageBase)
98
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/WsdlToPhp/PackageBase/badges/quality-score.png)](https://scrutinizer-ci.com/g/WsdlToPhp/PackageBase/)
109
[![Code Coverage](https://scrutinizer-ci.com/g/WsdlToPhp/PackageBase/badges/coverage.png)](https://scrutinizer-ci.com/g/WsdlToPhp/PackageBase/)
11-
[![Dependency Status](https://www.versioneye.com/user/projects/55b10586643533001c00010f/badge.svg)](https://www.versioneye.com/user/projects/55b10586643533001c00010f)
1210
[![StyleCI](https://styleci.io/repos/38760239/shield)](https://styleci.io/repos/38760239)
1311
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/bfbc0c8f-5793-489b-8151-36ea149ec98d/mini.png)](https://insight.sensiolabs.com/projects/bfbc0c8f-5793-489b-8151-36ea149ec98d)
1412

UPGRADE-2.0.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# UPGRADE FROM 1.0 to 2.0
2+
3+
The main change is that the property `$soapClient` in the abstract class `AbstractSoapClientBase` is no more static.
4+
5+
**Previously**:
6+
```php
7+
class MyService extends AbstractSoapClientBase
8+
{
9+
public function CreateQueue(\Api\StructType\ApiCreateQueue $body)
10+
{
11+
try {
12+
$this->setResult(self::getSoapClient()->CreateQueue($body));
13+
return $this->getResult();
14+
} catch (\SoapFault $soapFault) {
15+
$this->saveLastError(__METHOD__, $soapFault);
16+
return false;
17+
}
18+
}
19+
}
20+
```
21+
22+
`self::getSoapClient()` was used to access the SoapClient instance.
23+
24+
**Now**:
25+
```php
26+
class MyService extends AbstractSoapClientBase
27+
{
28+
public function CreateQueue(\Api\StructType\ApiCreateQueue $body)
29+
{
30+
try {
31+
$this->setResult($this->getSoapClient()->CreateQueue($body));
32+
return $this->getResult();
33+
} catch (\SoapFault $soapFault) {
34+
$this->saveLastError(__METHOD__, $soapFault);
35+
return false;
36+
}
37+
}
38+
}
39+
```
40+
41+
`$this->getSoapClient()` is now used to access the SoapClient instance.

composer.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
"name": "Arthur Moore",
2121
"email": "[email protected]",
2222
"role": "Contributor"
23+
},
24+
{
25+
"name": "Necati Yared Ozal",
26+
"email": "[email protected]",
27+
"role": "Contributor"
28+
},
29+
{
30+
"name": "Gemorroj",
31+
"email": "[email protected]",
32+
"role": "Contributor"
2333
}
2434
],
2535
"support" : {
@@ -38,7 +48,11 @@
3848
},
3949
"autoload": {
4050
"psr-4": {
41-
"WsdlToPhp\\PackageBase\\": "src",
51+
"WsdlToPhp\\PackageBase\\": "src"
52+
}
53+
},
54+
"autoload-dev": {
55+
"psr-4": {
4256
"WsdlToPhp\\PackageBase\\Tests\\": "tests"
4357
}
4458
}

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
@@ -218,13 +218,13 @@ public function testSetHeaders()
218218

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

221-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
221+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
222222

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

242-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
242+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
243243

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

272-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
272+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
273273

274274
$this->assertSame(array(
275275
'https' => array(
@@ -281,7 +281,7 @@ public function testSetHeadersOnExistingHttpsHeaders()
281281
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
282282
'X-Header-ID: X-Header-ID-Value',
283283
),
284-
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
284+
), stream_context_get_options($soapClient->getSoapClient()->_stream_context));
285285
}
286286
/**
287287
*
@@ -304,7 +304,7 @@ public function testSetHeadersOnExistingHttpHeaders()
304304
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
305305
$this->assertTrue($soapClient->setHttpHeader('X-Header-ID', 'X-Header-ID-Value'));
306306

307-
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
307+
$this->assertTrue(is_resource($soapClient->getSoapClient()->_stream_context));
308308

309309
$this->assertSame(array(
310310
'http' => array(
@@ -314,7 +314,7 @@ public function testSetHeadersOnExistingHttpHeaders()
314314
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
315315
'X-Header-ID: X-Header-ID-Value',
316316
),
317-
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
317+
), stream_context_get_options($soapClient->getSoapClient()->_stream_context));
318318
}
319319
/**
320320
*
@@ -399,7 +399,7 @@ public function testSetSoapHeader()
399399

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

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

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

0 commit comments

Comments
 (0)