summaryrefslogtreecommitdiffstats
path: root/vendor/gipfl/icingaweb2/src/Img.php
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/icingaweb2/src/Img.php
parentInitial commit. (diff)
downloadicingaweb2-module-incubator-upstream/0.20.0.tar.xz
icingaweb2-module-incubator-upstream/0.20.0.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/icingaweb2/src/Img.php')
-rw-r--r--vendor/gipfl/icingaweb2/src/Img.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/gipfl/icingaweb2/src/Img.php b/vendor/gipfl/icingaweb2/src/Img.php
new file mode 100644
index 0000000..3c68adb
--- /dev/null
+++ b/vendor/gipfl/icingaweb2/src/Img.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace gipfl\IcingaWeb2;
+
+use Icinga\Web\Url as WebUrl;
+use ipl\Html\Attribute;
+use ipl\Html\BaseHtmlElement;
+
+class Img extends BaseHtmlElement
+{
+ protected $tag = 'img';
+
+ /** @var Url */
+ protected $url;
+
+ protected $defaultAttributes = array('alt' => '');
+
+ protected function __construct()
+ {
+ }
+
+ /**
+ * @param Url|string $url
+ * @param array $urlParams
+ * @param array $attributes
+ *
+ * @return static
+ */
+ public static function create($url, $urlParams = null, array $attributes = null)
+ {
+ /** @var Img $img */
+ $img = new static();
+ $img->setAttributes($attributes);
+ $img->getAttributes()->registerAttributeCallback('src', array($img, 'getSrcAttribute'));
+ $img->setUrl($url, $urlParams);
+ return $img;
+ }
+
+ public function setUrl($url, $urlParams)
+ {
+ if ($url instanceof WebUrl) { // Hint: Url is also a WebUrl
+ if ($urlParams !== null) {
+ $url->addParams($urlParams);
+ }
+
+ $this->url = $url;
+ } else {
+ if ($urlParams === null) {
+ if (is_string($url) && substr($url, 0, 5) === 'data:') {
+ $this->url = $url;
+ return;
+ } else {
+ $this->url = Url::fromPath($url);
+ }
+ } else {
+ $this->url = Url::fromPath($url, $urlParams);
+ }
+ }
+
+ $this->url->getParams();
+ }
+
+ /**
+ * @return Attribute
+ */
+ public function getSrcAttribute()
+ {
+ if (is_string($this->url)) {
+ return new Attribute('src', $this->url);
+ } else {
+ return new Attribute('src', $this->getUrl()->getAbsoluteUrl('&'));
+ }
+ }
+
+ /**
+ * @return Url
+ */
+ public function getUrl()
+ {
+ // TODO: What if null? #?
+ return $this->url;
+ }
+}