view = $view; $this->data = $data; $this->compiler = $compiler; } /** * 渲染视图 * * @return string */ public function render(): string { // 编译视图 $compiledPath = $this->compiler->compile($this->view); // 提取数据 extract($this->data, EXTR_SKIP); // 初始化栈和 section 数组 $__stacks = []; $__sections = []; // 开始输出缓冲 ob_start(); try { // 包含编译后的 PHP 文件 require $compiledPath; } catch (\Throwable $e) { ob_end_clean(); \Kiri::getLogger()->json_log($throwable); throw new \RuntimeException("视图渲染失败: {$this->view}", 0, $e); } return ob_get_clean(); } /** * 获取视图名称 * * @return string */ public function getView(): string { return $this->view; } /** * 获取视图数据 * * @return array */ public function getData(): array { return $this->data; } }