Source for file Bootstrap.php

Documentation is available at Bootstrap.php

  1. <?php
  2. require_once 'Zend/Loader.php';
  3. /* -------------------------------------------------------------------------- */
  4. /* Module      : Bootstrap.php                                                */
  5. /*                                                                            */
  6. /* Version History :                                                          */
  7. /*                                                                            */
  8. /* Date        Vsn     Author          Description                            */
  9. /* -------------------------------------------------------------------------- */
  10. /* 18/02/09    1.0     S.Lindo         Initial version.                       */
  11. /* -------------------------------------------------------------------------- */
  12. /**
  13.  * Sets up the front controller and the environment (database access, registry variables etc).
  14.  * 
  15.  * @package Default
  16.  */
  17. class Bootstrap
  18. {
  19.  
  20.     public static $frontController null;
  21.     
  22.     /**
  23.      * Call each necessary function to set up the environment
  24.      *
  25.      * @return void 
  26.      */
  27.     public static function run()
  28.     {
  29.         Zend_Loader::registerAutoload();
  30.  
  31.         self::setupEnvironment();
  32.         self::prepare();
  33.         $response self::$frontController->dispatch();
  34.         self::sendResponse($response);
  35.     }
  36.     
  37.     /**
  38.      * Setup configuration details for the database access and registry
  39.      *
  40.      * @return void 
  41.      */
  42.     public static function setupEnvironment()
  43.     {
  44.         error_reporting(E_ALL|E_STRICT);
  45.         ini_set('display_errors'true);
  46.         date_default_timezone_set('Europe/London');
  47.  
  48.         $config new Zend_Config_Ini('../application/config/config.ini''production');
  49.         define('REQUIRED_INDICATOR'$config->required_indicator);
  50.         define('CURRENCY_INDICATOR'$config->currency_indicator);
  51.         define('CONTACT_US'$config->contact_us);
  52.  
  53.         $registry Zend_Registry::getInstance();
  54.         $registry->set('config'$config);
  55.  
  56.         // setup database
  57.         $db Zend_Db::factory($config->db);
  58.         Zend_Db_Table::setDefaultAdapter($db);
  59.  
  60.         // turn off profiler:
  61.         //$db->getProfiler()->setEnabled(false);
  62.         // turn on profiler:
  63.         $db->getProfiler()->setEnabled(true);
  64.  
  65.  
  66.         require 'Session_Wrapper.php';
  67.         require 'defines.php';
  68.  
  69.         $session Session_Wrapper::getInstance();
  70.         $session->set('client_id',CLIENT_DEMO_VILLA);
  71.         if $session->get('start_of_month'== null)
  72.         {
  73.             $session->set('start_of_month'DATE_TODAY);
  74.         }
  75.  
  76.     }
  77.     
  78.     /**
  79.      * Setup the front controller and view parts of the MVC pattern
  80.      *
  81.      * @return void 
  82.      */
  83.     public static function prepare()
  84.     {
  85.         self::setupFrontController();
  86.         self::setupView();
  87.     }
  88.     
  89.     /**
  90.      * Setup the front controller
  91.      *
  92.      * @return void 
  93.      */
  94.     public static function setupFrontController()
  95.     {
  96.         self::$frontController Zend_Controller_Front::getInstance();
  97.         self::$frontController->throwExceptions(true);
  98.         self::$frontController->returnResponse(true);
  99.         self::$frontController->setControllerDirectory
  100.         (
  101.             dirname__FILE__ '/controllers'
  102.         );
  103.         Zend_Controller_Action_HelperBroker::addPath(
  104.                 APPLICATION_PATH .'/controllers/helpers');
  105.         Zend_Controller_Action_HelperBroker::addPath(
  106.                 APPLICATION_PATH .'/controllers/helpers/ModelAccess');
  107.  
  108.     }
  109.     
  110.     /**
  111.      * Setup the view
  112.      *
  113.      * @return void 
  114.      */
  115.     public static function setupView()
  116.     {
  117.         // LAYOUT SETUP - Setup the layout component
  118.         // The Zend_Layout component implements a composite (or two-step-view)
  119.         // pattern. With this call we are telling the component where to find
  120.         // the layouts scripts.
  121.         Zend_Layout::startMvc(APPLICATION_PATH '/layouts/scripts');
  122.  
  123.         // VIEW SETUP - Initialize properties of the view object
  124.         // The Zend_View component is used for rendering views. Here, we grab
  125.         // a "global" view instance from the layout object, and specify the
  126.         // doctype we wish to use. In this case, XHTML1 Strict.
  127.         $view Zend_Layout::getMvcInstance()->getView();
  128.         $view->doctype('XHTML1_STRICT');
  129.     }
  130.     
  131.     /**
  132.      * Setup the page content type and send the HTTP response
  133.      *
  134.      * @return void 
  135.      */
  136.     public static function sendResponse(Zend_Controller_Response_Http $response)
  137.     {
  138.         $response->setHeader('Content-Type''text/html; charset=UTF-8'true);
  139.         $response->sendResponse();
  140.     }
  141.  
  142. }
  143. /**
  144. * Temporary functions to be removed once testing is complete.
  145. *
  146. * During the conversion from PHP4 to PHP5, these functions were retained to
  147. * ease the transition. From a purist point of view, they should ultimately be
  148. * removed and all references to them elsewhere amended/deleted.
  149. *
  150. @return void 
  151. */
  152. function tempMaster($in)
  153. {
  154. echo "<BR><FONT color=red><B>" basename(__FILE__" - $in</B></FONT>";
  155. }
  156. /**
  157. * Temporary function to be removed once testing is complete.
  158. *
  159. @deprecated
  160. @return void 
  161. */
  162. function displayErrorSpan($intempMaster($in)};
  163. /**
  164. @deprecated Temporary function to be removed once testing is complete.
  165. */
  166. function displayErrorBlock($intempMaster($in)};
  167. /**
  168. @deprecated Temporary function to be removed once testing is complete.
  169. */
  170. function displayDebugBlock($intempMaster($in)};
  171. /**
  172. @deprecated Temporary function to be removed once testing is complete.
  173. */
  174. function reportInfo($intempMaster($in)};
  175. /**
  176. @deprecated Temporary function to be removed once testing is complete.
  177. */
  178. function newObject($in)
  179. {
  180.     echo "<BR><FONT color=blue>Creating a new $in</FONT>";
  181.     require ("../application/models/".$in.".inc");
  182.     return new $in();
  183. };
  184. /**
  185. @deprecated Temporary function to be removed once testing is complete.
  186. */
  187. function newHelper($in)
  188. {
  189.     echo "<BR><FONT color=blue>Creating new helper$in</FONT>";
  190.     require ("../application/views/helpers/".$in.".php");
  191.     return new $in();
  192. };
  193. unset($config);

Documentation generated on Fri, 27 Mar 2009 13:48:23 +0000 by phpDocumentor 1.4.1