You are here

public function SalesforceSoapPartner::__construct in Salesforce Suite 7.3

Constructor for SalesforceSoapPartner.

Parameters

Salesforce $sfapi: Salesforce API object

string $wsdl: WSDL provided by Salesforce account. One will be created if not explicitly provided.

File

modules/salesforce_soap/salesforce_soap.inc, line 26
Contains SalesforceSoapPartner.

Class

SalesforceSoapPartner
Expose the partner SOAP API by extending SforcePartnerClient and configuring it with the OAUTH credentials and endpoints from the Salesforce API class.

Code

public function __construct(Salesforce $sfapi, $wsdl = NULL) {
  parent::__construct();
  if (empty($wsdl)) {
    $wsdl = libraries_get_path('salesforce') . '/soapclient/partner.wsdl.xml';
  }
  $this
    ->setConnected(FALSE);
  $this
    ->createConnection($wsdl);
  $this->salesforceApi = $sfapi;

  // Use the "isAuthorized" callback to initialize session headers.
  // Callers can use the trySoap() wrapper to automatically handle
  // the SoapFault invalid session exception.
  if ($this->salesforceApi
    ->isAuthorized()) {
    $token = $this->salesforceApi
      ->getAccessToken();
    if (!$token) {
      $token = $this->salesforceApi
        ->refreshToken();
    }
    $this
      ->setSessionHeader($token);
    $this
      ->setEndPoint($this->salesforceApi
      ->getApiEndPoint('partner'));
    $this
      ->setConnected(TRUE);
  }
  else {

    // Alert the caller that the Salesforce instance has not been configured.
    watchdog('salesforce_soap', 'Attempting to use an instance of
        the SalesforceSoapPartner class with a non-authorized Salesforce API
        instance. Please ensure the Salesforce API module has been configured
        and successfully authorized with a Salesforce org.', NULL, WATCHDOG_ERROR);
    $this
      ->setConnected(FALSE);
  }
}