XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/Events/SendListener.php';
12 //@require 'Swift/Events/SendEvent.php';
13 //@require 'Swift/Events/CommandListener.php';
14 //@require 'Swift/Events/CommandEvent.php';
15 //@require 'Swift/Events/ResponseListener.php';
16 //@require 'Swift/Events/ResponseEvent.php';
17 //@require 'Swift/InputByteStream.php';
18 
28 {
29 
35  private $_out = 0;
36 
42  private $_in = 0;
43 
45  private $_mirrors = array();
46 
51  {
52  }
53 
58  public function sendPerformed(Swift_Events_SendEvent $evt)
59  {
60  $message = $evt->getMessage();
61  $message->toByteStream($this);
62  }
63 
68  public function commandSent(Swift_Events_CommandEvent $evt)
69  {
70  $command = $evt->getCommand();
71  $this->_out += strlen($command);
72  }
73 
79  {
80  $response = $evt->getResponse();
81  $this->_in += strlen($response);
82  }
83 
88  public function write($bytes)
89  {
90  $this->_out += strlen($bytes);
91  foreach ($this->_mirrors as $stream)
92  {
93  $stream->write($bytes);
94  }
95  }
96 
100  public function commit()
101  {
102  }
103 
111  public function bind(Swift_InputByteStream $is)
112  {
113  $this->_mirrors[] = $is;
114  }
115 
124  public function unbind(Swift_InputByteStream $is)
125  {
126  foreach ($this->_mirrors as $k => $stream)
127  {
128  if ($is === $stream)
129  {
130  unset($this->_mirrors[$k]);
131  }
132  }
133  }
134 
138  public function flushBuffers()
139  {
140  foreach ($this->_mirrors as $stream)
141  {
142  $stream->flushBuffers();
143  }
144  }
145 
150  public function getBytesOut()
151  {
152  return $this->_out;
153  }
154 
159  public function getBytesIn()
160  {
161  return $this->_in;
162  }
163 
167  public function reset()
168  {
169  $this->_out = 0;
170  $this->_in = 0;
171  }
172 
173 }