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

118 lines
6.5 KiB
YAML

name: InfobipApiTransport
class_comment: null
dependencies:
- name: EventDispatcherInterface
type: class
source: Psr\EventDispatcher\EventDispatcherInterface
- name: LoggerInterface
type: class
source: Psr\Log\LoggerInterface
- 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: DataPart
type: class
source: Symfony\Component\Mime\Part\DataPart
- name: FormDataPart
type: class
source: Symfony\Component\Mime\Part\Multipart\FormDataPart
- name: DecodingExceptionInterface
type: class
source: Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface
- 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: addressesFormData
visibility: private
parameters:
- name: '&$message'
- name: property
- name: addresses
comment: "# * @see https://www.infobip.com/docs/api#channels/email/send-email\n\
# */\n# final class InfobipApiTransport extends AbstractApiTransport\n# {\n# private\
\ const API_VERSION = '3';\n# \n# private const HEADER_TO_MESSAGE = [\n# 'X-Infobip-IntermediateReport'\
\ => 'intermediateReport',\n# 'X-Infobip-NotifyUrl' => 'notifyUrl',\n# 'X-Infobip-NotifyContentType'\
\ => 'notifyContentType',\n# 'X-Infobip-MessageId' => 'messageId',\n# 'X-Infobip-Track'\
\ => 'track',\n# 'X-Infobip-TrackingUrl' => 'trackingUrl',\n# 'X-Infobip-TrackClicks'\
\ => 'trackClicks',\n# 'X-Infobip-TrackOpens' => 'trackOpens',\n# ];\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('infobip+api://%s',\
\ $this->getEndpoint());\n# }\n# \n# protected function doSendApi(SentMessage\
\ $sentMessage, Email $email, Envelope $envelope): ResponseInterface\n# {\n# $formData\
\ = $this->formDataPart($email, $envelope);\n# \n# $headers = $formData->getPreparedHeaders()->toArray();\n\
# $headers[] = 'Authorization: App '.$this->key;\n# $headers[] = 'Accept: application/json';\n\
# \n# $response = $this->client->request(\n# 'POST',\n# \\sprintf('https://%s/email/%s/send',\
\ $this->getEndpoint(), self::API_VERSION),\n# [\n# 'headers' => $headers,\n#\
\ 'body' => $formData->bodyToIterable(),\n# ]\n# );\n# \n# try {\n# $statusCode\
\ = $response->getStatusCode();\n# } catch (TransportExceptionInterface $e) {\n\
# throw new HttpTransportException('Could not reach the remote Infobip server.',\
\ $response, 0, $e);\n# }\n# \n# if (200 !== $statusCode) {\n# throw new HttpTransportException(\\\
sprintf('Unable to send an email: \"%s\" (code %d).', $response->getContent(false),\
\ $statusCode), $response);\n# }\n# \n# try {\n# $result = $response->toArray();\n\
# } catch (DecodingExceptionInterface $e) {\n# throw new HttpTransportException(\\\
sprintf('Unable to send an email: \"%s\" (code %d).', $response->getContent(false),\
\ $statusCode), $response, 0, $e);\n# }\n# \n# if (isset($result['messages'][0]['messageId']))\
\ {\n# $sentMessage->setMessageId($result['messages'][0]['messageId']);\n# }\n\
# \n# return $response;\n# }\n# \n# private function getEndpoint(): ?string\n\
# {\n# return $this->host.($this->port ? ':'.$this->port : '');\n# }\n# \n# private\
\ function formDataPart(Email $email, Envelope $envelope): FormDataPart\n# {\n\
# $fields = [\n# 'from' => $envelope->getSender()->toString(),\n# 'subject' =>\
\ $email->getSubject(),\n# ];\n# \n# $this->addressesFormData($fields, 'to', $this->getRecipients($email,\
\ $envelope));\n# \n# if ($email->getCc()) {\n# $this->addressesFormData($fields,\
\ 'cc', $email->getCc());\n# }\n# \n# if ($email->getBcc()) {\n# $this->addressesFormData($fields,\
\ 'bcc', $email->getBcc());\n# }\n# \n# if ($email->getReplyTo()) {\n# $this->addressesFormData($fields,\
\ 'replyto', $email->getReplyTo());\n# }\n# \n# if ($email->getTextBody()) {\n\
# $fields['text'] = $email->getTextBody();\n# }\n# \n# if ($email->getHtmlBody())\
\ {\n# $fields['HTML'] = $email->getHtmlBody();\n# }\n# \n# $this->attachmentsFormData($fields,\
\ $email);\n# \n# foreach ($email->getHeaders()->all() as $header) {\n# if ($convertConf\
\ = self::HEADER_TO_MESSAGE[$header->getName()] ?? false) {\n# $fields[$convertConf]\
\ = $header->getBodyAsString();\n# }\n# }\n# \n# return new FormDataPart($fields);\n\
# }\n# \n# private function attachmentsFormData(array &$message, Email $email):\
\ void\n# {\n# foreach ($email->getAttachments() as $attachment) {\n# $headers\
\ = $attachment->getPreparedHeaders();\n# $filename = $headers->getHeaderParameter('Content-Disposition',\
\ 'filename');\n# \n# $dataPart = new DataPart($attachment->getBody(), $filename,\
\ $attachment->getMediaType().'/'.$attachment->getMediaSubtype());\n# \n# if ('inline'\
\ === $headers->getHeaderBody('Content-Disposition')) {\n# $message[] = ['inlineImage'\
\ => $dataPart];\n# } else {\n# $message[] = ['attachment' => $dataPart];\n# }\n\
# }\n# }\n# \n# /**\n# * @param Address[] $addresses"
traits:
- Psr\EventDispatcher\EventDispatcherInterface
- Psr\Log\LoggerInterface
- 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\Component\Mime\Part\DataPart
- Symfony\Component\Mime\Part\Multipart\FormDataPart
- Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface
- Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
- Symfony\Contracts\HttpClient\HttpClientInterface
- Symfony\Contracts\HttpClient\ResponseInterface
interfaces: []