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