예제 #1
0
 public static function getInstance()
 {
     if (NULL === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
예제 #2
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new singleton();
     }
     return self::$instance;
 }
예제 #3
0
 public static function getInstance(&$sql, $location, $var, $type)
 {
     // 确定类型
     switch ($type) {
         default:
             // 默认使用字符串类型
         // 默认使用字符串类型
         case 'STRING':
             $var = addslashes($var);
             // 转义
             $var = "'" . $var . "'";
             // 加上单引号.sql语句中字符串插入必须加单引号
             break;
         case 'INTEGER':
         case 'INT':
             $var = (int) $var;
             // 强制转换成int
             // 还可以增加更多的类型...
     }
     $pos = 0;
     // 判断该类是否是第一次被实例化
     if (self::$instance == NULL) {
         self::$instance = new singleton();
         for ($i = 1; $i <= $location; $i++) {
             $pos = strpos($sql, '?', $pos + 1);
         }
     } else {
         for ($i = 1; $i <= $location - 1; $i++) {
             $pos = strpos($sql, '?', $pos + 1);
         }
     }
     return $sql = substr($sql, 0, $pos) . $var . substr($sql, $pos + 1);
 }
/**
 * This function returns a instance (and creates a new one
 * if there isnt already one) of a class.
 * 
 * @author Johannes Klose <*****@*****.**>
 * @param  string $class Class from where an instance should be returned.
 * @return object        Instance of $class
 **/
function &singleton($class)
{
    static $singleton;
    if (!is_object($singleton)) {
        $singleton = new singleton();
    }
    return $singleton->instance($class);
}
예제 #5
0
 public static function singleton($username, $password) {
     if (!(self::$instance)) {
         $className = __CLASS__;
         self::$instance = new Mongo("mongodb://${username}:${password}@localhost/test", array("persist" => "x"));
         ;
     }
     return self::$instance;
 }