Skip to content

Commit e19c860

Browse files
committed
🔨 improve on the ci() and app() diety functions
Signed-off-by: otengkwame <[email protected]>
1 parent ba9143d commit e19c860

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

Core/helpers/ci_core_helper.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ function ci(string $class = null, array $params = [])
3232
return Instance::create();
3333
}
3434

35+
if ($class === 'database') {
36+
get_instance()->use->database();
37+
return get_instance()->db;
38+
}
39+
3540
// Special cases 'user_agent' and 'unit_test' are loaded
3641
// with diferent names
3742
if ($class !== 'user_agent') {
@@ -84,9 +89,14 @@ function app(string $class = null, array $params = [])
8489
{
8590

8691
if ($class === null) {
87-
return Instance::create();
92+
return get_instance(); // Direct access to CI_Controller::get_instance();
8893
}
8994

95+
if ($class === 'database') {
96+
get_instance()->use->database();
97+
return get_instance()->db;
98+
}
99+
90100
if ((!empty($class) && class_exists($class)) && !empty($params)) {
91101
return new $class($params);
92102
}
@@ -1326,3 +1336,20 @@ function __($line, $log_errors = true)
13261336
return trans($line, $log_errors);
13271337
}
13281338
}
1339+
1340+
if ( ! function_exists('parse_lang'))
1341+
{
1342+
/**
1343+
* Translate a language line
1344+
* with placeholders
1345+
*
1346+
* @param string $lang_line
1347+
* @param array|mixed ...$placeholders
1348+
* @return string
1349+
*/
1350+
function parse_lang(string $lang_line, ...$placeholders)
1351+
{
1352+
$format = trans($lang_line);
1353+
return vsprintf($format, $placeholders);
1354+
}
1355+
}

0 commit comments

Comments
 (0)