template = $template; } /** * @param string $address * @param string|null $name * @return BMailTemplate */ public function sender(string $address, string $name = null): BMailTemplate { $this->sender['address'] = $address; if ($name) $this->sender['name'] = $name; return $this; } /** * @param string $address * @param string|null $name * @return BMailTemplate */ public function replyTo(string $address, string $name = null): BMailTemplate { $this->replyTo['address'] = $address; if ($name) $this->replyTo['name'] = $name; return $this; } /** * @param array $recipients * @return BMailTemplate */ public function recipients(array $recipients): BMailTemplate { if (!empty($recipients)) { foreach ($recipients as $recipient) { if (!empty($recipient[0]) && is_string($recipient[0])) { $data = [ 'address' => $recipient[0] ]; if (!empty($recipient[1])) { if (!empty($recipient[1]['name'])) $data['name'] = $recipient[1]['name']; if (!empty($recipient[1]['parameters'])) $data['parameters'] = $recipient[1]['parameters']; } $this->recipients[] = $data; } } } return $this; } /** * @param string $address * @param array $informations * @return BMailTemplate */ public function addRecipient(string $address, array $informations = []): BMailTemplate { $data = [ 'address' => $address ]; if (!empty($informations)) { if (!empty($informations['name'])) $data['name'] = $informations['name']; if (!empty($informations['parameters'])) $data['parameters'] = $informations['parameters']; } $this->recipients[] = $data; return $this; } /** * @param array $parameters * @return BMailTemplate */ public function parameters(array $parameters): BMailTemplate { $this->parameters = $parameters; return $this; } /** * @param string $key * @param string $value * @return BMailTemplate */ public function addParameter(string $key, string $value): BMailTemplate { $this->parameters[$key] = $value; return $this; } /** * Get an array representation of the message. * * @return array */ public function toArray() { return [ 'template' => $this->template, 'sender' => $this->sender, 'replyTo' => $this->replyTo, 'recipients' => $this->recipients, 'parameters' => $this->parameters, ]; } public function jsonSerialize() { return $this->toArray(); } }