Skip to content

Commit

Permalink
feat: removed view engine optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Dec 11, 2024
1 parent 5cd3088 commit a2f55f3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
26 changes: 2 additions & 24 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,6 @@ public static function loadApplicationConfig()
\Leaf\Vite::config('build', 'public/build');
\Leaf\Vite::config('hotFile', 'public/hot');
}

Config::attachView(ViewConfig('viewEngine'), 'template');

if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [
app()->template(),
[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]
]);
} else if (method_exists(app()->template(), 'configure')) {
app()->template()->configure([
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]);
}

if (is_callable(ViewConfig('extend'))) {
call_user_func_array(ViewConfig('extend'), app()->template());
}
}
}

Expand Down Expand Up @@ -209,11 +188,10 @@ protected static function loadConfig()
],
'view' => [
'viewEngine' => \Leaf\Blade::class,
'config' => function ($engine, $config) {
$engine->configure($config['views'], $config['cache']);
'config' => function ($config) {
app()->blade()->configure($config['views'], $config['cache']);
},
'render' => null,
'extend' => null,
],
'mail' => [
'host' => _env('MAIL_HOST', 'smtp.mailtrap.io'),
Expand Down
52 changes: 51 additions & 1 deletion src/globals/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,57 @@ function assets($assets = '')
*/
function view(string $view, $data = [])
{
return app()->template()->render($view, $data);
/// WILL REFACTOR IN NEXT VERSION
if (is_object($data)) {
$data = (array) $data;
}

if (ViewConfig('render')) {
if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [
[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]
]);
}
return ViewConfig('render')($view, $data);
}

$engine = ViewConfig('viewEngine');
$className = strtolower(get_class(new $engine));
$fullName = explode('\\', $className);
$className = $fullName[count($fullName) - 1];

if (\Leaf\Config::getStatic("views.$className")) {
if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [
[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]
]);
} else {
\Leaf\Config::get("views.$className")->configure(AppConfig('views.path'), AppConfig('views.cachePath'));
}

return \Leaf\Config::get("views.$className")->render($view, $data);
}

$engine = new $engine($engine);

if (ViewConfig('config')) {
call_user_func_array(ViewConfig('config'), [
[
'views' => AppConfig('views.path'),
'cache' => AppConfig('views.cachePath'),
]
]);
} else {
$engine->config(AppConfig('views.path'), AppConfig('views.cachePath'));
}

return $engine->render($view, $data);
}
}

Expand Down

0 comments on commit a2f55f3

Please sign in to comment.