Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^302) CHAPTER 20 ■ ADVANCED WEB SERVICES
The CallDetailRecord complex type, consisting of a number of XSD elements, defines the
structure of the data format. The CallDetailRecordArray complex type is then defined as a
SOAP-encoded array, where each entry is of your CallDetailRecord type. These types give your
API structure.
Creating a service for this WSDL is relatively simple. You need only to create a
CallDetailRecord class with public properties for each element and to return an array of them
when requested. To do this, simply look at what elements the ComplexType defines (boldfaced
in Listing 20-1). Then, using this information, model a PHP class, as shown in Listing 20-2.
Listing 20-2. Creating a SOAP Server for the Phone Company Web Service (PhoneCompany.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;
}
}
function GetCallDetailRecords($subscriber) {
/
This data would normally come from a database
using the data in $subscriber as a predicate
/
$records = array();
$records[] = new CallDetailRecord(
'20070509T21:48:00-07:00',
'3600',
'123-123-1234',
'123-123-1235'
);
$records[] = new CallDetailRecord(
'20070509T22:58:00-07:00',
'3600',
'123-123-1234',
'123-123-1236'
);
return $records;
}
$server = new SoapServer('PhoneCompany.wsdl');
McArthur_819-9.book Page 302 Friday, February 29, 2008 8:03 AM

Free download pdf