add JasonTable class
This commit is contained in:
60
src/JasonTable.php
Normal file
60
src/JasonTable.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user