Skip to content

Commit 9a17e51

Browse files
committed
Merge pull request #14 from simonharris/master
Allow passing an array of user-specified options to SoapClient
2 parents 2d397ad + fdb14c2 commit 9a17e51

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Use the client to query and manipulate your organisation’s Salesforce data. Fi
4949

5050
```php
5151
$builder = new \Phpforce\SoapClient\ClientBuilder(
52-
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml'
52+
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml',
5353
'username',
5454
'password',
5555
'security_token'
@@ -61,7 +61,7 @@ $client = $builder->build();
6161
### SOQL queries
6262

6363
```php
64-
$result = $client->query('select Name, SystemModstamp from Account limit 5');
64+
$results = $client->query('select Name, SystemModstamp from Account limit 5');
6565
```
6666

6767
This will fetch five accounts from Salesforce and return them as a
@@ -119,7 +119,7 @@ $log = new \Monolog\Logger('name');
119119
$log->pushHandler(new \Monolog\Handler\StreamHandler('path/to/your.log'));
120120

121121
$builder = new \Phpforce\SoapClient\ClientBuilder(
122-
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml'
122+
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml',
123123
'username',
124124
'password',
125125
'security_token'

src/Phpforce/SoapClient/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ protected function createSObject($object, $objectType)
665665

666666
foreach (get_object_vars($object) as $field => $value) {
667667
$type = $this->soapClient->getSoapElementType($objectType, $field);
668-
if (!$type) {
668+
if ($field != 'Id' && !$type) {
669669
continue;
670670
}
671671

src/Phpforce/SoapClient/ClientBuilder.php

+8-7
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

+14-10
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)