Zend_Json-Server.xml 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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> server implementation.
  8. It supports both the <ulink url="http://json-rpc.org/wiki/specification">JSON-RPC
  9. version 1 specification</ulink> as well as the <ulink
  10. url="http://groups.google.com/group/json-rpc/web/json-rpc-1-2-proposal">version 2
  11. specification</ulink>; additionally, it provides a <acronym>PHP</acronym> implementation
  12. of the <ulink
  13. 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. <acronym>JSON</acronym> for its messaging envelopes. This JSON-RPC implementation follows
  20. <acronym>PHP</acronym>'s <ulink
  21. url="http://www.php.net/manual/en/class.soapserver.php">SoapServer</ulink>
  22. <acronym>API</acronym>. This means, in a typical situation, you will simply:
  23. </para>
  24. <itemizedlist>
  25. <listitem><para>Instantiate the server object</para></listitem>
  26. <listitem>
  27. <para>Attach one or more functions and/or classes/objects to the server object</para>
  28. </listitem>
  29. <listitem><para>handle() the request</para></listitem>
  30. </itemizedlist>
  31. <para>
  32. <classname>Zend_Json_Server</classname> utilizes <link
  33. linkend="zend.server.reflection">Zend_Server_Reflection</link>
  34. to perform reflection on any attached classes or functions, and uses that
  35. information to build both the SMD and enforce method call signatures. As
  36. such, it is imperative that any attached functions and/or class methods
  37. have full <acronym>PHP</acronym> docblocks documenting, minimally:
  38. </para>
  39. <itemizedlist>
  40. <listitem><para>All parameters and their expected variable types</para></listitem>
  41. <listitem><para>The return value variable type</para></listitem>
  42. </itemizedlist>
  43. <para>
  44. <classname>Zend_Json_Server</classname> listens for POST requests only at this
  45. time; fortunately, most JSON-RPC client implementations in the wild at
  46. the time of this writing will only POST requests as it is. This makes it
  47. simple to utilize the same server end point to both handle requests as
  48. well as to deliver the service SMD, as is shown in the next example.
  49. </para>
  50. <example id="zend.json.server.usage">
  51. <title>Zend_Json_Server Usage</title>
  52. <para>
  53. First, let's define a class we wish to expose via the JSON-RPC
  54. server. We'll call the class 'Calculator', and define methods for
  55. 'add', 'subtract', 'multiply', and 'divide':
  56. </para>
  57. <programlisting language="php"><![CDATA[
  58. /**
  59. * Calculator - sample class to expose via JSON-RPC
  60. */
  61. class Calculator
  62. {
  63. /**
  64. * Return sum of two variables
  65. *
  66. * @param int $x
  67. * @param int $y
  68. * @return int
  69. */
  70. public function add($x, $y)
  71. {
  72. return $x + $y;
  73. }
  74. /**
  75. * Return difference of two variables
  76. *
  77. * @param int $x
  78. * @param int $y
  79. * @return int
  80. */
  81. public function subtract($x, $y)
  82. {
  83. return $x - $y;
  84. }
  85. /**
  86. * Return product of two variables
  87. *
  88. * @param int $x
  89. * @param int $y
  90. * @return int
  91. */
  92. public function multiply($x, $y)
  93. {
  94. return $x * $y;
  95. }
  96. /**
  97. * Return the division of two variables
  98. *
  99. * @param int $x
  100. * @param int $y
  101. * @return float
  102. */
  103. public function divide($x, $y)
  104. {
  105. return $x / $y;
  106. }
  107. }
  108. ]]></programlisting>
  109. <para>
  110. Note that each method has a docblock with entries indicating each
  111. parameter and its type, as well as an entry for the return value.
  112. This is <emphasis>absolutely critical</emphasis> when utilizing
  113. <classname>Zend_Json_Server</classname> or any other server component in
  114. Zend Framework, for that matter.
  115. </para>
  116. <para>
  117. Now we'll create a script to handle the requests:
  118. </para>
  119. <programlisting language="php"><![CDATA[
  120. $server = new Zend_Json_Server();
  121. // Indicate what functionality is available:
  122. $server->setClass('Calculator');
  123. // Handle the request:
  124. $server->handle();
  125. ]]></programlisting>
  126. <para>
  127. However, this will not address the issue of returning an SMD so that
  128. the JSON-RPC client can autodiscover methods. That can be
  129. accomplished by determining the <acronym>HTTP</acronym> request method, and then
  130. specifying some server metadata:
  131. </para>
  132. <programlisting language="php"><![CDATA[
  133. $server = new Zend_Json_Server();
  134. $server->setClass('Calculator');
  135. if ('GET' == $_SERVER['REQUEST_METHOD']) {
  136. // Indicate the URL endpoint, and the JSON-RPC version used:
  137. $server->setTarget('/json-rpc.php')
  138. ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
  139. // Grab the SMD
  140. $smd = $server->getServiceMap();
  141. // Return the SMD to the client
  142. header('Content-Type: application/json');
  143. echo $smd;
  144. return;
  145. }
  146. $server->handle();
  147. ]]></programlisting>
  148. <para>
  149. If utilizing the JSON-RPC server with Dojo toolkit, you will also
  150. need to set a special compatibility flag to ensure that the two
  151. interoperate properly:
  152. </para>
  153. <programlisting language="php"><![CDATA[
  154. $server = new Zend_Json_Server();
  155. $server->setClass('Calculator');
  156. if ('GET' == $_SERVER['REQUEST_METHOD']) {
  157. $server->setTarget('/json-rpc.php')
  158. ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
  159. $smd = $server->getServiceMap();
  160. // Set Dojo compatibility:
  161. $smd->setDojoCompatible(true);
  162. header('Content-Type: application/json');
  163. echo $smd;
  164. return;
  165. }
  166. $server->handle();
  167. ]]></programlisting>
  168. </example>
  169. <sect2 id="zend.json.server.details">
  170. <title>Advanced Details</title>
  171. <para>
  172. While most functionality for <classname>Zend_Json_Server</classname> is
  173. spelled out in <link linkend="zend.json.server.usage">this section</link>, more
  174. advanced functionality is available.
  175. </para>
  176. <sect3 id="zend.json.server.details.zendjsonserver">
  177. <title>Zend_Json_Server</title>
  178. <para>
  179. <classname>Zend_Json_Server</classname> is the core class in the JSON-RPC
  180. offering; it handles all requests and returns the response
  181. payload. It has the following methods:
  182. </para>
  183. <itemizedlist>
  184. <listitem>
  185. <para>
  186. <methodname>addFunction($function)</methodname>: Specify a
  187. userland function to attach to the server.
  188. </para>
  189. </listitem>
  190. <listitem>
  191. <para>
  192. <methodname>setClass($class)</methodname>: Specify a class
  193. or object to attach to the server; all public methods of
  194. that item will be exposed as JSON-RPC methods.
  195. </para>
  196. </listitem>
  197. <listitem>
  198. <para>
  199. <methodname>fault($fault = null, $code = 404, $data = null)</methodname>:
  200. Create and return a <classname>Zend_Json_Server_Error</classname> object.
  201. </para>
  202. </listitem>
  203. <listitem>
  204. <para>
  205. <methodname>handle($request = false)</methodname>: Handle a
  206. JSON-RPC request; optionally, pass a
  207. <classname>Zend_Json_Server_Request</classname> object to utilize
  208. (creates one by default).
  209. </para>
  210. </listitem>
  211. <listitem>
  212. <para>
  213. <methodname>getFunctions()</methodname>: Return a list of
  214. all attached methods.
  215. </para>
  216. </listitem>
  217. <listitem>
  218. <para>
  219. <methodname>setRequest(Zend_Json_Server_Request $request)</methodname>:
  220. Specify a request object for the server to utilize.
  221. </para>
  222. </listitem>
  223. <listitem>
  224. <para>
  225. <methodname>getRequest()</methodname>: Retrieve the request
  226. object used by the server.
  227. </para>
  228. </listitem>
  229. <listitem>
  230. <para>
  231. <methodname>setResponse(Zend_Json_Server_Response $response)</methodname>:
  232. Set the response object for the server to utilize.
  233. </para>
  234. </listitem>
  235. <listitem>
  236. <para>
  237. <methodname>getResponse()</methodname>: Retrieve the
  238. response object used by the server.
  239. </para>
  240. </listitem>
  241. <listitem>
  242. <para>
  243. <methodname>setAutoEmitResponse($flag)</methodname>:
  244. Indicate whether the server should automatically emit
  245. the response and all headers; by default, this is
  246. <constant>TRUE</constant>.
  247. </para>
  248. </listitem>
  249. <listitem>
  250. <para>
  251. <methodname>autoEmitResponse()</methodname>: Determine if
  252. auto-emission of the response is enabled.
  253. </para>
  254. </listitem>
  255. <listitem>
  256. <para>
  257. <methodname>getServiceMap()</methodname>: Retrieve the
  258. service map description in the form of a
  259. <classname>Zend_Json_Server_Smd</classname> object
  260. </para>
  261. </listitem>
  262. </itemizedlist>
  263. </sect3>
  264. <sect3 id="zend.json.server.details.zendjsonserverrequest">
  265. <title>Zend_Json_Server_Request</title>
  266. <para>
  267. The JSON-RPC request environment is encapsulated in the
  268. <classname>Zend_Json_Server_Request</classname> object. This object allows
  269. you to set necessary portions of the JSON-RPC request, including
  270. the request ID, parameters, and JSON-RPC specification version.
  271. It has the ability to load itself via <acronym>JSON</acronym> or a set of options,
  272. and can render itself as <acronym>JSON</acronym> via the
  273. <methodname>toJson()</methodname> method.
  274. </para>
  275. <para>
  276. The request object has the following methods available:
  277. </para>
  278. <itemizedlist>
  279. <listitem>
  280. <para>
  281. <methodname>setOptions(array $options)</methodname>: Specify
  282. object configuration. <varname>$options</varname> may contain
  283. keys matching any 'set' method:
  284. <methodname>setParams()</methodname>, <methodname>setMethod()</methodname>,
  285. <methodname>setId()</methodname>, and
  286. <methodname>setVersion()</methodname>.
  287. </para>
  288. </listitem>
  289. <listitem>
  290. <para>
  291. <methodname>addParam($value, $key = null)</methodname>: Add
  292. a parameter to use with the method call. Parameters can be
  293. just the values, or can optionally include the parameter name.
  294. </para>
  295. </listitem>
  296. <listitem>
  297. <para>
  298. <methodname>addParams(array $params)</methodname>: Add
  299. multiple parameters at once; proxies to
  300. <methodname>addParam()</methodname>
  301. </para>
  302. </listitem>
  303. <listitem>
  304. <para>
  305. <methodname>setParams(array $params)</methodname>: Set all
  306. parameters at once; overwrites any existing parameters.
  307. </para>
  308. </listitem>
  309. <listitem>
  310. <para>
  311. <methodname>getParam($index)</methodname>: Retrieve a
  312. parameter by position or name.
  313. </para>
  314. </listitem>
  315. <listitem>
  316. <para>
  317. <methodname>getParams()</methodname>: Retrieve all parameters at once.
  318. </para>
  319. </listitem>
  320. <listitem>
  321. <para>
  322. <methodname>setMethod($name)</methodname>: Set the method to call.
  323. </para>
  324. </listitem>
  325. <listitem>
  326. <para>
  327. <methodname>getMethod()</methodname>: Retrieve the method
  328. that will be called.
  329. </para>
  330. </listitem>
  331. <listitem>
  332. <para>
  333. <methodname>isMethodError()</methodname>: Determine whether
  334. or not the request is malformed and would result in an error.
  335. </para>
  336. </listitem>
  337. <listitem>
  338. <para>
  339. <methodname>setId($name)</methodname>: Set the request
  340. identifier (used by the client to match requests to responses).
  341. </para>
  342. </listitem>
  343. <listitem>
  344. <para>
  345. <methodname>getId()</methodname>: Retrieve the request identifier.
  346. </para>
  347. </listitem>
  348. <listitem>
  349. <para>
  350. <methodname>setVersion($version)</methodname>: Set the
  351. JSON-RPC specification version the request conforms to.
  352. May be either '1.0' or '2.0'.
  353. </para>
  354. </listitem>
  355. <listitem>
  356. <para>
  357. <methodname>getVersion()</methodname>: Retrieve the JSON-RPC
  358. specification version used by the request.
  359. </para>
  360. </listitem>
  361. <listitem>
  362. <para>
  363. <methodname>loadJson($json)</methodname>: Load the request
  364. object from a <acronym>JSON</acronym> string.
  365. </para>
  366. </listitem>
  367. <listitem>
  368. <para>
  369. <methodname>toJson()</methodname>: Render the request as
  370. a <acronym>JSON</acronym> string.
  371. </para>
  372. </listitem>
  373. </itemizedlist>
  374. <para>
  375. An <acronym>HTTP</acronym> specific version is available via
  376. <classname>Zend_Json_Server_Request_Http</classname>. This class will
  377. retrieve the request via <filename>php://input</filename>, and allows access to the
  378. raw <acronym>JSON</acronym> via the <methodname>getRawJson()</methodname> method.
  379. </para>
  380. </sect3>
  381. <sect3 id="zend.json.server.details.zendjsonserverresponse">
  382. <title>Zend_Json_Server_Response</title>
  383. <para>
  384. The JSON-RPC response payload is encapsulated in the
  385. <classname>Zend_Json_Server_Response</classname> object. This object allows
  386. you to set the return value of the request, whether or not the
  387. response is an error, the request identifier, the JSON-RPC
  388. specification version the response conforms to, and optionally
  389. the service map.
  390. </para>
  391. <para>
  392. The response object has the following methods available:
  393. </para>
  394. <itemizedlist>
  395. <listitem>
  396. <para>
  397. <methodname>setResult($value)</methodname>: Set the response result.
  398. </para>
  399. </listitem>
  400. <listitem>
  401. <para>
  402. <methodname>getResult()</methodname>: Retrieve the response result.
  403. </para>
  404. </listitem>
  405. <listitem>
  406. <para>
  407. <methodname>setError(Zend_Json_Server_Error $error)</methodname>: Set an
  408. error object. If set, this will be used as the response when serializing to
  409. <acronym>JSON</acronym>.
  410. </para>
  411. </listitem>
  412. <listitem>
  413. <para>
  414. <methodname>getError()</methodname>: Retrieve the error object, if any.
  415. </para>
  416. </listitem>
  417. <listitem>
  418. <para>
  419. <methodname>isError()</methodname>: Whether or not the response is an error
  420. response.
  421. </para>
  422. </listitem>
  423. <listitem>
  424. <para>
  425. <methodname>setId($name)</methodname>: Set the request identifier (so the
  426. client may match the response with the original request).
  427. </para>
  428. </listitem>
  429. <listitem>
  430. <para>
  431. <methodname>getId()</methodname>: Retrieve the request identifier.
  432. </para>
  433. </listitem>
  434. <listitem>
  435. <para>
  436. <methodname>setVersion($version)</methodname>: Set the
  437. JSON-RPC version the response conforms to.
  438. </para>
  439. </listitem>
  440. <listitem>
  441. <para>
  442. <methodname>getVersion()</methodname>: Retrieve the JSON-RPC
  443. version the response conforms to.
  444. </para>
  445. </listitem>
  446. <listitem>
  447. <para>
  448. <methodname>toJson()</methodname>: Serialize the response to
  449. <acronym>JSON</acronym>. If the response is an error response, serializes
  450. the error object.
  451. </para>
  452. </listitem>
  453. <listitem>
  454. <para>
  455. <methodname>setServiceMap($serviceMap)</methodname>: Set the
  456. service map object for the response.
  457. </para>
  458. </listitem>
  459. <listitem>
  460. <para>
  461. <methodname>getServiceMap()</methodname>: Retrieve the
  462. service map object, if any.
  463. </para>
  464. </listitem>
  465. </itemizedlist>
  466. <para>
  467. An <acronym>HTTP</acronym> specific version is available via
  468. <classname>Zend_Json_Server_Response_Http</classname>. This class will
  469. send the appropriate <acronym>HTTP</acronym> headers as well as serialize the
  470. response as <acronym>JSON</acronym>.
  471. </para>
  472. </sect3>
  473. <sect3 id="zend.json.server.details.zendjsonservererror">
  474. <title>Zend_Json_Server_Error</title>
  475. <para>
  476. JSON-RPC has a special format for reporting error conditions.
  477. All errors need to provide, minimally, an error message and error
  478. code; optionally, they can provide additional data, such as a
  479. backtrace.
  480. </para>
  481. <para>
  482. Error codes are derived from those recommended by <ulink
  483. url="http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php">the
  484. XML-RPC EPI project</ulink>. <classname>Zend_Json_Server</classname>
  485. appropriately assigns the code based on the error condition. For
  486. application exceptions, the code '-32000' is used.
  487. </para>
  488. <para>
  489. <classname>Zend_Json_Server_Error</classname> exposes the following
  490. methods:
  491. </para>
  492. <itemizedlist>
  493. <listitem>
  494. <para>
  495. <methodname>setCode($code)</methodname>: Set the error code;
  496. if the code is not in the accepted XML-RPC error code range,
  497. -32000 will be assigned.
  498. </para>
  499. </listitem>
  500. <listitem>
  501. <para>
  502. <methodname>getCode()</methodname>: Retrieve the current error code.
  503. </para>
  504. </listitem>
  505. <listitem>
  506. <para>
  507. <methodname>setMessage($message)</methodname>: Set the error message.
  508. </para>
  509. </listitem>
  510. <listitem>
  511. <para>
  512. <methodname>getMessage()</methodname>: Retrieve the current error message.
  513. </para>
  514. </listitem>
  515. <listitem>
  516. <para>
  517. <methodname>setData($data)</methodname>: Set auxiliary data
  518. further qualifying the error, such as a backtrace.
  519. </para>
  520. </listitem>
  521. <listitem>
  522. <para>
  523. <methodname>getData()</methodname>: Retrieve any current auxiliary error
  524. data.
  525. </para>
  526. </listitem>
  527. <listitem>
  528. <para>
  529. <methodname>toArray()</methodname>: Cast the error to an
  530. array. The array will contain the keys 'code', 'message', and 'data'.
  531. </para>
  532. </listitem>
  533. <listitem>
  534. <para>
  535. <methodname>toJson()</methodname>: Cast the error to a
  536. JSON-RPC error representation.
  537. </para>
  538. </listitem>
  539. </itemizedlist>
  540. </sect3>
  541. <sect3 id="zend.json.server.details.zendjsonserversmd">
  542. <title>Zend_Json_Server_Smd</title>
  543. <para>
  544. SMD stands for Service Mapping Description, a <acronym>JSON</acronym> schema that
  545. defines how a client can interact with a particular web service.
  546. At the time of this writing, the <ulink
  547. url="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal">specification</ulink>
  548. has not yet been formally ratified, but it is in use already
  549. within Dojo toolkit as well as other JSON-RPC consumer clients.
  550. </para>
  551. <para>
  552. At its most basic, a Service Mapping Description indicates the
  553. method of transport (POST, <constant>GET</constant>, <acronym>TCP</acronym>/IP,
  554. etc), the request envelope type (usually based on the protocol of the server), the
  555. target <acronym>URL</acronym> of the service provider, and a map of services
  556. available. In the case of JSON-RPC, the service map is a list of
  557. available methods, which each method documenting the available
  558. parameters and their types, as well as the expected return value
  559. type.
  560. </para>
  561. <para>
  562. <classname>Zend_Json_Server_Smd</classname> provides an object oriented
  563. way to build service maps. At its most basic, you pass it
  564. metadata describing the service using mutators, and specify
  565. services (methods and functions).
  566. </para>
  567. <para>
  568. The service descriptions themselves are typically instances of
  569. <classname>Zend_Json_Server_Smd_Service</classname>; you can also pass all
  570. information as an array to the various service mutators in
  571. <classname>Zend_Json_Server_Smd</classname>, and it will instantiate a
  572. service object for you. The service objects contain information
  573. such as the name of the service (typically the function or
  574. method name), the parameters (names, types, and position), and
  575. the return value type. Optionally, each service can have its own
  576. target and envelope, though this functionality is rarely used.
  577. </para>
  578. <para>
  579. <classname>Zend_Json_Server</classname> actually does all of this behind
  580. the scenes for you, by using reflection on the attached classes
  581. and functions; you should create your own service maps only if
  582. you need to provide custom functionality that class and function
  583. introspection cannot offer.
  584. </para>
  585. <para>
  586. Methods available in <classname>Zend_Json_Server_Smd</classname> include:
  587. </para>
  588. <itemizedlist>
  589. <listitem>
  590. <para>
  591. <methodname>setOptions(array $options)</methodname>: Setup
  592. an SMD object from an array of options. All mutators
  593. (methods beginning with 'set') can be used as keys.
  594. </para>
  595. </listitem>
  596. <listitem>
  597. <para>
  598. <methodname>setTransport($transport)</methodname>: Set the
  599. transport used to access the service; only POST is currently supported.
  600. </para>
  601. </listitem>
  602. <listitem>
  603. <para>
  604. <methodname>getTransport()</methodname>: Get the current service transport.
  605. </para>
  606. </listitem>
  607. <listitem>
  608. <para>
  609. <methodname>setEnvelope($envelopeType)</methodname>: Set the
  610. request envelope that should be used to access the
  611. service. Currently, supports the constants
  612. <constant>Zend_Json_Server_Smd::ENV_JSONRPC_1</constant> and
  613. <constant>Zend_Json_Server_Smd::ENV_JSONRPC_2</constant>.
  614. </para>
  615. </listitem>
  616. <listitem>
  617. <para>
  618. <methodname>getEnvelope()</methodname>: Get the current request envelope.
  619. </para>
  620. </listitem>
  621. <listitem>
  622. <para>
  623. <methodname>setContentType($type)</methodname>: Set the
  624. content type requests should use (by default, this is 'application/json').
  625. </para>
  626. </listitem>
  627. <listitem>
  628. <para>
  629. <methodname>getContentType()</methodname>: Get the current
  630. content type for requests to the service.
  631. </para>
  632. </listitem>
  633. <listitem>
  634. <para>
  635. <methodname>setTarget($target)</methodname>: Set the <acronym>URL</acronym>
  636. endpoint for the service.
  637. </para>
  638. </listitem>
  639. <listitem>
  640. <para>
  641. <methodname>getTarget()</methodname>: Get the <acronym>URL</acronym>
  642. endpoint for the service.
  643. </para>
  644. </listitem>
  645. <listitem>
  646. <para>
  647. <methodname>setId($id)</methodname>: Typically, this is the
  648. <acronym>URL</acronym> endpoint of the service (same as the target).
  649. </para>
  650. </listitem>
  651. <listitem>
  652. <para>
  653. <methodname>getId()</methodname>: Retrieve the service ID
  654. (typically the <acronym>URL</acronym> endpoint of the service).
  655. </para>
  656. </listitem>
  657. <listitem>
  658. <para>
  659. <methodname>setDescription($description)</methodname>: Set a
  660. service description (typically narrative information
  661. describing the purpose of the service).
  662. </para>
  663. </listitem>
  664. <listitem>
  665. <para>
  666. <methodname>getDescription()</methodname>: Get the service description.
  667. </para>
  668. </listitem>
  669. <listitem>
  670. <para>
  671. <methodname>setDojoCompatible($flag)</methodname>: Set a flag indicating
  672. whether or not the SMD is compatible with Dojo toolkit. When
  673. <constant>TRUE</constant>, the generated <acronym>JSON</acronym> SMD will
  674. be formatted to comply with the format that Dojo's JSON-RPC client expects.
  675. </para>
  676. </listitem>
  677. <listitem>
  678. <para>
  679. <methodname>isDojoCompatible()</methodname>: Returns the value of the
  680. Dojo compatibility flag (<constant>FALSE</constant>, by default).
  681. </para>
  682. </listitem>
  683. <listitem>
  684. <para>
  685. <methodname>addService($service)</methodname>: Add a service
  686. to the map. May be an array of information to pass to
  687. the constructor of
  688. <classname>Zend_Json_Server_Smd_Service</classname>, or an
  689. instance of that class.
  690. </para>
  691. </listitem>
  692. <listitem>
  693. <para>
  694. <methodname>addServices(array $services)</methodname>: Add
  695. multiple services at once.
  696. </para>
  697. </listitem>
  698. <listitem>
  699. <para>
  700. <methodname>setServices(array $services)</methodname>: Add
  701. multiple services at once, overwriting any previously set services.
  702. </para>
  703. </listitem>
  704. <listitem>
  705. <para>
  706. <methodname>getService($name)</methodname>: Get a service by its name.
  707. </para>
  708. </listitem>
  709. <listitem>
  710. <para>
  711. <methodname>getServices()</methodname>: Get all attached services.
  712. </para>
  713. </listitem>
  714. <listitem>
  715. <para>
  716. <methodname>removeService($name)</methodname>: Remove a
  717. service from the map.
  718. </para>
  719. </listitem>
  720. <listitem>
  721. <para>
  722. <methodname>toArray()</methodname>: Cast the service map to an array.
  723. </para>
  724. </listitem>
  725. <listitem>
  726. <para>
  727. <methodname>toDojoArray()</methodname>: Cast the service map
  728. to an array compatible with Dojo Toolkit.
  729. </para>
  730. </listitem>
  731. <listitem>
  732. <para>
  733. <methodname>toJson()</methodname>: Cast the service map to a
  734. <acronym>JSON</acronym> representation.
  735. </para>
  736. </listitem>
  737. </itemizedlist>
  738. <para>
  739. <classname>Zend_Json_Server_Smd_Service</classname> has the following
  740. methods:
  741. </para>
  742. <itemizedlist>
  743. <listitem>
  744. <para>
  745. <methodname>setOptions(array $options)</methodname>: Set
  746. object state from an array. Any mutator (methods
  747. beginning with 'set') may be used as a key and set via this method.
  748. </para>
  749. </listitem>
  750. <listitem>
  751. <para>
  752. <methodname>setName($name)</methodname>: Set the service
  753. name (typically, the function or method name).
  754. </para>
  755. </listitem>
  756. <listitem>
  757. <para>
  758. <methodname>getName()</methodname>: Retrieve the service name.
  759. </para>
  760. </listitem>
  761. <listitem>
  762. <para>
  763. <methodname>setTransport($transport)</methodname>: Set the
  764. service transport (currently, only transports supported
  765. by <classname>Zend_Json_Server_Smd</classname> are allowed).
  766. </para>
  767. </listitem>
  768. <listitem>
  769. <para>
  770. <methodname>getTransport()</methodname>: Retrieve the current transport.
  771. </para>
  772. </listitem>
  773. <listitem>
  774. <para>
  775. <methodname>setTarget($target)</methodname>: Set the <acronym>URL</acronym>
  776. endpoint of the service (typically, this will be the
  777. same as the overall SMD to which the service is attached).
  778. </para>
  779. </listitem>
  780. <listitem>
  781. <para>
  782. <methodname>getTarget()</methodname>: Get the <acronym>URL</acronym>
  783. endpoint of the service.
  784. </para>
  785. </listitem>
  786. <listitem>
  787. <para>
  788. <methodname>setEnvelope($envelopeType)</methodname>: Set the
  789. service envelope (currently, only envelopes supported
  790. by <classname>Zend_Json_Server_Smd</classname> are allowed).
  791. </para>
  792. </listitem>
  793. <listitem>
  794. <para>
  795. <methodname>getEnvelope()</methodname>: Retrieve the service envelope type.
  796. </para>
  797. </listitem>
  798. <listitem>
  799. <para>
  800. <methodname>addParam($type, array $options = array(), $order =
  801. null)</methodname>: Add a parameter to the service. By default, only the
  802. parameter type is necessary. However, you may also specify the order, as
  803. well as options such as:
  804. </para>
  805. <itemizedlist>
  806. <listitem>
  807. <para>
  808. <emphasis>name</emphasis>: the parameter name
  809. </para>
  810. </listitem>
  811. <listitem>
  812. <para>
  813. <emphasis>optional</emphasis>: whether or not the parameter is
  814. optional
  815. </para>
  816. </listitem>
  817. <listitem>
  818. <para>
  819. <emphasis>default</emphasis>: a default value for the parameter
  820. </para>
  821. </listitem>
  822. <listitem>
  823. <para>
  824. <emphasis>description</emphasis>: text describing the parameter
  825. </para>
  826. </listitem>
  827. </itemizedlist>
  828. </listitem>
  829. <listitem>
  830. <para>
  831. <methodname>addParams(array $params)</methodname>: Add
  832. several parameters at once; each param should be an assoc
  833. array containing minimally the key 'type' describing the
  834. parameter type, and optionally the key 'order'; any other
  835. keys will be passed as <varname>$options</varname> to
  836. <methodname>addOption()</methodname>.
  837. </para>
  838. </listitem>
  839. <listitem>
  840. <para>
  841. <methodname>setParams(array $params)</methodname>: Set many
  842. parameters at once, overwriting any existing parameters.
  843. </para>
  844. </listitem>
  845. <listitem>
  846. <para>
  847. <methodname>getParams()</methodname>: Retrieve all currently set parameters.
  848. </para>
  849. </listitem>
  850. <listitem>
  851. <para>
  852. <methodname>setReturn($type)</methodname>: Set the return
  853. value type of the service.
  854. </para>
  855. </listitem>
  856. <listitem>
  857. <para>
  858. <methodname>getReturn()</methodname>: Get the return value type of the
  859. service.
  860. </para>
  861. </listitem>
  862. <listitem>
  863. <para>
  864. <methodname>toArray()</methodname>: Cast the service to an array.
  865. </para>
  866. </listitem>
  867. <listitem>
  868. <para>
  869. <methodname>toJson()</methodname>: Cast the service to a
  870. <acronym>JSON</acronym> representation.
  871. </para>
  872. </listitem>
  873. </itemizedlist>
  874. </sect3>
  875. </sect2>
  876. </sect1>
  877. <!--
  878. vim:se ts=4 sw=4 et:
  879. -->