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

Source for file Config.php

Documentation is available at Config.php

  1. <?php
  2. /**
  3.  * Mai_Config
  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.  * @category Mai
  26.  * @package Config
  27.  */
  28.  
  29. /** Required files */
  30.  
  31. /* Please note:
  32.  * This require_once statement is always executed unless Mai::$_autoloader is defined true.
  33.  * After creation of this class the value of the config.ini file is used.
  34.  */
  35. {
  36.     //Zend_Config_Ini is needed to extend.
  37.     require_once 'Zend/Config/Ini.php';
  38. }
  39.  
  40. /**
  41.  * Mai_Config holds the config of Mai.
  42.  * 
  43.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  44.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  45.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  46.  * @link http://www.launchpad.net/mai
  47.  * 
  48.  * @category Mai
  49.  * @package Config
  50.  * @uses Zend_Config_Ini
  51.  */
  52.  
  53. class Mai_Config extends Zend_Config_Ini
  54. {
  55.     /**
  56.      * @var Mai_Config Singleton instance
  57.      */
  58.     protected static $_instance;
  59.     
  60.     /**
  61.      * @var string Location of the config file relative to the base dir.
  62.      */
  63.     protected static $_iniFile '/Mai/Config/Files/config.ini';
  64.  
  65.     /**
  66.      * Mai_Config can only be created by itself. Starts up the parent constructor.
  67.      * @return void 
  68.      */
  69.     public function __construct($creator$filename$section$options)
  70.     {
  71.         //Instanceof cannot be used because Mai_Config has to create itself.
  72.         if($creator !== 'Mai_Config')
  73.         {
  74.             trigger_error('Mai_Config is a singleton class.'E_USER_ERROR);
  75.         }
  76.         
  77.         parent::__construct($filename$section$options);
  78.     }
  79.     
  80.     /**
  81.      * Retrieve singleton instance
  82.      * 
  83.      * @return Mai_Config 
  84.      */
  85.     public static function getInstance($class null)
  86.     {
  87.         //Make sure that this class can only be used if Mai is running
  88.         if(!Mai::isInit(&& !($class instanceof Mai&& self::$_instance === null)
  89.         {
  90.             trigger_error('Mai has not been setup yet. Please use Mai::init().'E_USER_ERROR);
  91.         }
  92.         
  93.         if (null === self::$_instance{
  94.             //Start up and load ini file
  95.             $envName Mai::$_envNames[Mai::getEnv()];
  96.             self::$_instance new self(__CLASS__Mai::baseDir(self::$_iniFile$envNamearray());
  97.         }
  98.         return self::$_instance;
  99.     }
  100.     
  101.     /**
  102.      * Use to get variables form the ini file. Acts the same as getInstance()
  103.      * @return Mai_Config 
  104.      */
  105.     public static function getVar()
  106.     {
  107.         return self::getInstance();
  108.     }
  109.     
  110.     /**
  111.      * Cloning of a singleton class is not allowed.
  112.      * @return void 
  113.      */
  114.     final public function __clone()
  115.     {
  116.         trigger_error('Clone is not allowed.'E_USER_ERROR);
  117.     }
  118.  
  119.     /**
  120.      * Function to prevent deserializing
  121.      * @return void 
  122.      */
  123.     public function __wakeup()
  124.     {
  125.         trigger_error('Deserializing is not allowed.'E_USER_ERROR);
  126.     }
  127. }

Documentation generated on Mon, 27 Jul 2009 19:55:05 +0200 by phpDocumentor 1.4.1