Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.6.2

Request #16420 Debug handler function
Submitted: 2009-07-09 16:14 UTC Modified: 2009-07-14 06:44 UTC
From: alec Assigned: jon
Status: Closed Package: Net_SMTP (version 1.3.2)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  



Patch debug_handler.patch Revisions
Revision 2009-07-09 16:14 UTC
Developer alec
 
Download patch

--- SMTP.old	2009-07-06 11:13:11.000000000 +0200
+++ SMTP.php	2009-07-09 17:07:00.717933801 +0200
@@ -92,6 +92,13 @@
     var $_debug = false;
 
     /**
+     * Debugging callback function
+     * @var function
+     * @access private
+     */
+    var $_debug_handler = null;
+
+    /**
      * The socket resource being used to connect to the SMTP server.
      * @var resource
      * @access private
@@ -172,9 +179,10 @@
      * @access  public
      * @since   1.1.0
      */
-    function setDebug($debug)
+    function setDebug($debug, $handler=null)
     {
         $this->_debug = $debug;
+	$this->_debug_handler = $handler;
     }
 
     /**
@@ -189,9 +197,7 @@
      */
     function _send($data)
     {
-        if ($this->_debug) {
-            echo "DEBUG: Send: $data\n";
-        }
+        $this->Debug($data, 'Sent');
 
         if (PEAR::isError($error = $this->_socket->write($data))) {
             return PEAR::raiseError('Failed to write to socket: ' .
@@ -262,9 +268,7 @@
 
         for ($i = 0; $i <= $this->_pipelined_commands; $i++) {
             while ($line = $this->_socket->readLine()) {
-                if ($this->_debug) {
-                    echo "DEBUG: Recv: $line\n";
-                }
+                $this->Debug($line, 'Recv');
 
                 /* If we receive an empty line, the connection has been closed. */
                 if (empty($line)) {
@@ -1074,4 +1078,15 @@
         return true;
     }
 
+    function Debug($message, $direction='Recv')
+    {
+        if ($this->_debug) {
+	    if ($this->_debug_handler) {
+		return call_user_func_array($this->_debug_handler, array(&$this, $message, $direction));
+	    } else {
+		echo "DEBUG: $direction: $message\n";
+	    }
+	}
+	return null;
+    }
 }