*/ protected iterable $recipients; public function __construct(iterable $recipients, Mailable $mailable) { parent::__construct($mailable); foreach ($recipients as $recipient) { if (!is_a($recipient, Identity::class)) { throw new InvalidArgumentException('recipient array values should be an instances or ancestors of ' . Identity::class . ', ' . get_class($recipient) . ' is given'); } } $this->recipients = $recipients; } /** * @copydoc Variable::descriptions() */ public static function descriptions(): array { return [ self::RECIPIENT_FULL_NAME => __('emailTemplate.variable.recipient.userFullName'), self::RECIPIENT_USERNAME => __('emailTemplate.variable.recipient.username'), ]; } /** * @copydoc Variable::values() */ public function values(string $locale): array { return [ self::RECIPIENT_FULL_NAME => htmlspecialchars($this->getRecipientsFullName($locale)), self::RECIPIENT_USERNAME => htmlspecialchars($this->getRecipientsUserName()), ]; } /** * Full names of recipients in all supported locales separated by a comma */ protected function getRecipientsFullName(string $locale): string { $names = []; foreach ($this->recipients as $recipient) { $names[] = $recipient->getFullName(true, false, $locale); } return join(__('common.commaListSeparator'), $names); } /** * Usernames of recipients separated by a comma */ protected function getRecipientsUserName(): string { $userNames = []; foreach ($this->recipients as $recipient) { $userNames[] = $recipient->getData('userName'); } return join(__('common.commaListSeparator'), $userNames); } }