Location: PHPKode > projects > Mocovie web framework > mocovi/library/autoload/Singleton.php
<?php

abstract class Singleton
{
	private static $instances	= array();

	protected function __construct(Array $a = array())
	{}

	final private function __clone()
	{}

	final public static function getInstance()
	{
		if(substr(PHP_VERSION, 0, 1) >= 5 && substr(PHP_VERSION, 2, 1) >= 3) //if(version_compare(PHP_VERSION, $v) < 0)
		{
			//trigger_error('On this system runs PHP >= 5.3. In this case Singleton::get_called_class(); is deprecated.', E_USER_NOTICE);
			$class = get_called_class();
		}
		else
			$class = self::get_called_class(); // für Version < PHP 5.3 eigene Funktion;
		$args = func_get_args();
		if (!isset(self::$instances[$class]))
			self::$instances[$class] = self::new_object($class, $args);
		return self::$instances[$class];
	}

	final public static function new_object($class, Array $args)
	{
		switch(count($args))
		{
			case 1:
				return new $class($args[0]);
				break;
			case 2:
				return new $class($args[0], $args[1]);
				break;
			case 3:
				return new $class($args[0], $args[1], $args[2]);
				break;
			case 4:
				return new $class($args[0], $args[1], $args[2], $args[3]);
				break;
			case 5:
				return new $class($args[0], $args[1], $args[2], $args[3], $args[4]);
				break;
			default:
				return new $class();
		}
	}

	/**
	 * Returns called class
	 *
	 * @deprecated since PHP 5.3
	 */
	final public static function get_called_class()
	{
		$bt = debug_backtrace();
		$lines = file($bt[1]['file']);
		preg_match('/([A-z0-9\_]+)::'.$bt[1]['function'].'/', $lines[$bt[1]['line']-1], $matches);
		return $matches[1];
	}
}
Return current item: Mocovie web framework