[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Plugins/ -> BandwidthMonitorPlugin.php (source)

   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  /**
  12   * Reduces network flooding when sending large amounts of mail.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener, Swift_Events_CommandListener, Swift_Events_ResponseListener, Swift_InputByteStream
  17  {
  18      /**
  19       * The outgoing traffic counter.
  20       *
  21       * @var int
  22       */
  23      private $out = 0;
  24  
  25      /**
  26       * The incoming traffic counter.
  27       *
  28       * @var int
  29       */
  30      private $in = 0;
  31  
  32      /** Bound byte streams */
  33      private $mirrors = [];
  34  
  35      /**
  36       * Not used.
  37       */
  38      public function beforeSendPerformed(Swift_Events_SendEvent $evt)
  39      {
  40      }
  41  
  42      /**
  43       * Invoked immediately after the Message is sent.
  44       */
  45      public function sendPerformed(Swift_Events_SendEvent $evt)
  46      {
  47          $message = $evt->getMessage();
  48          $message->toByteStream($this);
  49      }
  50  
  51      /**
  52       * Invoked immediately following a command being sent.
  53       */
  54      public function commandSent(Swift_Events_CommandEvent $evt)
  55      {
  56          $command = $evt->getCommand();
  57          $this->out += strlen($command);
  58      }
  59  
  60      /**
  61       * Invoked immediately following a response coming back.
  62       */
  63      public function responseReceived(Swift_Events_ResponseEvent $evt)
  64      {
  65          $response = $evt->getResponse();
  66          $this->in += strlen($response);
  67      }
  68  
  69      /**
  70       * Called when a message is sent so that the outgoing counter can be increased.
  71       *
  72       * @param string $bytes
  73       */
  74      public function write($bytes)
  75      {
  76          $this->out += strlen($bytes);
  77          foreach ($this->mirrors as $stream) {
  78              $stream->write($bytes);
  79          }
  80      }
  81  
  82      /**
  83       * Not used.
  84       */
  85      public function commit()
  86      {
  87      }
  88  
  89      /**
  90       * Attach $is to this stream.
  91       *
  92       * The stream acts as an observer, receiving all data that is written.
  93       * All {@link write()} and {@link flushBuffers()} operations will be mirrored.
  94       */
  95      public function bind(Swift_InputByteStream $is)
  96      {
  97          $this->mirrors[] = $is;
  98      }
  99  
 100      /**
 101       * Remove an already bound stream.
 102       *
 103       * If $is is not bound, no errors will be raised.
 104       * If the stream currently has any buffered data it will be written to $is
 105       * before unbinding occurs.
 106       */
 107      public function unbind(Swift_InputByteStream $is)
 108      {
 109          foreach ($this->mirrors as $k => $stream) {
 110              if ($is === $stream) {
 111                  unset($this->mirrors[$k]);
 112              }
 113          }
 114      }
 115  
 116      /**
 117       * Not used.
 118       */
 119      public function flushBuffers()
 120      {
 121          foreach ($this->mirrors as $stream) {
 122              $stream->flushBuffers();
 123          }
 124      }
 125  
 126      /**
 127       * Get the total number of bytes sent to the server.
 128       *
 129       * @return int
 130       */
 131      public function getBytesOut()
 132      {
 133          return $this->out;
 134      }
 135  
 136      /**
 137       * Get the total number of bytes received from the server.
 138       *
 139       * @return int
 140       */
 141      public function getBytesIn()
 142      {
 143          return $this->in;
 144      }
 145  
 146      /**
 147       * Reset the internal counters to zero.
 148       */
 149      public function reset()
 150      {
 151          $this->out = 0;
 152          $this->in = 0;
 153      }
 154  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1