1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
<?php
namespace swag;
/**
* Singleton
*/
class Singleton {
private static $instances=array();
/**
* Init.
*/
public static function instance() {
$class=get_called_class();
if ($class=='swag\Singleton')
throw new Exception("Singleton should not be used directly.");
if (!isset(self::$instances[$class]))
self::$instances[$class]=new $class;
return self::$instances[$class];
}
}