You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
594 B
PHTML
34 lines
594 B
PHTML
5 years ago
|
<?php
|
||
|
class LtObjectUtil
|
||
|
{
|
||
|
static $instances;
|
||
|
|
||
|
static public function singleton($className, $autoInited = true)
|
||
|
{
|
||
|
if (empty($className))
|
||
|
{
|
||
|
trigger_error('empty class name');
|
||
|
return false;
|
||
|
}
|
||
|
$key = strtolower($className);
|
||
|
if (isset(self::$instances[$key]))
|
||
|
{
|
||
|
return self::$instances[$key];
|
||
|
}
|
||
|
else if (class_exists($className))
|
||
|
{
|
||
|
$newInstance = new $className;
|
||
|
if ($autoInited && method_exists($newInstance, 'init'))
|
||
|
{
|
||
|
$newInstance->init();
|
||
|
}
|
||
|
self::$instances[$key] = $newInstance;
|
||
|
return $newInstance;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|