diff --git "a/include/class-generic\\Singleton.php" "b/include/class-generic\\Singleton.php" index c2b9c3a..98b7edc 100644 --- "a/include/class-generic\\Singleton.php" +++ "b/include/class-generic\\Singleton.php" @@ -1,55 +1,58 @@ . # generic stuff namespace generic; /** * A singleton gives a getInstance() method */ trait Singleton { /** * Get an instance of this class * * @return self */ public static function getInstance() { static $instance; if( ! $instance ) { $instance = static::create(); } return $instance; } /** * Function to be overrided to create an instance of this class * * @return self */ protected static function create() { - throw new \Exception( 'must override' ); + return new static(); } /** * Throw an usage error */ - public static function throwWrongUsage() { - throw new \Exception( 'wrong usage' ); + protected static function throwSingletonUsage() { + throw new \Exception( sprintf( + 'wrong singleton usage, you must call %s::getInstance()', + static::class + ) ); } }