Zend_Json-Server.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.json.server">
  4. <title>Zend_Json_Server - JSON-RPC server</title>
  5. <para>
  6. <classname>Zend_Json_Server</classname> is a <ulink
  7. url="http://groups.google.com/group/json-rpc/">JSON-RPC</ulink>
  8. server implementation. It supports both the
  9. <ulink url="http://json-rpc.org/wiki/specification">JSON-RPC
  10. version 1 specification</ulink> as well as the
  11. <ulink url="http://groups.google.com/group/json-rpc/web/json-rpc-1-2-proposal">version 2 specification</ulink>;
  12. additionally, it provides a PHP implementation of the
  13. <ulink url="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal">Service
  14. Mapping Description (SMD) specification</ulink>
  15. for providing service metadata to service consumers.
  16. </para>
  17. <para>
  18. JSON-RPC is a lightweight Remote Procedure Call protocol that utilizes
  19. JSON for its messaging envelopes. This JSON-RPC implementation follows
  20. PHP's <ulink
  21. url="http://us.php.net/manual/en/function.soap-soapserver-construct.php">SoapServer</ulink>
  22. API. This means that in a typical situation, you will simply:
  23. </para>
  24. <itemizedlist>
  25. <listitem><para>Instantiate the server object</para></listitem>
  26. <listitem><para>Attach one or more functions and/or classes/objects to
  27. the server object</para></listitem>
  28. <listitem><para>handle() the request</para></listitem>
  29. </itemizedlist>
  30. <para>
  31. <classname>Zend_Json_Server</classname> utilizes <xref linkend="zend.server.reflection" /> to
  32. perform reflection on any attached classes or functions, and uses that
  33. information to build both the SMD and enforce method call signatures. As
  34. such, it is imperative that any attached functions and/or class methods
  35. have full PHP docblocks documenting, minimally:
  36. </para>
  37. <itemizedlist>
  38. <listitem><para>All parameters and their expected variable types</para></listitem>
  39. <listitem><para>The return value variable type</para></listitem>
  40. </itemizedlist>
  41. <para>
  42. <classname>Zend_Json_Server</classname> listens for POST requests only at this
  43. time; fortunately, most JSON-RPC client implementations in the wild at
  44. the time of this writing will only POST requests as it is. This makes it
  45. simple to utilize the same server end point to both handle requests as
  46. well as to deliver the service SMD, as is shown in the next example.
  47. </para>
  48. <example id="zend.json.server.usage">
  49. <title>Zend_Json_Server Usage</title>
  50. <para>
  51. First, let's define a class we wish to expose via the JSON-RPC
  52. server. We'll call the class 'Calculator', and define methods for
  53. 'add', 'subtract', 'multiply', and 'divide':
  54. </para>
  55. <programlisting language="php"><![CDATA[
  56. /**
  57. * Calculator - sample class to expose via JSON-RPC
  58. */
  59. class Calculator
  60. {
  61. /**
  62. * Return sum of two variables
  63. *
  64. * @param int $x
  65. * @param int $y
  66. * @return int
  67. */
  68. public function add($x, $y)
  69. {
  70. return $x + $y;
  71. }
  72. /**
  73. * Return difference of two variables
  74. *
  75. * @param int $x
  76. * @param int $y
  77. * @return int
  78. */
  79. public function subtract($x, $y)
  80. {
  81. return $x - $y;
  82. }
  83. /**
  84. * Return product of two variables
  85. *
  86. * @param int $x
  87. * @param int $y
  88. * @return int
  89. */
  90. public function multiply($x, $y)
  91. {
  92. return $x * $y;
  93. }
  94. /**
  95. * Return the division of two variables
  96. *
  97. * @param int $x
  98. * @param int $y
  99. * @return float
  100. */
  101. public function divide($x, $y)
  102. {
  103. return $x / $y;
  104. }
  105. }
  106. ]]></programlisting>
  107. <para>
  108. Note that each method has a docblock with entries indicating each
  109. parameter and its type, as well as an entry for the return value.
  110. This is <emphasis>absolutely critical</emphasis> when utilizing
  111. <classname>Zend_Json_Server</classname> -- or any other server component in
  112. Zend Framework, for that matter.
  113. </para>
  114. <para>
  115. Now we'll create a script to handle the requests:
  116. </para>
  117. <programlisting language="php"><![CDATA[
  118. $server = new Zend_Json_Server();
  119. // Indicate what functionality is available:
  120. $server->setClass('Calculator');
  121. // Handle the request:
  122. $server->handle();
  123. ]]></programlisting>
  124. <para>
  125. However, this will not address the issue of returning an SMD so that
  126. the JSON-RPC client can autodiscover methods. That can be
  127. accomplished by determining the HTTP request method, and then
  128. specifying some server metadata:
  129. </para>
  130. <programlisting language="php"><![CDATA[
  131. $server = new Zend_Json_Server();
  132. $server->setClass('Calculator');
  133. if ('GET' == $_SERVER['REQUEST_METHOD']) {
  134. // Indicate the URL endpoint, and the JSON-RPC version used:
  135. $server->setTarget('/json-rpc.php')
  136. ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
  137. // Grab the SMD
  138. $smd = $server->getServiceMap();
  139. // Return the SMD to the client
  140. header('Content-Type: application/json');
  141. echo $smd;
  142. return;
  143. }
  144. $server->handle();
  145. ]]></programlisting>
  146. <para>
  147. If utilizing the JSON-RPC server with Dojo toolkit, you will also
  148. need to set a special compatibility flag to ensure that the two
  149. interoperate properly:
  150. </para>
  151. <programlisting language="php"><![CDATA[
  152. $server = new Zend_Json_Server();
  153. $server->setClass('Calculator');
  154. if ('GET' == $_SERVER['REQUEST_METHOD']) {
  155. $server->setTarget('/json-rpc.php')
  156. ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
  157. $smd = $server->getServiceMap();
  158. // Set Dojo compatibility:
  159. $smd->setDojoCompatible(true);
  160. header('Content-Type: application/json');
  161. echo $smd;
  162. return;
  163. }
  164. $server->handle();
  165. ]]></programlisting>
  166. </example>
  167. <sect2 id="zend.json.server.details">
  168. <title>Advanced Details</title>
  169. <para>
  170. While most functionality for <classname>Zend_Json_Server</classname> is
  171. spelled out in <xref linkend="zend.json.server.usage" />, more
  172. advanced functionality is available.
  173. </para>
  174. <sect3 id="zend.json.server.details.zendjsonserver">
  175. <title>Zend_Json_Server</title>
  176. <para>
  177. <classname>Zend_Json_Server</classname> is the core class in the JSON-RPC
  178. offering; it handles all requests and returns the response
  179. payload. It has the following methods:
  180. </para>
  181. <itemizedlist>
  182. <listitem><para><code>addFunction($function)</code>: Specify a
  183. userland function to attach to the server.</para></listitem>
  184. <listitem><para><code>setClass($class)</code>: Specify a class
  185. or object to attach to the server; all public methods of
  186. that item will be exposed as JSON-RPC methods.</para></listitem>
  187. <listitem><para><code>fault($fault = null, $code = 404, $data =
  188. null)</code>: Create and return a
  189. <classname>Zend_Json_Server_Error</classname> object.</para></listitem>
  190. <listitem><para><code>handle($request = false)</code>: Handle a
  191. JSON-RPC request; optionally, pass a
  192. <classname>Zend_Json_Server_Request</classname> object to utilize
  193. (creates one by default).</para></listitem>
  194. <listitem><para><code>getFunctions()</code>: Return a list of
  195. all attached methods.</para></listitem>
  196. <listitem><para><code>setRequest(Zend_Json_Server_Request
  197. $request)</code>: Specify a request object for the
  198. server to utilize.</para></listitem>
  199. <listitem><para><code>getRequest()</code>: Retrieve the request
  200. object used by the server.</para></listitem>
  201. <listitem><para><code>setResponse(Zend_Json_Server_Response
  202. $response)</code>: Set the response object for the
  203. server to utilize.</para></listitem>
  204. <listitem><para><code>getResponse()</code>: Retrieve the
  205. response object used by the server.</para></listitem>
  206. <listitem><para><code>setAutoEmitResponse($flag)</code>:
  207. Indicate whether the server should automatically emit
  208. the response and all headers; by default, this is
  209. true.</para></listitem>
  210. <listitem><para><code>autoEmitResponse()</code>: Determine if
  211. auto-emission of the response is enabled.</para></listitem>
  212. <listitem><para><code>getServiceMap()</code>: Retrieve the
  213. service map description in the form of a
  214. <classname>Zend_Json_Server_Smd</classname> object</para></listitem>
  215. </itemizedlist>
  216. </sect3>
  217. <sect3 id="zend.json.server.details.zendjsonserverrequest">
  218. <title>Zend_Json_Server_Request</title>
  219. <para>
  220. The JSON-RPC request environment is encapsulated in the
  221. <classname>Zend_Json_Server_Request</classname> object. This object allows
  222. you to set necessary portions of the JSON-RPC request, including
  223. the request ID, parameters, and JSON-RPC specification version.
  224. It has the ability to load itself via JSON or a set of options,
  225. and can render itself as JSON via the <code>toJson()</code>
  226. method.
  227. </para>
  228. <para>
  229. The request object has the following methods available:
  230. </para>
  231. <itemizedlist>
  232. <listitem><para><code>setOptions(array $options)</code>: Specify
  233. object configuration. <code>$options</code> may contain
  234. keys matching any 'set' method:
  235. <code>setParams()</code>, <code>setMethod()</code>,
  236. <code>setId()</code>, and
  237. <code>setVersion()</code>.</para></listitem>
  238. <listitem><para><code>addParam($value, $key = null)</code>: Add
  239. a parameter to use with the method call. Parameters can be
  240. just the values, or can optionally include the parameter
  241. name.</para></listitem>
  242. <listitem><para><code>addParams(array $params)</code>: Add
  243. multiple parameters at once; proxies to
  244. <code>addParam()</code></para></listitem>
  245. <listitem><para><code>setParams(array $params)</code>: Set all
  246. parameters at once; overwrites any existing
  247. parameters.</para></listitem>
  248. <listitem><para><code>getParam($index)</code>: Retrieve a
  249. parameter by position or name.</para></listitem>
  250. <listitem><para><code>getParams()</code>: Retrieve all
  251. parameters at once.</para></listitem>
  252. <listitem><para><code>setMethod($name)</code>: Set the method to
  253. call.</para></listitem>
  254. <listitem><para><code>getMethod()</code>: Retrieve the method
  255. that will be called.</para></listitem>
  256. <listitem><para><code>isMethodError()</code>: Determine whether
  257. or not the request is malformed and would result in an
  258. error.</para></listitem>
  259. <listitem><para><code>setId($name)</code>: Set the request
  260. identifier (used by the client to match requests to
  261. responses).</para></listitem>
  262. <listitem><para><code>getId()</code>: Retrieve the request
  263. identifier.</para></listitem>
  264. <listitem><para><code>setVersion($version)</code>: Set the
  265. JSON-RPC specification version the request conforms to.
  266. May be either '1.0' or '2.0'.</para></listitem>
  267. <listitem><para><code>getVersion()</code>: Retrieve the JSON-RPC
  268. specification version used by the
  269. request.</para></listitem>
  270. <listitem><para><code>loadJson($json)</code>: Load the request
  271. object from a JSON string.</para></listitem>
  272. <listitem><para><code>toJson()</code>: Render the request as
  273. a JSON string.</para></listitem>
  274. </itemizedlist>
  275. <para>
  276. An HTTP specific version is available via
  277. <classname>Zend_Json_Server_Request_Http</classname>. This class will
  278. retrieve the request via <code>php://input</code>, and allows
  279. access to the raw JSON via the <code>getRawJson()</code> method.
  280. </para>
  281. </sect3>
  282. <sect3 id="zend.json.server.details.zendjsonserverresponse">
  283. <title>Zend_Json_Server_Response</title>
  284. <para>
  285. The JSON-RPC response payload is encapsulated in the
  286. <classname>Zend_Json_Server_Response</classname> object. This object allows
  287. you to set the return value of the request, whether or not the
  288. response is an error, the request identifier, the JSON-RPC
  289. specification version the response conforms to, and optionally
  290. the service map.
  291. </para>
  292. <para>
  293. The response object has the following methods available:
  294. </para>
  295. <itemizedlist>
  296. <listitem><para><code>setResult($value)</code>: Set the response
  297. result.</para></listitem>
  298. <listitem><para><code>getResult()</code>: Retrieve the response
  299. result.</para></listitem>
  300. <listitem><para><code>setError(Zend_Json_Server_Error
  301. $error)</code>: Set an error object. If set, this will be
  302. used as the response when serializing to JSON.</para></listitem>
  303. <listitem><para><code>getError()</code>: Retrieve the error
  304. object, if any.</para></listitem>
  305. <listitem><para><code>isError()</code>: Whether or not the
  306. response is an error response.</para></listitem>
  307. <listitem><para><code>setId($name)</code>: Set the request
  308. identifier (so the client may match the response with
  309. the original request).</para></listitem>
  310. <listitem><para><code>getId()</code>: Retrieve the request
  311. identifier.</para></listitem>
  312. <listitem><para><code>setVersion($version)</code>: Set the
  313. JSON-RPC version the response conforms to.</para></listitem>
  314. <listitem><para><code>getVersion()</code>: Retrieve the JSON-RPC
  315. version the response conforms to.</para></listitem>
  316. <listitem><para><code>toJson()</code>: Serialize the response to
  317. JSON. If the response is an error response, serializes the
  318. error object.</para></listitem>
  319. <listitem><para><code>setServiceMap($serviceMap)</code>: Set the
  320. service map object for the response.</para></listitem>
  321. <listitem><para><code>getServiceMap()</code>: Retrieve the
  322. service map object, if any.</para></listitem>
  323. </itemizedlist>
  324. <para>
  325. An HTTP specific version is available via
  326. <classname>Zend_Json_Server_Response_Http</classname>. This class will
  327. send the appropriate HTTP headers as well as serialize the
  328. response as JSON.
  329. </para>
  330. </sect3>
  331. <sect3 id="zend.json.server.details.zendjsonservererror">
  332. <title>Zend_Json_Server_Error</title>
  333. <para>
  334. JSON-RPC has a special format for reporting error conditions.
  335. All errors need to provide, minimally, an error message and error
  336. code; optionally, they can provide additional data, such as a
  337. backtrace.
  338. </para>
  339. <para>
  340. Error codes are derived from those recommended by <ulink
  341. url="http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php">the
  342. XML-RPC EPI project</ulink>. <classname>Zend_Json_Server</classname>
  343. appropriately assigns the code based on the error condition. For
  344. application exceptions, the code '-32000' is used.
  345. </para>
  346. <para>
  347. <classname>Zend_Json_Server_Error</classname> exposes the following
  348. methods:
  349. </para>
  350. <itemizedlist>
  351. <listitem><para><code>setCode($code)</code>: Set the error code;
  352. if the code is not in the accepted XML-RPC error code range,
  353. -32000 will be assigned.</para></listitem>
  354. <listitem><para><code>getCode()</code>: Retrieve the current
  355. error code.</para></listitem>
  356. <listitem><para><code>setMessage($message)</code>: Set the error
  357. message.</para></listitem>
  358. <listitem><para><code>getMessage()</code>: Retrieve the current
  359. error message.</para></listitem>
  360. <listitem><para><code>setData($data)</code>: Set auxiliary data
  361. further qualifying the error, such as a
  362. backtrace.</para></listitem>
  363. <listitem><para><code>getData()</code>: Retrieve any current
  364. auxiliary error data.</para></listitem>
  365. <listitem><para><code>toArray()</code>: Cast the error to an
  366. array. The array will contain the keys 'code', 'message',
  367. and 'data'.</para></listitem>
  368. <listitem><para><code>toJson()</code>: Cast the error to a
  369. JSON-RPC error representation.</para></listitem>
  370. </itemizedlist>
  371. </sect3>
  372. <sect3 id="zend.json.server.details.zendjsonserversmd">
  373. <title>Zend_Json_Server_Smd</title>
  374. <para>
  375. SMD stands for Service Mapping Description, a JSON schema that
  376. defines how a client can interact with a particular web service.
  377. At the time of this writing, the <ulink
  378. url="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal">specification</ulink>
  379. has not yet been formally ratified, but it is in use already
  380. within Dojo toolkit as well as other JSON-RPC consumer clients.
  381. </para>
  382. <para>
  383. At its most basic, a Service Mapping Description indicates the
  384. method of transport (POST, GET, TCP/IP, etc), the request
  385. envelope type (usually based on the protocol of the server), the
  386. target URL of the service provider, and a map of services
  387. available. In the case of JSON-RPC, the service map is a list of
  388. available methods, which each method documenting the available
  389. parameters and their types, as well as the expected return value
  390. type.
  391. </para>
  392. <para>
  393. <classname>Zend_Json_Server_Smd</classname> provides an object oriented
  394. way to build service maps. At its most basic, you pass it
  395. metadata describing the service using mutators, and specify
  396. services (methods and functions).
  397. </para>
  398. <para>
  399. The service descriptions themselves are typically instances of
  400. <classname>Zend_Json_Server_Smd_Service</classname>; you can also pass all
  401. information as an array to the various service mutators in
  402. <classname>Zend_Json_Server_Smd</classname>, and it will instantiate a
  403. service object for you. The service objects contain information
  404. such as the name of the service (typically the function or
  405. method name), the parameters (names, types, and position), and
  406. the return value type. Optionally, each service can have its own
  407. target and envelope, though this functionality is rarely used.
  408. </para>
  409. <para>
  410. <classname>Zend_Json_Server</classname> actually does all of this behind
  411. the scenes for you, by using reflection on the attached classes
  412. and functions; you should create your own service maps only if
  413. you need to provide custom functionality that class and function
  414. introspection cannot offer.
  415. </para>
  416. <para>
  417. Methods available in <classname>Zend_Json_Server_Smd</classname> include:
  418. </para>
  419. <itemizedlist>
  420. <listitem><para><code>setOptions(array $options)</code>: Setup
  421. an SMD object from an array of options. All mutators
  422. (methods beginning with 'set') can be used as
  423. keys.</para></listitem>
  424. <listitem><para><code>setTransport($transport)</code>: Set the
  425. transport used to access the service; only POST is
  426. currently supported.</para></listitem>
  427. <listitem><para><code>getTransport()</code>: Get the current
  428. service transport.</para></listitem>
  429. <listitem><para><code>setEnvelope($envelopeType)</code>: Set the
  430. request envelope that should be used to access the
  431. service. Currently, supports the constants
  432. <classname>Zend_Json_Server_Smd::ENV_JSONRPC_1</classname> and
  433. <classname>Zend_Json_Server_Smd::ENV_JSONRPC_2</classname>.</para></listitem>
  434. <listitem><para><code>getEnvelope()</code>: Get the current
  435. request envelope.</para></listitem>
  436. <listitem><para><code>setContentType($type)</code>: Set the
  437. content type requests should use (by default, this is
  438. 'application/json').</para></listitem>
  439. <listitem><para><code>getContentType()</code>: Get the current
  440. content type for requests to the service.</para></listitem>
  441. <listitem><para><code>setTarget($target)</code>: Set the URL
  442. endpoint for the service.</para></listitem>
  443. <listitem><para><code>getTarget()</code>: Get the URL endpoint
  444. for the service.</para></listitem>
  445. <listitem><para><code>setId($id)</code>: Typically, this is the
  446. URL endpoint of the service (same as the
  447. target).</para></listitem>
  448. <listitem><para><code>getId()</code>: Retrieve the service ID
  449. (typically the URL endpoint of the
  450. service).</para></listitem>
  451. <listitem><para><code>setDescription($description)</code>: Set a
  452. service description (typically narrative information
  453. describing the purpose of the service).</para></listitem>
  454. <listitem><para><code>getDescription()</code>: Get the service
  455. description.</para></listitem>
  456. <listitem><para><code>setDojoCompatible($flag)</code>: Set a
  457. flag indicating whether or not the SMD is compatible
  458. with Dojo toolkit. When true, the generated JSON SMD
  459. will be formatted to comply with the format that Dojo's
  460. JSON-RPC client expects.</para></listitem>
  461. <listitem><para><code>isDojoCompatible()</code>: Returns the
  462. value of the Dojo compatibility flag (false, by
  463. default).</para></listitem>
  464. <listitem><para><code>addService($service)</code>: Add a service
  465. to the map. May be an array of information to pass to
  466. the constructor of
  467. <classname>Zend_Json_Server_Smd_Service</classname>, or an
  468. instance of that class.</para></listitem>
  469. <listitem><para><code>addServices(array $services)</code>: Add
  470. multiple services at once.</para></listitem>
  471. <listitem><para><code>setServices(array $services)</code>: Add
  472. multiple services at once, overwriting any previously
  473. set services.</para></listitem>
  474. <listitem><para><code>getService($name)</code>: Get a service by
  475. its name.</para></listitem>
  476. <listitem><para><code>getServices()</code>: Get all attached
  477. services.</para></listitem>
  478. <listitem><para><code>removeService($name)</code>: Remove a
  479. service from the map.</para></listitem>
  480. <listitem><para><code>toArray()</code>: Cast the service map to
  481. an array.</para></listitem>
  482. <listitem><para><code>toDojoArray()</code>: Cast the service map
  483. to an array compatible with Dojo Toolkit.</para></listitem>
  484. <listitem><para><code>toJson()</code>: Cast the service map to a
  485. JSON representation.</para></listitem>
  486. </itemizedlist>
  487. <para>
  488. <classname>Zend_Json_Server_Smd_Service</classname> has the following
  489. methods:
  490. </para>
  491. <itemizedlist>
  492. <listitem><para><code>setOptions(array $options)</code>: Set
  493. object state from an array. Any mutator (methods
  494. beginning with 'set') may be used as a key and set via
  495. this method.</para></listitem>
  496. <listitem><para><code>setName($name)</code>: Set the service
  497. name (typically, the function or method name).</para></listitem>
  498. <listitem><para><code>getName()</code>: Retrieve the service
  499. name.</para></listitem>
  500. <listitem><para><code>setTransport($transport)</code>: Set the
  501. service transport (currently, only transports supported
  502. by <classname>Zend_Json_Server_Smd</classname> are allowed).</para></listitem>
  503. <listitem><para><code>getTransport()</code>: Retrieve the
  504. current transport.</para></listitem>
  505. <listitem><para><code>setTarget($target)</code>: Set the URL
  506. endpoint of the service (typically, this will be the
  507. same as the overall SMD to which the service is
  508. attached).</para></listitem>
  509. <listitem><para><code>getTarget()</code>: Get the URL endpoint
  510. of the service.</para></listitem>
  511. <listitem><para><code>setEnvelope($envelopeType)</code>: Set the
  512. service envelope (currently, only envelopes supported
  513. by <classname>Zend_Json_Server_Smd</classname> are allowed).</para></listitem>
  514. <listitem><para><code>getEnvelope()</code>: Retrieve the service
  515. envelope type.</para></listitem>
  516. <listitem><para><code>addParam($type, array $options = array(),
  517. $order = null)</code>: Add a parameter to the
  518. service. By default, only the parameter type is
  519. necessary. However, you may also specify the order, as
  520. well as options such as:</para>
  521. <itemizedlist>
  522. <listitem><para><emphasis>name</emphasis>: the parameter
  523. name</para></listitem>
  524. <listitem><para><emphasis>optional</emphasis>: whether
  525. or not the parameter is optional</para></listitem>
  526. <listitem><para><emphasis>default</emphasis>: a default
  527. value for the parameter</para></listitem>
  528. <listitem><para><emphasis>description</emphasis>: text
  529. describing the parameter</para></listitem>
  530. </itemizedlist>
  531. </listitem>
  532. <listitem><para><code>addParams(array $params)</code>: Add
  533. several parameters at once; each param should be an assoc
  534. array containing minimally the key 'type' describing the
  535. parameter type, and optionally the key 'order'; any other
  536. keys will be passed as <code>$options</code> to
  537. <code>addOption()</code>.</para></listitem>
  538. <listitem><para><code>setParams(array $params)</code>: Set many
  539. parameters at once, overwriting any existing
  540. parameters.</para></listitem>
  541. <listitem><para><code>getParams()</code>: Retrieve all currently
  542. set parameters.</para></listitem>
  543. <listitem><para><code>setReturn($type)</code>: Set the return
  544. value type of the service.</para></listitem>
  545. <listitem><para><code>getReturn()</code>: Get the return value
  546. type of the service.</para></listitem>
  547. <listitem><para><code>toArray()</code>: Cast the service to an
  548. array.</para></listitem>
  549. <listitem><para><code>toJson()</code>: Cast the service to a
  550. JSON representation.</para></listitem>
  551. </itemizedlist>
  552. </sect3>
  553. </sect2>
  554. </sect1>
  555. <!--
  556. vim:se ts=4 sw=4 et:
  557. -->