]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Email.php
Remove unused dependency
[friendica.git] / src / Object / Email.php
index 7a6858b0379bc8ed42d534310b843872336dde99..32d1382831702985e41f82c527a847daf6b8ed7c 100644 (file)
@@ -23,7 +23,7 @@ class Email implements IEmail
 
        /** @var string */
        private $subject;
-       /** @var string */
+       /** @var string|null */
        private $msgHtml;
        /** @var string */
        private $msgText;
@@ -33,14 +33,14 @@ class Email implements IEmail
        /** @var int|null */
        private $toUid = null;
 
-       public function __construct(string $fromName, string $fromEmail, string $replyTo, string $toEmail,
+       public function __construct(string $fromName, string $fromAddress, string $replyTo, string $toAddress,
                                    string $subject, string $msgHtml, string $msgText,
                                    string $additionalMailHeader = '', int $toUid = null)
        {
                $this->fromName             = $fromName;
-               $this->fromAddress          = $fromEmail;
+               $this->fromAddress          = $fromAddress;
                $this->replyTo              = $replyTo;
-               $this->toAddress            = $toEmail;
+               $this->toAddress            = $toAddress;
                $this->subject              = $subject;
                $this->msgHtml              = $msgHtml;
                $this->msgText              = $msgText;
@@ -117,19 +117,52 @@ class Email implements IEmail
        }
 
        /**
-        * Returns the current email with a new recipient
-        *
-        * @param string $email The email of the recipient
-        * @param int    $uid   The (optional) UID of the recipient for further infos
-        *
-        * @return static
+        * {@inheritDoc}
         */
-       public function withRecipient(string $email, int $uid = null)
+       public function withRecipient(string $address, int $uid = null)
        {
                $newEmail            = clone $this;
-               $newEmail->toAddress = $email;
+               $newEmail->toAddress = $address;
                $newEmail->toUid     = $uid;
 
                return $newEmail;
        }
+
+       /**
+        * {@inheritDoc}
+        */
+       public function withMessage(string $plaintext, string $html = null)
+       {
+               $newMail          = clone $this;
+               $newMail->msgText = $plaintext;
+               $newMail->msgHtml = $html;
+
+               return $newMail;
+       }
+
+       /**
+        * Returns the properties of the email as an array
+        *
+        * @return array
+        */
+       private function toArray()
+       {
+               return get_object_vars($this);
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function __toString()
+       {
+               return json_encode($this->toArray());
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public function jsonSerialize()
+       {
+               return $this->toArray();
+       }
 }