class SoapClient in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 modules/salesforce_soap/src/Soap/SoapClient.php \Drupal\salesforce_soap\Soap\SoapClient
- 5.0.x modules/salesforce_soap/src/Soap/SoapClient.php \Drupal\salesforce_soap\Soap\SoapClient
A client for communicating with the Salesforce SOAP API.
Hierarchy
- class \Drupal\salesforce_soap\Soap\SoapClient extends \SforcePartnerClient implements SoapClientInterface
Expanded class hierarchy of SoapClient
1 string reference to 'SoapClient'
- salesforce_soap.services.yml in modules/
salesforce_soap/ salesforce_soap.services.yml - modules/salesforce_soap/salesforce_soap.services.yml
1 service uses SoapClient
- salesforce.soap_client in modules/
salesforce_soap/ salesforce_soap.services.yml - Drupal\salesforce_soap\Soap\SoapClient
File
- modules/
salesforce_soap/ src/ Soap/ SoapClient.php, line 11
Namespace
Drupal\salesforce_soap\SoapView source
class SoapClient extends SforcePartnerClient implements SoapClientInterface {
/**
* Indicates whether or not a successfull connection was made to the SOAP API.
*
* @var bool
*/
protected $isConnected;
/**
* Salesforce REST API client.
*
* @var \Drupal\salesforce\Rest\RestClientInterface
*/
protected $restApi;
/**
* Path to the WSDL that should be used.
*
* @var string
*/
protected $wsdl;
/**
* Constructor which initializes the consumer.
*
* @param \Drupal\salesforce\Rest\RestClientInterface $rest_api
* The Salesforce REST API client.
* @param string $wsdl
* (Optional) Path to the WSDL that should be used. Defaults to using the
* partner WSDL from the developerforce/force.com-toolkit-for-php package.
*/
public function __construct(RestClientInterface $rest_api, $wsdl = NULL) {
parent::__construct();
$this->restApi = $rest_api;
if ($wsdl) {
$this->wsdl = $wsdl;
}
else {
// Determine location of the developerforce/force.com-toolkit-for-php WSDL
// files.
$reflector = new \ReflectionClass('SforcePartnerClient');
$wsdl_dir = dirname($reflector
->getFileName());
// Use the partner WSDL.
$this->wsdl = "{$wsdl_dir}/partner.wsdl.xml";
}
}
/**
* {@inheritdoc}
*/
public function connect() {
$this->isConnected = FALSE;
// Use the "isAuthorized" callback to initialize session headers.
if ($this->restApi
->isAuthorized()) {
$this
->createConnection($this->wsdl);
$token = $this->restApi
->getAccessToken();
if (!$token) {
$token = $this->restApi
->refreshToken();
}
$this
->setSessionHeader($token);
$this
->setEndPoint($this->restApi
->getApiEndPoint('partner'));
$this->isConnected = TRUE;
}
else {
throw new \Exception('Salesforce needs to be authorized to connect to this website.');
}
}
/**
* {@inheritdoc}
*/
public function isConnected() {
return $this->isConnected;
}
/**
* {@inheritdoc}
*/
public function trySoap($function, array $params = [], $refresh = FALSE) {
if ($refresh) {
$this->restApi
->refreshToken();
}
if (!$this->isConnected) {
$this
->connect();
}
try {
$results = call_user_func_array([
$this,
$function,
], $params);
return $results;
} catch (SoapFault $e) {
// sf:INVALID_SESSION_ID is thrown on expired login (and other reasons).
// Our only recourse is to try refreshing our auth token. If we get any
// other exception, bubble it up.
if ($e->faultcode != 'sf:INVALID_SESSION_ID') {
throw $e;
}
// If we didn't already try it, refresh the access token and try the call
// again.
if (!$refresh) {
return $this
->trySoap($function, $params, TRUE);
}
else {
// Our connection is not working.
$this->isConnected = FALSE;
throw $e;
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SoapClient:: |
protected | property | Indicates whether or not a successfull connection was made to the SOAP API. | |
SoapClient:: |
protected | property | Salesforce REST API client. | |
SoapClient:: |
protected | property | Path to the WSDL that should be used. | |
SoapClient:: |
public | function |
Establish a connection to the SOAP API. Overrides SoapClientInterface:: |
|
SoapClient:: |
public | function |
Whether or not this client is connected to the SOAP API. Overrides SoapClientInterface:: |
|
SoapClient:: |
public | function |
Salesforce SOAP API resource wrapper. Overrides SoapClientInterface:: |
|
SoapClient:: |
public | function | Constructor which initializes the consumer. |