Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00%
0 / 1
0.00%
0 / 4
CRAP
0.00%
0 / 8
Singleton
0.00%
0 / 1
0.00%
0 / 4
30
0.00%
0 / 8
 __construct()
0.00%
0 / 1
2
0.00%
0 / 1
 __clone()
0.00%
0 / 1
2
0.00%
0 / 1
 __wakeup()
0.00%
0 / 1
2
0.00%
0 / 1
 getInstance()
0.00%
0 / 1
6
0.00%
0 / 5
<?php
namespace BOTK\Core;
/*
* PHP 5.3 allows the creation of an inheritable Singleton class via late static binding:
* see: http://stackoverflow.com/questions/203336/creating-the-singleton-design-pattern-in-php5
* discussion
*
*/
class Singleton
{
private static $instances = array();
protected function __construct() {}
private function __clone() {}
public function __wakeup()
{
throw new Exception("Cannot unserialize singleton");
}
public static function getInstance()
{
$cls = get_called_class(); // late-static-bound class name
if (!isset(self::$instances[$cls])) {
self::$instances[$cls] = new static;
}
return self::$instances[$cls];
}