Previous Next

コア機能

ここではZend_Applicationのコアコンポーネントの すべてについて、APIのようにドキュメントをご覧いただけます。

Zend_Application

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.

Zend_Application options
Option Description
phpSettings

Array of php.ini settings to use. Keys should be the php.ini keys.

includePaths

Additional paths to prepend to the include_path. Should be an array of paths.

autoloaderNamespaces

Array of additional namespaces to register with the Zend_Loader_Autoloader instance.

bootstrap

Either the string path to the bootstrap class, or an array with elements for the 'path' and 'class' for the application bootstrap.

Note: Option names

Please note that option names are case insensitive.

Zend_Application Methods
Method Return Value Parameters Description
__construct($environment, $options = null) void
  • $environment: required,. String representing the current application environment. Typical strings might include "development", "testing", "qa", or "production", but will be defined by your organizational requirements.

  • $options: optional. Argument may be one of the following values:

    • String: path to a Zend_Config file to load as configuration for your application. $environment will be used to determine what section of the configuration to pull.

    • Array: associative array of configuration data for your application.

    • Zend_Config: configuration object instance.

Constructor. Arguments are as described, and will be used to set initial object state. An instance of Zend_Loader_Autoloader is registered during instantiation. Options passed to the constructor are passed to setOptions().

getEnvironment() string N/A

Retrieve the environment string passed to the constructor.

getAutoloader() Zend_Loader_Autoloader N/A

Retrieve the Zend_Loader_Autoloader instance registered during instantiation.

setOptions(array $options) Zend_Application
  • $options: required. An array of application options.

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 setPhpSettings(). (Option names are case insensitive.)

getOptions() array N/A

Retrieve all options used to initialize the object; could be used to cache Zend_Config options to a serialized format between requests.

hasOption($key) boolean
  • $key: String option key to lookup

Determine whether or not an option with the specified key has been registered. Keys are case insensitive.

getOption($key) mixed
  • $key: String option key to lookup

Retrieve the option value of a given key. Returns null if the key does not exist.

setPhpSettings(array $settings, $prefix = '') Zend_Application
  • $settings: required. Associative array of PHP INI settings.

  • $prefix: optional. String prefix with which to prepend option keys. Used internally to allow mapping nested arrays to dot-separated php.ini keys. In normal usage, this argument should never be passed by a user.

Set run-time php.ini settings. Dot-separated settings may be nested hierarchically (which may occur with INI Zend_Config files) via an array-of-arrays, and will still resolve correctly.

setAutoloaderNamespaces(array $namespaces) Zend_Application
  • $namespaces: required. Array of strings representing the namespaces to register with the Zend_Loader_Autoloader instance.

Register namespaces with the Zend_Loader_Autoloader instance.

setBootstrap($path, $class = null) Zend_Application
  • $path: required. May be either a Zend_Application_Bootstrap_Bootstrapper instance, a string path to the bootstrap class, an associative array of classname => filename, or an associative array with the keys 'class' and 'path'.

  • $class: optional. If $path is a string, $class may be specified, and should be a string class name of the class contained in the file represented by path.

getBootstrap() null | Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the registered bootstrap instance.

bootstrap() void N/A

Call the bootstrap's bootstrap() method to bootstrap the application.

run() void N/A

Call the bootstrap's run() method to dispatch the application.

Zend_Application_Bootstrap_Bootstrapper

Zend_Application_Bootstrap_Bootstrapper is the base interface all bootstrap classes must implement. The base functionality is aimed at configuration, identifying resources, bootstrapping (either individual resources or the entire application), and dispatching the application.

The following methods make up the definition of the interface.

Zend_Application_Bootstrap_Bootstrapper Interface
Method Return Value Parameters Description
__construct($application) void
  • $application: required. Should accept a Zend_Application or a Zend_Application_Bootstrap_Bootstrapper object as the sole argument.

Constructor. Accepts a single argument, which should be a Zend_Application object, or another bootstrap object.

setOptions(array $options) Zend_Application_Bootstrap_Bootstrapper
  • $options: required. Array of options to set.

Typically, any option that has a matching setter will invoke that setter; otherwise, the option will simply be stored for later retrieval.

getApplication() Zend_Application | Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the application/bootstrap object passed via the constructor.

getEnvironment() string N/A

Retrieve the environment string registered with the parent application/bootstrap object.

getClassResources() array N/A

Retrieve a list of available resource initializer names as defined in the class. This may be implementation specific.

bootstrap($resource = null) mixed
  • $resource: optional.

If $resource is empty, execute all bootstrap resources. If a string, execute that single resource; if an array, execute each resource in the array.

run() void N/A

Defines what application logic to run after bootstrapping.

Zend_Application_Bootstrap_ResourceBootstrapper

Zend_Application_Bootstrap_ResourceBootstrapper is an interface to use when a bootstrap class will be loading external resources -- i.e., one or more resources will not be defined directly in the class, but rather via plugins. It should be used in conjunction with Zend_Application_Bootstrap_Bootstrapper; Zend_Application_Bootstrap_BootstrapAbstract implements this functionality.

The following methods make up the definition of the interface.

Zend_Application_Bootstrap_ResourceBootstrapper Interface
Method Return Value Parameters Description
registerPluginResource($resource, $options = null) Zend_Application_Bootstrap_ResourceBootstrapper
  • $resource: required. A resource name or Zend_Application_Resource_Resource object.

  • $options: optional. An array or Zend_Config object to pass to the resource on instantiation.

Register a resource with the class, providing optional configuration to pass to the resource.

unregisterPluginResource($resource) Zend_Application_Bootstrap_ResourceBootstrapper
  • $resource: required. Name of a resource to unregister from the class.

Remove a plugin resource from the class.

hasPluginResource($resource) boolean
  • $resource: required. Name of the resource.

Determine if a specific resource has been registered with the class.

getPluginResource($resource) Zend_Application_Resource_Resource
  • $resource: required. Name of a resource to retrieve (string).

Retrieve a plugin resource instance by name.

getPluginResourceNames() array N/A

Retrieve a list of all registered plugin resource names.

setPluginLoader(Zend_Loader_PluginLoader_Interface $loader) Zend_Application_Bootstrap_ResourceBootstrapper
  • $loader: required. Plugin loader instance to use when resolving plugin names to classes.

Register a plugin loader instance to use when resolving plugin class names.

getPluginLoader() Zend_Loader_PluginLoader_Interface N/A

Retrieve the registered plugin loader.

Zend_Application_Bootstrap_BootstrapAbstract

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.

Zend_Application_Bootstrap_BootstrapAbstract Methods
Method Return Value Parameters Description
__construct($application) void
  • $application: required. Accepts either a Zend_Application or a Zend_Application_Bootstrap_Bootstrapper object as the sole argument.

Constructor. Accepts a single argument, which should be a Zend_Application object, or another bootstrap object.

setOptions(array $options) Zend_Application_Bootstrap_Bootstrapper
  • $options: required. Array of options to set.

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 setFoo() method, the option 'foo' would pass the value to that method.

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/filesystem path pairs. resources may be used to specify plugin resources to use, and should consist of plugin resource/instantiation options pairs.

getOption() array N/A

Returns all options registered via setOptions().

hasOption($key) boolean
  • $key: required. Option key to test.

Determine if an option key is present.

getOption($key) mixed
  • $key: required. Option key to retrieve.

Retrieve the value associated with an option key; returns null if no option is registered with that key.

setApplication(Zend_Application | Zend_Application_Bootstrap_Bootstrapper $application) Zend_Application_Bootstrap_BootstrapAbstract
  • $application: required.

Register the parent application/bootstrap object.

getApplication() Zend_Application | Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the application/bootstrap object passed via the constructor.

getEnvironment() string N/A

Retrieve the environment string registered with the parent application/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
  • $container, required. An object in which to store resources.

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
  • $name, required. Name of a resource to check.

When a resource method or plugin returns a value, it will be stored in the resource container (see getContainer() and setContainer(). This method will indicate whether or not a value for that resource has been set.

getResource($name) mixed
  • $name, required. Name of a resource to fetch.

When a resource method or plugin returns a value, it will be stored in the resource container (see getContainer() and setContainer(). This method will retrieve a resources from the container.

bootstrap($resource = null) mixed
  • $resource: optional.

If $resource is empty, execute all bootstrap resources. If a string, execute that single resource; if an array, execute each resource in the array.

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
  • $method: required. The method name to call.

  • $args: required. Array of arguments to use in the method call.

Provides convenience to bootstrapping individual resources by allowing you to call 'bootstrap<ResourceName>()' instead of using the bootstrap() method.

Zend_Application_Bootstrap_Bootstrap

Zend_Application_Bootstrap_BootstrapZend_Application_Bootstrap_BootstrapAbstract を具体的に実装したものです。 これは フロントコントローラリソース を登録し、デフォルトのモジュールが定義されていることと、 それからフロントコントローラをディスパッチすることを最初にチェックする run()メソッドという主要なフィーチャーです。

多くの場合、ブートストラップする必要性に応じて拡張するか、 このクラスを単純に使って、利用するリソースプラグインのリストを与えたいことでしょう。

Zend_Application_Resource_Resource

Zend_Application_Resource_Resource is an interface for plugin resources used with bootstrap classes implementing Zend_Application_Bootstrap_ResourceBootstrapper. Resource plugins are expected to allow configuration, be bootstrap aware, and implement a strategy pattern for initializing the resource.

Zend_Application_Resource_Resource Interface
Method Return Value Parameters Description
__construct($options = null) void
  • $options: optional. Options with which to set resource state.

The constructor should allow passing options with which to initialize state.

setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) Zend_Application_Resource_Resource
  • $bootstrap: required. Parent bootstrap initializing this resource.

Should allow registering the parent bootstrap object.

getBootstrap() Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the registered bootstrap instance.

setOptions(array $options) Zend_Application_Resource_Resource
  • $options: required. Options with which to set state.

Set resource state.

getOptions() array N/A

Retrieve registered options.

init() mixed N/A

Strategy pattern: run initialization of the resource.

Zend_Application_Resource_ResourceAbstract

Zend_Application_Resource_ResourceAbstract is an abstract class implementing Zend_Application_Resource_Resource, and is a good starting point for creating your own custom plugin resources.

Note: this abstract class does not implement the init() method; this is left for definition in concrete extensions of the class.

Zend_Application_Resource_ResourceAbstract Methods
Method Return Value Parameters Description
__construct($options = null) void
  • $options: optional. Options with which to set resource state.

The constructor should allow passing options with which to initialize state.

setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap) Zend_Application_Resource_ResourceAbstract
  • $bootstrap: required. Parent bootstrap initializing this resource.

Should allow registering the parent bootstrap object.

getBootstrap() Zend_Application_Bootstrap_Bootstrapper N/A

Retrieve the registered bootstrap instance.

setOptions(array $options) Zend_Application_Resource_ResourceAbstract
  • $options: required. Options with which to set state.

Set resource state.

getOptions() array N/A

Retrieve registered options.

Resource Names

When registering plugin resources, one issue that arises is how you should refer to them from the parent bootstrap class. There are three different mechanisms that may be used, depending on how you have configured the bootstrap and its plugin resources.

First, if your plugins are defined within a defined prefix path, you may refer to them simply by their "short name" -- i.e., the portion of the class name following the class prefix. As an example, the class "Zend_Application_Resource_View" may be referenced as simply "View", as the prefix path "ZenD_Application_Resource" is already registered. You may register them using the full class name or the short name:

$app = new Zend_Application(APPLICATION_ENV, array(
    'pluginPaths' => array(
        'My_Resource' => 'My/Resource/',
    ),
    'resources' => array(
        // if the following class exists:
        'My_Resource_View' => array(),

        // then this is equivalent:
        'View' => array(),
    ),
));

In each case, you can then bootstrap the resource and retrieve it later using the short name:

$bootstrap->bootstrap('view');
$view = $bootstrap->getResource('view');

Second, if no matching plugin path is defined, you may still pass a resource by the full class name. In this case, you can reference it using the resource's full class name:

$app = new Zend_Application(APPLICATION_ENV, array(
    'resources' => array(
        // This will load the standard 'View' resource:
        'View' => array(),

        // While this loads a resource with a specific class name:
        'My_Resource_View' => array(),
    ),
));

Obviously, this makes referencing the resource much more verbose:

$bootstrap->bootstrap('My_Resource_View');
$view = $bootstrap->getResource('My_Resource_View');

This brings us to the third option. You can specify an explicit name that a given resource class will register as. This can be done by adding a public $_explicitType property to the resource plugin class, with a string value; that value will then be used whenever you wish to reference the plugin resource via the bootstrap. As an example, let's define our own view class:

class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
{
    public $_explicitType = 'My_View';

    public function init()
    {
        // do some initialization...
    }
}

We can then bootstrap that resource or retrieve it by the name "My_View":

$bootstrap->bootstrap('My_View');
$view = $bootstrap->getResource('My_View');

Using these various naming approaches, you can override existing resources, add your own, mix multiple resources to achieve complex initialization, and more.

Previous Next
Introduction to Zend Framework
概要
インストール
Zend_Acl
導入
アクセス制御の洗練
高度な使用法
Zend_Amf
導入
Zend_Amf_Server
Zend_Application
導入
Zend_Application Quick Start
Theory of Operation
Examples
コア機能
利用できるリソースプラグイン
Zend_Auth
導入
データベースのテーブルでの認証
ダイジェスト認証
HTTP 認証アダプタ
LDAP 認証
Open ID 認証
Zend_Cache
導入
キャッシュの仕組み
Zend_Cache のフロントエンド
Zend_Cache のバックエンド
Zend_Captcha
導入
Captcha の方法
CAPTCHA アダプタ
Zend_CodeGenerator
導入
Zend_CodeGeneratorサンプル
Zend_CodeGeneratorリファレンス
Zend_Config
導入
動作原理
Zend_Config_Ini
Zend_Config_Xml
Zend_Config_Writer
Zend_Config_Writer
Zend_Console_Getopt
導入
Getopt の規則の宣言
オプションおよび引数の取得
Zend_Console_Getopt の設定
Zend_Controller
Zend_Controller クイックスタート
Zend_Controller の基本
フロントコントローラ
リクエストオブジェクト
標準のルータ
ディスパッチャ
アクションコントローラ
アクションヘルパー
レスポンスオブジェクト
プラグイン
モジュラーディレクトリ構造の規約の使用
MVC での例外
以前のバージョンからの移行
Zend_Currency
Zend_Currency について
通貨の操作方法
以前のバージョンからの移行
Zend_Date
導入
動作原理
基本メソッド
Zend_Date API の概要
日付の作成
日付関数全般用の定数
動作例
Zend_Db
Zend_Db_Adapter
Zend_Db_Statement
Zend_Db_Profiler
Zend_Db_Select
Zend_Db_Table
Zend_Db_Table_Row
Zend_Db_Table_Rowset
導入
Zend_Debug
変数の出力
Zend_Dojo
導入
Zend_Dojo_Data: dojo.data エンベロープ
Dojo ビューヘルパー
Dojoフォーム要素とデコレーター
Zend_Dom
導入
Zend_Dom_Query
Zend_Exception
例外の使用法
Zend_Feed
導入
フィードの読み込み
ウェブページからのフィードの取得
RSS フィードの使用
Atom フィードの使用
単一の Atom エントリの処理
フィードおよびエントリの構造の変更
独自のフィードクラスおよびエントリクラス
Zend_File
Zend_File_Transfer
Zend_File_Transfer 用のバリデータ
Filters for Zend_File_Transfer
以前のバージョンからの移行
Zend_Filter
導入
標準のフィルタクラス群
フィルタチェイン
フィルタの書き方
Zend_Filter_Input
Zend_Filter_Inflector
Zend_Form
Zend_Form
Zend_Form クイックスタート
Zend_Form_Element を用いたフォーム要素の作成
Zend_Form によるフォームの作成
Zend_Form_Decorator による独自のフォームマークアップの作成
Zend Framework に同梱されている標準のフォーム要素
Zend Framework に同梱されている標準のデコレータ
Zend_Form の国際化
Zend_Form の高度な使用法
Zend_Gdata
導入
AuthSub による認証
Using the Book Search Data API
ClientLogin による認証
Google Calendar の使用法
Google Documents List Data API の使用法
Using Google Health
Google Spreadsheets の使用法
Google Apps Provisioning の使用法
Google Base の使用法
Picasa Web Albums の使用法
YouTube Data API の使用法
Gdata の例外処理
Zend_Http
導入
Zend_Http_Client - 高度な使用法
Zend_Http_Client - 接続アダプタ
Zend_Http_Cookie および Zend_Http_CookieJar
Zend_Http_Response
Zend_InfoCard
導入
Zend_Json
導入
基本的な使用法
Zend_Json の高度な使用法
XML から JSON への変換
Zend_Json_Server - JSON-RPCサーバー
Zend_Layout
導入
Zend_Layout クイックスタート
Zend_Layout の設定オプション
Zend_Layout の高度な使用法
Zend_Ldap
導入
Zend_Loader
ファイルやクラスの動的な読み込み
The Autoloader
Resource Autoloaders
プラグインのロード
Zend_Locale
導入
Zend_Locale の使用法
正規化および地域化
日付および時刻の扱い
サポートするロケール
以前のバージョンからの移行
Zend_Log
概要
ライター
フォーマッタ
フィルタ
Zend_Mail
導入
SMTP 経由での送信
SMTP 接続による複数のメールの送信
異なる転送手段の使用
HTML メール
ファイルの添付
受信者の追加
MIME バウンダリの制御
追加のヘッダ
文字セット
エンコーディング
SMTP 認証
セキュアな SMTP トランスポート
メールメッセージの読み込み
Zend_Measure
導入
計測値の作成
計測値の出力
計測値の操作
計測値の型
Zend_Memory
概要
メモリマネージャ
メモリオブジェクト
Zend_Mime
Zend_Mime
Zend_Mime_Message
Zend_Mime_Part
Zend_Navigation
Introduction
画面
Containers
Zend_OpenId
導入
Zend_OpenId_Consumer の基本
Zend_OpenId_Provider
Zend_Paginator
導入
使用法
設定
高度な使用法
Zend_Pdf
導入
PDF ドキュメントの作成および読み込み
PDF ドキュメントへの変更内容の保存
ページの操作
描画
ドキュメントの情報およびメタデータ
Zend_Pdf モジュールの使用例
Zend_ProgressBar
Zend_ProgressBar
Zend_Reflection
導入
Zend_Reflectionサンプル
Zend_Reflectionリファレンス
Zend_Registry
レジストリの使用法
Zend_Rest
導入
Zend_Rest_Client
Zend_Rest_Server
Zend_Search_Lucene
概要
インデックスの構築
インデックスの検索
クエリ言語
クエリ作成用の API
文字セット
拡張性
Java Lucene との相互運用
応用
ベストプラクティス
Zend_Server
導入
Zend_Server_Reflection
Zend_Service
導入
Zend_Service_Akismet
Zend_Service_Amazon
Zend_Service_Amazon_Ec2
Zend_Service_Amazon_Ec2: Instances
Zend_Service_Amazon_Ec2: Windows Instances
Zend_Service_Amazon_Ec2: Reserved Instances
Zend_Service_Amazon_Ec2: CloudWatch Monitoring
Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)
Zend_Service_Amazon_Ec2: Elastic Block Stroage (EBS)
Zend_Service_Amazon_Ec2: Elastic IP Addresses
Zend_Service_Amazon_Ec2: Keypairs
Zend_Service_Amazon_Ec2: Regions and Availability Zones
Zend_Service_Amazon_Ec2: Security Groups
Zend_Service_Amazon_S3
Zend_Service_Audioscrobbler
Zend_Service_Delicious
Zend_Service_Flickr
Zend_Service_Nirvanix
Zend_Service_ReCaptcha
Zend_Service_Simpy
導入
Zend_Service_StrikeIron
Zend_Service_StrikeIron: バンドルされているサービス
Zend_Service_StrikeIron: 応用編
Zend_Service_Technorati
Zend_Service_Twitter
Zend_Service_Yahoo
Zend_Session
導入
基本的な使用法
高度な使用法
グローバルセッションの管理
Zend_Session_SaveHandler_DbTable
Zend_Soap
Zend_Soap_Server
Zend_Soap_Client
WSDLアクセッサ
自動検出
Zend_Tag
Introduction
Zend_Tag_Cloud
Zend_Test
導入
Zend_Test_PHPUnit
Zend_Text
Zend_Text_Figlet
Zend_Text_Table
Zend_TimeSync
導入
Zend_TimeSync の動作
Zend_Tool_Framework
Introduction
Using the CLI Tool
Architecture
Creating Providers to use with Zend_Tool_Framework
Shipped System Providers
Zend_Tool_Project
Zend_Tool_Project導入
Create A Project
Zend Tool Project Providers
Zend_Translate
導入
Zend_Translate のアダプタ
翻訳アダプタの使用法
以前のバージョンからの移行
Zend_Uri
Zend_Uri
Zend_Validate
導入
標準のバリデーションクラス群
バリデータチェイン
バリデータの書き方
検証メッセージ
Zend_Version
Zend Framework のバージョンの取得
Zend_View
導入
コントローラスクリプト
ビュースクリプト
ビューヘルパー
Zend_View_Abstract
以前のバージョンからの移行
Zend_Wildfire
Zend_Wildfire
Zend_XmlRpc
導入
Zend_XmlRpc_Client
Zend_XmlRpc_Server
Zend Framework のシステム要件
導入
Zend Framework PHP 標準コーディング規約
概要
PHP ファイルの書式
命名規約
コーディングスタイル
Zend Framework Performance Guide
導入
クラスの読み込み
Zend_Dbパフォーマンス
国際化(i18n)とローカライズ(l10n)
ビューのレンダリング
著作権に関する情報