/** * @return Db */ public static function getInstance() { // Exemplo de Singleton if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * 实例化 * @param string $type * @param array $config * @return object eg. Ssdb Redis... */ public static function getInstance($type, $config) { if (!self::$instance instanceof BaseDb) { $class = 'Database\\' . ucfirst($type); if (class_exists($type)) { self::$instance = new $class((array) $config); } else { self::$instance = null; } } return self::$instance; }