66 lines
1.2 KiB
PHP
66 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace itguild\forms\form\inputs;
|
||
|
|
||
|
use itguild\forms\form\templates\Template;
|
||
|
|
||
|
abstract class BaseInput
|
||
|
{
|
||
|
protected Template $inputTemplate;
|
||
|
protected bool $hasLabel = false;
|
||
|
protected string $html = '';
|
||
|
protected string|Label $label = "";
|
||
|
protected string $labelString = "";
|
||
|
|
||
|
/**
|
||
|
* @return void
|
||
|
*/
|
||
|
public function render(): void
|
||
|
{
|
||
|
echo $this->html;
|
||
|
}
|
||
|
|
||
|
public function fetch(): string
|
||
|
{
|
||
|
return $this->html;
|
||
|
}
|
||
|
|
||
|
public abstract function create();
|
||
|
|
||
|
/**
|
||
|
* @param string|Label $title
|
||
|
* @return $this
|
||
|
*/
|
||
|
public function setLabel(string|Label $title): self
|
||
|
{
|
||
|
$this->hasLabel = true;
|
||
|
$this->label= $title;
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
protected function createLabel()
|
||
|
{
|
||
|
if($this->hasLabel) {
|
||
|
if(is_string($this->label)){
|
||
|
$this->labelString = "<label>$this->label</label>";
|
||
|
}
|
||
|
else {
|
||
|
$this->labelString= $this->label->create()->fetch();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param $template
|
||
|
* @return $this
|
||
|
*/
|
||
|
public function setTemplate($template): self
|
||
|
{
|
||
|
$this->inputTemplate = new $template();
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|