1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
|
<?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:
-->
|