The bootstrap class

To complete our basic bootstrapping, we need to create the bootstrap class for

Zend_Application.

application/bootstrap/Bootstrap.php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

public $frontController;

protected function _initLocale() {}

protected function _initViewSettings() {}

To create a bootstrap class for zend_Application, we must subclass the zend_Application_Bootstrap_Bootstrap class. This class contains all the base functionality required for our bootstrap class. We call the class Bootstrap. This is the default name that zend_Application will look for when loading the bootstrap file.

We can also use a different name if required by using Zend_Application's bootstrap class configuration directive. To do this in our configuration file, we would use:

bootstrap.path = APPLICATION_PATH"/bootstrap/

Bootstrap.php" bootstrap.class = "MyBootstrapClass"

The Bootstrap class contains two methods, _initLocale() and _initviewSettings(), which will be called during the bootstrap process.

Bootstrap resource execution order

The order in which our Bootstrap Resources are executed is very important to us. For example, some parts of the bootstrap may depend on others, meaning we need to be able to control what is executed and when.

To handle dependencies between bootstrap resources, we use the bootstrap() method. By using this method, we can call any bootstrap resource registered to Zend_Application. For example, if view resource (_initViewSettings()) require that the frontcontroller resource be executed before it runs, we could add $this->bootstrap('frontcontroller'); inside the _initViewSettings() method's body. By doing this, we would make sure that the frontcontroller was ready before we configured our view. zend_Application will also make sure that resources are only ever called once. Therefore, we do not have to worry about multiple executions of bootstrap resources.

Zend_Application also has a "natural" order in which bootstrap resources are executed. First the resources within the bootstrap class are executed and then the registered bootstrap plugins are executed. All execution of both class resources and plugin resources are executed in FIFO (first in first out) order. Therefore, currently our bootstrap execution stack will be:

• ViewSettings class resource—_initViewSettings();

• Front Controller plugin resource

• View plugin resource

• Layout plugin resource

Bootstrap abstract class

The Zend_Application_Bootstrap_BootstrapAbstract class provides many methods that can help us with our bootstrapping process. Following are the main ones we should know about:

• bootstrap($resource = null): Calls the bootstrap resource(s)

• $resource null|array|string: Calls All|Multiple|single resource(s)

• getApplication(): Gets the Zend_Application instance

• getEnvironment(): Gets the application environment

• getOption($key): Get an option that was passed to Zend_Application $key string

• getOptions(): Get all options passed to Zend_Application

• hasOption($key): Check if an option exists $key string

• getClassResources(): Get an array of the Class Resource method names

• getPluginResources(): Get an array of Plugin Resources

• getPluginResource($resource): Get a single Plugin Resource instance $resource string—The Resource name

• hasPluginResource($resource): Check if a Plugin Resource is registered $resource string—The Resource name

Custom options

We can use custom options when instantiating Zend_Application. This means that we can pass in our own options that our resources can use through the options related methods.

Accessing Plugin Resource properties

If a Plugin Resource has data we need to access, then we can access it by getting the Resource Plugin instance using the getPluginResource() method, and then access its public properties.

+1 0

Average user rating: 5 stars out of 1 votes

Post a comment

  • Receive news updates via email from this site