Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (27 sloc) 806 Bytes
<?php
/**
* SingletonFactory
* @author stealth35, Benjamin Delespierre
*/
class Singleton
{
protected static $_instances;
public static $namespace = __NAMESPACE__;
public static function __callStatic($name, array $arguments = array())
{
$name = ltrim(static::$namespace, '\\') . '\\' . ltrim($name, '\\');
if(empty(static::$_instances[$name]) || !empty($arguments))
{
if(method_exists($name, '__construct'))
{
$class = new \ReflectionClass($name);
static::$_instances[$name] = $class->newInstanceArgs($arguments);
}
else
{
static::$_instances[$name] = new $name;
}
}
return static::$_instances[$name];
}
}
Something went wrong with that request. Please try again.