Programmer's Reference Guide
| Examples |
コア機能
ここでは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.
| Option | Description |
|---|---|
phpSettings |
Array of php.ini settings to use. Keys should be the php.ini keys. |
includePaths |
Additional paths to prepend to the
|
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. |
注意: Option names
Please note that option names are case insensitive.
| 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
Zend_Loader_Autoloader is registered
during instantiation. Options passed to the
constructor are passed to |
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 |
|
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 Zend_Config options to a serialized format between requests. |
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 null if the key does not exist. |
setPhpSettings(array $settings, $prefix = '') |
Zend_Application |
|
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 |
|
Register namespaces with the Zend_Loader_Autoloader instance. |
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
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.
| Method | Return Value | Parameters | Description |
|---|---|---|---|
__construct($application) |
void |
|
Constructor. Accepts a single argument, which should be a Zend_Application object, or another bootstrap object. |
setOptions(array $options) |
Zend_Application_Bootstrap_Bootstrapper |
|
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 |
|
If |
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.
| Method | Return Value | Parameters | Description |
|---|---|---|---|
registerPluginResource($resource, $options =
null) |
Zend_Application_Bootstrap_ResourceBootstrapper |
|
Register a resource with the class, providing optional configuration to pass to the resource. |
unregisterPluginResource($resource) |
Zend_Application_Bootstrap_ResourceBootstrapper |
|
Remove a plugin resource from the class. |
hasPluginResource($resource) |
boolean |
|
Determine if a specific resource has been registered with the class. |
getPluginResource($resource) |
Zend_Application_Resource_Resource |
|
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 |
|
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.
| Method | Return Value | Parameters | Description |
|---|---|---|---|
__construct($application) |
void |
|
Constructor. Accepts a single argument, which should be a Zend_Application object, or another bootstrap object. |
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.
|
getOption() |
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 null if no option is registered with that key. |
setApplication(Zend_Application |
Zend_Application_Bootstrap_Bootstrapper $application) |
Zend_Application_Bootstrap_BootstrapAbstract |
|
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 |
|
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_Bootstrapは Zend_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.
| Method | Return Value | Parameters | Description |
|---|---|---|---|
__construct($options = null) |
void |
|
The constructor should allow passing options with which to initialize state. |
setBootstrap(Zend_Application_Bootstrap_Bootstrapper
$bootstrap)
|
Zend_Application_Resource_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 |
|
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.
| Method | Return Value | Parameters | Description |
|---|---|---|---|
__construct($options = null) |
void |
|
The constructor should allow passing options with which to initialize state. |
setBootstrap(Zend_Application_Bootstrap_Bootstrapper
$bootstrap)
|
Zend_Application_Resource_ResourceAbstract |
|
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 |
|
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.
| Examples |
