EmailParser

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.

category

System

package

Extensions

subpackage

Emails

Methods

Class Constructor

__construct(\EmailServiceInterface $emailService) 

Arguments

$emailService

\EmailServiceInterface

Convert an EmailAttachment object to an array.

encodeAttachment(\EmailAttachmentInterface $attachment) : array

This conversions aims to help the JSON encoding of email contacts.

Arguments

$attachment

\EmailAttachmentInterface

Contains the attachment information.

Response

array

Encoded EmailAttachment object.

Encode EmailCollection object to an array that can be later encoded into JSON string.

encodeCollection(\EmailCollectionInterface $collection) : array

Arguments

$collection

\EmailCollectionInterface

Contains the email objects to be encoded.

Response

array

Returns an array that can be encoded to JSON and returned back to the client.

Convert an EmailContact object to an array.

encodeContact(\EmailContactInterface $contact) : array

This conversions aims to help the JSON encoding of email contacts.

Arguments

$contact

\EmailContactInterface

Contains the contact information.

Response

array

Encoded EmailContact object.

Encode Email object that contains the email information to an array.

encodeEmail(\EmailInterface $email) : array

The returned array can be then encoded into JSON and sent to the JavaScript code in the client's browser.

Arguments

$email

\EmailInterface

Contains the email information.

Response

array

Returns the equivalent array.

Parse the contact data and return an EmailAttachment object.

parseAttachment(array $encodedAttachment) : \EmailAttachment

Attachment name is not a mandatory field so it might be empty as well.

Arguments

$encodedAttachment

array

Contains the "path" and "name" keys.

Response

\EmailAttachment

Returns the parsed object.

Parse a JSON formatted email collection.

parseCollection(array $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.

Arguments

$encodedCollection

array

JSON formatted email collection.

Response

\EmailCollectionInterface

Returns the parsed email collection object.

Parse the contact data and return an EmailContact object.

parseContact(array $encodedContact) : \EmailContact

Contact name is not a mandatory field so it might be empty as well.

Arguments

$encodedContact

array

Contains the "email_address", "contact_type" and "contact_name" keys.

Response

\EmailContact

Returns the parsed object.

Parse array that contains the email information sent by the JavaScript files.

parseEmail(array $encodedEmail) : \EmailInterface

Arguments

$encodedEmail

array

Contains the email information.

Response

\EmailInterface

Returns the equivalent email object.

Properties

Used for creating email objects.

emailService : \EmailServiceInterface