AttachmentsHandler
in package
implements
AttachmentsHandlerInterface
Class AttachmentsHandler
This class will handle the email attachments organization. Every email must have its own attachments directory so that we can avoid file issues between emails.
Tags
Interfaces, Classes and Traits
- AttachmentsHandlerInterface
- Class AttachmentsHandlerInterface
Table of Contents
- $uploadsDirPath : string
- Full server path to "uploads" directory.
- $attachmentConfigurationService : AttachmentConfigurationServiceInterface
- __construct() : mixed
- Class Constructor
- backupEmailAttachments() : mixed
- Process email attachments.
- deleteAttachment() : mixed
- Removes a single email attachment.
- deleteEmailAttachments() : mixed
- Deletes email attachments.
- deleteEmailCollection() : mixed
- Delete attachments for each email in collection.
- deleteOldAttachments() : array<string|int, mixed>
- Delete old attachments prior to removal date.
- emptyTempDirectory() : mixed
- Removes all files within the "uploads/tmp" directory.
- getAttachmentsSize() : int
- Get attachments directory file size in bytes.
- uploadAttachment() : EmailAttachment
- Upload an attachment to "uploads/tmp" directory.
- uploadEmailCollection() : mixed
- Process attachments for each email in collection.
- checkAttachmentHash() : bool
- Checks if the attachment hash must be updated.
- getAttachmentConfigurationFactory() : AttachmentConfigurationFactory|mixed
- getAttachmentConfigurationService() : AttachmentConfigurationServiceInterface
Properties
$uploadsDirPath
Full server path to "uploads" directory.
protected
string
$uploadsDirPath
$attachmentConfigurationService
private
AttachmentConfigurationServiceInterface
$attachmentConfigurationService
Methods
__construct()
Class Constructor
public
__construct(string $p_uploadsDirPath[, AttachmentConfigurationServiceInterface|null $attachmentConfigurationService = null ]) : mixed
Parameters
- $p_uploadsDirPath : string
-
Path to the server's "uploads" directory. The uploads directory must already contain a "tmp" and an "attachments" directory created by an FTP client (resolves permission problems).
- $attachmentConfigurationService : AttachmentConfigurationServiceInterface|null = null
Return values
mixed —backupEmailAttachments()
Process email attachments.
public
backupEmailAttachments(EmailInterface &$email) : mixed
This method will move all the email attachments to the "uploads/attachments" directory and store them there for future reference and history navigation purposes. The email needs to be saved first because the email ID will be used to distinguish the emails.
Parameters
- $email : EmailInterface
-
Passed by reference, contains the email data.
Return values
mixed —deleteAttachment()
Removes a single email attachment.
public
deleteAttachment(EmailAttachmentInterface $attachment) : mixed
Parameters
- $attachment : EmailAttachmentInterface
-
E-Mail attachment.
Return values
mixed —deleteEmailAttachments()
Deletes email attachments.
public
deleteEmailAttachments(EmailInterface $email) : mixed
This method will remove all the email attachments from the server.
Parameters
- $email : EmailInterface
-
Contains the email information.
Return values
mixed —deleteEmailCollection()
Delete attachments for each email in collection.
public
deleteEmailCollection(EmailCollectionInterface $collection) : mixed
Every email has its own attachments directory. When emails are deleted we need to remove their respective attachments.
Parameters
- $collection : EmailCollectionInterface
-
Contains email records to be deleted.
Tags
Return values
mixed —deleteOldAttachments()
Delete old attachments prior to removal date.
public
deleteOldAttachments(DateTime $removalDate) : array<string|int, mixed>
This method will remove all the files and directories that are prior to the given date. It will return removal information so that user can see how much disc spaces was set free.
Parameters
- $removalDate : DateTime
-
From this date and before the attachment files will be removed.
Return values
array<string|int, mixed> —Returns an array which contains the "count" and "size" values or the operation.
emptyTempDirectory()
Removes all files within the "uploads/tmp" directory.
public
emptyTempDirectory() : mixed
There might be cases where old unused files are left within the "tmp" directory and they need to be deleted. This function will remove all these files.
Return values
mixed —getAttachmentsSize()
Get attachments directory file size in bytes.
public
getAttachmentsSize() : int
Tags
Return values
int —Returns the size in bytes.
uploadAttachment()
Upload an attachment to "uploads/tmp" directory.
public
uploadAttachment(EmailAttachmentInterface $attachment) : EmailAttachment
This method takes the uploaded file information and places it in the "uploads/tmp" directory as a temporary place, until the "uploadEmailCollection" moves it to the final destination.
Parameters
- $attachment : EmailAttachmentInterface
-
Contains the file information (path is required).
Tags
Return values
EmailAttachment —Returns an EmailAttachment instance with the new attachment path.
uploadEmailCollection()
Process attachments for each email in collection.
public
uploadEmailCollection(EmailCollectionInterface $collection) : mixed
Important! Use this method after you save the emails into the database. The reason is that this property separates each attachment file by its email ID, a value that is only accessible after the email is already saved.
Parameters
- $collection : EmailCollectionInterface
-
Passed by reference, contains emails of which the attachments must be processed.
Tags
Return values
mixed —checkAttachmentHash()
Checks if the attachment hash must be updated.
private
checkAttachmentHash(AttachmentConfigurationInterface $attachmentConfiguration) : bool
Parameters
- $attachmentConfiguration : AttachmentConfigurationInterface
Return values
bool —Returns whether if the attachment hash was updated or not.
getAttachmentConfigurationFactory()
private
getAttachmentConfigurationFactory() : AttachmentConfigurationFactory|mixed
Return values
AttachmentConfigurationFactory|mixed —getAttachmentConfigurationService()
private
getAttachmentConfigurationService() : AttachmentConfigurationServiceInterface