Skip to content

Commit fa8bfb0

Browse files
committed
view() Optimization
1 parent 193cc0a commit fa8bfb0

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/support/view/Blade.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ public static function render(string $template, array $vars, ?string $app = null
5959
$configPrefix = $plugin ? "plugin.$plugin." : '';
6060
$baseViewPath = $plugin ? base_path() . "/plugin/$plugin/app" : app_path();
6161
if ($template[0] === '/') {
62-
$viewPath = base_path();
63-
$template = substr($template, 1);
62+
if (strpos($template, '/view/') !== false) {
63+
[$viewPath, $template] = explode('/view/', $template, 2);
64+
$viewPath = base_path("$viewPath/view");
65+
} else {
66+
$viewPath = base_path();
67+
$template = ltrim($template, '/');
68+
}
6469
} else {
6570
$viewPath = $app === '' ? "$baseViewPath/view" : "$baseViewPath/$app/view";
6671
}

src/support/view/ThinkPHP.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ public static function render(string $template, array $vars, ?string $app = null
6060
$viewSuffix = config("{$configPrefix}view.options.view_suffix", 'html');
6161
$baseViewPath = $plugin ? base_path() . "/plugin/$plugin/app" : app_path();
6262
if ($template[0] === '/') {
63-
$viewPath = base_path() . dirname($template) . '/';
64-
$template = basename($template);
63+
if (strpos($template, '/view/') !== false) {
64+
[$viewPath, $template] = explode('/view/', $template, 2);
65+
$viewPath = base_path("$viewPath/view/");
66+
} else {
67+
$viewPath = base_path() . dirname($template) . '/';
68+
$template = basename($template);
69+
}
6570
} else {
6671
$viewPath = $app === '' ? "$baseViewPath/view/" : "$baseViewPath/$app/view/";
6772
}

src/support/view/Twig.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ public static function render(string $template, array $vars, ?string $app = null
6262
$viewSuffix = config("{$configPrefix}view.options.view_suffix", 'html');
6363
$baseViewPath = $plugin ? base_path() . "/plugin/$plugin/app" : app_path();
6464
if ($template[0] === '/') {
65-
$viewPath = base_path();
66-
$template = substr($template, 1);
65+
$template = ltrim($template, '/');
66+
if (strpos($template, '/view/') !== false) {
67+
[$viewPath, $template] = explode('/view/', $template, 2);
68+
$viewPath = base_path("$viewPath/view");
69+
} else {
70+
$viewPath = base_path();
71+
}
6772
} else {
6873
$viewPath = $app === '' ? "$baseViewPath/view/" : "$baseViewPath/$app/view/";
6974
}

0 commit comments

Comments
 (0)