From d535922b331821173fcb6bb543b8011d62386d4d Mon Sep 17 00:00:00 2001 From: fuziion_dev Date: Mon, 13 Apr 2026 22:41:07 +0200 Subject: [PATCH] feat: php 8.4 support --- composer.json | 2 +- composer.lock | 21 ----------------- src/Field.php | 63 +++++++++++++++++++++++++++++++++++++++------------ src/Form.php | 19 +++++++++++++--- 4 files changed, 65 insertions(+), 40 deletions(-) delete mode 100644 composer.lock diff --git a/composer.json b/composer.json index 1944156..910d45a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">7.0", + "php": ">=8.0", "ext-dom": "*" } } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index bf92da2..0000000 --- a/composer.lock +++ /dev/null @@ -1,21 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "428e323fa5c73818ac852cc600cfe722", - "packages": [], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": ">7.0", - "ext-dom": "*" - }, - "platform-dev": [], - "plugin-api-version": "2.3.0" -} diff --git a/src/Field.php b/src/Field.php index 7436d17..09a6aca 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1,8 +1,12 @@ -name = $attr['name'] ?? ''; - $this->placeholder = $attr['placeholder'] ?? ''; - $this->type = $attr['type'] ?? 'text'; - $this->style = $attr['class'] ?? ''; - $this->value = $attr['value'] ?? ''; + $this->name = $attributes['name'] ?? ''; + $this->placeholder = $attributes['placeholder'] ?? ''; + $this->type = $attributes['type'] ?? 'text'; + $this->style = $attributes['class'] ?? ''; + $this->value = $attributes['value'] ?? ''; } - public function name(string $name): self + /** + * @param string $name + * @return Field + */ + public function name(string $name): Field { $this->name = $name; return $this; } - public function placeholder(string $placeholder): self + /** + * @param string $placeholder + * @return Field + */ + public function placeholder(string $placeholder): Field { $this->placeholder = $placeholder; return $this; } - public function type(string $type): self + /** + * @param string $type + * @return Field + */ + public function type(string $type): Field { $this->type = $type; return $this; } - public function style(string $style): self + /** + * @param string $style + * @return Field + */ + public function style(string $style): Field { $this->style = $style; return $this; } - public function value(string $value): self + /** + * @param string $value + * @return Field + */ + public function value(string $value): Field { $this->value = $value; return $this; } - public function render(): mixed + /** + * @return DOMElement|null + */ + public function render(): ?DOMElement { try { $doc = new DOMDocument(); @@ -74,8 +104,11 @@ public function render(): mixed $doc->appendChild($input_elm); return $doc->documentElement; } - catch (\DOMException|\Exception $e) { - echo "An error occurred while rendering the field: " . $e->getMessage(); + catch (DOMException|Exception $e) { + echo sprintf( + 'An error occurred while rendering the field: %s', + $e->getMessage() + ); return null; } } diff --git a/src/Form.php b/src/Form.php index 74b1650..9ec6769 100644 --- a/src/Form.php +++ b/src/Form.php @@ -1,4 +1,5 @@ -action = $config['action'] ?? ''; @@ -19,6 +26,9 @@ public function __construct(array $config = []) $this->fields = []; } + /** + * @return Field + */ public function field(): Field { $field = new Field; @@ -26,6 +36,9 @@ public function field(): Field return $field; } + /** + * @return void + */ public function render(): void { try { @@ -44,7 +57,7 @@ public function render(): void foreach ($this->fields as $field) { $input = $field->render(); - if ($field === null) { + if ($input === null) { continue; } @@ -56,7 +69,7 @@ public function render(): void echo $doc->saveHTML(); } catch (\DOMException|\Exception $e) { - echo "An error occurred while rendering the form: " . $e->getMessage(); + echo sprintf('An error occurred while rendering the form: %s', $e->getMessage()); } } }