forms/inputs/TextInput.php
2024-05-28 17:10:06 +03:00

58 lines
1.3 KiB
PHP
Executable File

<?php
namespace itguild\forms\form\inputs;
use itguild\forms\form\templates\Simple\SimpleTemplate;
use itguild\forms\form\traits\CreateParams;
class TextInput extends BaseInput
{
use CreateParams;
private string $name;
private array $paramsArray;
/**
* @param string $name
* @param array $paramsArray
*/
public function __construct(string $name, array $paramsArray = [])
{
$this->name = $name;
$this->paramsArray = $paramsArray;
$this->inputTemplate = new SimpleTemplate();
}
/**
* @return self
*/
public function create(): self
{
$paramsString = $this->createParams($this->paramsArray);
$label = "";
$input = "<input name='$this->name' $paramsString >";
$this->createLabel();
$this->html = str_replace('{input}', $input, $this->inputTemplate->getInputTemplate());
$this->html = str_replace('{label}', $this->labelString, $this->html);
return $this;
}
/**
* @param string $name
* @param array $paramsArray
* @return void
*/
public static function build(string $name, array $paramsArray = []): void
{
$input = new self($name, $paramsArray);
$input->create()->render();
}
}