Skip to content

Commit 7fb8a3b

Browse files
committed
Merge branch 'feature/issue-28' into develop
1 parent 0a21fbd commit 7fb8a3b

File tree

4 files changed

+121
-26
lines changed

4 files changed

+121
-26
lines changed

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
```

src/AbstractSoapClientBase.php

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static function setSoapClient(\SoapClient $soapClient)
6060
* @uses AbstractSoapClientBase::getDefaultWsdlOptions()
6161
* @uses AbstractSoapClientBase::getSoapClientClassName()
6262
* @uses AbstractSoapClientBase::setSoapClient()
63+
* @uses AbstractSoapClientBase::OPTION_PREFIX
6364
* @param array $options WSDL options
6465
* @return void
6566
*/
@@ -74,20 +75,42 @@ public function initSoapClient(array $options)
7475
$wsdlOptions[str_replace(self::OPTION_PREFIX, '', $optionName)] = $optionValue;
7576
}
7677
}
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)]);
78+
if (self::canInstantiateSoapClientWithOptions($wsdlOptions)) {
79+
$wsdlUrl = null;
80+
if (array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URL), $wsdlOptions)) {
81+
$wsdlUrl = $wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)];
82+
unset($wsdlOptions[str_replace(self::OPTION_PREFIX, '', self::WSDL_URL)]);
83+
}
8084
$soapClientClassName = $this->getSoapClientClassName();
8185
static::setSoapClient(new $soapClientClassName($wsdlUrl, $wsdlOptions));
8286
}
8387
}
88+
/**
89+
* Checks if the provided options are sufficient to instantiate a SoapClient:
90+
* - WSDL-mode : only the WSDL is required
91+
* - non-WSDL-mode : URI and LOCATION are required, WSDL url can be empty then
92+
* @uses AbstractSoapClientBase::OPTION_PREFIX
93+
* @param $wsdlOptions
94+
* @return bool
95+
*/
96+
protected static function canInstantiateSoapClientWithOptions($wsdlOptions)
97+
{
98+
return (
99+
array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URL), $wsdlOptions) ||
100+
(
101+
array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_URI), $wsdlOptions) &&
102+
array_key_exists(str_replace(self::OPTION_PREFIX, '', self::WSDL_LOCATION), $wsdlOptions)
103+
)
104+
);
105+
}
84106
/**
85107
* Returns the SoapClient class name to use to create the instance of the SoapClient.
86108
* The SoapClient class is determined based on the package name.
87109
* If a class is named as {Api}SoapClient, then this is the class that will be used.
88110
* Be sure that this class inherits from the native PHP SoapClient class and this class has been loaded or can be loaded.
89111
* The goal is to allow the override of the SoapClient without having to modify this generated class.
90112
* Then the overridding SoapClient class can override for example the SoapClient::__doRequest() method if it is needed.
113+
* @uses AbstractSoapClientBase::DEFAULT_SOAP_CLIENT_CLASS
91114
* @return string
92115
*/
93116
public function getSoapClientClassName($soapClientClassName = null)
@@ -100,62 +123,68 @@ public function getSoapClientClassName($soapClientClassName = null)
100123
}
101124
/**
102125
* Method returning all default options values
103-
* @uses AbstractSoapClientBase::WSDL_CLASSMAP
126+
* @uses AbstractSoapClientBase::WSDL_AUTHENTICATION
104127
* @uses AbstractSoapClientBase::WSDL_CACHE_WSDL
128+
* @uses AbstractSoapClientBase::WSDL_CLASSMAP
105129
* @uses AbstractSoapClientBase::WSDL_COMPRESSION
106130
* @uses AbstractSoapClientBase::WSDL_CONNECTION_TIMEOUT
107131
* @uses AbstractSoapClientBase::WSDL_ENCODING
108132
* @uses AbstractSoapClientBase::WSDL_EXCEPTIONS
109133
* @uses AbstractSoapClientBase::WSDL_FEATURES
134+
* @uses AbstractSoapClientBase::WSDL_LOCAL_CERT
110135
* @uses AbstractSoapClientBase::WSDL_LOCATION
111136
* @uses AbstractSoapClientBase::WSDL_LOGIN
137+
* @uses AbstractSoapClientBase::WSDL_PASSPHRASE
112138
* @uses AbstractSoapClientBase::WSDL_PASSWORD
139+
* @uses AbstractSoapClientBase::WSDL_PROXY_HOST
140+
* @uses AbstractSoapClientBase::WSDL_PROXY_LOGIN
141+
* @uses AbstractSoapClientBase::WSDL_PROXY_PASSWORD
142+
* @uses AbstractSoapClientBase::WSDL_PROXY_PORT
113143
* @uses AbstractSoapClientBase::WSDL_SOAP_VERSION
144+
* @uses AbstractSoapClientBase::WSDL_SSL_METHOD
114145
* @uses AbstractSoapClientBase::WSDL_STREAM_CONTEXT
146+
* @uses AbstractSoapClientBase::WSDL_STYLE
115147
* @uses AbstractSoapClientBase::WSDL_TRACE
116148
* @uses AbstractSoapClientBase::WSDL_TYPEMAP
117149
* @uses AbstractSoapClientBase::WSDL_URL
118-
* @uses AbstractSoapClientBase::VALUE_WSDL_URL
150+
* @uses AbstractSoapClientBase::WSDL_URI
151+
* @uses AbstractSoapClientBase::WSDL_USE
119152
* @uses AbstractSoapClientBase::WSDL_USER_AGENT
120-
* @uses AbstractSoapClientBase::WSDL_PROXY_HOST
121-
* @uses AbstractSoapClientBase::WSDL_PROXY_PORT
122-
* @uses AbstractSoapClientBase::WSDL_PROXY_LOGIN
123-
* @uses AbstractSoapClientBase::WSDL_PROXY_PASSWORD
124-
* @uses AbstractSoapClientBase::WSDL_LOCAL_CERT
125-
* @uses AbstractSoapClientBase::WSDL_PASSPHRASE
126-
* @uses AbstractSoapClientBase::WSDL_AUTHENTICATION
127-
* @uses AbstractSoapClientBase::WSDL_SSL_METHOD
153+
* @uses WSDL_CACHE_NONE
128154
* @uses SOAP_SINGLE_ELEMENT_ARRAYS
129155
* @uses SOAP_USE_XSI_ARRAY_TYPE
130156
* @return array
131157
*/
132158
public static function getDefaultWsdlOptions()
133159
{
134160
return [
135-
self::WSDL_CLASSMAP => null,
161+
self::WSDL_AUTHENTICATION => null,
136162
self::WSDL_CACHE_WSDL => WSDL_CACHE_NONE,
163+
self::WSDL_CLASSMAP => null,
137164
self::WSDL_COMPRESSION => null,
138165
self::WSDL_CONNECTION_TIMEOUT => null,
139166
self::WSDL_ENCODING => null,
140167
self::WSDL_EXCEPTIONS => true,
141168
self::WSDL_FEATURES => SOAP_SINGLE_ELEMENT_ARRAYS | SOAP_USE_XSI_ARRAY_TYPE,
169+
self::WSDL_LOCAL_CERT => null,
142170
self::WSDL_LOCATION => null,
143171
self::WSDL_LOGIN => null,
172+
self::WSDL_PASSPHRASE => null,
144173
self::WSDL_PASSWORD => null,
174+
self::WSDL_PROXY_HOST => null,
175+
self::WSDL_PROXY_LOGIN => null,
176+
self::WSDL_PROXY_PASSWORD => null,
177+
self::WSDL_PROXY_PORT => null,
145178
self::WSDL_SOAP_VERSION => null,
179+
self::WSDL_SSL_METHOD => null,
146180
self::WSDL_STREAM_CONTEXT => null,
181+
self::WSDL_STYLE => null,
147182
self::WSDL_TRACE => true,
148183
self::WSDL_TYPEMAP => null,
149184
self::WSDL_URL => null,
185+
self::WSDL_URI => null,
186+
self::WSDL_USE => null,
150187
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,
159188
];
160189
}
161190
/**

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)