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

Source for file Registry.php

Documentation is available at Registry.php

  1. <?php
  2. /**
  3.  * Mai_Registry
  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 Registry
  27.  */
  28.  
  29. /** Required files */
  30. {
  31.     //Zend_Registry is needed to extend.
  32.     require_once 'Zend/Registry.php';
  33. }
  34.  
  35. /**
  36.  * Mai_Registry acts as the registry for Mai.
  37.  * 
  38.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  39.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  40.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  41.  * @link http://www.launchpad.net/mai
  42.  * 
  43.  * @category Mai
  44.  * @package Registry
  45.  * @uses Zend_Config_Ini
  46.  */
  47.  
  48. class Mai_Registry extends Zend_Registry
  49. {
  50.     /**
  51.      * @var Mai_Registry Singleton instance
  52.      */
  53.     protected static $_instance;
  54.     
  55.     /**
  56.      * @var string Location of the config file relative to the base dir.
  57.      */
  58.     protected static $_iniFile '/Config/Files/config.ini';
  59.  
  60.     /**
  61.      * Set default values.
  62.      * @return void 
  63.      */
  64.     function __construct($creator)
  65.     {
  66.         //Instanceof cannot be used because Mai_Registry has to create itself.
  67.         if($creator !== 'Mai_Registry')
  68.         {
  69.             trigger_error('Mai_Registry is a singleton class.'E_USER_ERROR);
  70.         }
  71.  
  72.         self::set('output'Mai_Config::getVar()->output->default);
  73.         
  74.         parent::__construct();
  75.     }
  76.     
  77.     /**
  78.      * Retrieve singleton instance
  79.      * 
  80.      * @return Mai_Registry 
  81.      */
  82.     public static function getInstance($class null)
  83.     {
  84.         //Make sure that this class can only be used if Mai is running
  85.         if(!Mai::isInit(&& !($class instanceof Mai&& self::$_instance === null)
  86.         {
  87.             trigger_error('Mai has not been setup yet. Please use Mai::init().'E_USER_ERROR);
  88.         }
  89.         
  90.         if (null === self::$_instance{
  91.             self::$_instance new self(__CLASS__);
  92.         }
  93.         return self::$_instance;
  94.     }
  95.     
  96.     /**
  97.      * Cloning of a singleton class is not allowed.
  98.      * @return void 
  99.      */
  100.     final public function __clone()
  101.     {
  102.         trigger_error('Clone is not allowed.'E_USER_ERROR);
  103.     }
  104.  
  105.     /**
  106.      * Function to prevent deserializing
  107.      * @return void 
  108.      */
  109.     public function __wakeup()
  110.     {
  111.         trigger_error('Deserializing is not allowed.'E_USER_ERROR);
  112.     }
  113. }

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