Compare commits

..

No commits in common. "master" and "0.1.5" have entirely different histories.

5 changed files with 10 additions and 120 deletions

View File

@ -1,16 +0,0 @@
<?php
namespace itguild\forms\builders;
use itguild\forms\inputs\BaseInput;
use itguild\forms\inputs\EmailInput;
use itguild\forms\inputs\TextInput;
class EmailBuilder implements Builder
{
public static function build(string $name, array $params = []): BaseInput
{
return new EmailInput(name: $name, paramsArray: $params);
}
}

View File

@ -7,20 +7,12 @@ use itguild\forms\inputs\Select;
class SelectBuilder
{
public static function build(string $name, array $params = []): Select
public static function build(string $name, array $params = [])
{
$value = $params['value'] ?? null;
unset($params['value']);
if (isset($params['prompt'])) {
$options['prompt'] = $params['prompt'];
foreach ($params['options'] as $key => $val) {
$options[$key] = $val;
}
unset($params['prompt']);
} else {
$options = $params['options'] ?? [];
}
$options = $params['options'] ?? [];
unset($params['options']);
return new Select(name: $name, options: $options, value: $value, paramsArray: $params);

View File

@ -1,62 +0,0 @@
<?php
namespace itguild\forms\inputs;
use itguild\forms\debug\Debug;
use itguild\forms\inputs\BaseInput;
use itguild\forms\templates\bootstrap5\Bootstrap5Template;
use itguild\forms\templates\Simple\SimpleTemplate;
use itguild\forms\templates\Template;
use itguild\forms\traits\CreateParams;
class EmailInput 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' type='email' $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();
}
}

View File

@ -2,8 +2,6 @@
namespace itguild\forms\traits;
use itguild\forms\debug\Debug;
trait CreateOption
{
/**
@ -14,37 +12,15 @@ trait CreateOption
public function createOption(array $options, $value = null): string
{
$optionsString = "";
if ($value) {
if (isset($options['prompt'])) {
$prompt = $options['prompt'];
$optionsString .= "<option value='''>$prompt</option>";
}
if (is_array($value)) {
foreach ($options as $val => $title) {
if ($val === 'prompt') continue;
$selected = in_array($title, $value) ? "selected" : "";
$optionsString .= "<option $selected value='$val'>$title</option>";
}
} else {
foreach ($options as $val => $title) {
if ($val === 'prompt') continue;
if (is_numeric($value)) {
$selected = (int)$value === $val ? "selected" : "";
} else {
$selected = $value === $val ? "selected" : "";
}
$optionsString .= "<option $selected value='$val'>$title</option>";
}
if (is_array($value)) {
foreach ($options as $val => $title) {
$selected = in_array($title, $value) ? "selected" : "";
$optionsString .= "<option $selected value='$val'>$title</option>";
}
} else {
if (isset($options['prompt'])) {
$prompt = $options['prompt'];
$optionsString .= "<option value='' selected='selected'>$prompt</option>";
}
foreach ($options as $val => $title) {
if ($val === 'prompt') continue;
$optionsString .= "<option value='$val'>$title</option>";
$selected = (int)$value === $val ? "selected" : "";
$optionsString .= "<option $selected value='$val'>$title</option>";
}
}

View File

@ -15,7 +15,7 @@ trait CreateParams
{
$paramsString = "";
foreach($data as $key => $param){
if(is_string($param) || is_numeric($param)){
if(is_string($param)){
$paramsString .= $key . "='" . $param . "'";
}
}