[ Index ]

MailPress 544

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

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/Plugins/ -> LoggerPlugin.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   * Does real time logging of Transport level information.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_Events_ResponseListener, Swift_Events_TransportChangeListener, Swift_Events_TransportExceptionListener, Swift_Plugins_Logger
  17  {
  18      /** The logger which is delegated to */
  19      private $_logger;
  20  
  21      /**
  22       * Create a new LoggerPlugin using $logger.
  23       *
  24       * @param Swift_Plugins_Logger $logger
  25       */
  26      public function __construct(Swift_Plugins_Logger $logger)
  27      {
  28          $this->_logger = $logger;
  29      }
  30  
  31      /**
  32       * Add a log entry.
  33       *
  34       * @param string $entry
  35       */
  36      public function add($entry)
  37      {
  38          $this->_logger->add($entry);
  39      }
  40  
  41      /**
  42       * Clear the log contents.
  43       */
  44      public function clear()
  45      {
  46          $this->_logger->clear();
  47      }
  48  
  49      /**
  50       * Get this log as a string.
  51       *
  52       * @return string
  53       */
  54      public function dump()
  55      {
  56          return $this->_logger->dump();
  57      }
  58  
  59      /**
  60       * Invoked immediately following a command being sent.
  61       *
  62       * @param Swift_Events_CommandEvent $evt
  63       */
  64      public function commandSent(Swift_Events_CommandEvent $evt)
  65      {
  66          $command = $evt->getCommand();
  67          $this->_logger->add(sprintf('>> %s', $command));
  68      }
  69  
  70      /**
  71       * Invoked immediately following a response coming back.
  72       *
  73       * @param Swift_Events_ResponseEvent $evt
  74       */
  75      public function responseReceived(Swift_Events_ResponseEvent $evt)
  76      {
  77          $response = $evt->getResponse();
  78          $this->_logger->add(sprintf('<< %s', $response));
  79      }
  80  
  81      /**
  82       * Invoked just before a Transport is started.
  83       *
  84       * @param Swift_Events_TransportChangeEvent $evt
  85       */
  86      public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt)
  87      {
  88          $transportName = get_class($evt->getSource());
  89          $this->_logger->add(sprintf('++ Starting %s', $transportName));
  90      }
  91  
  92      /**
  93       * Invoked immediately after the Transport is started.
  94       *
  95       * @param Swift_Events_TransportChangeEvent $evt
  96       */
  97      public function transportStarted(Swift_Events_TransportChangeEvent $evt)
  98      {
  99          $transportName = get_class($evt->getSource());
 100          $this->_logger->add(sprintf('++ %s started', $transportName));
 101      }
 102  
 103      /**
 104       * Invoked just before a Transport is stopped.
 105       *
 106       * @param Swift_Events_TransportChangeEvent $evt
 107       */
 108      public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt)
 109      {
 110          $transportName = get_class($evt->getSource());
 111          $this->_logger->add(sprintf('++ Stopping %s', $transportName));
 112      }
 113  
 114      /**
 115       * Invoked immediately after the Transport is stopped.
 116       *
 117       * @param Swift_Events_TransportChangeEvent $evt
 118       */
 119      public function transportStopped(Swift_Events_TransportChangeEvent $evt)
 120      {
 121          $transportName = get_class($evt->getSource());
 122          $this->_logger->add(sprintf('++ %s stopped', $transportName));
 123      }
 124  
 125      /**
 126       * Invoked as a TransportException is thrown in the Transport system.
 127       *
 128       * @param Swift_Events_TransportExceptionEvent $evt
 129       */
 130      public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt)
 131      {
 132          $e = $evt->getException();
 133          $message = $e->getMessage();
 134          $code = $e->getCode();
 135          $this->_logger->add(sprintf('!! %s (code: %s)', $message, $code));
 136          $message .= PHP_EOL;
 137          $message .= 'Log data:'.PHP_EOL;
 138          $message .= $this->_logger->dump();
 139          $evt->cancelBubble();
 140          throw new Swift_TransportException($message, $code, $e->getPrevious());
 141      }
 142  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1