Zend_XmlRpc_Client.xml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 19606 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.xmlrpc.client">
  5. <title>Zend_XmlRpc_Client</title>
  6. <sect2 id="zend.xmlrpc.client.introduction">
  7. <title>Introdución</title>
  8. <para>Zend Framework provee soporte para consumo remoto para servicios
  9. <acronym>XML-RPC</acronym> como un cliente en el paquete
  10. <classname>Zend_XmlRpc_Client</classname> . Su mejor
  11. característica es la conversión automática de tipos entre
  12. <acronym>PHP</acronym> y <acronym>XML-RPC</acronym>, un servidor
  13. de objeto proxy, y acceso a capacidades de instrospección del
  14. servidor.</para>
  15. </sect2>
  16. <sect2 id="zend.xmlrpc.client.method-calls">
  17. <title>Method Calls</title>
  18. <para>El constructor de <classname>Zend_XmlRpc_Client</classname>
  19. recibe la <acronym>URL</acronym> del servidor
  20. <acronym>XML-RPC</acronym> como su primer parámetro. La nueva
  21. instacia devuelta puede ser usada para llamar cualquier número de
  22. métodos remotos en el punto final.</para>
  23. <para>Para llamar un método remoto con el cliente
  24. <acronym>XML-RPC</acronym>, instáncealo y usa el método de
  25. instancia <methodname>call()</methodname> . El código de ejemplo a
  26. continuación utiliza una demostración en el servidor
  27. <acronym>XML-RPC</acronym> en el sitio web de Zend Framework .
  28. Puede utilizarlo para probar o explorar los componentes
  29. <methodname>Zend_XmlRpc</methodname>.</para>
  30. <example id="zend.xmlrpc.client.method-calls.example-1">
  31. <title>XML-RPC Method Call</title>
  32. <programlisting language="php"><![CDATA[
  33. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  34. echo $client->call('test.sayHello');
  35. // hello
  36. ]]></programlisting>
  37. </example>
  38. <para>El valor <acronym>XML-RPC</acronym> devuelto desde la llamada al
  39. método remoto automáticamente será convertida al tipo nativo
  40. <acronym>PHP</acronym> equivalente . En el ejemplo anterior, es
  41. devuelto un <type>string</type>
  42. <acronym>PHP</acronym> y está listo para ser usado inmediatamente.</para>
  43. <para>El primer parámetro del método <methodname>call()</methodname>
  44. recibe el nombre del método remoto que llamar. Si el método remoto
  45. requiere algún parámetro, éste puede ser enviado por el suministro
  46. de un segundo, parámetro opcional a <methodname>call()</methodname>
  47. con un <type>array</type> de valores para pasar el
  48. método remoto:</para>
  49. <example id="zend.xmlrpc.client.method-calls.example-2">
  50. <title>XML-RPC Method Call with Parameters</title>
  51. <programlisting language="php"><![CDATA[
  52. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  53. $arg1 = 1.1;
  54. $arg2 = 'foo';
  55. $result = $client->call('test.sayHello', array($arg1, $arg2));
  56. // $result es un tipo nativo PHP
  57. ]]></programlisting>
  58. </example>
  59. <para>si el método remoto no requiere parámetros, este parámetro
  60. opcional podrá ser excluido o se puede pasar un
  61. <methodname>array()</methodname> vacío. El array de parámeters
  62. para el método repoto puede contener tipos nativos <acronym>PHP</acronym>s, objetos
  63. <methodname>Zend_XmlRpc_Value</methodname> , o una combinación
  64. de estos.</para>
  65. <para>El método <methodname>call()</methodname> convertirá
  66. automáticamente la respuesta <acronym>XML-RPC</acronym> y devolverá
  67. su tipo nativo <acronym>PHP</acronym> equivalente. Un objeto
  68. <classname>Zend_XmlRpc_Response</classname> para el valor
  69. devuelto también estará disponible para llamar el método
  70. <methodname>getLastResponse()</methodname> después de la
  71. llamada.</para>
  72. </sect2>
  73. <sect2 id="zend.xmlrpc.value.parameters">
  74. <title>Tipos y Conversiones</title>
  75. <para>Algunas llamadas a métodos remoto requieren parámetros. Éstos son
  76. dados al método <methodname>call()</methodname> de
  77. <classname>Zend_XmlRpc_Client</classname> como un array en el
  78. segundo parámetro. Cada parámetro puede ser dado como un tipo nativo
  79. <acronym>PHP</acronym>, que será convertido automáticamente, o
  80. como un objeto que representa un tipo específico de
  81. <acronym>XML-RPC</acronym> (uno de los objetos
  82. <methodname>Zend_XmlRpc_Value</methodname>).</para>
  83. <sect3 id="zend.xmlrpc.value.parameters.php-native">
  84. <title>Tipos Nativos PHP como Parámetro</title>
  85. <para>Los parámetros pueden ser pasados a
  86. <methodname>call()</methodname> como variables
  87. <acronym>PHP</acronym> nativas, ya sea un
  88. <type>string</type>,
  89. <type>integer</type>,
  90. <type>float</type>,
  91. <type>boolean</type>,
  92. <type>array</type>, o un
  93. <type>object</type>. En este caso, cada tipo <acronym>PHP</acronym>
  94. nativo será autodetectado y convertido en uno de los tipos
  95. <acronym>XML-RPC</acronym> de acuerdo con esta tabla:</para>
  96. <table id="zend.xmlrpc.value.parameters.php-native.table-1">
  97. <title>Tipos de Conversión entre PHP y
  98. XML-RPC</title>
  99. <tgroup cols="2">
  100. <thead>
  101. <row>
  102. <entry>Tipo Nativo <acronym>PHP</acronym></entry>
  103. <entry>Tipo <acronym>XML-RPC</acronym></entry>
  104. </row>
  105. </thead>
  106. <tbody>
  107. <row>
  108. <entry>integer</entry>
  109. <entry>int</entry>
  110. </row>
  111. <row>
  112. <entry>Zend_Crypt_Math_BigInteger</entry>
  113. <entry>i8</entry>
  114. </row>
  115. <row>
  116. <row>
  117. <entry>double</entry>
  118. <entry>double</entry>
  119. </row>
  120. <row>
  121. <entry>boolean</entry>
  122. <entry>boolean</entry>
  123. </row>
  124. <row>
  125. <entry>string</entry>
  126. <entry>string</entry>
  127. </row>
  128. <row>
  129. <entry>null</entry>
  130. <entry>nil</entry>
  131. </row>
  132. <row>
  133. <row>
  134. <entry>array</entry>
  135. <entry>array</entry>
  136. </row>
  137. <row>
  138. <entry>array asociativo</entry>
  139. <entry>struct</entry>
  140. </row>
  141. <row>
  142. <entry>object</entry>
  143. <entry>array</entry>
  144. </row>
  145. <row>
  146. <entry>Zend_Date</entry>
  147. <entry>dateTime.iso8601</entry>
  148. </row>
  149. <row>
  150. <entry>DateTime</entry>
  151. <entry>dateTime.iso8601</entry>
  152. </row>
  153. </tbody>
  154. </tgroup>
  155. </table>
  156. <note>
  157. <title>¿A qué tipo se convierten los arrays Vacios?</title>
  158. <para>
  159. Passing an empty array to an <acronym>XML-RPC</acronym> method is problematic,
  160. as it could represent either an array or a struct.
  161. <classname>Zend_XmlRpc_Client</classname> detects such conditions and
  162. makes a request to the server's
  163. <command>system.methodSignature</command> method to determine the
  164. appropriate <acronym>XML-RPC</acronym> type to cast to.
  165. </para>
  166. <para>
  167. However, this in itself can lead to issues. First off,
  168. servers that do not support
  169. <command>system.methodSignature</command> will log failed
  170. requests, and <classname>Zend_XmlRpc_Client</classname> will resort to
  171. casting the value to an <acronym>XML-RPC</acronym> array type. Additionally,
  172. this means that any call with array arguments will result in
  173. an additional call to the remote server.
  174. </para>
  175. <para>
  176. To disable the lookup entirely, you can call the
  177. <methodname>setSkipSystemLookup()</methodname> method prior to making
  178. your <acronym>XML-RPC</acronym> call:
  179. </para>
  180. <programlisting language="php"><![CDATA[
  181. $client->setSkipSystemLookup(true);
  182. $result = $client->call('foo.bar', array(array()));
  183. ]]></programlisting>
  184. </note>
  185. </sect3>
  186. <sect3 id="zend.xmlrpc.value.parameters.xmlrpc-value">
  187. <title>Zend_XmlRpc_Value Objects as Parameters</title>
  188. <para>
  189. Parameters may also be created as <classname>Zend_XmlRpc_Value</classname>
  190. instances to specify an exact <acronym>XML-RPC</acronym> type. The primary reasons
  191. for doing this are:
  192. <itemizedlist>
  193. <listitem>
  194. <para>
  195. When you want to make sure the correct parameter
  196. type is passed to the procedure (i.e. the
  197. procedure requires an integer and you may get it
  198. from a database as a string)
  199. </para>
  200. </listitem>
  201. <listitem>
  202. <para>
  203. When the procedure requires <property>base64</property> or
  204. <property>dateTime.iso8601</property> type (which doesn't exists as a
  205. <acronym>PHP</acronym> native type)
  206. </para>
  207. </listitem>
  208. <listitem>
  209. <para>
  210. When auto-conversion may fail (i.e. you want to
  211. pass an empty <acronym>XML-RPC</acronym> struct as a parameter. Empty
  212. structs are represented as empty arrays in <acronym>PHP</acronym>
  213. but, if you give an empty array as a parameter it
  214. will be auto-converted to an <acronym>XML-RPC</acronym> array since
  215. it's not an associative array)
  216. </para>
  217. </listitem>
  218. </itemizedlist>
  219. </para>
  220. <para>
  221. There are two ways to create a <classname>Zend_XmlRpc_Value</classname>
  222. object: instantiate one of the <classname>Zend_XmlRpc_Value</classname>
  223. subclasses directly, or use the static factory method
  224. <methodname>Zend_XmlRpc_Value::getXmlRpcValue()</methodname>.
  225. </para>
  226. <table id="zend.xmlrpc.value.parameters.xmlrpc-value.table-1">
  227. <title>Zend_XmlRpc_Value Objects for XML-RPC Types</title>
  228. <tgroup cols="3">
  229. <thead>
  230. <row>
  231. <entry><acronym>XML-RPC</acronym> Type</entry>
  232. <entry><classname>Zend_XmlRpc_Value</classname> Constant</entry>
  233. <entry><classname>Zend_XmlRpc_Value</classname> Object</entry>
  234. </row>
  235. </thead>
  236. <tbody>
  237. <row>
  238. <entry>int</entry>
  239. <entry>
  240. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER</constant>
  241. </entry>
  242. <entry><classname>Zend_XmlRpc_Value_Integer</classname></entry>
  243. </row>
  244. <row>
  245. <entry>i8</entry>
  246. <entry>
  247. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_I8</constant>
  248. </entry>
  249. <entry><classname>Zend_XmlRpc_Value_BigInteger</classname></entry>
  250. </row>
  251. <row>
  252. <entry>ex:i8</entry>
  253. <entry>
  254. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_APACHEI8</constant>
  255. </entry>
  256. <entry><classname>Zend_XmlRpc_Value_BigInteger</classname></entry>
  257. </row>
  258. <row>
  259. <entry>double</entry>
  260. <entry>
  261. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE</constant>
  262. </entry>
  263. <entry><classname>Zend_XmlRpc_Value_Double</classname></entry>
  264. </row>
  265. <row>
  266. <entry>boolean</entry>
  267. <entry>
  268. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN</constant>
  269. </entry>
  270. <entry><classname>Zend_XmlRpc_Value_Boolean</classname></entry>
  271. </row>
  272. <row>
  273. <entry>string</entry>
  274. <entry>
  275. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_STRING</constant>
  276. </entry>
  277. <entry><classname>Zend_XmlRpc_Value_String</classname></entry>
  278. </row>
  279. <row>
  280. <entry>nil</entry>
  281. <entry>
  282. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_NIL</constant>
  283. </entry>
  284. <entry><classname>Zend_XmlRpc_Value_Nil</classname></entry>
  285. </row>
  286. <row>
  287. <entry>ex:nil</entry>
  288. <entry>
  289. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_APACHENIL</constant>
  290. </entry>
  291. <entry><classname>Zend_XmlRpc_Value_Nil</classname></entry>
  292. </row>
  293. <row>
  294. <entry>base64</entry>
  295. <entry>
  296. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64</constant>
  297. </entry>
  298. <entry><classname>Zend_XmlRpc_Value_Base64</classname></entry>
  299. </row>
  300. <row>
  301. <entry>dateTime.iso8601</entry>
  302. <entry>
  303. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME</constant>
  304. </entry>
  305. <entry><classname>Zend_XmlRpc_Value_DateTime</classname></entry>
  306. </row>
  307. <row>
  308. <entry>array</entry>
  309. <entry>
  310. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY</constant>
  311. </entry>
  312. <entry><classname>Zend_XmlRpc_Value_Array</classname></entry>
  313. </row>
  314. <row>
  315. <entry>struct</entry>
  316. <entry>
  317. <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT</constant>
  318. </entry>
  319. <entry><classname>Zend_XmlRpc_Value_Struct</classname></entry>
  320. </row>
  321. </tbody>
  322. </tgroup>
  323. </table>
  324. <para>
  325. <note>
  326. <title>Automatic Conversion</title>
  327. <para>
  328. When building a new <classname>Zend_XmlRpc_Value</classname>
  329. object, its value is set by a <acronym>PHP</acronym> type. The
  330. <acronym>PHP</acronym> type will be converted to the specified type using
  331. <acronym>PHP</acronym> casting. For example, if a string is given as a
  332. value to the <classname>Zend_XmlRpc_Value_Integer</classname>
  333. object, it will be converted using
  334. <command>(int)$value</command>.
  335. </para>
  336. </note>
  337. </para>
  338. </sect3>
  339. </sect2>
  340. <sect2 id="zend.xmlrpc.client.requests-and-responses">
  341. <title>Server Proxy Object</title>
  342. <para>
  343. Another way to call remote methods with the <acronym>XML-RPC</acronym> client is to
  344. use the server proxy. This is a <acronym>PHP</acronym> object that proxies a remote
  345. <acronym>XML-RPC</acronym> namespace, making it work as close to a native
  346. <acronym>PHP</acronym> object as possible.
  347. </para>
  348. <para>
  349. To instantiate a server proxy, call the <methodname>getProxy()</methodname>
  350. instance method of <classname>Zend_XmlRpc_Client</classname>. This will
  351. return an instance of <classname>Zend_XmlRpc_Client_ServerProxy</classname>.
  352. Any method call on the server proxy object will be forwarded to
  353. the remote, and parameters may be passed like any other <acronym>PHP</acronym>
  354. method.
  355. </para>
  356. <example id="zend.xmlrpc.client.requests-and-responses.example-1">
  357. <title>Proxy the Default Namespace</title>
  358. <programlisting language="php"><![CDATA[
  359. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  360. $service = $client->getProxy(); // Proxy the default namespace
  361. $hello = $service->test->sayHello(1, 2); // test.Hello(1, 2) returns "hello"
  362. ]]></programlisting>
  363. </example>
  364. <para>
  365. The <methodname>getProxy()</methodname> method receives an optional argument
  366. specifying which namespace of the remote server to proxy. If it
  367. does not receive a namespace, the default namespace will be
  368. proxied. In the next example, the 'test' namespace
  369. will be proxied:
  370. </para>
  371. <example id="zend.xmlrpc.client.requests-and-responses.example-2">
  372. <title>Proxy Any Namespace</title>
  373. <programlisting language="php"><![CDATA[
  374. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  375. $test = $client->getProxy('test'); // Proxy the "test" namespace
  376. $hello = $test->sayHello(1, 2); // test.Hello(1,2) returns "hello"
  377. ]]></programlisting>
  378. </example>
  379. <para>
  380. If the remote server supports nested namespaces of any depth,
  381. these can also be used through the server proxy. For example, if
  382. the server in the example above had a method
  383. <command>test.foo.bar()</command>, it could be called as
  384. <command>$test->foo->bar()</command>.
  385. </para>
  386. </sect2>
  387. <sect2 id="zend.xmlrpc.client.error-handling">
  388. <title>Error Handling</title>
  389. <para>
  390. Two kinds of errors can occur during an <acronym>XML-RPC</acronym> method call:
  391. <acronym>HTTP</acronym> errors and <acronym>XML-RPC</acronym> faults. The
  392. <classname>Zend_XmlRpc_Client</classname> recognizes each and provides the ability
  393. to detect and trap them independently.
  394. </para>
  395. <sect3 id="zend.xmlrpc.client.error-handling.http">
  396. <title>HTTP Errors</title>
  397. <para>
  398. If any <acronym>HTTP</acronym> error occurs, such as the remote
  399. <acronym>HTTP</acronym> server returns a <emphasis>404 Not Found</emphasis>, a
  400. <classname>Zend_XmlRpc_Client_HttpException</classname> will be thrown.
  401. </para>
  402. <example id="zend.xmlrpc.client.error-handling.http.example-1">
  403. <title>Handling HTTP Errors</title>
  404. <programlisting language="php"><![CDATA[
  405. $client = new Zend_XmlRpc_Client('http://foo/404');
  406. try {
  407. $client->call('bar', array($arg1, $arg2));
  408. } catch (Zend_XmlRpc_Client_HttpException $e) {
  409. // $e->getCode() returns 404
  410. // $e->getMessage() returns "Not Found"
  411. }
  412. ]]></programlisting>
  413. </example>
  414. <para>
  415. Regardless of how the <acronym>XML-RPC</acronym> client is used, the
  416. <classname>Zend_XmlRpc_Client_HttpException</classname> will be thrown
  417. whenever an <acronym>HTTP</acronym> error occurs.
  418. </para>
  419. </sect3>
  420. <sect3 id="zend.xmlrpc.client.error-handling.faults">
  421. <title>XML-RPC Faults</title>
  422. <para>
  423. An <acronym>XML-RPC</acronym> fault is analogous to a <acronym>PHP</acronym>
  424. exception. It is a special type returned from an <acronym>XML-RPC</acronym> method
  425. call that has both an error code and an error message. <acronym>XML-RPC</acronym>
  426. faults are handled differently depending on the context of how the
  427. <classname>Zend_XmlRpc_Client</classname> is used.
  428. </para>
  429. <para>
  430. When the <methodname>call()</methodname> method or the server
  431. proxy object is used, an <acronym>XML-RPC</acronym> fault will result in a
  432. <classname>Zend_XmlRpc_Client_FaultException</classname> being thrown.
  433. The code and message of the exception will map directly to
  434. their respective values in the original <acronym>XML-RPC</acronym> fault
  435. response.
  436. </para>
  437. <example id="zend.xmlrpc.client.error-handling.faults.example-1">
  438. <title>Handling XML-RPC Faults</title>
  439. <programlisting language="php"><![CDATA[
  440. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  441. try {
  442. $client->call('badMethod');
  443. } catch (Zend_XmlRpc_Client_FaultException $e) {
  444. // $e->getCode() returns 1
  445. // $e->getMessage() returns "Unknown method"
  446. }
  447. ]]></programlisting>
  448. </example>
  449. <para>Cuando el método <methodname>call()</methodname> es usado
  450. para realizar la petición,
  451. <methodname>Zend_XmlRpc_Client_FaultException</methodname>
  452. será lanzado como error. Un objeto
  453. <methodname>Zend_XmlRpc_Response</methodname> conteniendo el
  454. error estará disponible llamando a
  455. <methodname>getLastResponse()</methodname>.</para>
  456. <para>Cuando el método <methodname>doRequest()</methodname> sea
  457. usado para realizar una petición, no lanzará una excepción. En
  458. vez de eso, devolverá un objeto
  459. <methodname>Zend_XmlRpc_Response</methodname> que contendrá
  460. el error. Esto puede comprobarse con
  461. <methodname>isFault()</methodname> método instancia de
  462. <methodname>Zend_XmlRpc_Response</methodname>.</para>
  463. </sect3>
  464. </sect2>
  465. <sect2 id="zend.xmlrpc.client.introspection">
  466. <title>Server Introspection</title>
  467. <para>
  468. Some <acronym>XML-RPC</acronym> servers support the de facto introspection methods
  469. under the <acronym>XML-RPC</acronym> <emphasis>system.</emphasis> namespace.
  470. <classname>Zend_XmlRpc_Client</classname> provides special support for servers with
  471. these capabilities.
  472. </para>
  473. <para>
  474. A <classname>Zend_XmlRpc_Client_ServerIntrospection</classname> instance may be
  475. retrieved by calling the <methodname>getIntrospector()</methodname> method of
  476. <classname>Zend_XmlRpcClient</classname>. It can then be used to perform introspection
  477. operations on the server.
  478. </para>
  479. </sect2>
  480. <sect2 id="zend.xmlrpc.client.request-to-response">
  481. <title>From Request to Response</title>
  482. <para>
  483. Under the hood, the <methodname>call()</methodname> instance method of
  484. <classname>Zend_XmlRpc_Client</classname> builds a request object
  485. (<classname>Zend_XmlRpc_Request</classname>) and sends it to another method,
  486. <methodname>doRequest()</methodname>, that returns a response object
  487. (<classname>Zend_XmlRpc_Response</classname>).
  488. </para>
  489. <para>
  490. The <methodname>doRequest()</methodname> method is also available for use directly:
  491. </para>
  492. <example id="zend.xmlrpc.client.request-to-response.example-1">
  493. <title>Processing Request to Response</title>
  494. <programlisting language="php"><![CDATA[
  495. $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
  496. $request = new Zend_XmlRpc_Request();
  497. $request->setMethod('test.sayHello');
  498. $request->setParams(array('foo', 'bar'));
  499. $client->doRequest($request);
  500. // $client->getLastRequest() returns instanceof Zend_XmlRpc_Request
  501. // $client->getLastResponse() returns instanceof Zend_XmlRpc_Response
  502. ]]></programlisting>
  503. </example>
  504. <para>
  505. Whenever an <acronym>XML-RPC</acronym> method call is made by the client through any
  506. means, either the <methodname>call()</methodname> method,
  507. <methodname>doRequest()</methodname> method, or server proxy, the last request
  508. object and its resultant response object will always be available
  509. through the methods <methodname>getLastRequest()</methodname> and
  510. <methodname>getLastResponse()</methodname> respectively.
  511. </para>
  512. </sect2>
  513. <sect2 id="zend.xmlrpc.client.http-client">
  514. <title>HTTP Client and Testing</title>
  515. <para>
  516. In all of the prior examples, an <acronym>HTTP</acronym> client was never specified.
  517. When this is the case, a new instance of
  518. <classname>Zend_Http_Client</classname> will be created with its default
  519. options and used by <classname>Zend_XmlRpc_Client</classname> automatically.
  520. </para>
  521. <para>
  522. The <acronym>HTTP</acronym> client can be retrieved at any time with the
  523. <methodname>getHttpClient()</methodname> method. For most cases, the default
  524. <acronym>HTTP</acronym> client will be sufficient. However, the
  525. <methodname>setHttpClient()</methodname> method allows for a different
  526. <acronym>HTTP</acronym> client instance to be injected.
  527. </para>
  528. <para>
  529. The <methodname>setHttpClient()</methodname> is particularly useful for unit testing.
  530. When combined with the <classname>Zend_Http_Client_Adapter_Test</classname>, remote
  531. services can be mocked out for testing. See the unit tests for
  532. <classname>Zend_XmlRpc_Client</classname> for examples of how to do this.
  533. </para>
  534. </sect2>
  535. </sect1>
  536. <!--
  537. vim:se ts=4 sw=4 et:
  538. -->