mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Core/Cleanup
* set type declarations in DB Wrapper
This commit is contained in:
@@ -13,17 +13,16 @@ if (!defined('AOWOW_REVISION'))
|
|||||||
|
|
||||||
class DB
|
class DB
|
||||||
{
|
{
|
||||||
private static $interfaceCache = [];
|
private static array $interfaceCache = [];
|
||||||
private static $optionsCache = [];
|
private static array $optionsCache = [];
|
||||||
|
private static array $logs = [];
|
||||||
|
|
||||||
private static $logs = [];
|
private static function createConnectSyntax(array &$options) : string
|
||||||
|
|
||||||
private static function createConnectSyntax(&$options)
|
|
||||||
{
|
{
|
||||||
return 'mysqli://'.$options['user'].':'.$options['pass'].'@'.$options['host'].'/'.$options['db'];
|
return 'mysqli://'.$options['user'].':'.$options['pass'].'@'.$options['host'].'/'.$options['db'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function connect($idx)
|
public static function connect(int $idx) : void
|
||||||
{
|
{
|
||||||
if (self::isConnected($idx))
|
if (self::isConnected($idx))
|
||||||
{
|
{
|
||||||
@@ -73,7 +72,7 @@ class DB
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function errorHandler($message, $data)
|
public static function errorHandler(string $message, array $data) : void
|
||||||
{
|
{
|
||||||
if (!error_reporting())
|
if (!error_reporting())
|
||||||
return;
|
return;
|
||||||
@@ -94,7 +93,7 @@ class DB
|
|||||||
trigger_error($message, $isError ? E_USER_ERROR : E_USER_WARNING);
|
trigger_error($message, $isError ? E_USER_ERROR : E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function profiler($self, $query, $trace)
|
public static function profiler(mixed $self, string $query, mixed $trace) : void
|
||||||
{
|
{
|
||||||
if ($trace) // actual query
|
if ($trace) // actual query
|
||||||
self::$logs[] = [str_replace("\n", ' ', $query)];
|
self::$logs[] = [str_replace("\n", ' ', $query)];
|
||||||
@@ -105,7 +104,7 @@ class DB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getProfiles()
|
public static function getProfiles() : string
|
||||||
{
|
{
|
||||||
$out = '<pre><table style="font-size:12;"><tr><th></th><th>Time</th><th>Query</th></tr>';
|
$out = '<pre><table style="font-size:12;"><tr><th></th><th>Time</th><th>Query</th></tr>';
|
||||||
foreach (self::$logs as $i => [$l, $t])
|
foreach (self::$logs as $i => [$l, $t])
|
||||||
@@ -123,61 +122,61 @@ class DB
|
|||||||
return Util::jsEscape($out).'</table></pre>';
|
return Util::jsEscape($out).'</table></pre>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDB($idx)
|
public static function getDB(int $idx) : ?\DbSimple_Mysqli
|
||||||
{
|
{
|
||||||
return self::$interfaceCache[$idx];
|
return self::$interfaceCache[$idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isConnected($idx)
|
public static function isConnected(int $idx) : bool
|
||||||
{
|
{
|
||||||
return isset(self::$interfaceCache[$idx]) && self::$interfaceCache[$idx]->link;
|
return isset(self::$interfaceCache[$idx]) && self::$interfaceCache[$idx]->link;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isConnectable($idx)
|
public static function isConnectable(int $idx) : bool
|
||||||
{
|
{
|
||||||
return isset(self::$optionsCache[$idx]);
|
return isset(self::$optionsCache[$idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @static
|
* @static
|
||||||
* @return DbSimple_Mysql
|
* @return DbSimple_Mysqli
|
||||||
*/
|
*/
|
||||||
public static function Characters($realm)
|
public static function Characters(int $realmId) : ?\DbSimple_Mysqli
|
||||||
{
|
{
|
||||||
if (!isset(self::$optionsCache[DB_CHARACTERS.$realm]))
|
if (!isset(self::$optionsCache[DB_CHARACTERS.$realmId]))
|
||||||
die('Connection info not found for live database of realm #'.$realm.'. Aborted.');
|
die('Connection info not found for live database of realm #'.$realmId.'. Aborted.');
|
||||||
|
|
||||||
return self::getDB(DB_CHARACTERS.$realm);
|
return self::getDB(DB_CHARACTERS.$realmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @static
|
* @static
|
||||||
* @return DbSimple_Mysql
|
* @return DbSimple_Mysqli
|
||||||
*/
|
*/
|
||||||
public static function Auth()
|
public static function Auth() : ?\DbSimple_Mysqli
|
||||||
{
|
{
|
||||||
return self::getDB(DB_AUTH);
|
return self::getDB(DB_AUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @static
|
* @static
|
||||||
* @return DbSimple_Mysql
|
* @return DbSimple_Mysqli
|
||||||
*/
|
*/
|
||||||
public static function World()
|
public static function World() : ?\DbSimple_Mysqli
|
||||||
{
|
{
|
||||||
return self::getDB(DB_WORLD);
|
return self::getDB(DB_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @static
|
* @static
|
||||||
* @return DbSimple_Mysql
|
* @return DbSimple_Mysqli
|
||||||
*/
|
*/
|
||||||
public static function Aowow()
|
public static function Aowow() : ?\DbSimple_Mysqli
|
||||||
{
|
{
|
||||||
return self::getDB(DB_AOWOW);
|
return self::getDB(DB_AOWOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function load($idx, $config)
|
public static function load(int $idx, array $config) : void
|
||||||
{
|
{
|
||||||
self::$optionsCache[$idx] = $config;
|
self::$optionsCache[$idx] = $config;
|
||||||
self::connect($idx);
|
self::connect($idx);
|
||||||
|
|||||||
Reference in New Issue
Block a user