Created
February 5, 2016 14:57
-
-
Save jellyninjadev/275f8db3fb1465782530 to your computer and use it in GitHub Desktop.
Emails processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DigestService { | |
private $events; | |
function __construct($events) { | |
$this->events = $events; | |
} | |
function stack(\Closure $func) { | |
foreach ($this->events as $event) { | |
$func($event); | |
} | |
return $this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$data = json_decode('{ | |
"sender": "test.myapp.com", | |
"order": 1454679154162, | |
"recipient": 1, | |
"subject": "String", | |
"schedule": "2014-07-09 11:23:13", | |
"data": {}, | |
"urgent": false | |
}'); | |
class ProcessEmails extends \Phalcon\Cli\Task { | |
function mainAction($dateTime) { | |
/** | |
* Events aggregated and ordered | |
* app_id: 1 | |
* recipients: [] | |
* body: [[subject, data]] | |
* attachments: [] if needed | |
*/ | |
$events = EmailQueue::findByDateTime($dateTime); | |
$emails = (new DigestService($events)) | |
->stack($transformEmailBody) | |
->stack($toc) | |
->stack($addTemplate); | |
$toc = function ($event) { | |
// add toc | |
return $event; | |
}; | |
$transformEmailBody = function($event) { | |
// concatenate all email body | |
return $event; | |
} | |
$addTemplate = function($event) { | |
// wrap email body in template | |
return $event; | |
} | |
foreach ($emails as $email) { | |
// EmailService | |
$this->adapter->send($email); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment