|
|
@@ -0,0 +1,206 @@
|
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
|
+<!-- Reviewed: no -->
|
|
|
+<!-- EN-Revision: 16649 -->
|
|
|
+<sect2 id="zend.application.core-functionality.resource-resourceabstract">
|
|
|
+ <title>Zend_Application_Resource_ResourceAbstract</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <classname>Zend_Application_Resource_ResourceAbstract</classname>は
|
|
|
+ <link
|
|
|
+ linkend="zend.application.core-functionality.resource-resource">Zend_Application_Resource_Resource</link>を
|
|
|
+ 実装する抽象クラスで、
|
|
|
+ 独自のカスタム・プラグイン・リソースを作成し始めるために適しています。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ 注意: この抽象クラスは、<methodname>init()</methodname>メソッドを実装しません;
|
|
|
+ クラスを具体的に拡張する定義のために残されます。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <table id="zend.application.core-functionality.resource-resourceabstract.api">
|
|
|
+ <title>Zend_Application_Resource_ResourceAbstractメソッド</title>
|
|
|
+ <tgroup cols="4">
|
|
|
+ <thead>
|
|
|
+ <row>
|
|
|
+ <entry>メソッド</entry>
|
|
|
+ <entry>返り値</entry>
|
|
|
+ <entry>パラメータ</entry>
|
|
|
+ <entry>説明</entry>
|
|
|
+ </row>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <row>
|
|
|
+ <entry><methodname>__construct($options = null)</methodname></entry>
|
|
|
+ <entry><type>Void</type></entry>
|
|
|
+ <entry><itemizedlist>
|
|
|
+ <listitem><para>
|
|
|
+ <varname>$options</varname>: <emphasis>任意</emphasis>.
|
|
|
+ リソース状態を設定するオプション
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist></entry>
|
|
|
+ <entry><para>
|
|
|
+ 状態を初期化するためのオプションを、コンストラクタに渡すことができなければなりません。
|
|
|
+ </para></entry>
|
|
|
+ </row>
|
|
|
+
|
|
|
+ <row>
|
|
|
+ <entry>
|
|
|
+ <methodname>setBootstrap(Zend_Application_Bootstrap_Bootstrapper
|
|
|
+ $bootstrap)</methodname>
|
|
|
+ </entry>
|
|
|
+ <entry><classname>Zend_Application_Resource_ResourceAbstract</classname></entry>
|
|
|
+ <entry><itemizedlist>
|
|
|
+ <listitem><para>
|
|
|
+ <varname>$bootstrap</varname>: <emphasis>必須</emphasis>.
|
|
|
+ このリソースを初期化する親ブートストラップ
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist></entry>
|
|
|
+ <entry><para>
|
|
|
+ 親ブートストラップ・オブジェクトを登録できるようにしなければいけません。
|
|
|
+ </para></entry>
|
|
|
+ </row>
|
|
|
+
|
|
|
+ <row>
|
|
|
+ <entry><methodname>getBootstrap()</methodname></entry>
|
|
|
+ <entry><classname>Zend_Application_Bootstrap_Bootstrapper</classname></entry>
|
|
|
+ <entry>N/A</entry>
|
|
|
+ <entry><para>
|
|
|
+ 登録されたブートストラップ・インスタンスを取得します。
|
|
|
+ </para></entry>
|
|
|
+ </row>
|
|
|
+
|
|
|
+ <row>
|
|
|
+ <entry><methodname>setOptions(array $options)</methodname></entry>
|
|
|
+ <entry><classname>Zend_Application_Resource_ResourceAbstract</classname></entry>
|
|
|
+ <entry><itemizedlist>
|
|
|
+ <listitem><para>
|
|
|
+ <varname>$options</varname>: <emphasis>必須</emphasis>.
|
|
|
+ 状態を設定するオプション
|
|
|
+ </para></listitem>
|
|
|
+ </itemizedlist></entry>
|
|
|
+ <entry><para>
|
|
|
+ リソースの状態を設定。
|
|
|
+ </para></entry>
|
|
|
+ </row>
|
|
|
+
|
|
|
+ <row>
|
|
|
+ <entry><methodname>getOptions()</methodname></entry>
|
|
|
+ <entry><type>Array</type></entry>
|
|
|
+ <entry>N/A</entry>
|
|
|
+ <entry><para>
|
|
|
+ 登録されたオプションを取得
|
|
|
+ </para></entry>
|
|
|
+ </row>
|
|
|
+ </tbody>
|
|
|
+ </tgroup>
|
|
|
+ </table>
|
|
|
+
|
|
|
+ <sect3 id="zend.application.core-functionality.resource-resourceabstract.names">
|
|
|
+ <title>リソース名</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ プラグイン・リソースを登録するときに起きる問題の一つは、
|
|
|
+ どのように親ブートストラップ・クラスからそれらを参照すべきかということです。
|
|
|
+ 利用されるかもしれない3通りの異なる手法があります。
|
|
|
+ そして、ブートストラップとそのプラグイン・リソースを構成した方法によって決まります。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ 最初に、プラグインが定義済みのプレフィックス・パスの中で定義されるなら、
|
|
|
+ それらの「短い名前」 ― すなわち、クラス・プレフィックスの後のクラス名の部分 ―
|
|
|
+ によって単純にそれらを参照するかもしれません。
|
|
|
+ 例えば、プレフィックス・パス "<classname>Zend_Application_Resource</classname>" がすでに登録されていたら、
|
|
|
+ クラス "<classname>Zend_Application_Resource_View</classname>" は単純に "View" として参照されるかもしれません。
|
|
|
+ 完全なクラス名または短い名前を用いてそれらを登録するかもしれません:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$app = new Zend_Application(APPLICATION_ENV, array(
|
|
|
+ 'pluginPaths' => array(
|
|
|
+ 'My_Resource' => 'My/Resource/',
|
|
|
+ ),
|
|
|
+ 'resources' => array(
|
|
|
+ // もし下記のクラスが存在すれば:
|
|
|
+ 'My_Resource_View' => array(),
|
|
|
+
|
|
|
+ // その場合、これは等価です:
|
|
|
+ 'View' => array(),
|
|
|
+ ),
|
|
|
+));
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ それならどの場合もリソースを起動できて、
|
|
|
+ 後で短い名前を使って、それを取得できます:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$bootstrap->bootstrap('view');
|
|
|
+$view = $bootstrap->getResource('view');
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ 第2には、マッチするプラグイン・パスが定義されないならば、
|
|
|
+ 完全なクラス名によってリソースを今まで通り渡すかもしれません:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$app = new Zend_Application(APPLICATION_ENV, array(
|
|
|
+ 'resources' => array(
|
|
|
+ // 標準の 'View' リソースをロードします:
|
|
|
+ 'View' => array(),
|
|
|
+
|
|
|
+ // 一方で固有のクラス名でリソースをロードします:
|
|
|
+ 'My_Resource_View' => array(),
|
|
|
+ ),
|
|
|
+));
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ 明らかに、リソースの参照がもっと冗長になります:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$bootstrap->bootstrap('My_Resource_View');
|
|
|
+$view = $bootstrap->getResource('My_Resource_View');
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ これは、第3の選択肢です。
|
|
|
+ 与えられたリソースクラスが登録する、明示的な名前を指定できます。
|
|
|
+ これは public <varname>$_explicitType</varname>プロパティを
|
|
|
+ リソース・プラグイン・クラスに文字列値で加えることによって実現されます;
|
|
|
+ その場合、ブートストラップを通してプラグイン・リソースを参照したいときはいつでも、その値が使われます。
|
|
|
+ 例えば、独自のビュー・クラスを定義しましょう:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
|
|
|
+{
|
|
|
+ public $_explicitType = 'My_View';
|
|
|
+
|
|
|
+ public function init()
|
|
|
+ {
|
|
|
+ // 何らかの初期化実行...
|
|
|
+ }
|
|
|
+}
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ We can then bootstrap that resource or retrieve it by the name
|
|
|
+ その場合、そのリソースを起動するか、または名前 "<classname>My_View</classname>" によって
|
|
|
+ 取得できます:
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$bootstrap->bootstrap('My_View');
|
|
|
+$view = $bootstrap->getResource('My_View');
|
|
|
+]]></programlisting>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ これらのいろいろな命名方法を使用して、既存のリソースをオーバーライドできます。
|
|
|
+ そして、複雑な初期化を成し遂げるために、
|
|
|
+ 独自のものを追加したり、複数のリソースを混ぜたりすることなどができます。
|
|
|
+ </para>
|
|
|
+ </sect3>
|
|
|
+</sect2>
|