summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/html/src/FormElement/SelectOption.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:30:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:30:08 +0000
commit4ce65d59ca91871cfd126497158200a818720bce (patch)
treee277def01fc7eba7dbc21c4a4ae5576e8aa2cf1f /vendor/ipl/html/src/FormElement/SelectOption.php
parentInitial commit. (diff)
downloadicinga-php-library-96ecad332d1684426665842bfcebf1aa4692a020.tar.xz
icinga-php-library-96ecad332d1684426665842bfcebf1aa4692a020.zip
Adding upstream version 0.13.1.upstream/0.13.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ipl/html/src/FormElement/SelectOption.php')
-rw-r--r--vendor/ipl/html/src/FormElement/SelectOption.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/ipl/html/src/FormElement/SelectOption.php b/vendor/ipl/html/src/FormElement/SelectOption.php
new file mode 100644
index 0000000..3d799a2
--- /dev/null
+++ b/vendor/ipl/html/src/FormElement/SelectOption.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace ipl\Html\FormElement;
+
+use ipl\Html\BaseHtmlElement;
+
+class SelectOption extends BaseHtmlElement
+{
+ protected $tag = 'option';
+
+ /** @var string|int|null Value of the option */
+ protected $value;
+
+ /** @var string Label of the option */
+ protected $label;
+
+ /**
+ * SelectOption constructor.
+ *
+ * @param string|int|null $value
+ * @param string $label
+ */
+ public function __construct($value, string $label)
+ {
+ $this->value = $value === '' ? null : $value;
+ $this->label = $label;
+
+ $this->getAttributes()->registerAttributeCallback('value', [$this, 'getValueAttribute']);
+ }
+
+ /**
+ * Set the label of the option
+ *
+ * @param string $label
+ *
+ * @return $this
+ */
+ public function setLabel(string $label): self
+ {
+ $this->label = $label;
+
+ return $this;
+ }
+
+ /**
+ * Get the label of the option
+ *
+ * @return string
+ */
+ public function getLabel(): string
+ {
+ return $this->label;
+ }
+
+ /**
+ * Get the value of the option
+ *
+ * @return string|int|null
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Callback for the value attribute
+ *
+ * @return mixed
+ */
+ public function getValueAttribute()
+ {
+ return (string) $this->getValue();
+ }
+
+ protected function assemble()
+ {
+ $this->setContent($this->getLabel());
+ }
+}