123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
-
-
-
-
-
- class Swift_Plugins_BandwidthMonitorPlugin
- implements Swift_Events_SendListener, Swift_Events_CommandListener,
- Swift_Events_ResponseListener, Swift_InputByteStream
- {
-
-
-
- private $_out = 0;
-
-
-
- private $_in = 0;
-
-
- private $_mirrors = array();
-
-
-
- public function beforeSendPerformed(Swift_Events_SendEvent $evt)
- {
- }
-
-
-
- public function sendPerformed(Swift_Events_SendEvent $evt)
- {
- $message = $evt->getMessage();
- $message->toByteStream($this);
- }
-
-
-
- public function commandSent(Swift_Events_CommandEvent $evt)
- {
- $command = $evt->getCommand();
- $this->_out += strlen($command);
- }
-
-
-
- public function responseReceived(Swift_Events_ResponseEvent $evt)
- {
- $response = $evt->getResponse();
- $this->_in += strlen($response);
- }
-
-
-
- public function write($bytes)
- {
- $this->_out += strlen($bytes);
- foreach ($this->_mirrors as $stream)
- {
- $stream->write($bytes);
- }
- }
-
-
-
- public function commit()
- {
- }
-
-
-
- public function bind(Swift_InputByteStream $is)
- {
- $this->_mirrors[] = $is;
- }
-
-
-
- public function unbind(Swift_InputByteStream $is)
- {
- foreach ($this->_mirrors as $k => $stream)
- {
- if ($is === $stream)
- {
- unset($this->_mirrors[$k]);
- }
- }
- }
-
-
-
- public function flushBuffers()
- {
- foreach ($this->_mirrors as $stream)
- {
- $stream->flushBuffers();
- }
- }
-
-
-
- public function getBytesOut()
- {
- return $this->_out;
- }
-
-
-
- public function getBytesIn()
- {
- return $this->_in;
- }
-
-
-
- public function reset()
- {
- $this->_out = 0;
- $this->_in = 0;
- }
-
- }
|