hyperf-view/builder/View/Form/FormTab.php

58 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Builder\View\Form;
use Builder\View\Form;
use Builder\View\Layout\Row;
use Builder\Traits\JsonBuilder;
class FormTab extends JsonBuilder
{
protected $name;
protected $rows = [];
protected $form;
public function __construct($name,Form $form)
{
$this->name = $name;
$this->form = $form;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
* @return FormTab
*/
public function name($name)
{
$this->name = $name;
return $this;
}
/**
* @param Row|\Closure $closure
* @return $this
*/
public function row($closure)
{
if ($closure instanceof \Closure) {
$row = new Row();
call_user_func($closure, $row, $this->form);
$this->rows = collect($this->rows)->push($row);
} else {
$this->rows = collect($this->rows)->push($closure);
}
return $this;
}
public function jsonSerialize() :array
{
return ['name' => $this->name, 'rows' => $this->rows];
}
}