Skip to content

Commit e4f4ae6

Browse files
committed
Merge branch 'develop' of github.com:WsdlToPhp/PackageBase into develop
2 parents ad246a0 + d48a09c commit e4f4ae6

File tree

8 files changed

+92
-66
lines changed

8 files changed

+92
-66
lines changed

.php_cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
<?php
22

3-
$finder = Symfony\CS\Finder\DefaultFinder::create()
3+
$finder = PhpCsFixer\Finder::create()
44
->exclude('vendor')
5-
->exclude('Tests/resources')
5+
->exclude('tests')
66
->in(__DIR__);
77

8-
return Symfony\CS\Config\Config::create()
9-
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
10-
->finder($finder);
8+
return PhpCsFixer\Config::create()
9+
->setUsingCache(false)
10+
->setRules(array(
11+
'@PSR2' => true,
12+
'binary_operator_spaces' => true,
13+
'no_whitespace_in_blank_line' => true,
14+
'ternary_operator_spaces' => true,
15+
'cast_spaces' => true,
16+
'trailing_comma_in_multiline_array' => true
17+
))
18+
->setFinder($finder);

CHANGELOG.md

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

3+
## 1.0.7
4+
- Issue #3 - More than one SoapClient in Project
5+
6+
## 1.0.6
7+
- Pull request #4: Rename $optioName to $optionName
8+
9+
## 1.0.5
10+
- Update readme
11+
12+
## 1.0.4
13+
- Issue #2 - Var name change request from $methoName to $methodName
14+
315
## 1.0.3
416
- Add utility methods **getStreamContext()** and **getStreamContextOptions()** to AbstractSoapClientbase class
517

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Package Base
22
[![Latest Stable Version](https://poser.pugx.org/wsdltophp/packagebase/version.png)](https://packagist.org/packages/wsdltophp/packagebase)
3+
[![Total Downloads](https://poser.pugx.org/wsdltophp/packagebase/downloads)](https://packagist.org/packages/wsdltophp/packagebase)
34
[![Build Status](https://api.travis-ci.org/WsdlToPhp/PackageBase.svg)](https://travis-ci.org/WsdlToPhp/PackageBase)
45
[![PHP 7 ready](http://php7ready.timesplinter.ch/WsdlToPhp/PackageBase/badge.svg)](https://travis-ci.org/WsdlToPhp/PackageBase)
56
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/WsdlToPhp/PackageBase/badges/quality-score.png)](https://scrutinizer-ci.com/g/WsdlToPhp/PackageBase/)
@@ -33,10 +34,10 @@ There is at least/most one method that must be implemented so it's pretty fast t
3334

3435
### StructArrayInterface
3536
#### Description
36-
This interface must be used to define a new ArrayType class. The goal is to provide utility methods around Array Structs defined by the Wsdl in order to ease the handling of its content. Therefore, this interface inherits from our [StructInterface](#structinterface) interface interface plus the native [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php), [Iterator](http://php.net/manual/en/class.iterator.php) and [Countable](http://php.net/manual/en/class.countable.php) PHP interfaces
37+
This interface must be used to define a new ArrayType class. The goal is to provide utility methods around Array Structs defined by the Wsdl in order to ease the handling of its content. Therefore, this interface inherits from our [StructInterface](#structinterface) interface plus the native [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php), [Iterator](http://php.net/manual/en/class.iterator.php) and [Countable](http://php.net/manual/en/class.countable.php) PHP interfaces
3738

3839
#### What has to be implemented?
39-
The only method that must implement would be **getAttributeName** but be aware that it is implemented in every generated ArrayType class so no need to define it. It's just a reminder of what is available in ArrayType classes.
40+
The only method that must be implemented would be **getAttributeName** but be aware that it is implemented in every generated ArrayType class so no need to define it. It's just a reminder of what is available in ArrayType classes.
4041

4142
So, basically, you MUST at least override the methods declared by the PHP interfaces from which this interface inherits
4243

@@ -81,7 +82,7 @@ Here are the methods that must be implemented and why:
8182
- **getSoapClient()**: must return the [SoapClient](http://php.net/manual/en/class.soapclient.php) object that is responsible fo sending the requests.
8283
- **setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false, $actor = null)**: look to [AbstractSoapClientBase](#abstractsoapclientbase) part that details this method. Basically, it allows to define [SoapHeader](http://php.net/manual/en/class.soapheader.php)s for the request
8384
- **getLastError()**: must return the last error, its format is up to you
84-
- **saveLastError($methoName, \SoapFault $soapFault)**: look to [AbstractSoapClientBase](#abstractsoapclientbase) part that details this method. Basically, it must allow to store a catched [Soapfault](http://php.net/manual/en/class.soapfault.php) object when a request has failed
85+
- **saveLastError($methodName, \SoapFault $soapFault)**: look to [AbstractSoapClientBase](#abstractsoapclientbase) part that details this method. Basically, it must allow to store a catched [Soapfault](http://php.net/manual/en/class.soapfault.php) object when a request has failed
8586
- **getResult()**: should return the Soap Web Service response, it's up to you
8687
- **setResult($result)**: must accept any parameter type as it should received the Soap Web Service response
8788

@@ -201,7 +202,7 @@ $items->initInternArray(array(
201202
#### Description
202203
This class is the base class for any ```ServiceType``` class generated by [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator).
203204
Its goal is to provide utility/handful methods by implementing our [SoapClientInterface](#soapclientinterface) interface.
204-
It's basically a decorator design pattern as the class has the [SoapClient](http://php.net/manual/en/class.soapclient.php) object as a static property in order to be able apply methods on it. It is static property in order to have a singleton between multiple calls. It can be reset by passing true as the second parameter.
205+
It's basically a decorator design pattern as the class has the [SoapClient](http://php.net/manual/en/class.soapclient.php) object as a static property in order to be able to apply methods on it. It is a static property in order to have a singleton between multiple calls (allowing to send cookies automatically between calls). It can be reset by passing true as the second parameter.
205206

206207
#### Usage
207208
Let's say you have this type of generate ```ServiceType``` class:
@@ -241,7 +242,7 @@ Then call any of these base methods:
241242
- **getLastRequestHeaders($asArray = false)**: returns either the HTTP request's headers as a string or as an array (each HTTP header is parsed)
242243
- **getLastResponseHeaders($asArray = false)**: returns either the HTTP response's headers as a string or as an array
243244
- **getLastError**: automatically populated with an error when ```$this->saveLastError(__METHOD__, $soapFault)``` is called
244-
- **getLastErrorForMethod($methoName)** : returns the error associated to the called method. It should return a ```SoapFault``` object
245+
- **getLastErrorForMethod($methodName)** : returns the error associated to the called method. It should return a ```SoapFault``` object
245246
```php
246247
$result = $update->UpdateBulkOrder(new \Api\StructType\ApiUpdateBulkOrder())
247248
if ($result !== false) {

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"name": "Mikaël DELSOL",
1111
"email": "[email protected]",
1212
"role": "Owner"
13+
},
14+
{
15+
"name": "Luke Rodgers",
16+
"email": "[email protected]",
17+
"role": "Contributor"
1318
}
1419
],
1520
"support" : {
@@ -19,7 +24,7 @@
1924
"php" : ">=5.3.3"
2025
},
2126
"require-dev": {
22-
"fabpot/php-cs-fixer": "~1.8",
27+
"friendsofphp/php-cs-fixer": "~2.0",
2328
"phpunit/phpunit": "~4.0"
2429
},
2530
"autoload": {

src/AbstractSoapClientBase.php

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ public static function setSoapClient(\SoapClient $soapClient)
6666
public function initSoapClient(array $options)
6767
{
6868
$wsdlOptions = array();
69-
$defaultWsdlOptions = self::getDefaultWsdlOptions();
70-
foreach ($defaultWsdlOptions as $optioName => $optionValue) {
71-
if (array_key_exists($optioName, $options) && !empty($options[$optioName])) {
72-
$wsdlOptions[str_replace(self::OPTION_PREFIX, '', $optioName)] = $options[$optioName];
69+
$defaultWsdlOptions = static::getDefaultWsdlOptions();
70+
foreach ($defaultWsdlOptions as $optionName => $optionValue) {
71+
if (array_key_exists($optionName, $options) && !empty($options[$optionName])) {
72+
$wsdlOptions[str_replace(self::OPTION_PREFIX, '', $optionName)] = $options[$optionName];
7373
} elseif (!empty($optionValue)) {
74-
$wsdlOptions[str_replace(self::OPTION_PREFIX, '', $optioName)] = $optionValue;
74+
$wsdlOptions[str_replace(self::OPTION_PREFIX, '', $optionName)] = $optionValue;
7575
}
7676
}
7777
if (array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URL), $wsdlOptions)) {
7878
$wsdlUrl = $wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)];
7979
unset($wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)]);
8080
$soapClientClassName = $this->getSoapClientClassName();
81-
self::setSoapClient(new $soapClientClassName($wsdlUrl, $wsdlOptions));
81+
static::setSoapClient(new $soapClientClassName($wsdlUrl, $wsdlOptions));
8282
}
8383
}
8484
/**
@@ -132,30 +132,31 @@ public function getSoapClientClassName($soapClientClassName = null)
132132
public static function getDefaultWsdlOptions()
133133
{
134134
return array(
135-
self::WSDL_CLASSMAP => null,
136-
self::WSDL_CACHE_WSDL => WSDL_CACHE_NONE,
137-
self::WSDL_COMPRESSION => null,
138-
self::WSDL_CONNECTION_TIMEOUT => null,
139-
self::WSDL_ENCODING => null,
140-
self::WSDL_EXCEPTIONS => true,
141-
self::WSDL_FEATURES => SOAP_SINGLE_ELEMENT_ARRAYS | SOAP_USE_XSI_ARRAY_TYPE,
142-
self::WSDL_LOCATION => null,
143-
self::WSDL_LOGIN => null,
144-
self::WSDL_PASSWORD => null,
145-
self::WSDL_SOAP_VERSION => null,
146-
self::WSDL_STREAM_CONTEXT => null,
147-
self::WSDL_TRACE => true,
148-
self::WSDL_TYPEMAP => null,
149-
self::WSDL_URL => null,
150-
self::WSDL_USER_AGENT => null,
151-
self::WSDL_PROXY_HOST => null,
152-
self::WSDL_PROXY_PORT => null,
153-
self::WSDL_PROXY_LOGIN => null,
154-
self::WSDL_PROXY_PASSWORD => null,
155-
self::WSDL_LOCAL_CERT => null,
156-
self::WSDL_PASSPHRASE => null,
157-
self::WSDL_AUTHENTICATION => null,
158-
self::WSDL_SSL_METHOD => null);
135+
self::WSDL_CLASSMAP => null,
136+
self::WSDL_CACHE_WSDL => WSDL_CACHE_NONE,
137+
self::WSDL_COMPRESSION => null,
138+
self::WSDL_CONNECTION_TIMEOUT => null,
139+
self::WSDL_ENCODING => null,
140+
self::WSDL_EXCEPTIONS => true,
141+
self::WSDL_FEATURES => SOAP_SINGLE_ELEMENT_ARRAYS | SOAP_USE_XSI_ARRAY_TYPE,
142+
self::WSDL_LOCATION => null,
143+
self::WSDL_LOGIN => null,
144+
self::WSDL_PASSWORD => null,
145+
self::WSDL_SOAP_VERSION => null,
146+
self::WSDL_STREAM_CONTEXT => null,
147+
self::WSDL_TRACE => true,
148+
self::WSDL_TYPEMAP => null,
149+
self::WSDL_URL => null,
150+
self::WSDL_USER_AGENT => null,
151+
self::WSDL_PROXY_HOST => null,
152+
self::WSDL_PROXY_PORT => null,
153+
self::WSDL_PROXY_LOGIN => null,
154+
self::WSDL_PROXY_PASSWORD => null,
155+
self::WSDL_LOCAL_CERT => null,
156+
self::WSDL_PASSPHRASE => null,
157+
self::WSDL_AUTHENTICATION => null,
158+
self::WSDL_SSL_METHOD => null,
159+
);
159160
}
160161
/**
161162
* Allows to set the SoapClient location to call
@@ -166,8 +167,8 @@ public static function getDefaultWsdlOptions()
166167
*/
167168
public function setLocation($location)
168169
{
169-
if (self::getSoapClient() instanceof \SoapClient) {
170-
self::getSoapClient()->__setLocation($location);
170+
if (static::getSoapClient() instanceof \SoapClient) {
171+
static::getSoapClient()->__setLocation($location);
171172
}
172173
return $this;
173174
}
@@ -205,8 +206,8 @@ public function getLastResponse($asDomDocument = false)
205206
protected function getLastXml($method, $asDomDocument = false)
206207
{
207208
$xml = null;
208-
if (self::getSoapClient() instanceof \SoapClient) {
209-
$xml = self::getFormatedXml(self::getSoapClient()->$method(), $asDomDocument);
209+
if (static::getSoapClient() instanceof \SoapClient) {
210+
$xml = static::getFormatedXml(static::getSoapClient()->$method(), $asDomDocument);
210211
}
211212
return $xml;
212213
}
@@ -243,9 +244,9 @@ public function getLastResponseHeaders($asArray = false)
243244
*/
244245
protected function getLastHeaders($method, $asArray)
245246
{
246-
$headers = self::getSoapClient() instanceof \SoapClient ? self::getSoapClient()->$method() : null;
247+
$headers = static::getSoapClient() instanceof \SoapClient ? static::getSoapClient()->$method() : null;
247248
if (is_string($headers) && $asArray) {
248-
return self::convertStringHeadersToArray($headers);
249+
return static::convertStringHeadersToArray($headers);
249250
}
250251
return $headers;
251252
}
@@ -292,21 +293,21 @@ public static function convertStringHeadersToArray($headers)
292293
*/
293294
public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false, $actor = null)
294295
{
295-
if (self::getSoapClient()) {
296-
$defaultHeaders = (isset(self::getSoapClient()->__default_headers) && is_array(self::getSoapClient()->__default_headers)) ? self::getSoapClient()->__default_headers : array();
296+
if (static::getSoapClient()) {
297+
$defaultHeaders = (isset(static::getSoapClient()->__default_headers) && is_array(static::getSoapClient()->__default_headers)) ? static::getSoapClient()->__default_headers : array();
297298
foreach ($defaultHeaders as $index => $soapHeader) {
298299
if ($soapHeader->name === $name) {
299300
unset($defaultHeaders[$index]);
300301
break;
301302
}
302303
}
303-
self::getSoapClient()->__setSoapheaders(null);
304+
static::getSoapClient()->__setSoapheaders(null);
304305
if (!empty($actor)) {
305306
array_push($defaultHeaders, new \SoapHeader($nameSpace, $name, $data, $mustUnderstand, $actor));
306307
} else {
307308
array_push($defaultHeaders, new \SoapHeader($nameSpace, $name, $data, $mustUnderstand));
308309
}
309-
self::getSoapClient()->__setSoapheaders($defaultHeaders);
310+
static::getSoapClient()->__setSoapheaders($defaultHeaders);
310311
}
311312
return $this;
312313
}
@@ -322,7 +323,7 @@ public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false,
322323
public function setHttpHeader($headerName, $headerValue)
323324
{
324325
$state = false;
325-
if (self::getSoapClient() && !empty($headerName)) {
326+
if (static::getSoapClient() && !empty($headerName)) {
326327
$streamContext = $this->getStreamContext();
327328
if ($streamContext === null) {
328329
$options = array();
@@ -360,12 +361,12 @@ public function setHttpHeader($headerName, $headerValue)
360361
* Create context if it does not exist
361362
*/
362363
if ($streamContext === null) {
363-
$state = (self::getSoapClient()->_stream_context = stream_context_create($options)) ? true : false;
364+
$state = (static::getSoapClient()->_stream_context = stream_context_create($options)) ? true : false;
364365
} else {
365366
/**
366367
* Set the new context http header option
367368
*/
368-
$state = stream_context_set_option(self::getSoapClient()->_stream_context, 'http', 'header', $options['http']['header']);
369+
$state = stream_context_set_option(static::getSoapClient()->_stream_context, 'http', 'header', $options['http']['header']);
369370
}
370371
}
371372
}
@@ -377,7 +378,7 @@ public function setHttpHeader($headerName, $headerValue)
377378
*/
378379
public function getStreamContext()
379380
{
380-
return (self::getSoapClient() && isset(self::getSoapClient()->_stream_context) && is_resource(self::getSoapClient()->_stream_context)) ? self::getSoapClient()->_stream_context : null;
381+
return (static::getSoapClient() && isset(static::getSoapClient()->_stream_context) && is_resource(static::getSoapClient()->_stream_context)) ? static::getSoapClient()->_stream_context : null;
381382
}
382383
/**
383384
* Returns current \SoapClient::_stream_context resource options or empty array
@@ -412,23 +413,23 @@ private function setLastError($lastError)
412413
}
413414
/**
414415
* Method saving the last error returned by the SoapClient
415-
* @param string $methoName the method called when the error occurred
416+
* @param string $methodName the method called when the error occurred
416417
* @param \SoapFault $soapFault l'objet de l'erreur
417418
* @return AbstractSoapClientBase
418419
*/
419-
public function saveLastError($methoName, \SoapFault $soapFault)
420+
public function saveLastError($methodName, \SoapFault $soapFault)
420421
{
421-
$this->lastError[$methoName] = $soapFault;
422+
$this->lastError[$methodName] = $soapFault;
422423
return $this;
423424
}
424425
/**
425426
* Method getting the last error for a certain method
426-
* @param string $methoName method name to get error from
427+
* @param string $methodName method name to get error from
427428
* @return \SoapFault|null
428429
*/
429-
public function getLastErrorForMethod($methoName)
430+
public function getLastErrorForMethod($methodName)
430431
{
431-
return array_key_exists($methoName, $this->lastError) ? $this->lastError[$methoName] : null;
432+
return array_key_exists($methodName, $this->lastError) ? $this->lastError[$methodName] : null;
432433
}
433434
/**
434435
* Method returning current result from Soap call

src/AbstractStructBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static function __set_state(array $array)
1515
{
1616
$className = get_called_class();
1717
$object = @new $className();
18-
foreach ($array as $name=>$value) {
18+
foreach ($array as $name => $value) {
1919
$object->_set($name, $value);
2020
}
2121
return $object;

src/SoapClientInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false,
168168
public function getLastError();
169169
/**
170170
* Method saving the last error returned by the SoapClient
171-
* @param string $methoName the method called when the error occurred
171+
* @param string $methodName the method called when the error occurred
172172
* @param \SoapFault $soapFault l'objet de l'erreur
173173
* @return SoapClientInterface
174174
*/
175-
public function saveLastError($methoName, \SoapFault $soapFault);
175+
public function saveLastError($methodName, \SoapFault $soapFault);
176176
/**
177177
* Method returning current result from Soap call
178178
* @return mixed

tests/SoapClientTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace WsdlToPhp\PackageBase\Tests;
44

5-
65
use WsdlToPhp\PackageBase\Utils;
76
use WsdlToPhp\PackageBase\Tests\SoapClient;
87

@@ -339,7 +338,7 @@ public function testGetStreamContext()
339338
/**
340339
*
341340
*/
342-
public function testGetStreamContextAsNill()
341+
public function testGetStreamContextAsNull()
343342
{
344343
$soapClient = new SoapClient(array(
345344
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',

0 commit comments

Comments
 (0)