Skip to content

Commit 13b6aff

Browse files
author
Simon Harris
committed
Allow passing an array of user-specified options to SoapClient
1 parent ed434a5 commit 13b6aff

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/Phpforce/SoapClient/ClientBuilder.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ class ClientBuilder
1717
/**
1818
* Construct client builder with required parameters
1919
*
20-
* @param string $wsdl Path to your Salesforce WSDL
21-
* @param string $username Your Salesforce username
22-
* @param string $password Your Salesforce password
23-
* @param string $token Your Salesforce security token
20+
* @param string $wsdl Path to your Salesforce WSDL
21+
* @param string $username Your Salesforce username
22+
* @param string $password Your Salesforce password
23+
* @param string $token Your Salesforce security token
24+
* @param array $soapOptions Further options to be passed to the SoapClient
2425
*/
25-
public function __construct($wsdl, $username, $password, $token)
26+
public function __construct($wsdl, $username, $password, $token, array $soapOptions = array())
2627
{
2728
$this->wsdl = $wsdl;
2829
$this->username = $username;
2930
$this->password = $password;
3031
$this->token = $token;
32+
$this->soapOptions = $soapOptions;
3133
}
3234

3335
/**
@@ -52,7 +54,7 @@ public function withLog(LoggerInterface $log)
5254
public function build()
5355
{
5456
$soapClientFactory = new SoapClientFactory();
55-
$soapClient = $soapClientFactory->factory($this->wsdl);
57+
$soapClient = $soapClientFactory->factory($this->wsdl, $this->soapOptions);
5658

5759
$client = new Client($soapClient, $this->username, $this->password, $this->token);
5860

@@ -64,4 +66,3 @@ public function build()
6466
return $client;
6567
}
6668
}
67-

src/Phpforce/SoapClient/Soap/SoapClientFactory.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,23 @@ class SoapClientFactory
5252
protected $typeConverters;
5353

5454
/**
55-
* @param string $wsdl Some argument description
56-
*
55+
* @param string $wsdl Path to WSDL file
56+
* @param array $soapOptions
5757
* @return SoapClient
5858
*/
59-
public function factory($wsdl)
59+
public function factory($wsdl, array $soapOptions = array())
6060
{
61-
return new SoapClient($wsdl, array(
62-
'trace' => 1,
63-
'features' => \SOAP_SINGLE_ELEMENT_ARRAYS,
64-
'classmap' => $this->classmap,
65-
'typemap' => $this->getTypeConverters()->getTypemap(),
61+
$defaults = array(
62+
'trace' => 1,
63+
'features' => \SOAP_SINGLE_ELEMENT_ARRAYS,
64+
'classmap' => $this->classmap,
65+
'typemap' => $this->getTypeConverters()->getTypemap(),
6666
'cache_wsdl' => \WSDL_CACHE_MEMORY
67-
));
67+
);
68+
69+
$options = array_merge($defaults, $soapOptions);
70+
71+
return new SoapClient($wsdl, $options);
6872
}
6973

7074
/**
@@ -110,4 +114,4 @@ public function setTypeConverters(TypeConverter\TypeConverterCollection $typeCon
110114

111115
return $this;
112116
}
113-
}
117+
}

0 commit comments

Comments
 (0)