ApiTransport
extends AbstractTransport
in package
Abstract base for HTTP API-based email transports.
Provides shared helpers for extracting data from CakePHP Message objects and sending HTTP requests. Concrete subclasses implement the provider-specific API payload and authentication.
Table of Contents
Properties
- $_defaultConfig : array<string, mixed>
- $httpClient : Client|null
Methods
- setHttpClient() : static
- Set a custom HTTP client (useful for testing).
- assertSuccessResponse() : void
- Assert a successful HTTP response or throw.
- buildResult() : array{headers: string, message: string}
- Build the standard return value for send().
- checkRecipient() : void
- Validate that the message has at least one recipient.
- formatAttachments() : array<int, array{name: string, contentType: string, content: string}>
- Convert Message attachments to a provider-neutral format.
- formatRecipients() : array<int, array{email: string, name: string}>
- Convert Message address array to a flat list of recipient objects.
- getHttpClient() : Client
- Get or create the HTTP client instance.
- getSender() : array{email: string, name: string}
- Get the sender address from a Message.
Properties
$_defaultConfig
protected
array<string, mixed>
$_defaultConfig
= ['timeout' => 30]
$httpClient
protected
Client|null
$httpClient
= null
Methods
setHttpClient()
Set a custom HTTP client (useful for testing).
public
setHttpClient(Client $client) : static
Parameters
- $client : Client
Return values
staticassertSuccessResponse()
Assert a successful HTTP response or throw.
protected
assertSuccessResponse(Response $response, string $provider, int ...$acceptedCodes) : void
Parameters
- $response : Response
-
The HTTP response.
- $provider : string
-
Provider name for error messages.
- $acceptedCodes : int
-
HTTP status codes considered successful.
Tags
buildResult()
Build the standard return value for send().
protected
buildResult(Message $message) : array{headers: string, message: string}
Parameters
- $message : Message
Return values
array{headers: string, message: string}checkRecipient()
Validate that the message has at least one recipient.
protected
checkRecipient(Message $message) : void
Parameters
- $message : Message
-
The email message.
Tags
formatAttachments()
Convert Message attachments to a provider-neutral format.
protected
formatAttachments(Message $message) : array<int, array{name: string, contentType: string, content: string}>
Parameters
- $message : Message
Return values
array<int, array{name: string, contentType: string, content: string}>formatRecipients()
Convert Message address array to a flat list of recipient objects.
protected
formatRecipients(array<string, string> $addresses) : array<int, array{email: string, name: string}>
CakePHP stores addresses as ['email@example.com' => 'Display Name'].
Parameters
- $addresses : array<string, string>
Return values
array<int, array{email: string, name: string}>getHttpClient()
Get or create the HTTP client instance.
protected
getHttpClient() : Client
Return values
ClientgetSender()
Get the sender address from a Message.
protected
getSender(Message $message) : array{email: string, name: string}
Parameters
- $message : Message
-
The email message.