TYPO3  7.6
BandwidthMonitorPlugin.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
17 {
23  private $_out = 0;
24 
30  private $_in = 0;
31 
33  private $_mirrors = array();
34 
39  {
40  }
41 
47  public function sendPerformed(Swift_Events_SendEvent $evt)
48  {
49  $message = $evt->getMessage();
50  $message->toByteStream($this);
51  }
52 
58  public function commandSent(Swift_Events_CommandEvent $evt)
59  {
60  $command = $evt->getCommand();
61  $this->_out += strlen($command);
62  }
63 
70  {
71  $response = $evt->getResponse();
72  $this->_in += strlen($response);
73  }
74 
80  public function write($bytes)
81  {
82  $this->_out += strlen($bytes);
83  foreach ($this->_mirrors as $stream) {
84  $stream->write($bytes);
85  }
86  }
87 
91  public function commit()
92  {
93  }
94 
103  public function bind(Swift_InputByteStream $is)
104  {
105  $this->_mirrors[] = $is;
106  }
107 
117  public function unbind(Swift_InputByteStream $is)
118  {
119  foreach ($this->_mirrors as $k => $stream) {
120  if ($is === $stream) {
121  unset($this->_mirrors[$k]);
122  }
123  }
124  }
125 
129  public function flushBuffers()
130  {
131  foreach ($this->_mirrors as $stream) {
132  $stream->flushBuffers();
133  }
134  }
135 
141  public function getBytesOut()
142  {
143  return $this->_out;
144  }
145 
151  public function getBytesIn()
152  {
153  return $this->_in;
154  }
155 
159  public function reset()
160  {
161  $this->_out = 0;
162  $this->_in = 0;
163  }
164 }