Skip to content

Commit

Permalink
Added view-engine component. (#2737)
Browse files Browse the repository at this point in the history

Co-authored-by: nfangxu <[email protected]>
  • Loading branch information
limingxinleo and nfangxu authored Oct 30, 2020
1 parent 77aedc1 commit 5319e30
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions publish/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
'config' => [
'view_path' => BASE_PATH . '/storage/view/',
'cache_path' => BASE_PATH . '/runtime/view/',
'charset' => 'UTF-8',
],
];
9 changes: 8 additions & 1 deletion src/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(ContainerInterface $container, ConfigInterface $conf
public function render(string $template, array $data = []): ResponseInterface
{
return $this->response()
->withAddedHeader('content-type', 'text/html')
->withAddedHeader('content-type', $this->getContentType())
->withBody(new SwooleStream($this->getContents($template, $data)));
}

Expand All @@ -87,6 +87,13 @@ public function getContents(string $template, array $data = []): string
}
}

public function getContentType(): string
{
$charset = ! empty($this->config['charset']) ? '; charset=' . $this->config['charset'] : '';

return 'text/html' . $charset;
}

protected function response(): ResponseInterface
{
return Context::get(ResponseInterface::class);
Expand Down
2 changes: 2 additions & 0 deletions src/RenderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ interface RenderInterface
public function render(string $template, array $data = []): ResponseInterface;

public function getContents(string $template, array $data = []): string;

public function getContentType(): string;
}

0 comments on commit 5319e30

Please sign in to comment.