phpDocumentor

EmailService
in package
implements EmailServiceInterface

Class EmailService

Represents the public API for the Email service of the system. External users must use this class for all the email operations except.

Important: Since the attachments will be flat-stored in the "uploads/attachmetns" directory the "send" and "queue" method will have to perform multiple writes to the database in order to get robust attachment handling that will not crash the rest of the service.

Tags
category

System

Interfaces, Classes and Traits

EmailServiceInterface
Interface EmailServiceInterface

Table of Contents

$attachmentsHandler  : AttachmentsHandlerInterface
E-Mail attachments handler.
$factory  : EmailFactoryInterface
E-Mail factory.
$mailerAdapter  : MailerAdapterInterface
Mailer adapter.
$repository  : EmailRepositoryInterface
E-Mail repository.
__construct()  : mixed
Class Constructor
create()  : EmailInterface
Creates a new email
delete()  : mixed
Removes an email from the database.
deleteCollection()  : mixed
Deletes a collection of emails.
deleteEmailsByCustomerEmail()  : mixed
Removes all emails from the data base that have the given email address as sender or recipient.
deleteOldEmailsByDate()  : mixed
Deletes all emails that have creation date below the give date.
filter()  : EmailCollection
Filters email records with provided keyword string.
findById()  : EmailInterface|null
Finds an email by ID.
getAll()  : EmailCollection
Returns all email records from the database.
getById()  : EmailInterface
Returns an email by id.
getEmailsByCustomerEmail()  : EmailCollection
Gets all emails from the data base that have the given email address as sender or recipient.
getPending()  : EmailCollectionInterface
Return pending email records as an email collection.
getRecordCount()  : int
Returns the current count of the email records in the database.
getSent()  : EmailCollectionInterface
Returns sent email records as an email collection.
queue()  : mixed
Saves an email as pending (will not be sent).
queueCollection()  : mixed
Queues a collection of emails.
send()  : mixed
Sends and saves an email.
sendCollection()  : mixed
Sends a collection of emails.
sendPending()  : mixed
Sends pending email records.
validateEmailAddress()  : bool
Validate a string email address.
write()  : mixed
Writes an email instance to the DB.
writeCollection()  : mixed
Writes a collection of emails into database.

Properties

Methods

__construct()

Class Constructor

public __construct(EmailRepositoryInterface $repository, EmailFactoryInterface $factory, MailerAdapterInterface $mailerAdapter, AttachmentsHandlerInterface $attachmentsHandler) : mixed
Parameters
$repository : EmailRepositoryInterface

E-Mail repository.

$factory : EmailFactoryInterface

E-Mail factory.

$mailerAdapter : MailerAdapterInterface

Mailer adapter.

$attachmentsHandler : AttachmentsHandlerInterface

E-Mail attachments handler.

Return values
mixed

create()

Creates a new email

public create(EmailContactInterface $sender, EmailContactInterface $recipient, EmailSubjectInterface $subject[, EmailContentInterface $content = null ]) : EmailInterface

Use this method to can a valid email object that can be sent without any additional modification. Optionally you can add more information to the email object such as attachments, BCC & CC contacts etc.

Parameters
$sender : EmailContactInterface

Contains the sender information.

$recipient : EmailContactInterface

Contains the recipient information.

$subject : EmailSubjectInterface

Email record subject.

$content : EmailContentInterface = null

(optional) Html content of the email.

Return values
EmailInterface

Valid email.

deleteEmailsByCustomerEmail()

Removes all emails from the data base that have the given email address as sender or recipient.

public deleteEmailsByCustomerEmail(CustomerEmail $email) : mixed
Parameters
$email : CustomerEmail

E-Mail address.

Return values
mixed

deleteOldEmailsByDate()

Deletes all emails that have creation date below the give date.

public deleteOldEmailsByDate(DateTime $date) : mixed
Parameters
$date : DateTime
Return values
mixed

filter()

Filters email records with provided keyword string.

public filter(string $p_keyword[, array<string|int, mixed> $limit = [] ][, array<string|int, mixed> $order = [] ]) : EmailCollection
Parameters
$p_keyword : string

String to be used for filtering the email records.

$limit : array<string|int, mixed> = []

(optional) Array that contains LIMIT and OFFSET value e.g. array( 'limit' => 10, 'offset' => 5 )

$order : array<string|int, mixed> = []

(optional) Contains arrays with column, direction pairs e.g. array( 'column' => 'direction' )

Return values
EmailCollection

Email collection containing the email records.

getRecordCount()

Returns the current count of the email records in the database.

public getRecordCount([string $p_filterKeyword = '' ]) : int
Parameters
$p_filterKeyword : string = ''

(optional) If provided the records will be filtered.

Return values
int

The row number of the email table.

sendPending()

Sends pending email records.

public sendPending() : mixed
Return values
mixed

validateEmailAddress()

Validate a string email address.

public validateEmailAddress(string $p_emailAddress) : bool
Parameters
$p_emailAddress : string

Email address to be validated.

Tags
throws
InvalidArgumentException

If argument is not a string.

Return values
bool

Returns the validation result (true for success, false for failure).

write()

Writes an email instance to the DB.

public write(EmailInterface $email) : mixed

This method will store an email entity just the way it is without modifying other properties like the "send" or "queue" methods do. If you use this method or the "writeCollection" make sure that all the email properties are the desired ones.

Parameters
$email : EmailInterface

Email to write.

Return values
mixed

Search results