1 | <?php |
||
16 | class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin implements Swift_Plugins_Sleeper, Swift_Plugins_Timer |
||
|
|||
17 | { |
||
18 | /** Flag for throttling in bytes per minute */ |
||
19 | const BYTES_PER_MINUTE = 0x01; |
||
20 | |||
21 | /** Flag for throttling in emails per second (Amazon SES) */ |
||
22 | const MESSAGES_PER_SECOND = 0x11; |
||
23 | |||
24 | /** Flag for throttling in emails per minute */ |
||
25 | const MESSAGES_PER_MINUTE = 0x10; |
||
26 | |||
27 | /** |
||
28 | * The Sleeper instance for sleeping. |
||
29 | * |
||
30 | * @var Swift_Plugins_Sleeper |
||
31 | */ |
||
32 | private $_sleeper; |
||
33 | |||
34 | /** |
||
35 | * The Timer instance which provides the timestamp. |
||
36 | * |
||
37 | * @var Swift_Plugins_Timer |
||
38 | */ |
||
39 | private $_timer; |
||
40 | |||
41 | /** |
||
42 | * The time at which the first email was sent. |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | private $_start; |
||
47 | |||
48 | /** |
||
49 | * The rate at which messages should be sent. |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | private $_rate; |
||
54 | |||
55 | /** |
||
56 | * The mode for throttling. |
||
57 | * |
||
58 | * This is {@link BYTES_PER_MINUTE} or {@link MESSAGES_PER_MINUTE} |
||
59 | * |
||
60 | * @var int |
||
61 | */ |
||
62 | private $_mode; |
||
63 | |||
64 | /** |
||
65 | * An internal counter of the number of messages sent. |
||
66 | * |
||
67 | * @var int |
||
68 | */ |
||
69 | private $_messages = 0; |
||
70 | |||
71 | /** |
||
72 | * Create a new ThrottlerPlugin. |
||
73 | * |
||
74 | * @param int $rate |
||
75 | * @param int $mode, defaults to {@link BYTES_PER_MINUTE} |
||
76 | * @param Swift_Plugins_Sleeper $sleeper (only needed in testing) |
||
77 | * @param Swift_Plugins_Timer $timer (only needed in testing) |
||
78 | */ |
||
79 | 2 | public function __construct($rate, $mode = self::BYTES_PER_MINUTE, Swift_Plugins_Sleeper $sleeper = null, Swift_Plugins_Timer $timer = null) |
|
86 | |||
87 | /** |
||
88 | * Invoked immediately before the Message is sent. |
||
89 | * |
||
90 | * @param Swift_Events_SendEvent $evt |
||
91 | */ |
||
92 | 2 | public function beforeSendPerformed(Swift_Events_SendEvent $evt) |
|
119 | |||
120 | /** |
||
121 | * Invoked when a Message is sent. |
||
122 | * |
||
123 | * @param Swift_Events_SendEvent $evt |
||
124 | */ |
||
125 | 2 | public function sendPerformed(Swift_Events_SendEvent $evt) |
|
130 | |||
131 | /** |
||
132 | * Sleep for $seconds. |
||
133 | * |
||
134 | * @param int $seconds |
||
135 | */ |
||
136 | 2 | public function sleep($seconds) |
|
144 | |||
145 | /** |
||
146 | * Get the current UNIX timestamp. |
||
147 | * |
||
148 | * @return int |
||
149 | */ |
||
150 | 2 | public function getTimestamp() |
|
158 | |||
159 | /** |
||
160 | * Get a number of seconds to sleep for. |
||
161 | * |
||
162 | * @param int $timePassed |
||
163 | * |
||
164 | * @return int |
||
165 | */ |
||
166 | 1 | private function _throttleBytesPerMinute($timePassed) |
|
172 | |||
173 | /** |
||
174 | * Get a number of seconds to sleep for. |
||
175 | * |
||
176 | * @param int $timePassed |
||
177 | * |
||
178 | * @return int |
||
179 | */ |
||
180 | private function _throttleMessagesPerSecond($timePassed) |
||
186 | |||
187 | /** |
||
188 | * Get a number of seconds to sleep for. |
||
189 | * |
||
190 | * @param int $timePassed |
||
191 | * |
||
192 | * @return int |
||
193 | */ |
||
194 | 1 | private function _throttleMessagesPerMinute($timePassed) |
|
200 | } |
||
201 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.