• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

system/classes/singleton.php

00001 <?php
00007 namespace Habari;
00008 
00015 abstract class Singleton
00016 {
00017   // Single instance of class available.
00018   private static $instances = array();
00019 
00026   protected static function instance()
00027   {
00028     $class = get_called_class();
00029     return self::getInstanceOf($class);
00030   }
00031 
00042   /*
00043    * The overridden methods can't have a different signature, so there needs
00044    * to be two functions: one, internal to a class, that calls this one
00045    * (a singleton factory) that produces objects of the requested classes
00046    */
00047   protected static function getInstanceOf( $class )
00048   {
00049     if ( ! isset( self::$instances[$class] ) ) {
00050       self::$instances[$class] = new $class();
00051     }
00052     return self::$instances[$class];
00053   }
00054 
00059   protected final function __construct() {}
00060   private final function __clone() {}
00061 }
00062 
00063 ?>

Generated on Sun Aug 4 2013 12:51:43 for Habari by  doxygen 1.7.1