forked from Wavyzz/dolibarr
swiftmailer
This commit is contained in:
@@ -29,28 +29,28 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*
|
||||
* @var Swift_Plugins_Sleeper
|
||||
*/
|
||||
private $_sleeper;
|
||||
private $sleeper;
|
||||
|
||||
/**
|
||||
* The Timer instance which provides the timestamp.
|
||||
*
|
||||
* @var Swift_Plugins_Timer
|
||||
*/
|
||||
private $_timer;
|
||||
private $timer;
|
||||
|
||||
/**
|
||||
* The time at which the first email was sent.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_start;
|
||||
private $start;
|
||||
|
||||
/**
|
||||
* The rate at which messages should be sent.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_rate;
|
||||
private $rate;
|
||||
|
||||
/**
|
||||
* The mode for throttling.
|
||||
@@ -59,14 +59,14 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_mode;
|
||||
private $mode;
|
||||
|
||||
/**
|
||||
* An internal counter of the number of messages sent.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_messages = 0;
|
||||
private $messages = 0;
|
||||
|
||||
/**
|
||||
* Create a new ThrottlerPlugin.
|
||||
@@ -78,10 +78,10 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*/
|
||||
public function __construct($rate, $mode = self::BYTES_PER_MINUTE, Swift_Plugins_Sleeper $sleeper = null, Swift_Plugins_Timer $timer = null)
|
||||
{
|
||||
$this->_rate = $rate;
|
||||
$this->_mode = $mode;
|
||||
$this->_sleeper = $sleeper;
|
||||
$this->_timer = $timer;
|
||||
$this->rate = $rate;
|
||||
$this->mode = $mode;
|
||||
$this->sleeper = $sleeper;
|
||||
$this->timer = $timer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,22 +92,22 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
public function beforeSendPerformed(Swift_Events_SendEvent $evt)
|
||||
{
|
||||
$time = $this->getTimestamp();
|
||||
if (!isset($this->_start)) {
|
||||
$this->_start = $time;
|
||||
if (!isset($this->start)) {
|
||||
$this->start = $time;
|
||||
}
|
||||
$duration = $time - $this->_start;
|
||||
$duration = $time - $this->start;
|
||||
|
||||
switch ($this->_mode) {
|
||||
case self::BYTES_PER_MINUTE :
|
||||
$sleep = $this->_throttleBytesPerMinute($duration);
|
||||
switch ($this->mode) {
|
||||
case self::BYTES_PER_MINUTE:
|
||||
$sleep = $this->throttleBytesPerMinute($duration);
|
||||
break;
|
||||
case self::MESSAGES_PER_SECOND :
|
||||
$sleep = $this->_throttleMessagesPerSecond($duration);
|
||||
case self::MESSAGES_PER_SECOND:
|
||||
$sleep = $this->throttleMessagesPerSecond($duration);
|
||||
break;
|
||||
case self::MESSAGES_PER_MINUTE :
|
||||
$sleep = $this->_throttleMessagesPerMinute($duration);
|
||||
case self::MESSAGES_PER_MINUTE:
|
||||
$sleep = $this->throttleMessagesPerMinute($duration);
|
||||
break;
|
||||
default :
|
||||
default:
|
||||
$sleep = 0;
|
||||
break;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
public function sendPerformed(Swift_Events_SendEvent $evt)
|
||||
{
|
||||
parent::sendPerformed($evt);
|
||||
++$this->_messages;
|
||||
++$this->messages;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,8 +135,8 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*/
|
||||
public function sleep($seconds)
|
||||
{
|
||||
if (isset($this->_sleeper)) {
|
||||
$this->_sleeper->sleep($seconds);
|
||||
if (isset($this->sleeper)) {
|
||||
$this->sleeper->sleep($seconds);
|
||||
} else {
|
||||
sleep($seconds);
|
||||
}
|
||||
@@ -149,8 +149,8 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*/
|
||||
public function getTimestamp()
|
||||
{
|
||||
if (isset($this->_timer)) {
|
||||
return $this->_timer->getTimestamp();
|
||||
if (isset($this->timer)) {
|
||||
return $this->timer->getTimestamp();
|
||||
}
|
||||
|
||||
return time();
|
||||
@@ -163,9 +163,9 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function _throttleBytesPerMinute($timePassed)
|
||||
private function throttleBytesPerMinute($timePassed)
|
||||
{
|
||||
$expectedDuration = $this->getBytesOut() / ($this->_rate / 60);
|
||||
$expectedDuration = $this->getBytesOut() / ($this->rate / 60);
|
||||
|
||||
return (int) ceil($expectedDuration - $timePassed);
|
||||
}
|
||||
@@ -177,9 +177,9 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function _throttleMessagesPerSecond($timePassed)
|
||||
private function throttleMessagesPerSecond($timePassed)
|
||||
{
|
||||
$expectedDuration = $this->_messages / ($this->_rate);
|
||||
$expectedDuration = $this->messages / $this->rate;
|
||||
|
||||
return (int) ceil($expectedDuration - $timePassed);
|
||||
}
|
||||
@@ -191,9 +191,9 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function _throttleMessagesPerMinute($timePassed)
|
||||
private function throttleMessagesPerMinute($timePassed)
|
||||
{
|
||||
$expectedDuration = $this->_messages / ($this->_rate / 60);
|
||||
$expectedDuration = $this->messages / ($this->rate / 60);
|
||||
|
||||
return (int) ceil($expectedDuration - $timePassed);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user