mirror of
https://github.com/igorsimdyanov/php8.git
synced 2025-08-03 16:43:03 +00:00
35 lines
721 B
PHP
35 lines
721 B
PHP
<?php
|
|
namespace MVC\Views;
|
|
|
|
class HtmlView extends ViewFactory
|
|
{
|
|
const LAYOUT = <<<HTML
|
|
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<title>{{{title}}}</title>
|
|
<meta charset='utf-8' />
|
|
</head>
|
|
<body>{{{body}}}</body>
|
|
</html>
|
|
HTML;
|
|
|
|
protected $replacements;
|
|
|
|
public function __construct(object $decorator)
|
|
{
|
|
$this->replacements = [
|
|
'{{{title}}}' => $decorator->title(),
|
|
'{{{body}}}' => $decorator->body()
|
|
];
|
|
}
|
|
|
|
public function render() : string
|
|
{
|
|
return str_replace(
|
|
array_keys($this->replacements),
|
|
array_values($this->replacements),
|
|
self::LAYOUT);
|
|
}
|
|
}
|