Skip to content

Commit

Permalink
Merge pull request #14 from simonharris/master
Browse files Browse the repository at this point in the history
 Allow passing an array of user-specified options to SoapClient
  • Loading branch information
ddeboer committed Apr 5, 2015
2 parents 2d397ad + fdb14c2 commit 9a17e51
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Use the client to query and manipulate your organisation’s Salesforce data. Fi

```php
$builder = new \Phpforce\SoapClient\ClientBuilder(
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml'
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml',
'username',
'password',
'security_token'
Expand All @@ -61,7 +61,7 @@ $client = $builder->build();
### SOQL queries

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

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

$builder = new \Phpforce\SoapClient\ClientBuilder(
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml'
'/path/to/your/salesforce/wsdl/sandbox.enterprise.wsdl.xml',
'username',
'password',
'security_token'
Expand Down
2 changes: 1 addition & 1 deletion src/Phpforce/SoapClient/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ protected function createSObject($object, $objectType)

foreach (get_object_vars($object) as $field => $value) {
$type = $this->soapClient->getSoapElementType($objectType, $field);
if (!$type) {
if ($field != 'Id' && !$type) {
continue;
}

Expand Down
15 changes: 8 additions & 7 deletions src/Phpforce/SoapClient/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ class ClientBuilder
/**
* Construct client builder with required parameters
*
* @param string $wsdl Path to your Salesforce WSDL
* @param string $username Your Salesforce username
* @param string $password Your Salesforce password
* @param string $token Your Salesforce security token
* @param string $wsdl Path to your Salesforce WSDL
* @param string $username Your Salesforce username
* @param string $password Your Salesforce password
* @param string $token Your Salesforce security token
* @param array $soapOptions Further options to be passed to the SoapClient
*/
public function __construct($wsdl, $username, $password, $token)
public function __construct($wsdl, $username, $password, $token, array $soapOptions = array())
{
$this->wsdl = $wsdl;
$this->username = $username;
$this->password = $password;
$this->token = $token;
$this->soapOptions = $soapOptions;
}

/**
Expand All @@ -52,7 +54,7 @@ public function withLog(LoggerInterface $log)
public function build()
{
$soapClientFactory = new SoapClientFactory();
$soapClient = $soapClientFactory->factory($this->wsdl);
$soapClient = $soapClientFactory->factory($this->wsdl, $this->soapOptions);

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

Expand All @@ -64,4 +66,3 @@ public function build()
return $client;
}
}

24 changes: 14 additions & 10 deletions src/Phpforce/SoapClient/Soap/SoapClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,23 @@ class SoapClientFactory
protected $typeConverters;

/**
* @param string $wsdl Some argument description
*
* @param string $wsdl Path to WSDL file
* @param array $soapOptions
* @return SoapClient
*/
public function factory($wsdl)
public function factory($wsdl, array $soapOptions = array())
{
return new SoapClient($wsdl, array(
'trace' => 1,
'features' => \SOAP_SINGLE_ELEMENT_ARRAYS,
'classmap' => $this->classmap,
'typemap' => $this->getTypeConverters()->getTypemap(),
$defaults = array(
'trace' => 1,
'features' => \SOAP_SINGLE_ELEMENT_ARRAYS,
'classmap' => $this->classmap,
'typemap' => $this->getTypeConverters()->getTypemap(),
'cache_wsdl' => \WSDL_CACHE_MEMORY
));
);

$options = array_merge($defaults, $soapOptions);

return new SoapClient($wsdl, $options);
}

/**
Expand Down Expand Up @@ -110,4 +114,4 @@ public function setTypeConverters(TypeConverter\TypeConverterCollection $typeCon

return $this;
}
}
}

0 comments on commit 9a17e51

Please sign in to comment.