|
|
@@ -0,0 +1,719 @@
|
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
|
+<!-- Reviewed: no -->
|
|
|
+<!-- EN-Revision: 15807 -->
|
|
|
+<sect1 id="zend.json.server">
|
|
|
+ <title>Zend_Json_Server - JSON-RPCサーバー</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Json_Server</classname>は<ulink
|
|
|
+ url="http://groups.google.com/group/json-rpc/">JSON-RPC</ulink>
|
|
|
+ サーバー実装です。それは
|
|
|
+ <ulink url="http://groups.google.com/group/json-rpc/web/json-rpc-1-2-proposal">バージョン 2 仕様</ulink>
|
|
|
+ と同様に
|
|
|
+ <ulink url="http://json-rpc.org/wiki/specification">JSON-RPCバージョン 1 仕様</ulink>
|
|
|
+ の両方をサポートします;
|
|
|
+ それは、サービスのメタデータをサービス利用者に提供するために、
|
|
|
+ <ulink url="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal">サービス
|
|
|
+ マッピング定義 (SMD) 仕様</ulink>の
|
|
|
+ PHP実装を提供します。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ JSON-RPCは、軽量なリモート・プロシージャ呼出しプロトコルです。
|
|
|
+ そのプロトコルでは、JSONをそのメッセージのエンベロープのために利用します。
|
|
|
+ このJSON-RPC実装はPHPの<ulink
|
|
|
+ url="http://us.php.net/manual/en/function.soap-soapserver-construct.php">SoapServer</ulink>
|
|
|
+ APIに従います。
|
|
|
+ このことにより典型的状況では、簡単に下記のことができます:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para>サーバーオブジェクトのインスタンス化</para></listitem>
|
|
|
+ <listitem><para>一つ以上の関数やクラス/オブジェクトをサーバーオブジェクトに配置</para></listitem>
|
|
|
+ <listitem><para>リクエストの handle()</para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Json_Server</classname>は
|
|
|
+ どんな付属のクラスまたは関数でも<xref linkend="zend.server.reflection" />Reflectionを実行することを利用します。
|
|
|
+ また、SMDと実施するメソッド呼び出しのシグナチュアとの両方をビルドするためにその情報を使います。
|
|
|
+ そのように、それはどんな付属の関数またはクラス・メソッドでも完全なPHP docblock文書を最小限、持つ命令文です:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para>パラメータとそれらで期待される変数の型の全て</para></listitem>
|
|
|
+ <listitem><para>戻り値変数の型</para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Json_Server</classname>はこの時だけPOSTリクエストをリスンします;
|
|
|
+ 幸いにも、この文書の時点では、ワイルドなJSON-RPC実装の大半は、
|
|
|
+ そのようにリクエストをポストするだけです。
|
|
|
+ 次の例で示されるように、
|
|
|
+ リクエストの処理だけではなく、サービスSMDの配信の両方で
|
|
|
+ 同じサーバーエンドポイントを簡単に利用できるようにします。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <example id="zend.json.server.usage">
|
|
|
+ <title>Zend_Json_Server利用方法</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ 最初に、JSON-RPCサーバーによって公開したいクラスを定義しましょう。
|
|
|
+ そのクラスを 'Calculator' とし、
|
|
|
+ 'add'、'subtract'、'multiply' 及び 'divide'メソッドを定義します:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+/**
|
|
|
+ * Calculator - JSON-RPCを通じて公開するサンプル・クラス。
|
|
|
+ */
|
|
|
+class Calculator
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 2つの変数の合計を返します
|
|
|
+ *
|
|
|
+ * @param int $x
|
|
|
+ * @param int $y
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function add($x, $y)
|
|
|
+ {
|
|
|
+ return $x + $y;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2つの変数の差を返します
|
|
|
+ *
|
|
|
+ * @param int $x
|
|
|
+ * @param int $y
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function subtract($x, $y)
|
|
|
+ {
|
|
|
+ return $x - $y;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2つの変数の積を返します
|
|
|
+ *
|
|
|
+ * @param int $x
|
|
|
+ * @param int $y
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function multiply($x, $y)
|
|
|
+ {
|
|
|
+ return $x * $y;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2つの変数の除算結果を返します
|
|
|
+ *
|
|
|
+ * @param int $x
|
|
|
+ * @param int $y
|
|
|
+ * @return float
|
|
|
+ */
|
|
|
+ public function divide($x, $y)
|
|
|
+ {
|
|
|
+ return $x / $y;
|
|
|
+ }
|
|
|
+}
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ それぞれのメソッドで戻り値のための項目だけでなく、
|
|
|
+ それぞれのパラメータとその型を示す項目を持つdocblockを持つことに注意してください。
|
|
|
+ それに関しては、Zend Frameworkで<classname>Zend_Json_Server</classname>や
|
|
|
+ その他のいずれのサーバー構成要素を利用するときでも、これは<emphasis>絶対重要</emphasis>です。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ それでは、リクエストを処理するためのスクリプトを作成します:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$server = new Zend_Json_Server();
|
|
|
+
|
|
|
+// どのような機能が利用できるか示します:
|
|
|
+$server->setClass('Calculator');
|
|
|
+
|
|
|
+//リクエストを処理:
|
|
|
+$server->handle();
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ しかしながら、JSON-RPCクライアントがメソッドを自動検出することができるように、
|
|
|
+ SMDを返す問題を対象にしません。
|
|
|
+ それは、HTTPがメソッドをリクエストすることを確定し、
|
|
|
+ それから、若干のサーバー・メタデータを指定することによって達成されます:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$server = new Zend_Json_Server();
|
|
|
+$server->setClass('Calculator');
|
|
|
+
|
|
|
+if ('GET' == $_SERVER['REQUEST_METHOD']) {
|
|
|
+ // URLのエンドポイント及び使用するJSON-RPCのバージョンを示します:
|
|
|
+ $server->setTarget('/json-rpc.php')
|
|
|
+ ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
|
|
|
+
|
|
|
+ // SMDをつかみます
|
|
|
+ $smd = $server->getServiceMap();
|
|
|
+
|
|
|
+ // クライアントにSMDを返します
|
|
|
+ header('Content-Type: application/json');
|
|
|
+ echo $smd;
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+$server->handle();
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ DojoツールキットでJSON-RPCサーバーを利用するなら、
|
|
|
+ その2つがきちんと相互作用することを確実にするために、
|
|
|
+ 特別な互換性フラグをセットする必要もあります:
|
|
|
+ </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();
|
|
|
+
|
|
|
+ // Dojo互換を設定します:
|
|
|
+ $smd->setDojoCompatible(true);
|
|
|
+
|
|
|
+ header('Content-Type: application/json');
|
|
|
+ echo $smd;
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+$server->handle();
|
|
|
+]]></programlisting>
|
|
|
+ </example>
|
|
|
+
|
|
|
+ <sect2 id="zend.json.server.details">
|
|
|
+ <title>高度な詳細</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Json_Server</classname>の機能の大半が
|
|
|
+ <xref linkend="zend.json.server.usage" />で説明されており、
|
|
|
+ より高度な機能を利用できます。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <sect3 id="zend.json.server.details.zendjsonserver">
|
|
|
+ <title>Zend_Json_Server</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Json_Server</classname>は、
|
|
|
+ JSON-RPCを提供する中心的なクラスです;
|
|
|
+ それはすべてのリクエストを扱い、
|
|
|
+ レスポンス・ペイロードを返します。
|
|
|
+ 下記のメソッドがあります:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para><code>addFunction($function)</code>:
|
|
|
+ サーバーに関連するユーザーランド関数を指定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setClass($class)</code>:
|
|
|
+ サーバーに関連するクラスまたはオブジェクトを指定します;
|
|
|
+ そのアイテムのすべてのpublicメソッドは、
|
|
|
+ JSON-RPCメソッドに公開されます。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>fault($fault = null, $code = 404, $data =
|
|
|
+ null)</code>:
|
|
|
+ <classname>Zend_Json_Server_Error</classname>オブジェクトを生成して返します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>handle($request = false)</code>:
|
|
|
+ JSON-RPCリクエストを処理します;
|
|
|
+ 任意で、利用するための<classname>Zend_Json_Server_Request</classname>オブジェクトを渡します。
|
|
|
+ (デフォルトで1つ生成されます)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getFunctions()</code>:
|
|
|
+ 付属のメソッド全ての一覧を返します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setRequest(Zend_Json_Server_Request
|
|
|
+ $request)</code>:
|
|
|
+ サーバーのために使用するためのリクエストオブジェクトを指定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getRequest()</code>:
|
|
|
+ サーバーで使われるリクエストオブジェクトを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setResponse(Zend_Json_Server_Response
|
|
|
+ $response)</code>:
|
|
|
+ サーバーのために使用するためのレスポンスオブジェクトを設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getResponse()</code>:
|
|
|
+ サーバーで使われるレスポンスオブジェクトを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setAutoEmitResponse($flag)</code>:
|
|
|
+ サーバーがレスポンスとすべてのヘッダを自動的に送り出さなければならないかどうか示します;
|
|
|
+ デフォルトで、これはtrueです。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>autoEmitResponse()</code>:
|
|
|
+ レスポンスの自動送出が使用可能かどうか決定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getServiceMap()</code>:
|
|
|
+ <classname>Zend_Json_Server_Smd</classname>オブジェクトの形で
|
|
|
+ サービス・マップ記述を取得します
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+ </sect3>
|
|
|
+
|
|
|
+ <sect3 id="zend.json.server.details.zendjsonserverrequest">
|
|
|
+ <title>Zend_Json_Server_Request</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ JSON-RPCのリクエスト環境は、
|
|
|
+ <classname>Zend_Json_Server_Request</classname>オブジェクトにカプセル化されます。
|
|
|
+ このオブジェクトによって、リクエストIDやパラメータ、JSON-RPC仕様のバージョンを含む
|
|
|
+ JSON-RPCリクエストの必要な部分を設定することができます。
|
|
|
+ それにはJSONまたは一組のオプションによってそれ自体をロードする能力があって、
|
|
|
+ それ自体を<code>toJson()</code>メソッドによりJSONとして翻訳できます。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ リクエスト・オブジェクトでは、以下のメソッドを利用できます:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para><code>setOptions(array $options)</code>:
|
|
|
+ オブジェクトの設定を指定します。
|
|
|
+ <code>$options</code>は、どの 'set' メソッドにもマッチするキーを含むでしょう:
|
|
|
+ <code>setParams()</code>、<code>setMethod()</code>、
|
|
|
+ <code>setId()</code>及び<code>setVersion()</code>
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>addParam($value, $key = null)</code>:
|
|
|
+ メソッド呼び出しで使うパラメータを追加します。
|
|
|
+ パラメータは値そのものか、パラメータ名を任意に含むことができます。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>addParams(array $params)</code>:
|
|
|
+ 一度に複数のパラメータを追加します。
|
|
|
+ <code>addParam()</code>の代わりになります。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setParams(array $params)</code>:
|
|
|
+ 一度に全てのパラメータを設定します;
|
|
|
+ 既存の全てのパラメータを上書きします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getParam($index)</code>:
|
|
|
+ 位置または名前でパラメータを返します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getParams()</code>:
|
|
|
+ 一度に全てのパラメータを返します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setMethod($name)</code>:
|
|
|
+ 呼び出すメソッドを設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getMethod()</code>:
|
|
|
+ 呼び出されるメソッドを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>isMethodError()</code>:
|
|
|
+ リクエストが異常で、エラーに終わるかどうか決定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setId($name)</code>:
|
|
|
+ リクエスト識別子(クライアントでレスポンスにリクエストにマッチすることに使われる)をセットします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getId()</code>:
|
|
|
+ リクエストの識別子を取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setVersion($version)</code>:
|
|
|
+ リクエストが適合するJSON-RPC仕様バージョンを設定します。
|
|
|
+ おそらく '1.0' かまたは '2.0' のどちらかです。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getVersion()</code>:
|
|
|
+ リクエストで使われるJSON-RPC仕様バージョンを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>loadJson($json)</code>:
|
|
|
+ JSON文字列からリクエストオブジェクトを読み込みます。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toJson()</code>:
|
|
|
+ リクエストをJSONストリングに翻訳します。
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ HTTPに特有のバージョンは、
|
|
|
+ <classname>Zend_Json_Server_Request_Http</classname>を通して利用できます。
|
|
|
+ このクラスは<code>php://input</code>を通じてリクエストを取得し、
|
|
|
+ <code>getRawJson()</code>メソッドを通じて生のJSONへのアクセスを可能にします。
|
|
|
+ </para>
|
|
|
+ </sect3>
|
|
|
+
|
|
|
+ <sect3 id="zend.json.server.details.zendjsonserverresponse">
|
|
|
+ <title>Zend_Json_Server_Response</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <!-- TODO -->
|
|
|
+ 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>
|
|
|
+ レスポンス・オブジェクトでは、以下のメソッドを利用できます:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para><code>setResult($value)</code>:
|
|
|
+ レスポンス結果を設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getResult()</code>:
|
|
|
+ レスポンス結果を取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setError(Zend_Json_Server_Error
|
|
|
+ $error)</code>:
|
|
|
+ エラーオブジェクトを設定します。
|
|
|
+ 設定すると、JSONにシリアライズ化するとき、これがレスポンスとして使われます。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getError()</code>:
|
|
|
+ もしあれば、エラーオブジェクトを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>isError()</code>:
|
|
|
+ レスポンスがエラー・レスポンスであるかどうか。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setId($name)</code>:
|
|
|
+ リクエスト識別子
|
|
|
+ (クライアントはオリジナルのリクエストでレスポンスにマッチするかもしれません)
|
|
|
+ を設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getId()</code>:
|
|
|
+ リクエスト識別子を取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setVersion($version)</code>:
|
|
|
+ レスポンスが適合するJSON-RPCバージョンを設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getVersion()</code>:
|
|
|
+ レスポンスが適合するJSON-RPCバージョンを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toJson()</code>:
|
|
|
+ レスポンスがエラー・レスポンスで、エラー・オブジェクトをシリアライズ化するならば、
|
|
|
+ JSONに対するレスポンスをシリアライズ化します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setServiceMap($serviceMap)</code>:
|
|
|
+ サービス・マップ・オブジェクトをレスポンスに設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getServiceMap()</code>:
|
|
|
+ もしあれば、サービス・マップ・オブジェクトを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <!-- TODO -->
|
|
|
+ An HTTP specific version is available via
|
|
|
+ <classname>Zend_Json_Server_Response_Http</classname>. This class will
|
|
|
+ send the appropriate HTTP headers as well as serialize the
|
|
|
+ response as JSON.
|
|
|
+ </para>
|
|
|
+ </sect3>
|
|
|
+
|
|
|
+ <sect3 id="zend.json.server.details.zendjsonservererror">
|
|
|
+ <title>Zend_Json_Server_Error</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <!-- TODO -->
|
|
|
+ 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>
|
|
|
+ <!-- TODO -->
|
|
|
+ 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>
|
|
|
+ は以下のメソッドを公開します:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para><code>setCode($code)</code>:
|
|
|
+ エラーコードを設定します;
|
|
|
+ 認められたXML-RPCエラーコード範囲にそのコードがないならば、
|
|
|
+ -32000が割り当てられます。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getCode()</code>:
|
|
|
+ 現行のエラーコードを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setMessage($message)</code>:
|
|
|
+ エラーメッセージを設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getMessage()</code>:
|
|
|
+ 現行のエラーメッセージを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setData($data)</code>:
|
|
|
+ backtraceのような、
|
|
|
+ エラーを制限する補助データをさらにセットします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getData()</code>:
|
|
|
+ 現行のエラー補助データをいずれも取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toArray()</code>:
|
|
|
+ エラーを配列にキャストします。
|
|
|
+ 配列は 'code'や'message'及び'data'キーを含むでしょう。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toJson()</code>:
|
|
|
+ エラーをJSON-RPCエラー表現にキャストします。
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+ </sect3>
|
|
|
+
|
|
|
+ <sect3 id="zend.json.server.details.zendjsonserversmd">
|
|
|
+ <title>Zend_Json_Server_Smd</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <!-- TODO -->
|
|
|
+ SMD stands for Service Mapping Description, a JSON 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>
|
|
|
+ <!-- TODO -->
|
|
|
+ At its most basic, a Service Mapping Description indicates the
|
|
|
+ method of transport (POST, GET, TCP/IP, etc), the request
|
|
|
+ envelope type (usually based on the protocol of the server), the
|
|
|
+ target URL 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>
|
|
|
+ <!-- TODO -->
|
|
|
+ <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>
|
|
|
+ <!-- TODO -->
|
|
|
+ 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>
|
|
|
+ <!-- TODO -->
|
|
|
+ <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>
|
|
|
+ <classname>Zend_Json_Server_Smd</classname>での利用可能なメソッドを含みます:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para><code>setOptions(array $options)</code>:
|
|
|
+ オプション配列からSMDオブジェクトをセットアップします。
|
|
|
+ ミューテーターのすべてを、キーとして使うことができます。
|
|
|
+ (メソッドは 'set' で始まります)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setTransport($transport)</code>:
|
|
|
+ サービスにアクセスするために使われるトランスポートを設定します;
|
|
|
+ 現行では POST だけがサポートされます。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getTransport()</code>:
|
|
|
+ 現行のサービストランスポートを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setEnvelope($envelopeType)</code>:
|
|
|
+ サービスにアクセスするために使われるであろうリクエスト・エンベロープを設定します。
|
|
|
+ 現行では定数の
|
|
|
+ <classname>Zend_Json_Server_Smd::ENV_JSONRPC_1</classname>及び
|
|
|
+ <classname>Zend_Json_Server_Smd::ENV_JSONRPC_2</classname>をサポートします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getEnvelope()</code>:
|
|
|
+ 現行のリクエスト・エンベロープを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setContentType($type)</code>:
|
|
|
+ リクエストが使うであろうコンテンツタイプを設定します。
|
|
|
+ (デフォルトでは、これは 'application/json' です)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getContentType()</code>:
|
|
|
+ サービスにリクエストするための、現行のコンテンツタイプを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setTarget($target)</code>:
|
|
|
+ サービスのためのURLエンドポイントを設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getTarget()</code>:
|
|
|
+ サービスのためのURLエンドポイントを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setId($id)</code>:
|
|
|
+ 一般的に、(ターゲットと同じく)これはサービスのURLエンドポイントです。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getId()</code>:
|
|
|
+ サービスIDを取得します。
|
|
|
+ (一般的に、サービスのURLエンドポイントです)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setDescription($description)</code>:
|
|
|
+ サービスの定義を設定します。
|
|
|
+ (一般的に、サービスの目的を説明する物語の情報です)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getDescription()</code>:
|
|
|
+ サービスの定義を取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setDojoCompatible($flag)</code>:
|
|
|
+ SMDがDojoツールキットと互換かどうか示すフラグを設定します。
|
|
|
+ trueの場合、生成されたJSON SMDは、
|
|
|
+ DojoのJSON-RPCクライアントが期待する形式に従ってフォーマットされます。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>isDojoCompatible()</code>:
|
|
|
+ Dojo互換性フラグの値を返します。
|
|
|
+ (デフォルトではfalseです)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>addService($service)</code>:
|
|
|
+ マップするサービスを追加します。
|
|
|
+ <classname>Zend_Json_Server_Smd_Service</classname>のコンストラクタに渡す情報の配列か、
|
|
|
+ またはそのクラスのインスタンスでしょう。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>addServices(array $services)</code>:
|
|
|
+ 一度に複数のサービスを追加します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setServices(array $services)</code>:
|
|
|
+ 一度に複数のサービスを設定します。
|
|
|
+ 以前に設定されたサービスを全て上書きします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getService($name)</code>:
|
|
|
+ 名前でサービスを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getServices()</code>:
|
|
|
+ 付属のサービスを全て取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>removeService($name)</code>:
|
|
|
+ マップからサービスを除去します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toArray()</code>:
|
|
|
+ サービスマップを配列にキャストします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toDojoArray()</code>:
|
|
|
+ サービスマップをDojoツールキット互換の配列にキャストします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toJson()</code>:
|
|
|
+ サービスマップをJSON表現にキャストします。
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Json_Server_Smd_Service</classname>には下記のメソッドがあります:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <itemizedlist>
|
|
|
+ <listitem><para><code>setOptions(array $options)</code>:
|
|
|
+ 配列からオブジェクトの状態を設定します。
|
|
|
+ どのミューテーター(メソッドは 'set' で始まります)でもキーとして使われ、
|
|
|
+ このメソッドを通じて設定されるでしょう。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setName($name)</code>:
|
|
|
+ サービス名を設定します。
|
|
|
+ (一般的には、関数やメソッドの名前)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getName()</code>:
|
|
|
+ サービス名を取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setTransport($transport)</code>:
|
|
|
+ サービスのトランスポートを設定します。
|
|
|
+ (現行では、<classname>Zend_Json_Server_Smd</classname>によりサポートされる
|
|
|
+ トランスポートのみ許可されます)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getTransport()</code>: Retrieve the
|
|
|
+ current transport.</para></listitem>
|
|
|
+ <listitem><para><code>setTarget($target)</code>:
|
|
|
+ サービスのURLエンドポイントを設定します。
|
|
|
+ (一般的には、
|
|
|
+ <!-- TODO -->
|
|
|
+ this will be the
|
|
|
+ same as the overall SMD to which the service is
|
|
|
+ attached).</para></listitem>
|
|
|
+ <listitem><para><code>getTarget()</code>:
|
|
|
+ サービスのURLエンドポイントを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setEnvelope($envelopeType)</code>:
|
|
|
+ サービスのエンベロープタイプを設定します。
|
|
|
+ (現行では、<classname>Zend_Json_Server_Smd</classname>によりサポートされる
|
|
|
+ エンベロープのみ許可されます)
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getEnvelope()</code>:
|
|
|
+ サービスのエンベロープタイプを取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>addParam($type, array $options = array(),
|
|
|
+ $order = null)</code>:
|
|
|
+ <!-- TODO -->
|
|
|
+ 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>:
|
|
|
+ パラメータ名
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><emphasis>optional</emphasis>:
|
|
|
+ パラメータが任意か否か
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><emphasis>default</emphasis>:
|
|
|
+ パラメータの既定値
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><emphasis>description</emphasis>:
|
|
|
+ パラメータを記述するテキスト
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+ </listitem>
|
|
|
+ <listitem><para><code>addParams(array $params)</code>:
|
|
|
+ <!-- TODO -->
|
|
|
+ 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 <code>$options</code> to
|
|
|
+ <code>addOption()</code>.</para></listitem>
|
|
|
+ <listitem><para><code>setParams(array $params)</code>:
|
|
|
+ 一度に複数のパラメーターを設定します。
|
|
|
+ 既存のパラメータを全て上書きします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getParams()</code>:
|
|
|
+ 現行で設定されているパラメータを全て取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>setReturn($type)</code>:
|
|
|
+ サービスの返り値の型を設定します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>getReturn()</code>:
|
|
|
+ サービスの返り値の型を取得します。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toArray()</code>:
|
|
|
+ サービスを配列にキャストします。
|
|
|
+ </para></listitem>
|
|
|
+ <listitem><para><code>toJson()</code>:
|
|
|
+ サービスをJSON表現にキャストします。
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist>
|
|
|
+ </sect3>
|
|
|
+ </sect2>
|
|
|
+</sect1>
|
|
|
+<!--
|
|
|
+vim:se ts=4 sw=4 et:
|
|
|
+-->
|