Skip to content

Commit cc57d91

Browse files
committed
Merge branch 'release/2.0.3'
2 parents 110fc75 + 9eb3736 commit cc57d91

File tree

10 files changed

+156
-31
lines changed

10 files changed

+156
-31
lines changed

.docker/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM php:7.2-apache
2+
3+
RUN apt-get update \
4+
&& apt-get install -y libxml2-dev git zip zlib1g \
5+
&& docker-php-ext-install soap
6+
7+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
8+
COPY . /var/www/html
9+
10+
WORKDIR /var/www/html

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ matrix:
1111
- php: 7.1
1212
- php: 7.2
1313

14-
before_install:
15-
- composer self-update
16-
1714
install:
1815
- composer install
1916

CHANGELOG.md

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

3+
## 2.0.3 - 2019-01-10
4+
- Issue #25 - Enhancement: Improve output from running php-cs-fixer
5+
- Issue #26 - Enhancement: Keep packages sorted in composer.json
6+
- Issue #28 - Add the URI as an option in the soapClient parameters
7+
8+
39
## 2.0.2 - 2018-07-23
410
- Issue #22 / Pull request #23 - Add support to invoke getLastRequest without throwing an InvalidArgumentException if the request is not executed
511

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Here are the constants/options defined by this interface and their utility:
5757
- **DEFAULT_SOAP_CLIENT_CLASS = '\SoapClient'**: this is the default [SoapClient](http://php.net/manual/en/class.soapclient.php) class that is used to send the request. Feel free to override it if you want to use another [SoapClient](http://php.net/manual/en/class.soapclient.php) class
5858
- **OPTION_PREFIX**: this is the prefix used for any constant's option name
5959
- **WSDL_URL**: option index used to pass the WSDL url
60+
- **WSDL_URI**: option index used to pass the target namespace of the SOAP service (required for non-WSDL-mode with with the `location`)
61+
- **WSDL_USE**: option index used to pass non-WSDL-mode option use
62+
- **WSDL_STYLE**: option index used to pass non-WSDL-mode option style
6063
- **WSDL_CLASSMAP**: the classmap's array
6164
- **WSDL_LOGIN**: the basic authentication's login
6265
- **WSDL_PASSWORD**: the basic authentication's password
@@ -285,5 +288,5 @@ You can run the unit tests with the following command:
285288
```
286289
$ cd /path/to/src/WsdlToPhp/PackageBase/
287290
$ composer install
288-
$ phpunit
291+
$ composer test
289292
```

UPGRADE-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ class MyService extends AbstractSoapClientBase
3838
}
3939
```
4040

41-
`$this->getSoapClient()` is now used to access the SoapClient instance.
41+
`$this->getSoapClient()` is now used to access the SoapClient instance.

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
"name": "Gemorroj",
3131
"email": "[email protected]",
3232
"role": "Contributor"
33+
},
34+
{
35+
"name": "hordijk",
36+
"role": "Contributor"
3337
}
3438
],
3539
"support" : {
@@ -40,7 +44,7 @@
4044
},
4145
"scripts": {
4246
"test": "vendor/bin/phpunit",
43-
"lint": "vendor/bin/php-cs-fixer fix"
47+
"lint": "vendor/bin/php-cs-fixer fix --ansi --diff --verbose"
4448
},
4549
"require-dev": {
4650
"friendsofphp/php-cs-fixer": "~2.0",
@@ -55,5 +59,8 @@
5559
"psr-4": {
5660
"WsdlToPhp\\PackageBase\\Tests\\": "tests"
5761
}
62+
},
63+
"config": {
64+
"sort-packages": true
5865
}
5966
}

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3.4'
2+
3+
services:
4+
php:
5+
build:
6+
context: .
7+
dockerfile: .docker/Dockerfile
8+
volumes:
9+
- .:/var/www/html:rw
10+
container_name: package_base

src/AbstractSoapClientBase.php

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function setSoapClient(\SoapClient $soapClient)
5757
* @uses AbstractSoapClientBase::getDefaultWsdlOptions()
5858
* @uses AbstractSoapClientBase::getSoapClientClassName()
5959
* @uses AbstractSoapClientBase::setSoapClient()
60+
* @uses AbstractSoapClientBase::OPTION_PREFIX
6061
* @param array $options WSDL options
6162
* @return void
6263
*/
@@ -71,20 +72,42 @@ public function initSoapClient(array $options)
7172
$wsdlOptions[str_replace(self::OPTION_PREFIX, '', $optionName)] = $optionValue;
7273
}
7374
}
74-
if (array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URL), $wsdlOptions)) {
75-
$wsdlUrl = $wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)];
76-
unset($wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)]);
75+
if (self::canInstantiateSoapClientWithOptions($wsdlOptions)) {
76+
$wsdlUrl = null;
77+
if (array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URL), $wsdlOptions)) {
78+
$wsdlUrl = $wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)];
79+
unset($wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)]);
80+
}
7781
$soapClientClassName = $this->getSoapClientClassName();
7882
$this->setSoapClient(new $soapClientClassName($wsdlUrl, $wsdlOptions));
7983
}
8084
}
85+
/**
86+
* Checks if the provided options are sufficient to instantiate a SoapClient:
87+
* - WSDL-mode : only the WSDL is required
88+
* - non-WSDL-mode : URI and LOCATION are required, WSDL url can be empty then
89+
* @uses AbstractSoapClientBase::OPTION_PREFIX
90+
* @param $wsdlOptions
91+
* @return bool
92+
*/
93+
protected static function canInstantiateSoapClientWithOptions($wsdlOptions)
94+
{
95+
return (
96+
array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URL), $wsdlOptions) ||
97+
(
98+
array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URI), $wsdlOptions) &&
99+
array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_LOCATION), $wsdlOptions)
100+
)
101+
);
102+
}
81103
/**
82104
* Returns the SoapClient class name to use to create the instance of the SoapClient.
83105
* The SoapClient class is determined based on the package name.
84106
* If a class is named as {Api}SoapClient, then this is the class that will be used.
85107
* Be sure that this class inherits from the native PHP SoapClient class and this class has been loaded or can be loaded.
86108
* The goal is to allow the override of the SoapClient without having to modify this generated class.
87109
* Then the overridding SoapClient class can override for example the SoapClient::__doRequest() method if it is needed.
110+
* @uses AbstractSoapClientBase::DEFAULT_SOAP_CLIENT_CLASS
88111
* @return string
89112
*/
90113
public function getSoapClientClassName($soapClientClassName = null)
@@ -97,62 +120,68 @@ public function getSoapClientClassName($soapClientClassName = null)
97120
}
98121
/**
99122
* Method returning all default options values
100-
* @uses AbstractSoapClientBase::WSDL_CLASSMAP
123+
* @uses AbstractSoapClientBase::WSDL_AUTHENTICATION
101124
* @uses AbstractSoapClientBase::WSDL_CACHE_WSDL
125+
* @uses AbstractSoapClientBase::WSDL_CLASSMAP
102126
* @uses AbstractSoapClientBase::WSDL_COMPRESSION
103127
* @uses AbstractSoapClientBase::WSDL_CONNECTION_TIMEOUT
104128
* @uses AbstractSoapClientBase::WSDL_ENCODING
105129
* @uses AbstractSoapClientBase::WSDL_EXCEPTIONS
106130
* @uses AbstractSoapClientBase::WSDL_FEATURES
131+
* @uses AbstractSoapClientBase::WSDL_LOCAL_CERT
107132
* @uses AbstractSoapClientBase::WSDL_LOCATION
108133
* @uses AbstractSoapClientBase::WSDL_LOGIN
134+
* @uses AbstractSoapClientBase::WSDL_PASSPHRASE
109135
* @uses AbstractSoapClientBase::WSDL_PASSWORD
136+
* @uses AbstractSoapClientBase::WSDL_PROXY_HOST
137+
* @uses AbstractSoapClientBase::WSDL_PROXY_LOGIN
138+
* @uses AbstractSoapClientBase::WSDL_PROXY_PASSWORD
139+
* @uses AbstractSoapClientBase::WSDL_PROXY_PORT
110140
* @uses AbstractSoapClientBase::WSDL_SOAP_VERSION
141+
* @uses AbstractSoapClientBase::WSDL_SSL_METHOD
111142
* @uses AbstractSoapClientBase::WSDL_STREAM_CONTEXT
143+
* @uses AbstractSoapClientBase::WSDL_STYLE
112144
* @uses AbstractSoapClientBase::WSDL_TRACE
113145
* @uses AbstractSoapClientBase::WSDL_TYPEMAP
114146
* @uses AbstractSoapClientBase::WSDL_URL
115-
* @uses AbstractSoapClientBase::VALUE_WSDL_URL
147+
* @uses AbstractSoapClientBase::WSDL_URI
148+
* @uses AbstractSoapClientBase::WSDL_USE
116149
* @uses AbstractSoapClientBase::WSDL_USER_AGENT
117-
* @uses AbstractSoapClientBase::WSDL_PROXY_HOST
118-
* @uses AbstractSoapClientBase::WSDL_PROXY_PORT
119-
* @uses AbstractSoapClientBase::WSDL_PROXY_LOGIN
120-
* @uses AbstractSoapClientBase::WSDL_PROXY_PASSWORD
121-
* @uses AbstractSoapClientBase::WSDL_LOCAL_CERT
122-
* @uses AbstractSoapClientBase::WSDL_PASSPHRASE
123-
* @uses AbstractSoapClientBase::WSDL_AUTHENTICATION
124-
* @uses AbstractSoapClientBase::WSDL_SSL_METHOD
150+
* @uses WSDL_CACHE_NONE
125151
* @uses SOAP_SINGLE_ELEMENT_ARRAYS
126152
* @uses SOAP_USE_XSI_ARRAY_TYPE
127153
* @return array
128154
*/
129155
public static function getDefaultWsdlOptions()
130156
{
131157
return [
132-
self::WSDL_CLASSMAP => null,
158+
self::WSDL_AUTHENTICATION => null,
133159
self::WSDL_CACHE_WSDL => WSDL_CACHE_NONE,
160+
self::WSDL_CLASSMAP => null,
134161
self::WSDL_COMPRESSION => null,
135162
self::WSDL_CONNECTION_TIMEOUT => null,
136163
self::WSDL_ENCODING => null,
137164
self::WSDL_EXCEPTIONS => true,
138165
self::WSDL_FEATURES => SOAP_SINGLE_ELEMENT_ARRAYS | SOAP_USE_XSI_ARRAY_TYPE,
166+
self::WSDL_LOCAL_CERT => null,
139167
self::WSDL_LOCATION => null,
140168
self::WSDL_LOGIN => null,
169+
self::WSDL_PASSPHRASE => null,
141170
self::WSDL_PASSWORD => null,
171+
self::WSDL_PROXY_HOST => null,
172+
self::WSDL_PROXY_LOGIN => null,
173+
self::WSDL_PROXY_PASSWORD => null,
174+
self::WSDL_PROXY_PORT => null,
142175
self::WSDL_SOAP_VERSION => null,
176+
self::WSDL_SSL_METHOD => null,
143177
self::WSDL_STREAM_CONTEXT => null,
178+
self::WSDL_STYLE => null,
144179
self::WSDL_TRACE => true,
145180
self::WSDL_TYPEMAP => null,
146181
self::WSDL_URL => null,
182+
self::WSDL_URI => null,
183+
self::WSDL_USE => null,
147184
self::WSDL_USER_AGENT => null,
148-
self::WSDL_PROXY_HOST => null,
149-
self::WSDL_PROXY_PORT => null,
150-
self::WSDL_PROXY_LOGIN => null,
151-
self::WSDL_PROXY_PASSWORD => null,
152-
self::WSDL_LOCAL_CERT => null,
153-
self::WSDL_PASSPHRASE => null,
154-
self::WSDL_AUTHENTICATION => null,
155-
self::WSDL_SSL_METHOD => null,
156185
];
157186
}
158187
/**

src/SoapClientInterface.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ interface SoapClientInterface
117117
* @var string
118118
*/
119119
const WSDL_STREAM_CONTEXT = 'wsdl_stream_context';
120+
/**
121+
* Option key to define WSDL style
122+
* @var string
123+
*/
124+
const WSDL_STYLE = 'wsdl_style';
120125
/**
121126
* Option key to define WSDL trace option
122127
* @var string
@@ -132,6 +137,16 @@ interface SoapClientInterface
132137
* @var string
133138
*/
134139
const WSDL_URL = 'wsdl_url';
140+
/**
141+
* Option key to define WSDL uri
142+
* @var string
143+
*/
144+
const WSDL_URI = 'wsdl_uri';
145+
/**
146+
* Option key to define WSDL use
147+
* @var string
148+
*/
149+
const WSDL_USE = 'wsdl_use';
135150
/**
136151
* Option key to define WSDL user_agent
137152
* @var string

tests/SoapClientTest.php

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ public function testSetLocation()
4949

5050
$soapClient->setLocation('http://api.bing.net:80/soap.asm');
5151

52-
$this->assertSAme('http://api.bing.net:80/soap.asm', $soapClient->getSoapClient()->location);
52+
$this->assertSame('http://api.bing.net:80/soap.asm', $soapClient->getSoapClient()->location);
5353
}
5454
/**
5555
*
5656
*/
57-
public function testLocationOotion()
57+
public function testLocationOption()
5858
{
5959
$soapClient = new SoapClient(array(
6060
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
6161
SoapClient::WSDL_CLASSMAP => self::classMap(),
6262
SoapClient::WSDL_LOCATION => 'http://api.bing.net:80/soap.asm',
6363
));
6464

65-
$this->assertSAme('http://api.bing.net:80/soap.asm', $soapClient->getSoapClient()->location);
65+
$this->assertSame('http://api.bing.net:80/soap.asm', $soapClient->getSoapClient()->location);
6666
}
6767
/**
6868
*
@@ -481,4 +481,52 @@ public static function classMap()
481481
'WebSearchTag' => 'ApiStructWebSearchTag',
482482
);
483483
}
484+
/**
485+
*
486+
*/
487+
public function testInvalidNonWsdlModeMustNotCreateASoapInstanceForMissingUriAndLocationOptions()
488+
{
489+
$soapClient = new SoapClient(array(
490+
SoapClient::WSDL_URL => null,
491+
));
492+
493+
$this->assertNull($soapClient->getSoapClient());
494+
}
495+
/**
496+
*
497+
*/
498+
public function testInvalidNonWsdlModeMustNotCreateASoapInstanceForMissingLocationOption()
499+
{
500+
$soapClient = new SoapClient(array(
501+
SoapClient::WSDL_URL => null,
502+
SoapClient::WSDL_URI => 'http://api.bing.net:80/soap.asmx',
503+
));
504+
505+
$this->assertNull($soapClient->getSoapClient());
506+
}
507+
/**
508+
*
509+
*/
510+
public function testInvalidNonWsdlModeMustNotCreateASoapInstanceForMissingUriOption()
511+
{
512+
$soapClient = new SoapClient(array(
513+
SoapClient::WSDL_URL => null,
514+
SoapClient::WSDL_LOCATION => 'http://api.bing.net:80/soap.asmx',
515+
));
516+
517+
$this->assertNull($soapClient->getSoapClient());
518+
}
519+
/**
520+
*
521+
*/
522+
public function testInvalidNonWsdlModeMustCreateASoapInstanceWithUriAndLocationOptions()
523+
{
524+
$soapClient = new SoapClient(array(
525+
SoapClient::WSDL_URL => null,
526+
SoapClient::WSDL_LOCATION => 'http://api.bing.net:80/soap.asmx',
527+
SoapClient::WSDL_URI => 'http://api.bing.net:80/soap.asmx',
528+
));
529+
530+
$this->assertInstanceOf('\SoapClient', $soapClient->getSoapClient());
531+
}
484532
}

0 commit comments

Comments
 (0)