/** * handle */ public static function handle() { if ($error = error_get_last()) { $md5key = md5(json_encode($error)); if (FCache::S($md5key)) { return; } if (isset(self::$errtype[$error['type']])) { $error['type'] = self::$errtype[$error['type']]; if (isset($error['message']) && stripos($error['message'], 'SQLSTATE')) { $error['sql'] = Yod::db()->lastQuery(); } $error['trace'] = debug_backtrace(); } // http_filter foreach (Errlog::$http_filter as $key => $rules) { if (empty($_SERVER[$key])) { continue; } foreach ($rules as $value) { if (strripos($_SERVER[$key], $value) !== false) { return; } } } FCache::S($md5key, $error, 1800); Errlog::sendlog($error); } }
/** * getInstance * @access public * @param mixed $config * @return Yod_Database */ public static function getInstance($config = 'db_dsn') { if (is_string($config)) { $config = Yod::config($config); } if (!is_array($config)) { return false; } if (empty($config['type']) || !is_string($config['type'])) { $config['type'] = 'pdo'; } $md5key = md5(serialize($config)); if (empty(self::$_db[$md5key])) { if ($config['type'] == 'pdo') { $classname = 'Yod_DbPdo'; } else { $classname = 'Yod_Db' . ucwords($config['type']); } if (!class_exists($classname, false)) { include YOD_RUNPATH . '/Driver/' . substr($classname, 4) . '.php'; } self::$_db[$md5key] = new $classname($config); } return self::$_db[$md5key]; }