note 100276 deleted from soapclient.soapcall by danbrown
| From: | danbrown@php.net | Date: | Wed, 06 Oct 2010 14:53:03 +0000 |
| Subject: | note 100276 deleted from soapclient.soapcall by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173021@lists.php.net to get a copy of this message | ||
Note Submitter: spechal at gmail dot com
----
This was not a pleasant experience, but it works ... dissect it as needed.
<?php
/**
*
* When making calls to _call(), the second argument should be stdClass
*
* i.e.
* $params = new stdClass;
* $params->ListID = 123;
* $this->_call('GetContactList', $params);
*/
class Listrak {
const WSDL = 'https://webservices.listrak.com/v31/IntegrationService.asmx?WSDL';
const SOAP_NS = 'http://webservices.listrak.com/v31/';
protected $_soap = NULL;
protected $_user = NULL;
protected $_pass = NULL;
protected $_list_id = NULL;
protected $_authHeader = NULL;
public function __construct($user, $pass, $listId = NULL){
$this->_soap = new SoapClient(self::WSDL, array('soap_version' => SOAP_1_2));
$this->_user = $user;
$this->_pass = $pass;
if($listId)
$this->listId($listId);
$this->_buildAuthHeader();
}
protected function _buildAuthHeader(){
$auth = array();
$auth['UserName'] = new SoapVar($this->_user, XSD_STRING, NULL, NULL, NULL,
self::SOAP_NS);
$auth['Password'] = new SoapVar($this->_pass, XSD_STRING, NULL, NULL, NULL,
self::SOAP_NS);
$headerVar = new SoapVar($auth, SOAP_ENC_OBJECT);
$header = new SoapHeader(self::SOAP_NS, 'WSUser', $headerVar);
$this->_soap->__setSoapHeaders(array($header));
}
public function listId($listId = NULL){
if($listId)
$this->_list_id = $listId;
return $this->_list_id;
}
protected function _call($method){
$args = func_get_args();
array_shift($args);
try {
return $this->_soap->__soapCall($method, $args);
} catch(SoapFault $e){
die('There was an error: '.$e->getMessage()."\n");
}
}
public function getContactListCollection(){
return $this->_call('GetContactListCollection');
}
public function getContactList($listId = NULL){
if($listId)
$this->listId($listId);
$listId = new stdClass;
$listId->ListID = $this->listId();
return $this->_call('GetContactList', $listId);
}
}
// test
$client = new Listrak('username', 'password');
print_r($client->getContactListCollection());
?>