first commit
This commit is contained in:
66
inputs/BaseInput.php
Executable file
66
inputs/BaseInput.php
Executable file
@ -0,0 +1,66 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user