appwrite/src/Appwrite/Event/Mail.php

177 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace Appwrite\Event;
use Resque;
use Utopia\Database\Document;
class Mail extends Event
{
protected string $recipient = '';
protected string $from = '';
protected string $name = '';
protected string $subject = '';
protected string $body = '';
2023-03-12 02:12:09 +00:00
protected array $smtp = [];
public function __construct()
{
parent::__construct(Event::MAILS_QUEUE_NAME, Event::MAILS_CLASS_NAME);
}
2022-04-18 16:21:45 +00:00
/**
* Sets subject for the mail event.
2022-04-18 16:21:45 +00:00
*
* @param string $subject
2022-04-18 16:21:45 +00:00
* @return self
*/
public function setSubject(string $subject): self
{
$this->subject = $subject;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns set team for the mail event.
*
* @return string
2022-04-18 16:21:45 +00:00
*/
public function getSubject(): string
{
return $this->subject;
}
2022-04-18 16:21:45 +00:00
/**
* Sets recipient for the mail event.
*
* @param string $recipient
* @return self
*/
public function setRecipient(string $recipient): self
{
$this->recipient = $recipient;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns set recipient for mail event.
*
* @return string
*/
public function getRecipient(): string
{
return $this->recipient;
}
2022-04-18 16:21:45 +00:00
/**
* Sets from for the mail event.
2022-04-18 16:21:45 +00:00
*
* @param string $from
2022-04-18 16:21:45 +00:00
* @return self
*/
public function setFrom(string $from): self
{
$this->from = $from;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns from for mail event.
2022-04-18 16:21:45 +00:00
*
* @return string
*/
public function getFrom(): string
{
return $this->from;
}
2022-04-18 16:21:45 +00:00
/**
* Sets body for the mail event.
2022-04-18 16:21:45 +00:00
*
* @param string $body
2022-04-18 16:21:45 +00:00
* @return self
*/
public function setBody(string $body): self
{
$this->body = $body;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns body for the mail event.
2022-04-18 16:21:45 +00:00
*
* @return string
*/
public function getBody(): string
{
return $this->body;
}
2022-04-18 16:21:45 +00:00
/**
* Sets name for the mail event.
*
* @param string $name
* @return self
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
2022-04-18 16:21:45 +00:00
/**
* Returns set name for the mail event.
*
* @return string
*/
public function getName(): string
{
return $this->name;
}
2023-03-12 02:12:09 +00:00
/**
* Set SMTP
*
* @param array $smtp
* @return self
*/
public function setSmtp(array $smtp): self
{
$this->smtp = $smtp;
return $this;
}
/**
* Get SMTP
*
* @return string
*/
public function getSmtp(): array
{
return $this->smtp;
}
2022-04-18 16:21:45 +00:00
/**
* Executes the event and sends it to the mails worker.
*
* @return string|bool
* @throws \InvalidArgumentException
*/
public function trigger(): string|bool
{
return Resque::enqueue($this->queue, $this->class, [
'from' => $this->from,
'recipient' => $this->recipient,
'name' => $this->name,
'subject' => $this->subject,
'body' => $this->body,
'events' => Event::generateEvents($this->getEvent(), $this->getParams())
]);
}
2022-04-18 16:21:45 +00:00
}