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