ここではZend_Application
のコアコンポーネントの
すべてについて、APIのようにドキュメントをご覧いただけます。
Zend_Application
provides the base functionality of the
component, and the entry point to your Zend Framework application. It's
purpose is two-fold: to setup the PHP environment (including
autoloading), and to execute your application bootstrap.
Typically, you will pass all configuration to the
Zend_Application
constructor, but you can also configure
the object entirely using its own methods. This reference is intended to
illustrate both use cases.
表2 Zend_Application options
Option | Description |
---|---|
phpSettings |
Array of |
includePaths |
Additional paths to prepend to the include_path. Should be an array of paths. |
autoloaderNamespaces |
Array of additional namespaces to register with the
|
bootstrap |
Either the string path to the bootstrap class, or an array with elements for the 'path' and 'class' for the application bootstrap. |
Option names
Please note that option names are case insensitive.
表3 Zend_Application Methods
Method | Return Value | Parameters | Description |
---|---|---|---|
__construct($environment, $options = null)
|
Void |
|
Constructor. Arguments are as described, and will be
used to set initial object state. An instance of
|
getEnvironment() |
String | N/A |
Retrieve the environment string passed to the constructor. |
getAutoloader() |
Zend_Loader_Autoloader |
N/A |
Retrieve the |
setOptions(array $options) |
Zend_Application |
|
All options are stored internally, and calling the
method multiple times will merge options. Options
matching the various setter methods will be passed
to those methods. As an example, the option
"phpSettings" will then be passed to
|
getOptions() |
Array | N/A |
Retrieve all options used to initialize the object;
could be used to cache |
hasOption($key) |
Boolean |
|
Determine whether or not an option with the specified key has been registered. Keys are case insensitive. |
getOption($key) |
Mixed |
|
Retrieve the option value of a given key. Returns
|
setPhpSettings(array $settings, $prefix = '')
|
Zend_Application |
|
Set run-time |
setAutoloaderNamespaces(array $namespaces)
|
Zend_Application |
|
Register namespaces with the
|
setBootstrap($path, $class = null) |
Zend_Application |
|
|
getBootstrap() |
NULL |
Zend_Application_Bootstrap_Bootstrapper
|
N/A | Retrieve the registered bootstrap instance. |
bootstrap() |
Void | N/A |
Call the bootstrap's |
run() |
Void | N/A |
Call the bootstrap's |
Zend_Application_Bootstrap_Bootstrapper
は、
ブートストラップ・クラス全てで実装しなければならない基底インターフェースです。
基本的な機能として、構成、リソースの確認、起動(個々のリソースかまたはアプリケーション全て)、
及びアプリケーションのディスパッチを意図しています。
以下のメソッドで、インターフェースの定義が用意されています。
表4 Zend_Application_Bootstrap_Bootstrapperインタフェース
メソッド | 返り値 | パラメータ | 説明 |
---|---|---|---|
__construct($application) |
Void |
|
コンストラクタ。 |
setOptions(array $options) |
Zend_Application_Bootstrap_Bootstrapper |
|
一般的に、一致するセッターを持つどんな選択肢でも、そのセッターを起動します; これ以外の場合には、選択肢は単純に後の検索に備えてたくわえられます。 |
getApplication() |
Zend_Application |
Zend_Application_Bootstrap_Bootstrapper
|
N/A | コンストラクタによって渡されるアプリケーションまたはブートストラップ・オブジェクトを取得します。 |
getEnvironment() |
String | N/A | 親アプリケーションまたはブートストラップ・オブジェクトで登録された環境文字列を取得します。 |
getClassResources() |
Array | N/A | クラスで定義された、利用可能なりソース・イニシャライザ名のリストを取得します。 これは、固有の実装かもしれません。 |
bootstrap($resource = null) |
Mixed |
|
もし |
run() |
Void | N/A | 起動した後にどんなアプリケーション・ロジックを実行すべきか定義します。 |
Zend_Application_Bootstrap_ResourceBootstrapper
は、
ブートストラップ・クラスが外部リソースをロードしようとするとき、
使用するインタフェースです。
すなわち、一つ以上のリソースがクラスで直接定められず、むしろプラグインによって定められます。
それはZend_Application_Bootstrap_Bootstrapper
とともに使われなければなりません、
そして、Zend_Application_Bootstrap_BootstrapAbstract
がこの機能を実装します。
以下のメソッドで、インターフェースの定義が用意されています。
表5 Zend_Application_Bootstrap_ResourceBootstrapperインタフェース
メソッド | 返り値 | パラメータ | 説明 |
---|---|---|---|
registerPluginResource($resource, $options = null)
|
Zend_Application_Bootstrap_ResourceBootstrapper
|
|
クラスでリソースを登録します。 そして、リソースに渡すオプションの構成を提供します。 |
unregisterPluginResource($resource) |
Zend_Application_Bootstrap_ResourceBootstrapper
|
|
クラスからプラグイン・リソースを除去します |
hasPluginResource($resource) |
ブール値 |
|
指定したりソースがクラスに登録されているか判断します |
getPluginResource($resource) |
Zend_Application_Resource_Resource |
|
プラグイン・リソースのインスタンスを名前により取得 |
getPluginResourceNames() |
配列 | N/A | 登録された全てのプラグインリソースの名前の一覧を取得 |
setPluginLoader(Zend_Loader_PluginLoader_Interface
$loader)
|
Zend_Application_Bootstrap_ResourceBootstrapper
|
|
プラグインのクラス名を解決するときに使うプラグインローダーのインスタンスを登録 |
getPluginLoader() |
Zend_Loader_PluginLoader_Interface |
N/A | 登録されたプラグインローダーを取得 |
Zend_Application_Bootstrap_BootstrapAbstract
is an abstract class
which provides the base functionality of a common bootstrap. It implements
both
Zend_Application_Bootstrap_Bootstrapper
and
Zend_Application_Bootstrap_ResourceBootstrapper
.
表6 Zend_Application_Bootstrap_BootstrapAbstract Methods
Method | Return Value | Parameters | Description |
---|---|---|---|
__construct($application) |
Void |
|
Constructor. Accepts a single argument, which should be a
|
setOptions(array $options) |
Zend_Application_Bootstrap_Bootstrapper |
|
Any option that has a matching setter will
invoke that setter; otherwise, the option will simply be
stored for later retrieval. As an example, if your
extending class defined a Two additional, special options keys may also be used. pluginPaths may be used to specify prefix paths to plugin resources; it should be an array of class prefix to filesystem path pairs. resources may be used to specify plugin resources to use, and should consist of plugin resource to instantiation options pairs. |
getOptions() |
Array | N/A |
Returns all options registered via
|
hasOption($key) |
Boolean |
|
Determine if an option key is present. |
getOption($key) |
Mixed |
|
Retrieve the value associated with an option key; returns
|
setApplication(Zend_Application |
Zend_Application_Bootstrap_Bootstrapper $application)
|
Zend_Application_Bootstrap_BootstrapAbstract
|
|
Register the parent application or bootstrap object. |
getApplication() |
Zend_Application |
Zend_Application_Bootstrap_Bootstrapper
|
N/A |
Retrieve the application or bootstrap object passed via the constructor. |
getEnvironment() |
String | N/A |
Retrieve the environment string registered with the parent application or bootstrap object. |
getClassResources() |
Array | N/A |
Retrieve a list of available resource initializer names as defined in the class. This may be implementation specific. |
getContainer() |
Object | N/A |
Retrieves the container that stores resources. If no container is currently registered, it registers a Zend_Registry instance before returning it. |
setContainer($container) |
Zend_Application_Bootstrap_BootstrapAbstract
|
|
Provide a container in which to store resources. When a resource method or plugin returns a value, it will be stored in this container for later retrieval. |
hasResource($name) |
Boolean |
|
When a resource method or plugin returns a value, it
will be stored in the resource container (see
|
getResource($name) |
Mixed |
|
When a resource method or plugin returns a value, it
will be stored in the resource container (see
|
bootstrap($resource = null) |
Mixed |
|
If This method can be used to run individual bootstraps either defined in the class itself or via resource plugin classes. A resource defined in the class will be run in preference over a resource plugin in the case of naming conflicts. |
run() |
Void | N/A |
Defines what application logic to run after bootstrapping. |
__call($method, $args) |
Mixed |
|
Provides convenience to bootstrapping individual
resources by allowing you to call
'bootstrap<ResourceName>()' instead of using the
|
Zend_Application_Bootstrap_Bootstrap
は
Zend_Application_Bootstrap_BootstrapAbstract
を具体的に実装したものです。
これは
フロントコントローラリソース
を登録し、デフォルトのモジュールが定義されていることと、
それからフロントコントローラをディスパッチすることを最初にチェックする
run()
メソッドという主要なフィーチャーです。
多くの場合、ブートストラップする必要性に応じて拡張するか、 このクラスを単純に使って、利用するリソースプラグインのリストを与えたいことでしょう。
さらに、このブートストラップ実装により、 そのツリーに位置するリソースに対する "namespace" またはクラス接頭辞を指定できるようになります。 それにより、様々なアプリケーション・リソースをオートローディングできるようになります。 基本的に、それは Zend_Application_Module_Autoloader オブジェクトのインスタンスを生成します。 そして引数として、要求された名前空間およびブートストラップのディレクトリを提示します。 "appnamespace" 構成オプションに名前空間を提示することにより、この機能を使用可能にできるでしょう。 INI 例としては、
appnamespace = "Application"
または XMLで、
<appnamespace>Application</appnamespace>
デフォルトでは、Zend_Tool
は、
"Application" 変数でこのオプションを有効にします。
あるいは、ブートストラップ・クラスの $_appNamespace
プロパティを適切な値で簡単に定義できます。
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected $_appNamespace = 'Application'; }
Zend_Application_Resource_Resource
は、
Zend_Application_Bootstrap_ResourceBootstrapper
を実装する
ブートストラップ・クラスで使われるプラグイン・リソースのためのインターフェースです。
プラグイン・リソースでは、構成を可能にし、ブートストラップを認識し、
そして、リソースを初期化するためのストラテジー・パターンを実装するよう、
期待されます。
表7 Zend_Application_Resource_Resourceインターフェース
メソッド | 返り値 | パラメータ | 説明 |
---|---|---|---|
__construct($options = null) |
Void |
|
状態を初期化するためのオプションを、コンストラクタに渡すことができなければなりません。 |
setBootstrap(Zend_Application_Bootstrap_Bootstrapper
$bootstrap)
|
Zend_Application_Resource_Resource |
|
親ブートストラップ・オブジェクトを登録できるようにしなければいけません。 |
getBootstrap() |
Zend_Application_Bootstrap_Bootstrapper |
N/A | 登録されたブートストラップ・インスタンスを取得します。 |
setOptions(array $options) |
Zend_Application_Resource_Resource |
|
リソースの状態を設定。 |
getOptions() |
Array | N/A | 登録されたオプションを取得 |
init() |
Mixed | N/A | ストラテジー・パターン: リソースの初期化を実行。 |
Zend_Application_Resource_ResourceAbstract
は
Zend_Application_Resource_Resourceを
実装する抽象クラスで、
独自のカスタム・プラグイン・リソースを作成し始めるために適しています。
注意: この抽象クラスは、init()
メソッドを実装しません;
クラスを具体的に拡張する定義のために残されます。
表8 Zend_Application_Resource_ResourceAbstractメソッド
メソッド | 返り値 | パラメータ | 説明 |
---|---|---|---|
__construct($options = null) |
Void |
|
状態を初期化するためのオプションを、コンストラクタに渡すことができなければなりません。 |
setBootstrap(Zend_Application_Bootstrap_Bootstrapper
$bootstrap)
|
Zend_Application_Resource_ResourceAbstract |
|
親ブートストラップ・オブジェクトを登録できるようにしなければいけません。 |
getBootstrap() |
Zend_Application_Bootstrap_Bootstrapper |
N/A | 登録されたブートストラップ・インスタンスを取得します。 |
setOptions(array $options) |
Zend_Application_Resource_ResourceAbstract |
|
リソースの状態を設定。 |
getOptions() |
Array | N/A | 登録されたオプションを取得 |
プラグイン・リソースを登録するときに起きる問題の一つは、 どのように親ブートストラップ・クラスからそれらを参照すべきかということです。 利用されるかもしれない3通りの異なる手法があります。 そして、ブートストラップとそのプラグイン・リソースを構成した方法によって決まります。
最初に、プラグインが定義済みのプレフィックス・パスの中で定義されるなら、
それらの「短い名前」 ― すなわち、クラス・プレフィックスの後のクラス名の部分 ―
によって単純にそれらを参照するかもしれません。
例えば、プレフィックス・パス "Zend_Application_Resource
" がすでに登録されていたら、
クラス "Zend_Application_Resource_View
" は単純に "View" として参照されるかもしれません。
完全なクラス名または短い名前を用いてそれらを登録するかもしれません:
$app = new Zend_Application(APPLICATION_ENV, array( 'pluginPaths' => array( 'My_Resource' => 'My/Resource/', ), 'resources' => array( // もし下記のクラスが存在すれば: 'My_Resource_View' => array(), // その場合、これは等価です: 'View' => array(), ), ));
それならどの場合もリソースを起動できて、 後で短い名前を使って、それを取得できます:
$bootstrap->bootstrap('view'); $view = $bootstrap->getResource('view');
第2には、マッチするプラグイン・パスが定義されないならば、 完全なクラス名によってリソースを今まで通り渡すかもしれません:
$app = new Zend_Application(APPLICATION_ENV, array( 'resources' => array( // 標準の 'View' リソースをロードします: 'View' => array(), // 一方で固有のクラス名でリソースをロードします: 'My_Resource_View' => array(), ), ));
明らかに、リソースの参照がもっと冗長になります:
$bootstrap->bootstrap('My_Resource_View'); $view = $bootstrap->getResource('My_Resource_View');
これは、第3の選択肢です。
与えられたリソースクラスが登録する、明示的な名前を指定できます。
これは public $_explicitType
プロパティを
リソース・プラグイン・クラスに文字列値で加えることによって実現されます;
その場合、ブートストラップを通してプラグイン・リソースを参照したいときはいつでも、その値が使われます。
例えば、独自のビュー・クラスを定義しましょう:
class My_Resource_View extends Zend_Application_Resource_ResourceAbstract { public $_explicitType = 'My_View'; public function init() { // 何らかの初期化実行... } }
その場合、そのリソースを起動するか、または名前 "My_View
" によって
取得できます:
$bootstrap->bootstrap('My_View'); $view = $bootstrap->getResource('My_View');
これらのいろいろな命名方法を使用して、既存のリソースをオーバーライドできます。 そして、複雑な初期化を成し遂げるために、 独自のものを追加したり、複数のリソースを混ぜたりすることなどができます。