commit 000e0acfb86a3c9bf5f8d24cb92cc9a7736b3b8b Author: kali Date: Fri Mar 15 14:17:25 2024 +0300 first diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..47cc021 --- /dev/null +++ b/index.php @@ -0,0 +1,33 @@ +beginForm("tsad"); +$form->textInput("phone", ['placeholder' => 'Введите телефон', 'class' => 'form-group']); +$form->textInput("email", ['placeholder' => 'Введите email']); +$form->textInput("name", ['type' => 'number']); +$form->checkBox("Button", "1", ["class" => 'sdsa', "id" => "b1"]); +$form->checkBox("Button", "2", ["class" => 'sdsa', "id" => "b1"]); +$form->checkBox("Button", "3", ["class" => 'sdsa', "id" => "b1"]); +$form->label("RadioButton", ["for" => "r2"]); +$form->radio("name1", ["id" => "r2"]); +$form->label("RadioButton", ["for" => "r3"]); +$form->radio("name1", ["id" => "r3"]); +$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(); diff --git a/src/Form.php b/src/Form.php new file mode 100644 index 0000000..b38b1b3 --- /dev/null +++ b/src/Form.php @@ -0,0 +1,110 @@ +"; + } + + /** + * @param string $name + * @param array $paramsArray + * @return void + */ + + public function textInput(string $name, array $paramsArray = []): void + { + TextInput::build($name, $paramsArray); + } + + /** + * @param string $name + * @param string $value + * @param array $paramsArray + * @return void + */ + public function checkBox(string $name, string $value, array $paramsArray = []): void + { + Checkbox::build($name, $value, $paramsArray); + + } + + /** + * @param string $title + * @param array $paramsArray + * @return void + */ + public function label(string $title, array $paramsArray = []): void + { + Label::build($title, $paramsArray); + } + + /** + * @param string $name + * @param array $paramsArray + * @return void + */ + public function radio(string $name, array $paramsArray = []): void + { + Radio::build($name, $paramsArray); + } + + /** + * @param string $name + * @param string $value + * @param array $paramsArray + * @return void + */ + public function textarea(string $name, string $value = "", array $paramsArray = []): void + { + TextArea::build($name, $value, $paramsArray); + } + + /** + * @param string $name + * @param array $options + * @param $value + * @param array $paramsArray + * @return void + */ + public function select(string $name, array $options = [], $value = null, array $paramsArray = []): void + { + Select::build($name, $options, $value, $paramsArray); + + } + + /** + * @param string $name + * @param string $value + * @param array $paramsArray + * @return void + */ + public function button(string $name, string $value, array $paramsArray = []): void + { + Button::build($name, $value, $paramsArray); + } + + /** + * @return void + */ + public function endForm(): void + { + echo ""; + + } +} diff --git a/src/debug/Debug.php b/src/debug/Debug.php new file mode 100644 index 0000000..d3b8f43 --- /dev/null +++ b/src/debug/Debug.php @@ -0,0 +1,20 @@ +'; + print_r($content); + echo ''; + } + public static function dd($content) + { + echo '
';
+        print_r($content);
+        echo '
'; + die(); + } +} \ No newline at end of file diff --git a/src/inputs/Button.php b/src/inputs/Button.php new file mode 100644 index 0000000..a377ac3 --- /dev/null +++ b/src/inputs/Button.php @@ -0,0 +1,33 @@ +name = $name; + $this->paramsArray = $paramsArray; + $this->value = $value; + } + + public function create(): void + { + $paramsString = $this->createParams($this->paramsArray); + echo ""; + } + + public static function build(string $name, string $value, array $paramsArray = []): void + { + $input = new self($name, $value, $paramsArray); + $input->create(); + } + +} \ No newline at end of file diff --git a/src/inputs/Checkbox.php b/src/inputs/Checkbox.php new file mode 100644 index 0000000..ea3796a --- /dev/null +++ b/src/inputs/Checkbox.php @@ -0,0 +1,34 @@ +name = $name; + $this->value = $value; + $this->paramsArray = $paramsArray; + } + public function create(): void + { + $paramsString = $this->createParams($this->paramsArray); + echo ""; + } + + public static function build(string $name, string $value, array $paramsArray): void + { + $checkbox = new self($name, $value, $paramsArray); + $checkbox->create(); + + } + +} \ No newline at end of file diff --git a/src/inputs/Label.php b/src/inputs/Label.php new file mode 100644 index 0000000..2b829c5 --- /dev/null +++ b/src/inputs/Label.php @@ -0,0 +1,35 @@ +title = $title; + $this->paramsArray = $paramsArray; + } + + public function create(): void + { + $paramsString = $this->createParams($this->paramsArray); + echo ""; + + } + + public static function build(string $title, array $paramsArray = []) + { + $label = new self($title, $paramsArray); + $label->create(); + + } + + + +} \ No newline at end of file diff --git a/src/inputs/Radio.php b/src/inputs/Radio.php new file mode 100644 index 0000000..9af3bc9 --- /dev/null +++ b/src/inputs/Radio.php @@ -0,0 +1,36 @@ +name = $name; + $this->paramsArray = $paramsArray; + } + + /** + * @return void + */ + public function create(): void + { + $paramsString = $this->createParams($this->paramsArray); + echo ""; + } + + /** + * @param string $name + * @param array $paramsArray + * @return void + */ + public static function build(string $name, array $paramsArray = []): void + { + $label = new self($name, $paramsArray); + $label->create(); + } +} \ No newline at end of file diff --git a/src/inputs/Select.php b/src/inputs/Select.php new file mode 100644 index 0000000..c4777d8 --- /dev/null +++ b/src/inputs/Select.php @@ -0,0 +1,55 @@ +name = $name; + $this->options = $options; + $this->value = $value; + $this->paramsArray = $paramsArray; + } + + /** + * @return void + */ + public function create(): void + { + $paramsString = $this->createParams($this->paramsArray); + $optionsString = $this->createOption($this->options, $this->value); + echo ""; + + } + + /** + * @param string $name + * @param array $options + * @param $value + * @param array $paramsArray + * @return void + */ + public static function build(string $name, array $options = [], $value = null, array $paramsArray = []): void + { + $textarea = new self($name, $options, $value, $paramsArray); + $textarea->create(); + } + +} \ No newline at end of file diff --git a/src/inputs/TextArea.php b/src/inputs/TextArea.php new file mode 100644 index 0000000..193d7b8 --- /dev/null +++ b/src/inputs/TextArea.php @@ -0,0 +1,47 @@ +name = $name; + $this->value = $value; + $this->paramsArray = $paramsArray; + } + + /** + * @return void + */ + public function create(): void + { + $paramsString = $this->createParams($this->paramsArray); + echo ""; + } + + /** + * @param string $name + * @param string $value + * @param array $paramsArray + * @return void + */ + public static function build(string $name, string $value, array $paramsArray = []): void + { + $textarea = new self($name, $value, $paramsArray); + $textarea->create(); + } + + +} \ No newline at end of file diff --git a/src/inputs/TextInput.php b/src/inputs/TextInput.php new file mode 100644 index 0000000..7a7d89d --- /dev/null +++ b/src/inputs/TextInput.php @@ -0,0 +1,45 @@ +name = $name; + $this->paramsArray = $paramsArray; + } + + /** + * @return void + */ + public function create(): void + { + $paramsString = $this->createParams($this->paramsArray); + echo ""; + } + + /** + * @param string $name + * @param array $paramsArray + * @return void + */ + public static function build(string $name, array $paramsArray = []): void + { + $input = new self($name, $paramsArray); + $input->create(); + } + +} \ No newline at end of file diff --git a/src/traits/CreateOption.php b/src/traits/CreateOption.php new file mode 100644 index 0000000..544ea13 --- /dev/null +++ b/src/traits/CreateOption.php @@ -0,0 +1,21 @@ + $title){ + $selected = $value === $val ? "selected" : ""; + $optionsString .= ""; + } + return $optionsString; + } +} \ No newline at end of file diff --git a/src/traits/CreateParams.php b/src/traits/CreateParams.php new file mode 100644 index 0000000..0aac971 --- /dev/null +++ b/src/traits/CreateParams.php @@ -0,0 +1,22 @@ + $param){ + $paramsString .= $key . "='" . $param . "'"; + } + + return $paramsString; + } + +} \ No newline at end of file