Skip to content

Commit 880b20e

Browse files
committed
🔨 improve on the app() helper function to support instantiating classes and loading action based classes
Signed-off-by: otengkwame <developerkwame@gmail.com>
1 parent 36684e6 commit 880b20e

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

Core/helpers/ci_core_helper.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ function app(string $class = null, array $params = [])
8686
if ($class === null) {
8787
return Instance::create();
8888
}
89-
89+
90+
if ((!empty($class) && class_exists($class)) && !empty($params)) {
91+
return new $class($params);
92+
}
93+
94+
if ((!empty($class) && class_exists($class))) {
95+
return new $class();
96+
}
97+
9098
$get_class = explode('/', has_dot($class));
9199
$class_type = count($get_class);
92100

@@ -106,6 +114,13 @@ function app(string $class = null, array $params = [])
106114
return ci()->{$class_name}; // return model object
107115
}
108116

117+
if (contains('Action', $class)) {
118+
119+
use_action($class); // load action
120+
121+
return ci()->{$class_name}; // return action object
122+
}
123+
109124
// let's assume it's a model without
110125
// the above conditions
111126
// If it does not exists we will load a library

0 commit comments

Comments
 (0)