Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // this is /application/bootstrap.php
- // define these global path constants here
- define('ROOT_PATH', dirname(dirname(__FILE__)));
- define('LIB_PATH', ROOT_PATH . '/library');
- define('APP_PATH', ROOT_PATH . '/application');
- define('VIEW_PATH', ROOT_PATH . '/application/views');
- define('MODEL_PATH', ROOT_PATH . '/application/models');
- define('LAYOUT_PATH', ROOT_PATH . '/application/layouts');
- define('CONTROLLER_PATH', ROOT_PATH . '/application/controllers');
- // do not use 'development' when live, instead use 'production'
- define('APP_ENV', 'development');
- // define the path for config.ini
- define('CONFIG_PATH', ROOT_PATH . '/config');
- // set the php include path
- set_include_path(
- APP_PATH . PATH_SEPARATOR .
- LIB_PATH . PATH_SEPARATOR .
- VIEW_PATH . PATH_SEPARATOR .
- MODEL_PATH . PATH_SEPARATOR .
- get_include_path()
- );
- // require Zend Loader
- require_once 'Zend/Loader.php';
- /**
- * Static Bootstrap class setup and initializes the application using static methods
- * @package Bootstrap
- * @author Atir Javid
- * @copyright Atir Javid
- * @license GNU General Public License (Open Source Software)
- * @method static runApplication() Run the application.
- * @method static setupApplicationEnvironment() Prepare by loading Zend lib, call setup methods (FrontController, View, Database etc.)
- * @method static setupFrontController() Get instance of Zend front controller, set basic options, specify default controller path.
- * @method static setupApplicationView() Get an instance of Zend view, renderer and set it as a view helper.
- * @method static setupApplicationDatabase() Load the DB config and default adapter of Zend_Db_Table.
- * @method static setupApplicationConfig() Setup the application's config.ini using Zend_Config_Ini.
- * @method static sendResponseHeader() Receive the response object and set the header before sending output.
- */
- class Bootstrap
- {
- /**
- * Stores the static instance of Front controller
- *
- * @var object
- */
- public static $fc = null;
- /**
- * Run the actual application and call outside the bootstrap class as a static method.
- *
- * @method runApplication()
- * @return void
- */
- public static function runApplication()
- {
- self::setupApplicationEnvironment();
- $response = self::$fc->dispatch();
- self::sendResponseHeader($response);
- }
- /**
- * Setup the environment for the application to run in.
- *
- * @method setupApplicationEnvironment()
- * @return void
- */
- public static function setupApplicationEnvironment()
- {
- date_default_timezone_set('America/New_York');
- self::setupFrontController();
- self::setupApplicationView();
- self::setupApplicationConfiguration();
- self::setupApplicationDatabase();
- }
- /**
- * Setup the applications Front Controller, throw exceptions based on environment condition, setup controller directory and register the class autoloading.
- *
- * @method setupFrontController()
- * @return void
- */
- public static function setupFrontController()
- {
- Zend_Loader::registerAutoload();
- self::$fc = Zend_Controller_Front::getInstance();
- if(APP_ENV !== "production")
- {
- error_reporting(E_ALL|E_STRICT|E_NOTICE);
- ini_set('display_errors', true);
- self::$fc->throwExceptions(false);
- }
- else
- {
- self::$fc->throwExceptions(true);
- ini_set('display_errors', false);
- }
- self::$fc->returnResponse(true);
- self::$fc->setControllerDirectory(CONTROLLER_PATH);
- }
- /**
- * Setup Zend_View, Zend_Layout, and renderer and doctype action helpers and set DOCTYPE XHTML1 STRICT.
- *
- * @method setupView()
- * @return void
- */
- public static function setupApplicationView()
- {
- $view = new Zend_View();
- $view->setEncoding('utf-8');
- $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
- Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
- $doctypeHelper = new Zend_View_Helper_Doctype();
- $doctypeHelper->doctype('XHTML1_STRICT');
- Zend_Layout::startMvc(
- array(
- 'layoutPath' => LAYOUT_PATH,
- 'layout' => 'main'
- )
- );
- }
- /**
- * Setup the config.ini file using Zend_Config
- *
- * @method
- * @return void
- */
- public static function setupApplicationConfiguration()
- {
- }
- /**
- * Setup the database from the connection settings in config.ini
- *
- * @method
- * @return void
- */
- public static function setupApplicationDatabase()
- {
- }
- /**
- * Sends the default response header containing the content type and encoding.
- *
- * @method sendResponseHeader()
- * @param string response header text (content type, encoding etc.)
- * @return void
- */
- public static function sendResponseHeader(Zend_Controller_Response_Http $response)
- {
- $response->setHeader('content-type', 'text/html; charset=UTF-8', true);
- $response->sendResponse();
- }
- }
- Bootstrap::runApplication();
Add Comment
Please, Sign In to add comment