json = $json; $this->data = json_decode($this->json, true); $this->dataJson = $this->data['data']; } public function beginTable(): void { $paramsStr = $this->createParams($this->data['meta']['params']); //Хук перед выводом ячейки if (isset($this->beforePrintTable)){ $hook = $this->beforePrintTable; $this->html = $hook(); } $this->html .= ""; } public function createRows(): string { foreach ($this->data['meta']['rows'] as $key => $row){ if ($this->issetRow($key)){ if (isset($this->beforePrintCell)){ $hook = $this->beforePrintCell; $this->dataJson[$key] = $hook($key, $this->dataJson[$key]); } $this->html .= ""; } } return $this->html; } private function issetRow($column): bool { if (isset($this->data['meta']['rows'])){ foreach ($this->data['meta']['rows'] as $key => $currentColumn){ if ($key === $column){ return true; } } } return false; } public function endTable(): void { $this->html .= "
" . $row . ": " . $this->dataJson[$key] . "
"; if(isset($this->afterPrintTable)){ $hookAfter = $this->afterPrintTable; $this->html .= $hookAfter(); } } public function create(): void { $this->beginTable(); $this->createRows(); $this->endTable(); } public function beforeTable(\Closure $closure): void { $this->beforePrintTable = $closure; } public function afterTable(\Closure $closure): void { $this->afterPrintTable = $closure; } public function render(): void { echo $this->html; } public function setBeforePrintCell(\Closure $closure): void { $this->beforePrintCell = $closure; } }