add JasonTable class

This commit is contained in:
2024-08-02 15:40:13 +03:00
parent 67a3f5770e
commit f53346610e
5 changed files with 80 additions and 103 deletions

60
src/JasonTable.php Normal file
View File

@ -0,0 +1,60 @@
<?php
namespace Itguild\Tables;
abstract 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 setBeforePrintCell(\Closure|array $data): void
{
if(is_array($data)) {
foreach ($data as $key => $value) {
$this->beforePrintCell[$key] = $value;
}
} else {
$this->beforePrintCell = $data;
}
}
public function getCustomCeil(string $key, string $ceil)
{
if (is_array($this->beforePrintCell)) {
foreach ($this->beforePrintCell as $_key => $closure) {
if ($key == $_key) {
$hook = $closure;
$ceil = $hook($ceil);
}
}
} else {
$hook = $this->beforePrintCell;
$ceil = $hook($key, $ceil);
}
return $ceil;
}
public function afterPrint(\Closure $closure): void
{
$this->afterPrintHook = $closure;
}
public function beforePrint(\Closure $closure): void
{
$this->beforePrintHook = $closure;
}
}