From 5bda1e05259032c888904e292a7bda7e34af0cb7 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 15 Mar 2024 16:56:03 +0300 Subject: [PATCH] update --- .gitignore | 3 ++- composer.json | 15 +++++++++++++++ index.php | 31 +++++++++++++++++++------------ src/ActiveForm.php | 32 ++++++++++++++++++++++++++++++++ src/Form.php | 16 ++++++++-------- src/debug/Debug.php | 2 +- src/inputs/BaseInput.php | 25 +++++++++++++++++++++++++ src/inputs/Button.php | 28 +++++++++++++++++++++------- src/inputs/Checkbox.php | 26 +++++++++++++++++++------- src/inputs/Label.php | 18 +++++++++++------- src/inputs/Radio.php | 28 +++++++++++++++++++++------- src/inputs/Select.php | 29 +++++++++++++++++++++-------- src/inputs/TextArea.php | 32 ++++++++++++++++++++++++-------- src/inputs/TextInput.php | 30 +++++++++++++++++++++++------- src/traits/CreateOption.php | 2 +- src/traits/CreateParams.php | 2 +- 16 files changed, 244 insertions(+), 75 deletions(-) create mode 100644 composer.json create mode 100644 src/ActiveForm.php create mode 100644 src/inputs/BaseInput.php diff --git a/.gitignore b/.gitignore index 723ef36..9fd1dab 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +/vendor/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a1f8c3b --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "name": "itguild/forms", + "type": "library", + "autoload": { + "psr-4": { + "itguild\\forms\\": "src/" + } + }, + "authors": [ + { + "name": "nikita" + } + ], + "require": {} +} diff --git a/index.php b/index.php index dc09474..4bd2cea 100644 --- a/index.php +++ b/index.php @@ -1,19 +1,13 @@ beginForm("tsad"); @@ -32,3 +26,16 @@ $form->textarea("textarea", "dsadasads", ["id" => "t1"]); $form->select("select", ["class1" => "option", "class2" => "b2", "class3" => "b4"], 'class2', ["id" => "s1"]); $form->button('button', "Кнопка", ["id" => "button"]); $form->endForm(); + +$activeForm = new \itguild\forms\ActiveForm(); +$activeForm->field(class: TextInput::class, name: 'nnn', params: ["style" => "color:RED;display:flex"]) + ->setLabel("dfdfdffd") + ->render(); + +$activeForm->field(class: TextInput::class, name: 'bbb', params: []) + ->setLabel("bbbbbb") + ->render(); + +$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"]) + ->setLabel("bbbbb") + ->render(); \ No newline at end of file diff --git a/src/ActiveForm.php b/src/ActiveForm.php new file mode 100644 index 0000000..6118d52 --- /dev/null +++ b/src/ActiveForm.php @@ -0,0 +1,32 @@ +fieldObject = new $class($name, $params); + $this->fieldObject->create(); + + return $this; + } + + public function setLabel(string $title) + { + $this->fieldObject->setLabel($title); + + return $this; + } + + public function render() + { + $this->fieldObject->render(); + } + +} \ No newline at end of file diff --git a/src/Form.php b/src/Form.php index b38b1b3..285423e 100644 --- a/src/Form.php +++ b/src/Form.php @@ -1,14 +1,14 @@ html; + } + + public abstract function create(); + + /** + * @return $this + */ + + +} \ No newline at end of file diff --git a/src/inputs/Button.php b/src/inputs/Button.php index d4e77cc..7b29f25 100644 --- a/src/inputs/Button.php +++ b/src/inputs/Button.php @@ -1,16 +1,19 @@ createParams($this->paramsArray); - echo ""; + $this->html = ""; + + return $this; } /** @@ -41,7 +46,16 @@ class Button public static function build(string $name, string $value, array $paramsArray = []): void { $input = new self($name, $value, $paramsArray); - $input->create(); + $input->create()->render(); + } + /** + * @param string $title + * @return $this + */ + public function setLabel(string $title): self + { + $this->html = ""; + return $this; } } \ No newline at end of file diff --git a/src/inputs/Checkbox.php b/src/inputs/Checkbox.php index d3a9c79..d00ce18 100644 --- a/src/inputs/Checkbox.php +++ b/src/inputs/Checkbox.php @@ -1,10 +1,11 @@ createParams($this->paramsArray); - echo ""; + $this->html = ""; + return $this; } /** @@ -42,8 +45,17 @@ class Checkbox public static function build(string $name, string $value, array $paramsArray): void { $checkbox = new self($name, $value, $paramsArray); - $checkbox->create(); + $checkbox->create()->render(); } + /** + * @param string $title + * @return $this + */ + public function setLabel(string $title): self + { + $this->html = ""; + return $this; + } } \ No newline at end of file diff --git a/src/inputs/Label.php b/src/inputs/Label.php index 342159d..35f74f7 100644 --- a/src/inputs/Label.php +++ b/src/inputs/Label.php @@ -1,9 +1,10 @@ createParams($this->paramsArray); - echo ""; + $this->html = ""; + + return $this; } @@ -39,7 +43,7 @@ class Label public static function build(string $title, array $paramsArray = []) { $label = new self($title, $paramsArray); - $label->create(); + $label->create()->render(); } diff --git a/src/inputs/Radio.php b/src/inputs/Radio.php index 9af3bc9..c6389c9 100644 --- a/src/inputs/Radio.php +++ b/src/inputs/Radio.php @@ -1,13 +1,15 @@ name = $name; @@ -15,12 +17,14 @@ class Radio } /** - * @return void + * @return $this */ - public function create(): void + public function create(): self { $paramsString = $this->createParams($this->paramsArray); - echo ""; + $this->html = ""; + + return $this; } /** @@ -31,6 +35,16 @@ class Radio public static function build(string $name, array $paramsArray = []): void { $label = new self($name, $paramsArray); - $label->create(); + $label->create()->render(); + } + + /** + * @param string $title + * @return $this + */ + public function setLabel(string $title): self + { + $this->html = ""; + return $this; } } \ No newline at end of file diff --git a/src/inputs/Select.php b/src/inputs/Select.php index c4777d8..317a454 100644 --- a/src/inputs/Select.php +++ b/src/inputs/Select.php @@ -1,11 +1,12 @@ createParams($this->paramsArray); $optionsString = $this->createOption($this->options, $this->value); - echo ""; + $this->html = ""; + + return $this; } @@ -49,7 +53,16 @@ class Select public static function build(string $name, array $options = [], $value = null, array $paramsArray = []): void { $textarea = new self($name, $options, $value, $paramsArray); - $textarea->create(); + $textarea->create()->render(); } + /** + * @param string $title + * @return $this + */ + public function setLabel(string $title): self + { + $this->html = ""; + return $this; + } } \ No newline at end of file diff --git a/src/inputs/TextArea.php b/src/inputs/TextArea.php index 193d7b8..2e9140e 100644 --- a/src/inputs/TextArea.php +++ b/src/inputs/TextArea.php @@ -1,8 +1,11 @@ name = $name; $this->value = $value; @@ -23,14 +26,17 @@ class TextArea } /** - * @return void + * @return $this */ - public function create(): void + public function create(): self { $paramsString = $this->createParams($this->paramsArray); - echo ""; + $this->html = ""; + + return $this; } + /** * @param string $name * @param string $value @@ -40,7 +46,17 @@ class TextArea public static function build(string $name, string $value, array $paramsArray = []): void { $textarea = new self($name, $value, $paramsArray); - $textarea->create(); + $textarea->create()->render(); + } + + /** + * @param string $title + * @return $this + */ + public function setLabel(string $title): self + { + $this->html = ""; + return $this; } diff --git a/src/inputs/TextInput.php b/src/inputs/TextInput.php index 7a7d89d..185cd46 100644 --- a/src/inputs/TextInput.php +++ b/src/inputs/TextInput.php @@ -1,10 +1,11 @@ createParams($this->paramsArray); - echo ""; + $this->html = ""; + + return $this; } /** @@ -39,7 +43,19 @@ class TextInput public static function build(string $name, array $paramsArray = []): void { $input = new self($name, $paramsArray); - $input->create(); + $input->create()->render(); + } + /** + * @param string $title + * @return $this + */ + public function setLabel(string $title): self + { + $this->html = ""; + return $this; + } + + } \ No newline at end of file diff --git a/src/traits/CreateOption.php b/src/traits/CreateOption.php index 544ea13..c915d57 100644 --- a/src/traits/CreateOption.php +++ b/src/traits/CreateOption.php @@ -1,6 +1,6 @@