Skip to content

Commit a2f55f3

Browse files
committed
feat: removed view engine optimizations
1 parent 5cd3088 commit a2f55f3

File tree

2 files changed

+53
-25
lines changed

2 files changed

+53
-25
lines changed

src/Core.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,6 @@ public static function loadApplicationConfig()
6464
\Leaf\Vite::config('build', 'public/build');
6565
\Leaf\Vite::config('hotFile', 'public/hot');
6666
}
67-
68-
Config::attachView(ViewConfig('viewEngine'), 'template');
69-
70-
if (ViewConfig('config')) {
71-
call_user_func_array(ViewConfig('config'), [
72-
app()->template(),
73-
[
74-
'views' => AppConfig('views.path'),
75-
'cache' => AppConfig('views.cachePath'),
76-
]
77-
]);
78-
} else if (method_exists(app()->template(), 'configure')) {
79-
app()->template()->configure([
80-
'views' => AppConfig('views.path'),
81-
'cache' => AppConfig('views.cachePath'),
82-
]);
83-
}
84-
85-
if (is_callable(ViewConfig('extend'))) {
86-
call_user_func_array(ViewConfig('extend'), app()->template());
87-
}
8867
}
8968
}
9069

@@ -209,11 +188,10 @@ protected static function loadConfig()
209188
],
210189
'view' => [
211190
'viewEngine' => \Leaf\Blade::class,
212-
'config' => function ($engine, $config) {
213-
$engine->configure($config['views'], $config['cache']);
191+
'config' => function ($config) {
192+
app()->blade()->configure($config['views'], $config['cache']);
214193
},
215194
'render' => null,
216-
'extend' => null,
217195
],
218196
'mail' => [
219197
'host' => _env('MAIL_HOST', 'smtp.mailtrap.io'),

src/globals/functions.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,57 @@ function assets($assets = '')
2222
*/
2323
function view(string $view, $data = [])
2424
{
25-
return app()->template()->render($view, $data);
25+
/// WILL REFACTOR IN NEXT VERSION
26+
if (is_object($data)) {
27+
$data = (array) $data;
28+
}
29+
30+
if (ViewConfig('render')) {
31+
if (ViewConfig('config')) {
32+
call_user_func_array(ViewConfig('config'), [
33+
[
34+
'views' => AppConfig('views.path'),
35+
'cache' => AppConfig('views.cachePath'),
36+
]
37+
]);
38+
}
39+
return ViewConfig('render')($view, $data);
40+
}
41+
42+
$engine = ViewConfig('viewEngine');
43+
$className = strtolower(get_class(new $engine));
44+
$fullName = explode('\\', $className);
45+
$className = $fullName[count($fullName) - 1];
46+
47+
if (\Leaf\Config::getStatic("views.$className")) {
48+
if (ViewConfig('config')) {
49+
call_user_func_array(ViewConfig('config'), [
50+
[
51+
'views' => AppConfig('views.path'),
52+
'cache' => AppConfig('views.cachePath'),
53+
]
54+
]);
55+
} else {
56+
\Leaf\Config::get("views.$className")->configure(AppConfig('views.path'), AppConfig('views.cachePath'));
57+
}
58+
59+
return \Leaf\Config::get("views.$className")->render($view, $data);
60+
}
61+
62+
$engine = new $engine($engine);
63+
64+
if (ViewConfig('config')) {
65+
call_user_func_array(ViewConfig('config'), [
66+
[
67+
'views' => AppConfig('views.path'),
68+
'cache' => AppConfig('views.cachePath'),
69+
]
70+
]);
71+
} else {
72+
$engine->config(AppConfig('views.path'), AppConfig('views.cachePath'));
73+
}
74+
75+
return $engine->render($view, $data);
2676
}
2777
}
2878

0 commit comments

Comments
 (0)