Greetings,

I just started on the idea of creating a more accessible interface for monitoring my servers via the Customer API.. but I ran into a problem straight away with the PHP SoapClient not supporting basic authentication when fetching the WSDL and subsequent imports. The fix is simple enough to add the user/pass to the URI for the WSDL, but that doesn't solve the imports.. and if you are clever and str_replace the URIs in the WSDL, then you still have the problem that the imports have imports in them too.. *sigh*

I wrote some code to fetch and edit the XML on-demand, and the demo would now look like this:

CODE
function URI_fixer($uri, $params) {
$host = 'https://' . urlencode($params['login']) . ':' . urlencode($params['password']) . '@api.theplanet.com/';
return str_replace('https://api.theplanet.com/', $host, $uri);
}

function fetch_xml($uri, $params, $uri_fixer, &$uri_memo) {
$uri = call_user_func($uri_fixer, $uri, $params);

if(isset($uri_memo[$uri]))
return $uri_memo[$uri];

$xml_file = tempnam('/tmp', 'xml');
copy($uri, $xml_file);

$uri_memo[$uri] = $xml_file;

$dom = new DOMDocument();
$dom->loadXML(file_get_contents($xml_file));

$imports = $dom->getElementsByTagName('import');
foreach($imports as $import) {
if($import->hasAttribute('schemaLocation')) {
$import_uri = $import->getAttribute('schemaLocation');
$import_file = fetch_xml($import_uri, $params, $uri_fixer, $uri_memo);
$import->setAttribute('schemaLocation', $import_file);
} else if($import->hasAttribute('location')) {
$import_uri = $import->getAttribute('location');
$import_file = fetch_xml($import_uri, $params, $uri_fixer, $uri_memo);
$import->setAttribute('location', $import_file);
}
}

$f = fopen($xml_file, 'w');
fwrite($f, $dom->saveXML());
fclose($f);

register_shutdown_function('unlink', $xml_file);
return $xml_file;
}

ini_set('soap.wsdl_cache_enabled', false);

$params = array(
'login' => 'USERNAME',
'password' => 'PASSWORD'
);

$uri_memo = array();
$wsdl_file = fetch_xml('https://api.theplanet.com/Svc/TicketTicketService.svc?WSDL', $params, 'URI_fixer', $uri_memo);

$tkt_tkt_svc = new SoapClient($wsdl_file, $params);

$ticket = $tkt_tkt_svc->GetTicketByID(new SoapParam('5861434', 'TicketID'));

print_r($ticket);


Hope that saves somebody else some time..

-Scott