Bootstrap
[ class tree: Bootstrap ] [ index: Bootstrap ] [ all elements ]

Source for file Base.php

Documentation is available at Base.php

  1. <?php
  2. /**
  3.  * Application_Bootstrap_Base
  4.  * 
  5.  * Copyright (C) 2009  Mai (Me Artificial Intelligence)
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  * 
  20.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  21.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  22.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  23.  * @link http://www.launchpad.net/mai
  24.  * 
  25.  * @package Bootstrap
  26.  * @subpackage Base
  27.  * 
  28.  */
  29.  
  30. /**
  31.  * Application_Bootstrap_Base is a base class for bootstrap classes.
  32.  * 
  33.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  34.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  35.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  36.  * @link http://www.launchpad.net/mai
  37.  * 
  38.  * @package Bootstrap
  39.  * @subpackage Base
  40.  *  
  41.  */
  42.  
  43. {    
  44.     /**
  45.      * Private constructor to prevent creation of this object.
  46.      * @return void 
  47.      */
  48.     private function __construct(){}
  49.     
  50.     /**
  51.      * Starts up the bootstrap.
  52.      * @return void 
  53.      */
  54.     static public function run(){}
  55.     
  56.     /**
  57.      * Loads the global.ini file and saves it to the registry.
  58.      * @return void 
  59.      */
  60.     final static protected function initGlobalConfig()
  61.     {
  62.         $config new Zend_Config_Ini(APPLICATION_PATH '/config/config.ini''global');
  63.         Zend_Registry::set('config'$config);
  64.     }
  65.     
  66.     /**
  67.      * Loads the db.ini file.
  68.      * @return Zend_Config_Ini 
  69.      */
  70.     final static protected function returnDbConfig()
  71.     {
  72.         return new Zend_Config_Ini(APPLICATION_PATH '/config/config.ini''db');
  73.     }
  74.     
  75.     /**
  76.      * Loads the doctrine-cli.ini file and outputs an array with config variables for the base db.
  77.      * @return void 
  78.      */
  79.     final static protected function returnDoctrineCliConfigBase()
  80.     {
  81.         $config =  new Zend_Config_Ini(APPLICATION_PATH '/config/doctrine-cli.ini');
  82.         return array(
  83.             'data_fixtures_path'         =>  BASE_PATH $config->doctrine_cli->path_fixtures_base,
  84.             'models_path'                =>  BASE_PATH $config->doctrine_cli->path_models_base,
  85.             'migrations_path'             =>  BASE_PATH $config->doctrine_cli->path_migrations_base,
  86.             'sql_path'                   =>  BASE_PATH $config->doctrine_cli->path_sql_base,
  87.             'yaml_schema_path'            =>  BASE_PATH $config->doctrine_cli->path_schema_base,
  88.             'generate_models_options'     =>     array('generateTableClasses' => true)
  89.         );
  90.     }
  91.  
  92.     /**
  93.      * Loads the doctrine-cli.ini file and outputs an array with config variables for the user db.
  94.      * @return void 
  95.      */
  96.     final static protected function returnDoctrineCliConfigUser()
  97.     {
  98.         $config =  new Zend_Config_Ini(APPLICATION_PATH '/config/doctrine-cli.ini');
  99.         
  100.         return array(
  101.             'data_fixtures_path'         =>  BASE_PATH $config->doctrine_cli->path_fixtures_user,
  102.             'models_path'                =>  BASE_PATH $config->doctrine_cli->path_models_user,
  103.             'migrations_path'             =>  BASE_PATH $config->doctrine_cli->path_migrations_user,
  104.             'sql_path'                   =>    BASE_PATH $config->doctrine_cli->path_sql_user,
  105.             'yaml_schema_path'            =>  BASE_PATH $config->doctrine_cli->path_schema_user,
  106.             'generate_models_options'     => array('generateTableClasses' => true)
  107.         );
  108.     }
  109.     
  110.     /**
  111.      * Connect to base db.
  112.      * @param array $config 
  113.      * @return void 
  114.      */
  115.     final static protected function initBaseDbConnection(Zend_Config_Ini $config)
  116.     {
  117.         //Data Source Name
  118.         $dsn =  sprintf('%s://%s:%s@%s/%s',   
  119.                     $config->db_base->dbtype,   
  120.                     $config->db_base->username,   
  121.                     $config->db_base->password,   
  122.                     $config->db_base->host,   
  123.                     $config->db_base->dbname);
  124.         try
  125.         {
  126.             $conn Doctrine_Manager::connection($dsn$config->db_base->connection_name);
  127.             //Save the connection
  128.             Zend_Registry::set('conn_dbbase'$conn);
  129.         }
  130.         catch(Exception $e)
  131.         {
  132.             die($e->getMessage());
  133.         }
  134.     }
  135.  
  136.     /**
  137.      * Connect to user db.
  138.      * @param array $config 
  139.      * @return void 
  140.      */
  141.     final static protected function initUserDbConnection(Zend_Config_Ini $config)
  142.     {
  143.         //Data Source Name
  144.         $dsn =  sprintf('%s://%s:%s@%s/%s',   
  145.                     $config->db_user->dbtype,   
  146.                     $config->db_user->username,   
  147.                     $config->db_user->password,   
  148.                     $config->db_user->host,   
  149.                     $config->db_user->dbname);
  150.         try
  151.         {
  152.             $conn Doctrine_Manager::connection($dsn$config->db_user->connection_name);
  153.             //Save the connection
  154.             Zend_Registry::set('conn_dbuser'$conn);
  155.         }
  156.         catch(Exception $e)
  157.         {
  158.             die($e->getMessage());
  159.         }
  160.     }
  161.     
  162.     /**
  163.      * Set include paths.
  164.      * @return void 
  165.      */
  166.     final static protected function initIncludePaths()
  167.     {
  168.         set_include_path('.'
  169.             . PATH_SEPERATOR get_include_path()
  170.             
  171.             //Include paths for libraries
  172.             . PATH_SEPERATOR BASE_PATH '/library'
  173.             
  174.             //Models
  175.             . PATH_SEPERATOR APPLICATION_PATH '/models'
  176.         );
  177.     }
  178.     
  179.     /**
  180.      * Setup auto loading of classes.
  181.      * @return void 
  182.      */
  183.     final static protected function initAutoLoader()
  184.     {
  185.         //Require files
  186.         require_once('Zend/Loader.php');
  187.         require_once('Zend/Loader/Autoloader.php');
  188.  
  189.         $autoloader Zend_Loader_Autoloader::getInstance();
  190.  
  191.         //Register namespace Mai_
  192.         $autoloader->registerNamespace('Mai_');
  193.         $autoloader->registerNamespace('Doctrine_');
  194.         $autoloader->registerNamespace('Doctrine');
  195.     
  196.         $autoloader->setFallbackAutoloader(true);
  197.         
  198.         //Show errors
  199.         $autoloader->suppressNotFoundWarnings(false);
  200.     }
  201.     
  202.     /**
  203.      * Cloning of a bootstrap class is not allowed.
  204.      * @return void 
  205.      */
  206.     final public function __clone()
  207.     {
  208.         trigger_error('Clone is not allowed.'E_USER_ERROR);
  209.     }
  210.     
  211. }

Documentation generated on Mon, 27 Jul 2009 19:51:47 +0200 by phpDocumentor 1.4.1