Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\XmlRpc\Client Class Reference

Public Member Functions

 __construct (Socket\Client $client, $script)
 
 getHeader ($message)
 
 send (Message\Request $message)
 
 getScript ()
 

Protected Attributes

 $_client = null
 
 $_script = null
 

Detailed Description

Class .

A XML-RPC client.

Definition at line 49 of file Client.php.

Constructor & Destructor Documentation

Hoa\XmlRpc\Client::__construct ( Socket\Client  $client,
  $script 
)

Constructor.

Parameters
\Hoa\Socket\Client$clientClient.
string$scriptScript.
Returns
void
Exceptions

Definition at line 75 of file Client.php.

76  {
77  $this->_client = $client;
78  $this->_script = $script;
79  $client->connect();
80 
81  return;
82  }

Member Function Documentation

Hoa\XmlRpc\Client::getHeader (   $message)

Pack message to HTTP header format.

Parameters
string$messageMessage.
Returns
string

Definition at line 90 of file Client.php.

91  {
92  return
93  'POST /' . $this->getScript() . ' HTTP/1.1' . "\r\n" .
94  'User-Agent: Hoa' . "\r\n" .
95  'Host: ' . $this->_client->getSocket()->getAddress() . "\r\n" .
96  'Content-Type: text/xml' . "\r\n" .
97  'Content-Length: ' . strlen($message) . "\r\n" .
98  "\r\n" .
99  $message;
100  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\XmlRpc\Client::getScript ( )

Get script.

Returns
string

Definition at line 158 of file Client.php.

159  {
160  return $this->_script;
161  }

Here is the caller graph for this function:

Hoa\XmlRpc\Client::send ( Message\Request  $message)

Send a request and get a response.

Parameters
\Hoa\XmlRpc\Message\Request$messageMessage.
Returns
Exceptions

Definition at line 109 of file Client.php.

110  {
111  $request = $message->__toString();
112  $this->_client->writeAll($this->getHeader($request));
113  $response = $this->_client->readAll();
114 
115  if (false === $pos = strpos($response, "\r\n\r\n")) {
116  throw new Exception(
117  'Oops, an unknown error occured. Headers seem to be corrupted.',
118  0
119  );
120  }
121 
122  $response = substr($response, $pos + 4);
123 
124  if (0 !== preg_match('#<methodResponse>(\s|\n)*<fault>#i', $response)) {
125  preg_match(
126  '#<(i4|int)>(?:\s|\n)*(\d+)(?:\s|\n)*</\1>#i',
127  $response,
128  $faultCodeMatches
129  );
130  preg_match(
131  '#<string>(?:\s|\n)*(.*)(?:\s|\n)*</string>#i',
132  $response,
133  $faultStringMatches
134  );
135 
136  $faultCode = -1;
137  $faultString = 'An ununderstable fault from the server occured.';
138 
139  if (isset($faultCodeMatches[2])) {
140  $faultCode = $faultCodeMatches[2];
141  }
142 
143  if (isset($faultStringMatches[1])) {
144  $faultString = $faultStringMatches[1];
145  }
146 
147  throw new Exception\Fault($faultString, $faultCode, $request);
148  }
149 
150  return new Message\Response($response);
151  }
getHeader($message)
Definition: Client.php:90

Here is the call graph for this function:

Member Data Documentation

Hoa\XmlRpc\Client::$_client = null
protected

Definition at line 56 of file Client.php.

Hoa\XmlRpc\Client::$_script = null
protected

Definition at line 63 of file Client.php.


The documentation for this class was generated from the following file: