<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.json.server">
    <title>Zend_Json_Server - JSON-RPC server</title>

    <para>
        <classname>Zend_Json_Server</classname> is a <ulink
            url="http://groups.google.com/group/json-rpc/">JSON-RPC</ulink> server implementation.
        It supports both the <ulink url="http://json-rpc.org/wiki/specification">JSON-RPC
            version 1 specification</ulink> as well as the <ulink
            url="http://groups.google.com/group/json-rpc/web/json-rpc-1-2-proposal">version 2
            specification</ulink>; additionally, it provides a <acronym>PHP</acronym> implementation
        of the <ulink
            url="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal">Service
            Mapping Description (SMD) specification</ulink>
        for providing service metadata to service consumers.
    </para>

    <para>
        JSON-RPC is a lightweight Remote Procedure Call protocol that utilizes
        <acronym>JSON</acronym> for its messaging envelopes. This JSON-RPC implementation follows
        <acronym>PHP</acronym>'s <ulink
            url="http://www.php.net/manual/en/class.soapserver.php">SoapServer</ulink>
        <acronym>API</acronym>. This means, in a typical situation, you will simply:
    </para>

    <itemizedlist>
        <listitem><para>Instantiate the server object</para></listitem>

        <listitem>
            <para>Attach one or more functions and/or classes/objects to the server object</para>
        </listitem>

        <listitem><para>handle() the request</para></listitem>
    </itemizedlist>

    <para>
        <classname>Zend_Json_Server</classname> utilizes <link
            linkend="zend.server.reflection">Zend_Server_Reflection</link>
        to perform reflection on any attached classes or functions, and uses that
        information to build both the SMD and enforce method call signatures. As
        such, it is imperative that any attached functions and/or class methods
        have full <acronym>PHP</acronym> docblocks documenting, minimally:
    </para>

    <itemizedlist>
        <listitem><para>All parameters and their expected variable types</para></listitem>
        <listitem><para>The return value variable type</para></listitem>
    </itemizedlist>

    <para>
        <classname>Zend_Json_Server</classname> listens for POST requests only at this
        time; fortunately, most JSON-RPC client implementations in the wild at
        the time of this writing will only POST requests as it is. This makes it
        simple to utilize the same server end point to both handle requests as
        well as to deliver the service SMD, as is shown in the next example.
    </para>

    <example id="zend.json.server.usage">
        <title>Zend_Json_Server Usage</title>

        <para>
            First, let's define a class we wish to expose via the JSON-RPC
            server. We'll call the class 'Calculator', and define methods for
            'add', 'subtract', 'multiply', and 'divide':
        </para>

        <programlisting language="php"><![CDATA[
/**
 * Calculator - sample class to expose via JSON-RPC
 */
class Calculator
{
    /**
     * Return sum of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return int
     */
    public function add($x, $y)
    {
        return $x + $y;
    }

    /**
     * Return difference of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return int
     */
    public function subtract($x, $y)
    {
        return $x - $y;
    }

    /**
     * Return product of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return int
     */
    public function multiply($x, $y)
    {
        return $x * $y;
    }

    /**
     * Return the division of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return float
     */
    public function divide($x, $y)
    {
        return $x / $y;
    }
}
]]></programlisting>

        <para>
            Note that each method has a docblock with entries indicating each
            parameter and its type, as well as an entry for the return value.
            This is <emphasis>absolutely critical</emphasis> when utilizing
            <classname>Zend_Json_Server</classname> or any other server component in
            Zend Framework, for that matter.
        </para>

        <para>
            Now we'll create a script to handle the requests:
        </para>

        <programlisting language="php"><![CDATA[
$server = new Zend_Json_Server();

// Indicate what functionality is available:
$server->setClass('Calculator');

// Handle the request:
$server->handle();
]]></programlisting>

        <para>
            However, this will not address the issue of returning an SMD so that
            the JSON-RPC client can autodiscover methods. That can be
            accomplished by determining the <acronym>HTTP</acronym> request method, and then
            specifying some server metadata:
        </para>

        <programlisting language="php"><![CDATA[
$server = new Zend_Json_Server();
$server->setClass('Calculator');

if ('GET' == $_SERVER['REQUEST_METHOD']) {
    // Indicate the URL endpoint, and the JSON-RPC version used:
    $server->setTarget('/json-rpc.php')
           ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);

    // Grab the SMD
    $smd = $server->getServiceMap();

    // Return the SMD to the client
    header('Content-Type: application/json');
    echo $smd;
    return;
}

$server->handle();
]]></programlisting>

        <para>
            If utilizing the JSON-RPC server with Dojo toolkit, you will also
            need to set a special compatibility flag to ensure that the two
            interoperate properly:
        </para>

        <programlisting language="php"><![CDATA[
$server = new Zend_Json_Server();
$server->setClass('Calculator');

if ('GET' == $_SERVER['REQUEST_METHOD']) {
    $server->setTarget('/json-rpc.php')
           ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
    $smd = $server->getServiceMap();

    // Set Dojo compatibility:
    $smd->setDojoCompatible(true);

    header('Content-Type: application/json');
    echo $smd;
    return;
}

$server->handle();
]]></programlisting>
    </example>

    <sect2 id="zend.json.server.details">
        <title>Advanced Details</title>

        <para>
            While most functionality for <classname>Zend_Json_Server</classname> is
            spelled out in <link linkend="zend.json.server.usage">this section</link>, more
            advanced functionality is available.
        </para>

        <sect3 id="zend.json.server.details.zendjsonserver">
            <title>Zend_Json_Server</title>

            <para>
                <classname>Zend_Json_Server</classname> is the core class in the JSON-RPC
                offering; it handles all requests and returns the response
                payload. It has the following methods:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        <methodname>addFunction($function)</methodname>: Specify a
                        userland function to attach to the server.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setClass($class)</methodname>: Specify a class
                        or object to attach to the server; all public methods of
                        that item will be exposed as JSON-RPC methods.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>fault($fault = null, $code = 404, $data = null)</methodname>:
                        Create and return a <classname>Zend_Json_Server_Error</classname> object.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>handle($request = false)</methodname>: Handle a
                        JSON-RPC request; optionally, pass a
                        <classname>Zend_Json_Server_Request</classname> object to utilize
                        (creates one by default).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getFunctions()</methodname>: Return a list of
                        all attached methods.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setRequest(Zend_Json_Server_Request $request)</methodname>:
                        Specify a request object for the server to utilize.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getRequest()</methodname>: Retrieve the request
                        object used by the server.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setResponse(Zend_Json_Server_Response $response)</methodname>:
                        Set the response object for the server to utilize.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getResponse()</methodname>: Retrieve the
                        response object used by the server.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setAutoEmitResponse($flag)</methodname>:
                        Indicate whether the server should automatically emit
                        the response and all headers; by default, this is
                        <constant>TRUE</constant>.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>autoEmitResponse()</methodname>: Determine if
                        auto-emission of the response is enabled.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getServiceMap()</methodname>: Retrieve the
                        service map description in the form of a
                        <classname>Zend_Json_Server_Smd</classname> object
                    </para>
                </listitem>
            </itemizedlist>
        </sect3>

        <sect3 id="zend.json.server.details.zendjsonserverrequest">
            <title>Zend_Json_Server_Request</title>

            <para>
                The JSON-RPC request environment is encapsulated in the
                <classname>Zend_Json_Server_Request</classname> object. This object allows
                you to set necessary portions of the JSON-RPC request, including
                the request ID, parameters, and JSON-RPC specification version.
                It has the ability to load itself via <acronym>JSON</acronym> or a set of options,
                and can render itself as <acronym>JSON</acronym> via the
                <methodname>toJson()</methodname> method.
            </para>

            <para>
                The request object has the following methods available:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        <methodname>setOptions(array $options)</methodname>: Specify
                        object configuration. <varname>$options</varname> may contain
                        keys matching any 'set' method:
                        <methodname>setParams()</methodname>, <methodname>setMethod()</methodname>,
                        <methodname>setId()</methodname>, and
                        <methodname>setVersion()</methodname>.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>addParam($value, $key = null)</methodname>: Add
                        a parameter to use with the method call. Parameters can be
                        just the values, or can optionally include the parameter name.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>addParams(array $params)</methodname>: Add
                        multiple parameters at once; proxies to
                        <methodname>addParam()</methodname>
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setParams(array $params)</methodname>: Set all
                        parameters at once; overwrites any existing parameters.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getParam($index)</methodname>: Retrieve a
                        parameter by position or name.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getParams()</methodname>: Retrieve all parameters at once.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setMethod($name)</methodname>: Set the method to call.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getMethod()</methodname>: Retrieve the method
                        that will be called.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>isMethodError()</methodname>: Determine whether
                        or not the request is malformed and would result in an error.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setId($name)</methodname>: Set the request
                        identifier (used by the client to match requests to responses).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getId()</methodname>: Retrieve the request identifier.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setVersion($version)</methodname>: Set the
                        JSON-RPC specification version the request conforms to.
                        May be either '1.0' or '2.0'.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getVersion()</methodname>: Retrieve the JSON-RPC
                        specification version used by the request.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>loadJson($json)</methodname>: Load the request
                        object from a <acronym>JSON</acronym> string.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toJson()</methodname>: Render the request as
                        a <acronym>JSON</acronym> string.
                    </para>
                </listitem>
            </itemizedlist>

            <para>
                An <acronym>HTTP</acronym> specific version is available via
                <classname>Zend_Json_Server_Request_Http</classname>. This class will
                retrieve the request via <filename>php://input</filename>, and allows access to the
                raw <acronym>JSON</acronym> via the <methodname>getRawJson()</methodname> method.
            </para>
        </sect3>

        <sect3 id="zend.json.server.details.zendjsonserverresponse">
            <title>Zend_Json_Server_Response</title>

            <para>
                The JSON-RPC response payload is encapsulated in the
                <classname>Zend_Json_Server_Response</classname> object. This object allows
                you to set the return value of the request, whether or not the
                response is an error, the request identifier, the JSON-RPC
                specification version the response conforms to, and optionally
                the service map.
            </para>

            <para>
                The response object has the following methods available:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        <methodname>setResult($value)</methodname>: Set the response result.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getResult()</methodname>: Retrieve the response result.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setError(Zend_Json_Server_Error $error)</methodname>: Set an
                        error object. If set, this will be used as the response when serializing to
                        <acronym>JSON</acronym>.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getError()</methodname>: Retrieve the error object, if any.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>isError()</methodname>: Whether or not the response is an error
                        response.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setId($name)</methodname>: Set the request identifier (so the
                        client may match the response with the original request).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getId()</methodname>: Retrieve the request identifier.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setVersion($version)</methodname>: Set the
                        JSON-RPC version the response conforms to.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getVersion()</methodname>: Retrieve the JSON-RPC
                        version the response conforms to.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toJson()</methodname>: Serialize the response to
                        <acronym>JSON</acronym>. If the response is an error response, serializes
                        the error object.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setServiceMap($serviceMap)</methodname>: Set the
                        service map object for the response.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getServiceMap()</methodname>: Retrieve the
                        service map object, if any.
                    </para>
                </listitem>
            </itemizedlist>

            <para>
                An <acronym>HTTP</acronym> specific version is available via
                <classname>Zend_Json_Server_Response_Http</classname>. This class will
                send the appropriate <acronym>HTTP</acronym> headers as well as serialize the
                response as <acronym>JSON</acronym>.
            </para>
        </sect3>

        <sect3 id="zend.json.server.details.zendjsonservererror">
            <title>Zend_Json_Server_Error</title>

            <para>
                JSON-RPC has a special format for reporting error conditions.
                All errors need to provide, minimally, an error message and error
                code; optionally, they can provide additional data, such as a
                backtrace.
            </para>

            <para>
                Error codes are derived from those recommended by <ulink
                    url="http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php">the
                    XML-RPC EPI project</ulink>. <classname>Zend_Json_Server</classname>
                appropriately assigns the code based on the error condition. For
                application exceptions, the code '-32000' is used.
            </para>

            <para>
                <classname>Zend_Json_Server_Error</classname> exposes the following
                methods:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        <methodname>setCode($code)</methodname>: Set the error code;
                        if the code is not in the accepted XML-RPC error code range,
                        -32000 will be assigned.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getCode()</methodname>: Retrieve the current error code.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setMessage($message)</methodname>: Set the error message.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getMessage()</methodname>: Retrieve the current error message.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setData($data)</methodname>: Set auxiliary data
                        further qualifying the error, such as a backtrace.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getData()</methodname>: Retrieve any current auxiliary error
                        data.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toArray()</methodname>: Cast the error to an
                        array. The array will contain the keys 'code', 'message', and 'data'.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toJson()</methodname>: Cast the error to a
                        JSON-RPC error representation.
                    </para>
                </listitem>
            </itemizedlist>
        </sect3>

        <sect3 id="zend.json.server.details.zendjsonserversmd">
            <title>Zend_Json_Server_Smd</title>

            <para>
                SMD stands for Service Mapping Description, a <acronym>JSON</acronym> schema that
                defines how a client can interact with a particular web service.
                At the time of this writing, the <ulink
                    url="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal">specification</ulink>
                has not yet been formally ratified, but it is in use already
                within Dojo toolkit as well as other JSON-RPC consumer clients.
            </para>

            <para>
                At its most basic, a Service Mapping Description indicates the
                method of transport (POST, <constant>GET</constant>, <acronym>TCP</acronym>/IP,
                etc), the request envelope type (usually based on the protocol of the server), the
                target <acronym>URL</acronym> of the service provider, and a map of services
                available. In the case of JSON-RPC, the service map is a list of
                available methods, which each method documenting the available
                parameters and their types, as well as the expected return value
                type.
            </para>

            <para>
                <classname>Zend_Json_Server_Smd</classname> provides an object oriented
                way to build service maps. At its most basic, you pass it
                metadata describing the service using mutators, and specify
                services (methods and functions).
            </para>

            <para>
                The service descriptions themselves are typically instances of
                <classname>Zend_Json_Server_Smd_Service</classname>; you can also pass all
                information as an array to the various service mutators in
                <classname>Zend_Json_Server_Smd</classname>, and it will instantiate a
                service object for you. The service objects contain information
                such as the name of the service (typically the function or
                method name), the parameters (names, types, and position), and
                the return value type. Optionally, each service can have its own
                target and envelope, though this functionality is rarely used.
            </para>

            <para>
                <classname>Zend_Json_Server</classname> actually does all of this behind
                the scenes for you, by using reflection on the attached classes
                and functions; you should create your own service maps only if
                you need to provide custom functionality that class and function
                introspection cannot offer.
            </para>

            <para>
                Methods available in <classname>Zend_Json_Server_Smd</classname> include:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        <methodname>setOptions(array $options)</methodname>: Setup
                        an SMD object from an array of options. All mutators
                        (methods beginning with 'set') can be used as keys.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setTransport($transport)</methodname>: Set the
                        transport used to access the service; only POST is currently supported.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getTransport()</methodname>: Get the current service transport.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setEnvelope($envelopeType)</methodname>: Set the
                        request envelope that should be used to access the
                        service. Currently, supports the constants
                        <constant>Zend_Json_Server_Smd::ENV_JSONRPC_1</constant> and
                        <constant>Zend_Json_Server_Smd::ENV_JSONRPC_2</constant>.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getEnvelope()</methodname>: Get the current request envelope.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setContentType($type)</methodname>: Set the
                        content type requests should use (by default, this is 'application/json').
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getContentType()</methodname>: Get the current
                        content type for requests to the service.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setTarget($target)</methodname>: Set the <acronym>URL</acronym>
                        endpoint for the service.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getTarget()</methodname>: Get the <acronym>URL</acronym>
                        endpoint for the service.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setId($id)</methodname>: Typically, this is the
                        <acronym>URL</acronym> endpoint of the service (same as the target).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getId()</methodname>: Retrieve the service ID
                        (typically the <acronym>URL</acronym> endpoint of the service).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setDescription($description)</methodname>: Set a
                        service description (typically narrative information
                        describing the purpose of the service).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getDescription()</methodname>: Get the service description.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setDojoCompatible($flag)</methodname>: Set a flag indicating
                        whether or not the SMD is compatible with Dojo toolkit. When
                        <constant>TRUE</constant>, the generated <acronym>JSON</acronym> SMD will
                        be formatted to comply with the format that Dojo's JSON-RPC client expects.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>isDojoCompatible()</methodname>: Returns the value of the
                        Dojo compatibility flag (<constant>FALSE</constant>, by default).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>addService($service)</methodname>: Add a service
                        to the map. May be an array of information to pass to
                        the constructor of
                        <classname>Zend_Json_Server_Smd_Service</classname>, or an
                        instance of that class.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>addServices(array $services)</methodname>: Add
                        multiple services at once.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setServices(array $services)</methodname>: Add
                        multiple services at once, overwriting any previously set services.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getService($name)</methodname>: Get a service by its name.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getServices()</methodname>: Get all attached services.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>removeService($name)</methodname>: Remove a
                        service from the map.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toArray()</methodname>: Cast the service map to an array.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toDojoArray()</methodname>: Cast the service map
                        to an array compatible with Dojo Toolkit.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toJson()</methodname>: Cast the service map to a
                        <acronym>JSON</acronym> representation.
                    </para>
                </listitem>
            </itemizedlist>

            <para>
                <classname>Zend_Json_Server_Smd_Service</classname> has the following
                methods:
            </para>

            <itemizedlist>
                <listitem>
                    <para>
                        <methodname>setOptions(array $options)</methodname>: Set
                        object state from an array. Any mutator (methods
                        beginning with 'set') may be used as a key and set via this method.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setName($name)</methodname>: Set the service
                        name (typically, the function or method name).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getName()</methodname>: Retrieve the service name.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setTransport($transport)</methodname>: Set the
                        service transport (currently, only transports supported
                        by <classname>Zend_Json_Server_Smd</classname> are allowed).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getTransport()</methodname>: Retrieve the current transport.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setTarget($target)</methodname>: Set the <acronym>URL</acronym>
                        endpoint of the service (typically, this will be the
                        same as the overall SMD to which the service is attached).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getTarget()</methodname>: Get the <acronym>URL</acronym>
                        endpoint of the service.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setEnvelope($envelopeType)</methodname>: Set the
                        service envelope (currently, only envelopes supported
                        by <classname>Zend_Json_Server_Smd</classname> are allowed).
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getEnvelope()</methodname>: Retrieve the service envelope type.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>addParam($type, array $options = array(), $order =
                            null)</methodname>: Add a parameter to the service. By default, only the
                        parameter type is necessary. However, you may also specify the order, as
                        well as options such as:
                    </para>

                    <itemizedlist>
                        <listitem>
                            <para>
                                <emphasis>name</emphasis>: the parameter name
                            </para>
                        </listitem>

                        <listitem>
                            <para>
                                <emphasis>optional</emphasis>: whether or not the parameter is
                                optional
                            </para>
                        </listitem>

                        <listitem>
                            <para>
                                <emphasis>default</emphasis>: a default value for the parameter
                            </para>
                        </listitem>

                        <listitem>
                            <para>
                                <emphasis>description</emphasis>: text describing the parameter
                            </para>
                        </listitem>
                    </itemizedlist>
                </listitem>

                <listitem>
                    <para>
                        <methodname>addParams(array $params)</methodname>: Add
                        several parameters at once; each param should be an assoc
                        array containing minimally the key 'type' describing the
                        parameter type, and optionally the key 'order'; any other
                        keys will be passed as <varname>$options</varname> to
                        <methodname>addOption()</methodname>.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setParams(array $params)</methodname>: Set many
                        parameters at once, overwriting any existing parameters.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getParams()</methodname>: Retrieve all currently set parameters.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>setReturn($type)</methodname>: Set the return
                        value type of the service.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>getReturn()</methodname>: Get the return value type of the
                        service.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toArray()</methodname>: Cast the service to an array.
                    </para>
                </listitem>

                <listitem>
                    <para>
                        <methodname>toJson()</methodname>: Cast the service to a
                        <acronym>JSON</acronym> representation.
                    </para>
                </listitem>
            </itemizedlist>
        </sect3>
    </sect2>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->
