Add AvatarDecorator
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 17 Feb 2021 14:49:23 +0000 (15:49 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 18 Feb 2021 11:41:15 +0000 (12:41 +0100)
wcfsetup/install/files/lib/data/user/avatar/AvatarDecorator.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/data/user/avatar/AvatarDecorator.class.php b/wcfsetup/install/files/lib/data/user/avatar/AvatarDecorator.class.php
new file mode 100644 (file)
index 0000000..21649bc
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+
+namespace wcf\data\user\avatar;
+
+/**
+ * Wraps avatars to provide compatibility layers.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data\User\Avatar
+ */
+final class AvatarDecorator implements IUserAvatar, ISafeFormatAvatar
+{
+    /**
+     * @var IUserAvatar
+     */
+    private $avatar;
+
+    public function __construct(IUserAvatar $avatar)
+    {
+        $this->avatar = $avatar;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getSafeURL(?int $size = null): string
+    {
+        if ($this->avatar instanceof ISafeFormatAvatar) {
+            return $this->avatar->getSafeURL($size);
+        }
+
+        return $this->avatar->getURL($size);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getSafeImageTag(?int $size = null): string
+    {
+        if ($this->avatar instanceof ISafeFormatAvatar) {
+            return $this->avatar->getSafeImageTag($size);
+        }
+
+        return $this->avatar->getImageTag($size);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getURL($size = null)
+    {
+        return $this->avatar->getURL();
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getImageTag($size = null)
+    {
+        return $this->avatar->getImageTag($size);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getWidth()
+    {
+        return $this->avatar->getWidth();
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function getHeight()
+    {
+        return $this->avatar->getHeight();
+    }
+}