Compare commits
No commits in common. "master" and "0.1.2" have entirely different histories.
@ -3,7 +3,7 @@ require_once __DIR__ . "/vendor/autoload.php";
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm("/some_action");
|
||||
$form->field(class: \itguild\forms\inputs\File::class, name: "login", params: [
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "login", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Логин',
|
||||
])
|
||||
|
@ -4,12 +4,11 @@ require_once __DIR__ . "/vendor/autoload.php";
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm("/some_action");
|
||||
$form->field(class: \itguild\forms\inputs\File::class, name: "login", params: [
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "login", params: [
|
||||
'class' => "form-control",
|
||||
'placeholder' => 'Файл',
|
||||
'placeholder' => 'Логин',
|
||||
])
|
||||
->setLabel("Файл")
|
||||
->setMultiple()
|
||||
->setLabel("Логин")
|
||||
->render();
|
||||
|
||||
$form->endForm();
|
@ -4,7 +4,6 @@ namespace itguild\forms;
|
||||
|
||||
use itguild\forms\builders\ButtonBuilder;
|
||||
use itguild\forms\builders\CheckBoxBuilder;
|
||||
use itguild\forms\builders\FileBuilder;
|
||||
use itguild\forms\builders\HiddenBuilder;
|
||||
use itguild\forms\builders\RadioButtonBuilder;
|
||||
use itguild\forms\builders\SelectBuilder;
|
||||
@ -14,7 +13,6 @@ use itguild\forms\debug\Debug;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
use itguild\forms\inputs\Button;
|
||||
use itguild\forms\inputs\Checkbox;
|
||||
use itguild\forms\inputs\File;
|
||||
use itguild\forms\inputs\Hidden;
|
||||
use itguild\forms\inputs\RadioButton;
|
||||
use itguild\forms\inputs\Select;
|
||||
@ -31,9 +29,9 @@ class ActiveForm
|
||||
* @param string $action
|
||||
* @return void
|
||||
*/
|
||||
public function beginForm(string $action, string $enctype = 'application/x-www-form-urlencoded'): void
|
||||
public function beginForm(string $action): void
|
||||
{
|
||||
echo "<form method='POST' action='$action' enctype='$enctype'>";
|
||||
echo "<form method='POST' action='$action'>";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +43,7 @@ class ActiveForm
|
||||
|
||||
}
|
||||
|
||||
public function field($class, string $name, array $params = []): static
|
||||
public function field($class, string $name, array $params = [])
|
||||
{
|
||||
if ($class === Select::class){
|
||||
$this->fieldObject = SelectBuilder::build($name, $params);
|
||||
@ -68,12 +66,10 @@ class ActiveForm
|
||||
elseif ($class === Hidden::class){
|
||||
$this->fieldObject = HiddenBuilder::build($name, $params);
|
||||
}
|
||||
elseif ($class === File::class){
|
||||
$this->fieldObject = FileBuilder::build($name, $params);
|
||||
}
|
||||
else {
|
||||
$this->fieldObject = new $class($name, $params);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -98,13 +94,6 @@ class ActiveForm
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMultiple(): self
|
||||
{
|
||||
$this->fieldObject->setMultiple();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->fieldObject->create();
|
||||
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\builders;
|
||||
|
||||
use itguild\forms\debug\Debug;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
use itguild\forms\inputs\File;
|
||||
|
||||
class FileBuilder implements Builder
|
||||
{
|
||||
public static function build(string $name, array $params = []): BaseInput
|
||||
{
|
||||
return new File(name: $name, paramsArray: $params);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\inputs;
|
||||
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
use itguild\forms\templates\Simple\SimpleTemplate;
|
||||
use itguild\forms\traits\CreateParams;
|
||||
|
||||
class File extends BaseInput
|
||||
{
|
||||
use CreateParams;
|
||||
private string $name;
|
||||
private array $paramsArray;
|
||||
private string $multiple;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $paramsArray
|
||||
*/
|
||||
|
||||
public function __construct(string $name, array $paramsArray = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->paramsArray = $paramsArray;
|
||||
$this->inputTemplate = new SimpleTemplate();
|
||||
$this->multiple = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
public function create(): self
|
||||
{
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$input = "<input type='file' name='$this->name' $this->multiple $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();
|
||||
}
|
||||
|
||||
public function setMultiple(): void
|
||||
{
|
||||
$this->multiple = 'multiple';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user