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

Source for file Container.php

Documentation is available at Container.php

  1. <?php
  2. /**
  3.  * Mai_Container
  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 Container
  27.  * 
  28.  */
  29.  
  30. /**
  31.  * Mai_Container is a gateway for container 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.  * @category Mai
  39.  * @package Container
  40.  * 
  41.  */
  42.  
  43. {
  44.     /**
  45.      * @var Mai_Cache Singleton instance
  46.      */
  47.     protected static $_instance;
  48.     
  49.     /**
  50.      * Private constructor to prevent creation of this object.
  51.      * @return void 
  52.      */
  53.     private function __construct(){}
  54.     
  55.     /**
  56.      * Retrieve singleton instance
  57.      * 
  58.      * @return Mai_Cache 
  59.      */
  60.     public static function getInstance()
  61.     {            
  62.         if(!Mai::isInit())
  63.         {
  64.             trigger_error('Mai has not been setup yet. Please use Mai::init().'E_USER_ERROR);
  65.         }
  66.         
  67.         if (null === self::$_instance{
  68.             self::$_instance new self();
  69.         }
  70.         return self::$_instance;
  71.     }
  72.     
  73.     /**
  74.      * Create a new word container.
  75.      * @param $word The word to store.
  76.      * @return Mai_Container_Word 
  77.      */
  78.     public static function newContainerWord($word)
  79.     {
  80.         if(!is_string($word))
  81.         {
  82.             trigger_error('Word must be set and a string.'E_USER_ERROR);
  83.            }
  84.            
  85.            //Require word
  86.            if(!Mai::getAutoloader())
  87.            {
  88.                require_once('Mai/Container/Word.php');
  89.            }
  90.            
  91.            return new Mai_Container_Word($word);
  92.     }
  93.  
  94.     /**
  95.      * Create a new sentence container.
  96.      * @return Mai_Container_Sentnce 
  97.      */
  98.     public static function newContainerSentence()
  99.     {
  100.            //Require class
  101.            if(!Mai::getAutoloader())
  102.            {
  103.                require_once('Mai/Container/Sentence.php');
  104.            }
  105.            
  106.            return new Mai_Container_Sentence();
  107.     }
  108.  
  109.     /**
  110.      * Create a new input container.
  111.      * @return Mai_Container_Input 
  112.      */
  113.     public static function newContainerInput()
  114.     {
  115.            //Require class
  116.            if(!Mai::getAutoloader())
  117.            {
  118.                require_once('Mai/Container/Input.php');
  119.            }
  120.            
  121.            return new Mai_Container_Input();
  122.     }
  123.     
  124.     /**
  125.      * Cloning of a singleton class is not allowed.
  126.      * @return void 
  127.      */
  128.     final public function __clone()
  129.     {
  130.         trigger_error('Clone is not allowed.'E_USER_ERROR);
  131.     }
  132.  
  133.     /**
  134.      * Function to prevent deserializing
  135.      * @return void 
  136.      */
  137.     public function __wakeup()
  138.     {
  139.         trigger_error('Deserializing is not allowed.'E_USER_ERROR);
  140.     }
  141. }

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