daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php // this is /application/bootstrap.php
  2.  
  3. // define these global path constants here
  4. define('ROOT_PATH', dirname(dirname(__FILE__)));
  5. define('LIB_PATH', ROOT_PATH . '/library');
  6. define('APP_PATH', ROOT_PATH . '/application');
  7. define('VIEW_PATH', ROOT_PATH . '/application/views');
  8. define('MODEL_PATH', ROOT_PATH . '/application/models');
  9. define('LAYOUT_PATH', ROOT_PATH . '/application/layouts');
  10. define('CONTROLLER_PATH', ROOT_PATH . '/application/controllers');
  11.  
  12. // do not use 'development' when live, instead use 'production'
  13. define('APP_ENV', 'development');
  14.  
  15. // define the path for config.ini
  16. define('CONFIG_PATH', ROOT_PATH . '/config');
  17.  
  18. // set the php include path
  19. set_include_path(
  20.       APP_PATH . PATH_SEPARATOR .
  21.       LIB_PATH . PATH_SEPARATOR .
  22.       VIEW_PATH . PATH_SEPARATOR .
  23.       MODEL_PATH . PATH_SEPARATOR .
  24.       get_include_path()
  25. );
  26.  
  27. // require Zend Loader
  28. require_once 'Zend/Loader.php';
  29.  
  30. /**
  31.  * Static Bootstrap class setup and initializes the application using static methods
  32.  *      @package Bootstrap
  33.  *      @author    Atir Javid
  34.  *      @copyright  Atir Javid
  35.  *      @license  GNU General Public License (Open Source Software)
  36.  *      @method  static runApplication() Run the application.
  37.  *      @method  static setupApplicationEnvironment()  Prepare by loading Zend lib, call setup methods (FrontController,  View, Database etc.)
  38.  *      @method  static setupFrontController() Get instance of Zend front controller, set basic options, specify default controller path.
  39.  *      @method  static setupApplicationView() Get an instance of Zend view, renderer and set it as a view helper.
  40.  *      @method  static setupApplicationDatabase() Load the DB config and default adapter of Zend_Db_Table.
  41.  *      @method  static setupApplicationConfig() Setup the application's config.ini using Zend_Config_Ini.
  42.  *      @method  static sendResponseHeader() Receive the response object and set the header before sending output.
  43.  */
  44.  
  45. class Bootstrap
  46. {
  47.     /**
  48.      * Stores the static instance of Front controller
  49.      *
  50.      * @var object  
  51.      */
  52.     public static $fc = null;
  53.     /**
  54.      * Run the actual application and call outside the bootstrap class as a static method.
  55.      *
  56.      * @method  runApplication()
  57.      * @return  void
  58.      */
  59.     public static function runApplication()
  60.     {
  61.         self::setupApplicationEnvironment();
  62.         $response = self::$fc->dispatch();
  63.         self::sendResponseHeader($response);
  64.     }
  65.     /**
  66.      * Setup the environment for the application to run in.  
  67.      *
  68.      * @method setupApplicationEnvironment()
  69.      * @return void
  70.      */
  71.     public static function setupApplicationEnvironment()
  72.     {
  73.        
  74.         date_default_timezone_set('America/New_York');
  75.         self::setupFrontController();
  76.         self::setupApplicationView();
  77.         self::setupApplicationConfiguration();
  78.         self::setupApplicationDatabase();
  79.        
  80.        
  81.     }
  82.  
  83.      /**
  84.      * Setup the applications Front Controller, throw exceptions based on environment condition, setup controller directory and register the class autoloading.  
  85.      *
  86.      * @method setupFrontController()
  87.      * @return void
  88.      */
  89.     public static function setupFrontController()
  90.     {
  91.         Zend_Loader::registerAutoload();
  92.         self::$fc = Zend_Controller_Front::getInstance();
  93.         if(APP_ENV !== "production")
  94.         {
  95.             error_reporting(E_ALL|E_STRICT|E_NOTICE);
  96.             ini_set('display_errors', true);
  97.             self::$fc->throwExceptions(false);
  98.         }
  99.         else
  100.         {
  101.             self::$fc->throwExceptions(true);
  102.             ini_set('display_errors', false);
  103.         }
  104.         self::$fc->returnResponse(true);
  105.         self::$fc->setControllerDirectory(CONTROLLER_PATH);
  106.     }
  107.    
  108.     /**
  109.      * Setup Zend_View, Zend_Layout, and renderer and doctype action helpers and set DOCTYPE XHTML1 STRICT.  
  110.      *
  111.      * @method setupView()
  112.      * @return void
  113.      */
  114.     public static function setupApplicationView()
  115.     {
  116.         $view = new Zend_View();
  117.         $view->setEncoding('utf-8');
  118.         $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
  119.         Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
  120.         $doctypeHelper = new Zend_View_Helper_Doctype();
  121.         $doctypeHelper->doctype('XHTML1_STRICT');
  122.         Zend_Layout::startMvc(
  123.             array(
  124.                 'layoutPath' => LAYOUT_PATH,
  125.                 'layout' => 'main'
  126.             )
  127.         );
  128.     }
  129.      
  130.     /**
  131.      * Setup the config.ini file using Zend_Config
  132.      *
  133.      * @method
  134.      * @return void
  135.      */
  136.     public static function setupApplicationConfiguration()
  137.     {
  138.  
  139.        
  140.     }
  141.    
  142.     /**
  143.      * Setup the database from the connection settings in config.ini
  144.      *
  145.      * @method
  146.      * @return void
  147.      */
  148.     public static function setupApplicationDatabase()
  149.     {
  150.  
  151.     }
  152.    
  153.     /**
  154.      * Sends the default response header containing the content type and encoding.  
  155.      *
  156.      * @method sendResponseHeader()
  157.      * @param string  response header text (content type, encoding etc.)
  158.      * @return void
  159.      */
  160.     public static function sendResponseHeader(Zend_Controller_Response_Http $response)
  161.     {
  162.         $response->setHeader('content-type', 'text/html; charset=UTF-8', true);
  163.         $response->sendResponse();
  164.     }
  165. }
  166. Bootstrap::runApplication();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top