Source for file Singleton.class.php

Documentation is available at Singleton.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Singleton
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Singleton Pattern Interface
  22.  * 
  23.  * The Singleton Design Pattern ensures that only one object of the class
  24.  * is instantiated during runtime.  The static method checks if an object
  25.  * has been created.  If the reference is null, it creates a new object
  26.  * using the private Constructor.
  27.  * 
  28.  * Requirements:
  29.  * - private static property to hold single object reference
  30.  * - private constructor
  31.  * 
  32.  * Typical Implementation:
  33.  * <pre>
  34.  * private static $_instance = null;
  35.  * private function __construct () {}
  36.  * public static function instance () {
  37.  *     if (self::$_instance == null) {
  38.  *         self::$_instance = new MyClassName ();
  39.  *     }
  40.  *     return self::$_instance;
  41.  * }
  42.  * </pre>
  43.  *
  44.  * @category Gumbo
  45.  * @package Singleton
  46.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  47.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  48.  * @author Michael Luster <mluster79@yahoo.com>
  49.  * @link http://sourceforge.net/projects/phpgumbo
  50.  * @desc Singleton Pattern Interface
  51.  * @version 0.0.1
  52.  */
  53.  
  54.     
  55.     /**
  56.      * Returns an instance of the class
  57.      * @return Gumbo_Interface_Singleton 
  58.      */
  59.     public static function instance ();
  60.     
  61. }
  62.  
  63. ?>