Skip to content

Commit

Permalink
改进模板exists方法
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jan 8, 2025
1 parent 7556ef4 commit 6a46068
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/think/view/driver/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,25 @@ public function __construct(App $app, array $config = [])
* @return bool
*/
public function exists(string $template): bool
{
$template = $this->getTemplateFile($template);

return is_file($template);
}

protected function getTemplateFile(string $template): string
{
if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
// 获取模板文件名
$template = $this->parseTemplate($template);
} else {
$path = $this->config['view_path'] ?: $this->getViewPath($this->app->http->getName());
$template = $path . $template;
}

return is_file($template);
return $template;
}

/**
* 渲染模板文件
* @param string $template 模板文件
Expand All @@ -69,13 +79,7 @@ public function exists(string $template): bool
*/
public function fetch(string $template, array $data = []): void
{
if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
// 获取模板文件名
$template = $this->parseTemplate($template);
} else {
$path = $this->config['view_path'] ?: $this->getViewPath($this->app->http->getName());
$template = $path . $template;
}
$template = $this->getTemplateFile($template);

// 模板不存在 抛出异常
if (!is_file($template)) {
Expand Down

0 comments on commit 6a46068

Please sign in to comment.