32 lines
795 B
PHP
32 lines
795 B
PHP
<?php
|
|
|
|
namespace Ardent\Undercurrent\View;
|
|
|
|
use Ardent\Undercurrent\AppConfig;
|
|
use Ardent\Undercurrent\Http\GenericResponse;
|
|
use Ardent\Undercurrent\Http\ResponseInterface;
|
|
|
|
class BaseView implements ViewInterface
|
|
{
|
|
public function __construct(
|
|
private readonly string $path,
|
|
private readonly array $data = [],
|
|
private ?string $extends = null,
|
|
)
|
|
{
|
|
}
|
|
|
|
public function render(AppConfig $config): string
|
|
{
|
|
$path = $config->getRootPath() . $this->path;
|
|
|
|
ob_start();
|
|
include $path;
|
|
$output = ob_get_clean();
|
|
if ($this->extends) {
|
|
$output = (new BaseView($this->extends, $this->data + ['slot' => $output]))->render($config);
|
|
}
|
|
|
|
return $output;
|
|
}
|
|
} |