Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^304) CHAPTER 20 ■ ADVANCED WEB SERVICES
int(3600)
["Caller"]=>
string(12) "123-123-1234"
["Callee"]=>
string(12) "123-123-1236"
}
}
Some debugging data is included in Listing 20-3. Notice how getTypes() now gives you a
detailed description of the data types that exist in the service.


Class Mapping.


One thing you will notice in the result data from Listing 20-3 is that the results, despite being
objects in the WSDL, were returned as stdClass objects. To resolve this and return proper
instances of the CallDetailRecord class, you must map the class to the type in the SOAP client,
as shown in Listing 20-4.

Listing 20-4. Class Mapping (replaces PhoneClient.php)

<?php

class CallDetailRecord {
public $StartTime, $Duration, $Caller, $Callee;

public function __construct(
$startTime, $duration, $caller, $callee)
{
$this->StartTime = $startTime;
$this->Duration = $duration;
$this->Caller = $caller;
$this->Callee = $callee;
}
}

$classmap = array('CallDetailRecord'=>'CallDetailRecord');
$client = new SoapClient(
'PhoneCompany.wsdl',
array(
'trace'=>true,
'classmap'=>$classmap
)
);

$response = $client->GetCallDetailRecords('A-121-332');

var_dump($response);

McArthur_819-9.book Page 304 Friday, February 29, 2008 8:03 AM

Free download pdf