Skip to content

Allow passing an array of user-specified options to SoapClient #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}