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

Source for file Cache.php

Documentation is available at Cache.php

  1. <?php
  2. /**
  3.  * Mai_Cache
  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 Cache
  27.  * 
  28.  */
  29.  
  30. /**
  31.  * Mai_Cache is an gateway for cache 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 Cache
  40.  * 
  41.  */
  42.  
  43. class Mai_Cache
  44. {
  45.     /**
  46.      * @var Mai_Cache Singleton instance
  47.      */
  48.     protected static $_instance;
  49.     
  50.     /**
  51.      * Private constructor to prevent creation of this object.
  52.      * @return void 
  53.      */
  54.     private function __construct(){}
  55.     
  56.     /**
  57.      * Retrieve singleton instance
  58.      * 
  59.      * @return Mai_Cache 
  60.      */
  61.     public static function getInstance()
  62.     {            
  63.         if(!Mai::isInit())
  64.         {
  65.             trigger_error('Mai has not been setup yet. Please use Mai::init().'E_USER_ERROR);
  66.         }
  67.         
  68.         if (null === self::$_instance{
  69.             //Start up and load ini file
  70.             self::$_instance new self();
  71.         }
  72.         return self::$_instance;
  73.     }
  74.     
  75.     /**
  76.      * Create a new words cache file.
  77.      * @return Mai_Cache_Words 
  78.      */
  79.     public static function newCacheWords($location null$filename$varName)
  80.     {
  81.         if(!is_string($filename))
  82.         {
  83.             trigger_error('$filename must be a string.'E_USER_ERROR);
  84.         }
  85.         
  86.         if(!is_string($varName))
  87.         {
  88.             trigger_error('$varName must be a string.'E_USER_ERROR);
  89.         }
  90.         
  91.         /** Required file */
  92.         if(!Mai::getAutoloader())
  93.         {
  94.             require_once 'Mai/Cache/Words.php';
  95.         }
  96.         
  97.         return new Mai_Cache_Words($location$filename$varNameself::getInstance());
  98.     }
  99.     
  100.     /**
  101.      * Cloning of a singleton class is not allowed.
  102.      * @return void 
  103.      */
  104.     final public function __clone()
  105.     {
  106.         trigger_error('Clone is not allowed.'E_USER_ERROR);
  107.     }
  108.  
  109.     /**
  110.      * Function to prevent deserializing
  111.      * @return void 
  112.      */
  113.     public function __wakeup()
  114.     {
  115.         trigger_error('Deserializing is not allowed.'E_USER_ERROR);
  116.     }
  117. }

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