| 199 |
lars |
1 |
<?php namespace Clockwork\DataSource;
|
|
|
2 |
|
|
|
3 |
use Clockwork\Request\Request;
|
|
|
4 |
use Clockwork\Request\Timeline\Timeline;
|
|
|
5 |
use Clockwork\Support\Swift\SwiftPluginClockworkTimeline;
|
|
|
6 |
|
|
|
7 |
use Swift_Mailer;
|
|
|
8 |
|
|
|
9 |
// Data source for Swift mailer, provides sent emails
|
|
|
10 |
class SwiftDataSource extends DataSource
|
|
|
11 |
{
|
|
|
12 |
// Swift instance
|
|
|
13 |
protected $swift;
|
|
|
14 |
|
|
|
15 |
// Clockwork timeline instance
|
|
|
16 |
protected $timeline;
|
|
|
17 |
|
|
|
18 |
// Create a new data source, takes a Swift instance as an argument
|
|
|
19 |
public function __construct(Swift_Mailer $swift)
|
|
|
20 |
{
|
|
|
21 |
$this->swift = $swift;
|
|
|
22 |
|
|
|
23 |
$this->timeline = new Timeline;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
// Listen to the email events
|
|
|
27 |
public function listenToEvents()
|
|
|
28 |
{
|
|
|
29 |
$this->swift->registerPlugin(new SwiftPluginClockworkTimeline($this->timeline));
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
// Adds send emails to the request
|
|
|
33 |
public function resolve(Request $request)
|
|
|
34 |
{
|
|
|
35 |
$request->emailsData = array_merge($request->emailsData, $this->timeline->finalize());
|
|
|
36 |
|
|
|
37 |
return $request;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
// Reset the data source to an empty state, clearing any collected data
|
|
|
41 |
public function reset()
|
|
|
42 |
{
|
|
|
43 |
$this->timeline = new Timeline;
|
|
|
44 |
}
|
|
|
45 |
}
|