sss
This commit is contained in:
69
src/JsonForm.php
Normal file
69
src/JsonForm.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms;
|
||||
|
||||
use itguild\forms\builders\Builder;
|
||||
use itguild\forms\builders\LabelBuilder;
|
||||
use itguild\forms\debug\Debug;
|
||||
use itguild\forms\mappers\JsonInputMapper;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
use itguild\forms\ActiveForm;
|
||||
|
||||
class JsonForm
|
||||
{
|
||||
private $jsonData;
|
||||
|
||||
private $html = '';
|
||||
|
||||
public function __construct($json)
|
||||
{
|
||||
$this->jsonData = json_decode($json, true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function convertHTML(): void
|
||||
{
|
||||
|
||||
foreach ($this->jsonData['data'] as $item) {
|
||||
|
||||
if (isset($item["type"]) and isset($item["name"])) {
|
||||
|
||||
/**
|
||||
* @var $builder Builder
|
||||
*/
|
||||
$builder = JsonInputMapper::getBuilder($item["type"]);
|
||||
unset($item["type"]);
|
||||
$name = $item["name"];
|
||||
unset($item["name"]);
|
||||
$label = '';
|
||||
if (isset($item['label'])) {
|
||||
$label = $this->createLabel($item['label']);
|
||||
}
|
||||
unset($item['label']);
|
||||
$input = $builder::build($name, $item);
|
||||
$input->setLabel($label)->create();
|
||||
$this->html .= $input->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//return $this->fetch($html);
|
||||
}
|
||||
|
||||
private function createLabel($labelParams)
|
||||
{
|
||||
$title = '';
|
||||
if(isset($labelParams['title'])){
|
||||
$title = $labelParams['title'];
|
||||
unset($labelParams['title']);
|
||||
}
|
||||
return LabelBuilder::build($title, $labelParams);
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
{
|
||||
echo $this->html;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user