summaryrefslogtreecommitdiffstats
path: root/vendor/gipfl/web/src/Table
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gipfl/web/src/Table')
-rw-r--r--vendor/gipfl/web/src/Table/NameValueTable.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/gipfl/web/src/Table/NameValueTable.php b/vendor/gipfl/web/src/Table/NameValueTable.php
new file mode 100644
index 0000000..7227de7
--- /dev/null
+++ b/vendor/gipfl/web/src/Table/NameValueTable.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace gipfl\Web\Table;
+
+use ipl\Html\BaseHtmlElement;
+use ipl\Html\Table;
+
+class NameValueTable extends Table
+{
+ protected $defaultAttributes = ['class' => 'gipfl-name-value-table'];
+
+ public static function create($pairs = [])
+ {
+ $self = new static;
+ $self->addNameValuePairs($pairs);
+
+ return $self;
+ }
+
+ public function createNameValueRow($name, $value)
+ {
+ return $this::tr([$this::th($name), $this::wantTd($value)]);
+ }
+
+ public function addNameValueRow($name, $value)
+ {
+ return $this->add($this->createNameValueRow($name, $value));
+ }
+
+ public function addNameValuePairs($pairs)
+ {
+ foreach ($pairs as $name => $value) {
+ $this->addNameValueRow($name, $value);
+ }
+
+ return $this;
+ }
+
+ protected function wantTd($value)
+ {
+ if ($value instanceof BaseHtmlElement && $value->getTag() === 'td') {
+ return $value;
+ } else {
+ return $this::td($value);
+ }
+ }
+}