Source for file Email.class.php

Documentation is available at Email.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Debug
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Debug Email Report Class
  22.  *
  23.  * @category Gumbo
  24.  * @package Debug
  25.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  26.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  27.  * @author Michael Luster <mluster79@yahoo.com>
  28.  * @link http://sourceforge.net/projects/phpgumbo
  29.  * @desc Debug Email Report Class
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Debug_Report");
  34. gumbo_load ("Date");
  35. gumbo_load ("Valid_Web");
  36.  
  37.  
  38.     /** @var string $_email address to send Debug Report */
  39.     private $_email;
  40.  
  41.  
  42.  
  43.     /**
  44.      * Constructor
  45.      * @param string $email 
  46.      */
  47.     public function __construct ($email=null{
  48.         if (defined ("GUMBO_DEBUG_EMAIL")) $this->setEmail (GUMBO_DEBUG_EMAIL)}
  49.         if (!is_null ($email)) $this->setEmail ($email)}
  50.     }
  51.  
  52.  
  53.  
  54.     /** ACTION METHODS **/
  55.     /**
  56.      * Runs the Report
  57.      * @param num $start_time initial start time of script debugger
  58.      * @throws Gumbo_Exception
  59.      * @uses Gumbo_Date
  60.      */
  61.     public function run ($start_time=null{
  62.         try {
  63.             // verify precondition
  64.             if (!$this->getEmail ()) {
  65.                 throw new Gumbo_Exception ("Debug Email Undefined");
  66.             }
  67.             
  68.             $txt null;
  69.             foreach ($this->getMessages (as $mess{
  70.                 $mess->setSeconds ($start_time);
  71.                 
  72.                 $txt .= $mess->getSeconds ("||" $mess->getMessage ("||";
  73.                 $txt .= $mess->getFile ("||" $mess->getLine ("||";
  74.                 $txt .= $mess->getFunction ("||" $mess->getClass ("\n";
  75.                 
  76.                 $start_time $mess->getTime ();
  77.             }
  78.             
  79.             $date new Gumbo_Date ();
  80.             @mail ($this->getEmail ()"Debug Report: " $date->get ()$txt);
  81.         catch (Gumbo_Exception $e{
  82.             $e->setFunction (__METHOD__);
  83.             gumbo_trigger ($e);
  84.         }
  85.     }
  86.  
  87.  
  88.  
  89.     /** MUTATOR METHODS **/
  90.     /**
  91.      * Sets the Debug Email Address
  92.      * @param string $email 
  93.      * @throws Gumbo_Exception
  94.      * @uses Gumbo_Valid_Web
  95.      */
  96.     public function setEmail ($email{
  97.         try {
  98.             // verify precondition
  99.             if (!is_string ($email)) {
  100.                 throw new Gumbo_Exception ("Invalid Argument 'email:str' => {$email}:gettype ($email));
  101.             }
  102.             $valid new Gumbo_Valid_Web ();
  103.             if (!$valid->isEmail ($email)) {
  104.                 throw new Gumbo_Exception ("Invalid Email Address: {$email}");
  105.             }
  106.                 
  107.             $this->_email = $email;
  108.         catch (Gumbo_Exception $e{
  109.             $e->setFunction (__METHOD__);
  110.             gumbo_trigger ($e);
  111.         }
  112.     }
  113.  
  114.  
  115.  
  116.     /** ACCESSOR METHODS **/
  117.     /**
  118.      * Returns the Debug Email
  119.      * @return string 
  120.      */
  121.     public function getEmail ({
  122.         return $this->_email;
  123.     }
  124.  
  125. }
  126.  
  127. ?>