summaryrefslogtreecommitdiffstats
path: root/vendor/gipfl/web/src/Widget
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:44:51 +0000
commita1ec78bf0dc93d0e05e5f066f1949dc3baecea06 (patch)
treeee596ce1bc9840661386f96f9b8d1f919a106317 /vendor/gipfl/web/src/Widget
parentInitial commit. (diff)
downloadicingaweb2-module-incubator-upstream.tar.xz
icingaweb2-module-incubator-upstream.zip
Adding upstream version 0.20.0.upstream/0.20.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gipfl/web/src/Widget')
-rw-r--r--vendor/gipfl/web/src/Widget/CollapsibleList.php74
-rw-r--r--vendor/gipfl/web/src/Widget/ConfigDiff.php106
-rw-r--r--vendor/gipfl/web/src/Widget/Hint.php45
3 files changed, 225 insertions, 0 deletions
diff --git a/vendor/gipfl/web/src/Widget/CollapsibleList.php b/vendor/gipfl/web/src/Widget/CollapsibleList.php
new file mode 100644
index 0000000..0df8234
--- /dev/null
+++ b/vendor/gipfl/web/src/Widget/CollapsibleList.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace gipfl\Web\Widget;
+
+use ipl\Html\BaseHtmlElement;
+use ipl\Html\Html;
+use InvalidArgumentException;
+use LogicException;
+use function count;
+
+class CollapsibleList extends BaseHtmlElement
+{
+ protected $tag = 'ul';
+
+ protected $defaultAttributes = [
+ 'class' => 'gipfl-collapsible'
+ ];
+
+ protected $defaultListAttributes;
+
+ protected $defaultSectionAttributes;
+
+ protected $items = [];
+
+ public function __construct($items = [], $listAttributes = null)
+ {
+ if ($listAttributes !== null) {
+ $this->defaultListAttributes = $listAttributes;
+ }
+ foreach ($items as $title => $item) {
+ $this->addItem($title, $item);
+ }
+ }
+
+ public function addItem($title, $content)
+ {
+ if ($this->hasItem($title)) {
+ throw new LogicException("Cannot add item with title '$title' twice");
+ }
+ $item = Html::tag('li', [
+ Html::tag('a', ['href' => '#', 'class' => 'gipfl-collapsible-control'], $title),
+ $content
+ ]);
+
+ if (count($this->items) > 0) {
+ $item->getAttributes()->add('class', 'collapsed');
+ }
+ $this->items[$title] = $item;
+ }
+
+ public function hasItem($title)
+ {
+ return isset($this->items[$title]);
+ }
+
+ public function getItem($name)
+ {
+ if (isset($this->items[$name])) {
+ return $this->items[$name];
+ }
+
+ throw new InvalidArgumentException("There is no '$name' item in this list");
+ }
+
+ protected function assemble()
+ {
+ if ($this->defaultListAttributes) {
+ $this->addAttributes($this->defaultListAttributes);
+ }
+ foreach ($this->items as $item) {
+ $this->add($item);
+ }
+ }
+}
diff --git a/vendor/gipfl/web/src/Widget/ConfigDiff.php b/vendor/gipfl/web/src/Widget/ConfigDiff.php
new file mode 100644
index 0000000..8ac366f
--- /dev/null
+++ b/vendor/gipfl/web/src/Widget/ConfigDiff.php
@@ -0,0 +1,106 @@
+<?php
+
+namespace gipfl\Web\Widget;
+
+use Diff;
+use ipl\Html\ValidHtml;
+use InvalidArgumentException;
+
+/**
+ * @deprecated - please use gipfl\Diff
+ */
+class ConfigDiff implements ValidHtml
+{
+ protected $a;
+
+ protected $b;
+
+ protected $diff;
+
+ protected $htmlRenderer = 'SideBySide';
+
+ protected $knownHtmlRenderers = [
+ 'SideBySide',
+ 'Inline',
+ ];
+
+ protected $knownTextRenderers = [
+ 'Context',
+ 'Unified',
+ ];
+
+ protected $vendorDir;
+
+ protected function __construct($a, $b)
+ {
+ $this->vendorDir = \dirname(\dirname(__DIR__)) . '/vendor';
+ require_once $this->vendorDir . '/php-diff/lib/Diff.php';
+
+ if (empty($a)) {
+ $this->a = [];
+ } else {
+ $this->a = explode("\n", (string) $a);
+ }
+
+ if (empty($b)) {
+ $this->b = [];
+ } else {
+ $this->b = explode("\n", (string) $b);
+ }
+
+ $options = [
+ 'context' => 5,
+ // 'ignoreWhitespace' => true,
+ // 'ignoreCase' => true,
+ ];
+ $this->diff = new Diff($this->a, $this->b, $options);
+ }
+
+ public function render()
+ {
+ return $this->renderHtml();
+ }
+
+ /**
+ * @return string
+ */
+ public function renderHtml()
+ {
+ return $this->diff->Render($this->getHtmlRenderer());
+ }
+
+ public function setHtmlRenderer($name)
+ {
+ if (in_array($name, $this->knownHtmlRenderers)) {
+ $this->htmlRenderer = $name;
+ } else {
+ throw new InvalidArgumentException("There is no known '$name' renderer");
+ }
+
+ return $this;
+ }
+
+ protected function getHtmlRenderer()
+ {
+ $filename = sprintf(
+ '%s/vendor/php-diff/lib/Diff/Renderer/Html/%s.php',
+ $this->vendorDir,
+ $this->htmlRenderer
+ );
+ require_once($filename);
+
+ $class = 'Diff_Renderer_Html_' . $this->htmlRenderer;
+
+ return new $class();
+ }
+
+ public function __toString()
+ {
+ return $this->renderHtml();
+ }
+
+ public static function create($a, $b)
+ {
+ return new static($a, $b);
+ }
+}
diff --git a/vendor/gipfl/web/src/Widget/Hint.php b/vendor/gipfl/web/src/Widget/Hint.php
new file mode 100644
index 0000000..785d9e4
--- /dev/null
+++ b/vendor/gipfl/web/src/Widget/Hint.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace gipfl\Web\Widget;
+
+use ipl\Html\BaseHtmlElement;
+use ipl\Html\Html;
+
+class Hint extends BaseHtmlElement
+{
+ protected $tag = 'div';
+
+ protected $defaultAttributes = [
+ 'class' => 'gipfl-widget-hint'
+ ];
+
+ public function __construct($message, $class = 'ok', ...$params)
+ {
+ $this->addAttributes(['class' => $class]);
+ if (empty($params)) {
+ $this->setContent($message);
+ } else {
+ $this->setContent(Html::sprintf($message, ...$params));
+ }
+ }
+
+ public static function ok($message, ...$params)
+ {
+ return new static($message, 'ok', ...$params);
+ }
+
+ public static function info($message, ...$params)
+ {
+ return new static($message, 'info', ...$params);
+ }
+
+ public static function warning($message, ...$params)
+ {
+ return new static($message, 'warning', ...$params);
+ }
+
+ public static function error($message, ...$params)
+ {
+ return new static($message, 'error', ...$params);
+ }
+}