Getting an MVC application configured and ready to dispatch has required an increasing amount of code as more features become available: setting up the database, configuring your view and view helpers, configuring your layouts, registering plugins, registering action helpers, and more.
Additionally, you will often want to reuse the same code to bootstrap your tests, a cronjob, or a service script. While it's possible to simply include your bootstrap script, oftentimes there are initializations that are environment specific – you may not need the MVC for a cronjob, or just the DB layer for a service script.
Zend_Application aims to make this easier and to
promote reuse by encapsulating bootstrapping into OOP paradigms.
Zend_Application is broken into three realms:
Zend_Application: loads the PHP environment, including include_paths and autoloading, and instantiates the requested bootstrap class.
Zend_Application_Bootstrap: provides interfaces for bootstrap classes.
Zend_Application_Bootstrap_Bootstrapprovides common functionality for most bootstrapping needs, including dependency checking algorithms and the ability to load bootstrap resources on demand.
Zend_Application_Resourceprovides an interface for standard bootstrapping resources that can be loaded on demand by a bootstrap instance, as well as several default resource implementations.
Developers create a bootstrap class for their application, extending
Zend_Application_Bootstrap_Bootstrap or implementing (minimally)
Zend_Application_Bootstrap_Bootstrapper. The entry point
public/index.php) will load
Zend_Application, and instantiate it by passing:
The current environment
Options for bootstrapping
The bootstrap options include the path to the file containing the bootstrap class and optionally:
Any extra include_paths to set
Any additional autoloader namespaces to register
php.inisettings to initialize
The class name for the bootstrap class (if not "Bootstrap")
Resource prefix to path pairs to use
Any resources to use (by class name or short name)
Additional path to a configuration file to load
Additional configuration options
Options may be an array, a
Zend_Config object, or the path
to a configuration file.