Skip to content

Commit 3d340aa

Browse files
committed
issue #28 - allow the non-WSDL-mode to be used
1 parent 82564ea commit 3d340aa

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

src/AbstractSoapClientBase.php

Lines changed: 26 additions & 3 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)

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)