public static function getInstance() { if (!static::$db) { static::$db = static::factory(Config::get("database")); static::$registerEvents = Config::get("database.registerEvents", true); if (static::$registerEvents) { static::$db->hook("pre_open", function ($h) { Event::fire("sugi.database.pre_open"); }); static::$db->hook("post_open", function ($h) { Event::fire("sugi.database.post_open"); }); static::$db->hook("pre_query", function ($h, $query) { Event::fire("sugi.database.pre_query", array("query" => $query)); }); static::$db->hook("post_query", function ($h, $query) { Event::fire("sugi.database.post_query", array("query" => $query)); }); } } return static::$db; }