EmailParser
in package
Class EmailParser
Handles the Email entity object parsing and encoding so that PHP can pass email records to JavaScript and vice versa. What it actually does is convert an email record into an array that can be encoded into JSON and parsed from JavaScript.
Tags
Table of Contents
- $emailService : EmailServiceInterface
- Used for creating email objects.
- __construct() : mixed
- Class Constructor
- encodeAttachment() : array<string|int, mixed>
- Convert an EmailAttachment object to an array.
- encodeCollection() : array<string|int, mixed>
- Encode EmailCollection object to an array that can be later encoded into JSON string.
- encodeContact() : array<string|int, mixed>
- Convert an EmailContact object to an array.
- encodeEmail() : array<string|int, mixed>
- Encode Email object that contains the email information to an array.
- parseAttachment() : EmailAttachment
- Parse the contact data and return an EmailAttachment object.
- parseCollection() : EmailCollectionInterface
- Parse a JSON formatted email collection.
- parseContact() : EmailContact
- Parse the contact data and return an EmailContact object.
- parseEmail() : EmailInterface
- Parse array that contains the email information sent by the JavaScript files.
Properties
$emailService
Used for creating email objects.
protected
EmailServiceInterface
$emailService
Methods
__construct()
Class Constructor
public
__construct(EmailServiceInterface $emailService) : mixed
Parameters
- $emailService : EmailServiceInterface
Return values
mixed —encodeAttachment()
Convert an EmailAttachment object to an array.
public
encodeAttachment(EmailAttachmentInterface $attachment) : array<string|int, mixed>
This conversions aims to help the JSON encoding of email contacts.
Parameters
- $attachment : EmailAttachmentInterface
-
Contains the attachment information.
Return values
array<string|int, mixed> —Encoded EmailAttachment object.
encodeCollection()
Encode EmailCollection object to an array that can be later encoded into JSON string.
public
encodeCollection(EmailCollectionInterface $collection) : array<string|int, mixed>
Parameters
- $collection : EmailCollectionInterface
-
Contains the email objects to be encoded.
Return values
array<string|int, mixed> —Returns an array that can be encoded to JSON and returned back to the client.
encodeContact()
Convert an EmailContact object to an array.
public
encodeContact(EmailContactInterface $contact) : array<string|int, mixed>
This conversions aims to help the JSON encoding of email contacts.
Parameters
- $contact : EmailContactInterface
-
Contains the contact information.
Return values
array<string|int, mixed> —Encoded EmailContact object.
encodeEmail()
Encode Email object that contains the email information to an array.
public
encodeEmail(EmailInterface $email) : array<string|int, mixed>
The returned array can be then encoded into JSON and sent to the JavaScript code in the client's browser.
Parameters
- $email : EmailInterface
-
Contains the email information.
Return values
array<string|int, mixed> —Returns the equivalent array.
parseAttachment()
Parse the contact data and return an EmailAttachment object.
public
parseAttachment(array<string|int, mixed> $encodedAttachment) : EmailAttachment
Attachment name is not a mandatory field so it might be empty as well.
Parameters
- $encodedAttachment : array<string|int, mixed>
-
Contains the "path" and "name" keys.
Return values
EmailAttachment —Returns the parsed object.
parseCollection()
Parse a JSON formatted email collection.
public
parseCollection(array<string|int, mixed> $encodedCollection) : EmailCollectionInterface
When JavaScript makes AJAX requests to the server it will always sent a JSON formatted collection that contain email records. This collection will be parsed to an EmailCollection object in order to be used by methods inside the controller.
Parameters
- $encodedCollection : array<string|int, mixed>
-
JSON formatted email collection.
Return values
EmailCollectionInterface —Returns the parsed email collection object.
parseContact()
Parse the contact data and return an EmailContact object.
public
parseContact(array<string|int, mixed> $encodedContact) : EmailContact
Contact name is not a mandatory field so it might be empty as well.
Parameters
- $encodedContact : array<string|int, mixed>
-
Contains the "email_address", "contact_type" and "contact_name" keys.
Return values
EmailContact —Returns the parsed object.
parseEmail()
Parse array that contains the email information sent by the JavaScript files.
public
parseEmail(array<string|int, mixed> $encodedEmail) : EmailInterface
Parameters
- $encodedEmail : array<string|int, mixed>
-
Contains the email information.
Return values
EmailInterface —Returns the equivalent email object.