aboutsummaryrefslogtreecommitdiff
path: root/Psso/Input.php
diff options
context:
space:
mode:
authorwinter Sparkles2026-08-08 23:01:51 +0100
committerwinter Sparkles2026-08-08 23:01:51 +0100
commitb422b6ded608807c7d3bb8b965b3797ca513610b (patch)
tree7925fa972efbfff2a9bf8648334d49e3fd6b5df1 /Psso/Input.php
parent880a274e1ecbed42c76d3dc4a81161b3ae372726 (diff)
implement a large chunk of the auth system itself :D
Diffstat (limited to 'Psso/Input.php')
-rw-r--r--Psso/Input.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/Psso/Input.php b/Psso/Input.php
new file mode 100644
index 0000000..019d79f
--- /dev/null
+++ b/Psso/Input.php
@@ -0,0 +1,42 @@
+<?php
+namespace Psso;
+
+class Input {
+ // input-type constants that map to their HTML equivalents
+ /** Plain text. */
+ public const string TEXT = 'text';
+ /** Hidden/masked text. */
+ public const string SECRET = 'password';
+ /** Integer. */
+ public const string NUMERIC = 'number';
+
+ public protected(set) string $id;
+ public protected(set) string $type;
+ public protected(set) string $label;
+ public protected(set) bool $required;
+ public private(set) string $serial;
+
+ public function __construct(
+ string $id, string $type, string $label, bool $required = true
+ ) {
+ $this->id = $id;
+ $this->type = $type;
+ $this->label = $label;
+ $this->required = $required;
+ $this->serial = base64_encode(random_bytes(9));
+ }
+
+ private function getUniqueName(): string {
+ return $this->id . '__' . $this->serial;
+ }
+
+ public function addAsHtml(\SimpleXMLElement $parent): void {
+ $label = $parent->addChild('label', L($this->label));
+ $label->addAttribute('for', 'input-' . $this->getUniqueName());
+ $input = $parent->addChild('input');
+ $input->addAttribute('type', $this->type);
+ $input->addAttribute('name', $this->getUniqueName());
+ $input->addAttribute('id', 'input-' . $this->getUniqueName());
+ if ($this->required) $input->addAttribute('required', '');
+ }
+}