api/symfony/Component/Mailer/Bridge/MailerSend/Transport/MailerSendApiTransport.yaml
2024-09-26 02:03:21 -07:00

103 lines
5.1 KiB
YAML

name: MailerSendApiTransport
class_comment: null
dependencies:
- name: EventDispatcherInterface
type: class
source: Psr\EventDispatcher\EventDispatcherInterface
- name: LoggerInterface
type: class
source: Psr\Log\LoggerInterface
- name: JsonException
type: class
source: Symfony\Component\HttpClient\Exception\JsonException
- name: Envelope
type: class
source: Symfony\Component\Mailer\Envelope
- name: HttpTransportException
type: class
source: Symfony\Component\Mailer\Exception\HttpTransportException
- name: SentMessage
type: class
source: Symfony\Component\Mailer\SentMessage
- name: AbstractApiTransport
type: class
source: Symfony\Component\Mailer\Transport\AbstractApiTransport
- name: Address
type: class
source: Symfony\Component\Mime\Address
- name: Email
type: class
source: Symfony\Component\Mime\Email
- name: TransportExceptionInterface
type: class
source: Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
- name: HttpClientInterface
type: class
source: Symfony\Contracts\HttpClient\HttpClientInterface
- name: ResponseInterface
type: class
source: Symfony\Contracts\HttpClient\ResponseInterface
properties: []
methods:
- name: prepareAddresses
visibility: private
parameters:
- name: addresses
comment: "# * @see https://developers.mailersend.com/api/v1/email.html\n# */\n#\
\ final class MailerSendApiTransport extends AbstractApiTransport\n# {\n# public\
\ function __construct(\n# #[\\SensitiveParameter] private string $key,\n# ?HttpClientInterface\
\ $client = null,\n# ?EventDispatcherInterface $dispatcher = null,\n# ?LoggerInterface\
\ $logger = null,\n# ) {\n# parent::__construct($client, $dispatcher, $logger);\n\
# }\n# \n# public function __toString(): string\n# {\n# return \\sprintf('mailersend+api://%s',\
\ $this->getEndpoint());\n# }\n# \n# protected function doSendApi(SentMessage\
\ $sentMessage, Email $email, Envelope $envelope): ResponseInterface\n# {\n# $response\
\ = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v1/email',\
\ [\n# 'json' => $this->getPayload($email, $envelope),\n# 'headers' => [\n# 'Authorization'\
\ => 'Bearer '.$this->key,\n# ],\n# ]);\n# \n# try {\n# $statusCode = $response->getStatusCode();\n\
# $content = $response->getContent(false);\n# $headers = $response->getHeaders(false);\n\
# } catch (TransportExceptionInterface $e) {\n# throw new HttpTransportException('Could\
\ not reach the remote MailerSend server.', $response, 0, $e);\n# }\n# \n# try\
\ {\n# $result = '' !== $content ? $response->toArray(false) : null;\n# } catch\
\ (JsonException $e) {\n# throw new HttpTransportException(\\sprintf('Unable to\
\ send an email: \"%s\" (code %d).', $content, $statusCode), $response, 0, $e);\n\
# }\n# \n# if (202 !== $statusCode) {\n# throw new HttpTransportException('Unable\
\ to send an email: '.($result['message'] ?? '').\\sprintf(' (code %d).', $statusCode),\
\ $response);\n# }\n# \n# if (isset($result['warnings'][0]['type']) && 'ALL_SUPPRESSED'\
\ === $result['warnings'][0]['type']) {\n# throw new HttpTransportException('Unable\
\ to send an email: '.$result['message'] ?? 'All suppressed', $response);\n# }\n\
# \n# if (isset($headers['x-message-id'][0])) {\n# $sentMessage->setMessageId($headers['x-message-id'][0]);\n\
# }\n# \n# return $response;\n# }\n# \n# private function getPayload(Email $email,\
\ Envelope $envelope): array\n# {\n# $sender = $envelope->getSender();\n# \n#\
\ $payload = [\n# 'from' => array_filter([\n# 'email' => $sender->getAddress(),\n\
# 'name' => $sender->getName(),\n# ]),\n# 'to' => $this->prepareAddresses($this->getRecipients($email,\
\ $envelope)),\n# 'subject' => $email->getSubject(),\n# ];\n# \n# if ($attachments\
\ = $this->prepareAttachments($email)) {\n# $payload['attachments'] = $attachments;\n\
# }\n# \n# if ($replyTo = $email->getReplyTo()) {\n# $payload['reply_to'] = current($this->prepareAddresses($replyTo));\n\
# }\n# \n# if ($cc = $email->getCc()) {\n# $payload['cc'] = $this->prepareAddresses($cc);\n\
# }\n# \n# if ($bcc = $email->getBcc()) {\n# $payload['bcc'] = $this->prepareAddresses($bcc);\n\
# }\n# \n# if ($email->getTextBody()) {\n# $payload['text'] = $email->getTextBody();\n\
# }\n# \n# if ($email->getHtmlBody()) {\n# $payload['html'] = $email->getHtmlBody();\n\
# }\n# \n# return $payload;\n# }\n# \n# /**\n# * @param Address[] $addresses"
- name: prepareAttachments
visibility: private
parameters:
- name: email
comment: null
- name: getEndpoint
visibility: private
parameters: []
comment: null
traits:
- Psr\EventDispatcher\EventDispatcherInterface
- Psr\Log\LoggerInterface
- Symfony\Component\HttpClient\Exception\JsonException
- Symfony\Component\Mailer\Envelope
- Symfony\Component\Mailer\Exception\HttpTransportException
- Symfony\Component\Mailer\SentMessage
- Symfony\Component\Mailer\Transport\AbstractApiTransport
- Symfony\Component\Mime\Address
- Symfony\Component\Mime\Email
- Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
- Symfony\Contracts\HttpClient\HttpClientInterface
- Symfony\Contracts\HttpClient\ResponseInterface
interfaces: []