firstPHP/src/inputs/TextInput.php

62 lines
1.4 KiB
PHP
Raw Normal View History

2024-03-15 14:17:25 +03:00
<?php
2024-03-15 16:56:03 +03:00
namespace itguild\forms\inputs;
2024-03-15 14:17:25 +03:00
2024-03-18 17:52:16 +03:00
use itguild\forms\debug\Debug;
2024-03-15 16:56:03 +03:00
use itguild\forms\inputs\BaseInput;
2024-03-18 17:52:16 +03:00
use itguild\forms\templates\bootstrap5\Bootstrap5Template;
use itguild\forms\templates\Simple\SimpleTemplate;
use itguild\forms\templates\Template;
2024-03-15 16:56:03 +03:00
use itguild\forms\traits\CreateParams;
2024-03-15 14:17:25 +03:00
2024-03-15 16:56:03 +03:00
class TextInput extends BaseInput
2024-03-15 14:17:25 +03:00
{
use CreateParams;
private string $name;
private array $paramsArray;
2024-03-19 17:40:27 +03:00
2024-03-18 17:52:16 +03:00
2024-03-15 16:56:03 +03:00
2024-03-15 14:17:25 +03:00
/**
* @param string $name
* @param array $paramsArray
*/
public function __construct(string $name, array $paramsArray = [])
{
$this->name = $name;
$this->paramsArray = $paramsArray;
2024-03-18 17:52:16 +03:00
$this->inputTemplate = new SimpleTemplate();
2024-03-15 14:17:25 +03:00
}
/**
2024-03-15 16:56:03 +03:00
* @return self
2024-03-15 14:17:25 +03:00
*/
2024-03-15 16:56:03 +03:00
public function create(): self
2024-03-15 14:17:25 +03:00
{
$paramsString = $this->createParams($this->paramsArray);
2024-03-18 17:52:16 +03:00
$label = "";
$input = "<input name='$this->name' $paramsString >";
2024-03-20 18:31:49 +03:00
$this->createLabel();
2024-03-15 16:56:03 +03:00
2024-03-18 17:52:16 +03:00
$this->html = str_replace('{input}', $input, $this->inputTemplate->getInputTemplate());
2024-03-20 18:31:49 +03:00
$this->html = str_replace('{label}', $this->labelString, $this->html);
2024-03-18 17:52:16 +03:00
2024-03-15 16:56:03 +03:00
return $this;
2024-03-15 14:17:25 +03:00
}
/**
* @param string $name
* @param array $paramsArray
* @return void
*/
public static function build(string $name, array $paramsArray = []): void
{
$input = new self($name, $paramsArray);
2024-03-15 16:56:03 +03:00
$input->create()->render();
}
2024-03-15 14:17:25 +03:00
}