49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Itguild\Tables;
|
|
|
|
class JasonTable
|
|
{
|
|
protected string $html = "";
|
|
protected \Closure|array|false $beforePrintCell;
|
|
protected \Closure|false $afterPrintHook;
|
|
protected \Closure|false $beforePrintHook;
|
|
|
|
|
|
public function render(): void
|
|
{
|
|
echo $this->html;
|
|
}
|
|
|
|
public function setBeforePrintCell(\Closure $closure): void
|
|
{
|
|
$this->beforePrintCell = $closure;
|
|
}
|
|
|
|
public function getCustomCell(string $key, string $cell)
|
|
{
|
|
if (is_array($this->beforePrintCell)) {
|
|
foreach ($this->beforePrintCell as $currentKey => $closure) {
|
|
if ($key == $currentKey) {
|
|
$hook = $closure;
|
|
$cell = $hook($cell);
|
|
}
|
|
}
|
|
} else {
|
|
$hook = $this->beforePrintCell;
|
|
$cell = $hook($key, $cell);
|
|
}
|
|
|
|
return $cell;
|
|
}
|
|
|
|
public function afterPrint(\Closure $closure): void
|
|
{
|
|
$this->afterPrintHook = $closure;
|
|
}
|
|
|
|
public function beforePrint(\Closure $closure): void
|
|
{
|
|
$this->beforePrintHook = $closure;
|
|
}
|
|
} |