Source for file Message.class.php

Documentation is available at Message.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 Message 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 Message Class
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Interface_Debug_Message");
  34.  
  35. class Gumbo_Debug_Message implements Gumbo_Interface_Debug_Message {
  36.     
  37.     /** @var num $_time timestamp when message was created */
  38.     private $_time;
  39.     /** @var num $_seconds time to execute Debug Message */
  40.     private $_seconds = 0;
  41.     
  42.     /** @var int $_line line where message occured */
  43.     private $_line;
  44.     /** @var string $_file file where message was created */
  45.     private $_file;
  46.     /** @var string $_class class name */
  47.     private $_class;
  48.     /** @var string $_function method/function of message */
  49.     private $_function;
  50.     
  51.     /** @var string $_message the custom message */
  52.     private $_message;
  53.     
  54.     
  55.     
  56.     /**
  57.      * Constructor
  58.      * @param string $mess message
  59.      * @param string $file file name __FILE__
  60.      * @param int $line line number __LINE__
  61.      * @param string $func function/method name __FUNCTION__
  62.      * @param string $cls class name __CLASS__
  63.      */
  64.     public function __construct ($mess$file$line$func=null$cls=null{
  65.         $this->_setTime (microtime (true));
  66.         
  67.         $this->setMessage ($mess);
  68.         $this->setFile ($file);
  69.         $this->setLine ($line);
  70.         if (!is_null ($cls)) $this->setClass ($cls)}
  71.         if (!is_nul ($func)) $this->setFunction ($func)}
  72.     }
  73.     
  74.     
  75.     
  76.     /** ACTION METHODS **/
  77.     
  78.     
  79.     
  80.     /** MUTATOR METHODS **/
  81.     /**
  82.      * Sets the time stamp when the message was created
  83.      * @param num $time 
  84.      * @throws Gumbo_Exception
  85.      */
  86.     private function _setTime ($time{
  87.         try {
  88.             // verify precondition
  89.             if (!is_numeric ($time)) {
  90.                 throw new Gumbo_Exception ("Invalid Argument 'time:num' => {$time}:gettype ($time));
  91.             }
  92.             
  93.             $this->_time = $time;
  94.         catch (Gumbo_Exception $e{
  95.             $e->setFunction (__METHOD__);
  96.             gumbo_trigger ($e);
  97.         }
  98.     }
  99.     
  100.     /**
  101.      * Sets the message contents of the message
  102.      * @param string $mess 
  103.      * @throws Gumbo_Exception
  104.      */
  105.     public function setMessage ($mess{
  106.         try {
  107.             // verify precondtion
  108.             if (!is_string ($mess)) {
  109.                 throw new Gumbo_Exception ("Invalid Argument 'mess:str' => {$mess}:gettype ($mess));
  110.             }
  111.             
  112.             $this->_message = $mess;
  113.         catch (Gumbo_Exception $e{
  114.             $e->setFunction (__METHOD__);
  115.             gumbo_trigger ($e);
  116.         }
  117.     }
  118.     
  119.     /**
  120.      * Sets the file where the message occured
  121.      * @precondition file_exists ($file)
  122.      * @param string $file 
  123.      * @throws Gumbo_Exception
  124.      */
  125.     public function setFile ($file{
  126.         try {
  127.             // verify precondition
  128.             if (!is_string ($file)) {
  129.                 throw new Gumbo_Exception ("Invalid Argument 'file:str' => {$file}:gettype ($file));
  130.             }
  131.             if (!file_exists ($file)) {
  132.                 throw new Gumbo_Exception ("File Not Found: {$file}");
  133.             }
  134.             
  135.             $this->_file = $file;
  136.         catch (Gumbo_Exception $e{
  137.             $e->setFunction (__METHOD__);
  138.             gumbo_trigger ($e);
  139.         }
  140.     }
  141.     
  142.     /**
  143.      * Sets the line number of the message
  144.      * @param int $line 
  145.      * @throws Gumbo_Exception
  146.      */
  147.     public function setLine ($line{
  148.         try {
  149.             // verify precondition
  150.             if (!is_int ($line)) {
  151.                 throw new Gumbo_Exception ("Invalid Argument 'line:int' => {$line}:gettype ($line));
  152.             }
  153.             if ($line 0{
  154.                 throw new Gumbo_Exception ("Must Be Positive Number: {$line}");
  155.             }
  156.             
  157.             $this->_line = $line;
  158.         catch (Gumbo_Exception $e{
  159.             $e->setFunction (__METHOD__);
  160.             gumbo_trigger ($e);
  161.         }
  162.     }
  163.     
  164.     /**
  165.      * Sets the function/method name
  166.      * @precondition function_exists ($func)
  167.      * @param string $func 
  168.      * @throws Gumbo_Exception
  169.      */
  170.     public function setFunction ($func{
  171.         try {
  172.             // verify precondition
  173.             if (!is_string ($func)) {
  174.                 throw new Gumbo_Exception ("Invalid Argument 'func:str' => {$func}:gettype ($func));
  175.             }
  176.             if ($this->getClass (&& !method_exists ($this->getClass ()$func)) {
  177.                 throw new Gumbo_Exception ("Class Method Does Not Exist: " $this->getClass ("::{$func}");
  178.             }
  179.             if (!$this->getClass (&& !function_exists ($func)) {
  180.                 throw new Gumbo_Exception ("Function Does Not Exist: {$func}");
  181.             }
  182.             
  183.             $this->_function = $func;
  184.         catch (Gumbo_Exception $e{
  185.             $e->setFunction (__METHOD__);
  186.             gumbo_trigger ($e);
  187.         }
  188.     }
  189.     
  190.     /**
  191.      * Sets the class name
  192.      * @precondtion class_exists ($cls)
  193.      * @param string $cls 
  194.      * @throws Gumbo_Exception
  195.      */
  196.     public function setClass ($cls{
  197.         try {
  198.             // verify precondition
  199.             if (!is_string ($cls)) {
  200.                 throw new Gumbo_Exception ("Invalid Argument 'cls:str' => {$cls}:gettype ($cls));
  201.             }
  202.             if (!class_exists ($clsfalse)) {
  203.                 throw new Gumbo_Exception ("Class|Interface Does Not Exist: {$cls}");
  204.             }
  205.             
  206.             $this->_class = $cls;
  207.             if ($this->getFunction ()) {
  208.                 $this->setFunction ($this->getFunction ());
  209.             }
  210.         catch (Gumbo_Exception $e{
  211.             $e->setFunction (__METHOD__);
  212.             gumbo_trigger ($e);
  213.         }
  214.     }
  215.     
  216.     /**
  217.      * Sets the time (in seconds) to get to debug message from last message
  218.      * @param num $time 
  219.      */
  220.     public function setSeconds ($time=null{
  221.         try {
  222.             // verify precondition
  223.             if (!is_null ($time&& !is_numeric ($time)) {
  224.                 throw new Gumbo_Exception ("Invalid Argument 'time:num' => {$time}:gettype ($time));
  225.             }
  226.         catch (Gumbo_Exception $e{
  227.             $e->setFunction (__METHOD__);
  228.             gumbo_trigger ($e);
  229.             $time null;
  230.         }
  231.         if (is_null ($time)) {
  232.             $time 0;
  233.         }
  234.         $this->_seconds = $this->getTime ($time;
  235.     }
  236.     
  237.     
  238.     
  239.     /** ACCESSOR METHODS **/
  240.     /**
  241.      * Returns the time when message occured
  242.      * @return num 
  243.      */
  244.     public function getTime ({
  245.         return $this->_time;
  246.     }
  247.     
  248.     /**
  249.      * Returns the message
  250.      * @return string 
  251.      */
  252.     public function getMessage ({
  253.         return $this->_message;
  254.     }
  255.     
  256.     /**
  257.      * Returns the file
  258.      * @return string 
  259.      */
  260.     public function getFile ({
  261.         return $this->_file;
  262.     }
  263.     
  264.     /**
  265.      * Returns the line number
  266.      * @return int 
  267.      */
  268.     public function getLine ({
  269.         return $this->_line;
  270.     }
  271.     
  272.     /**
  273.      * Returns the function/method
  274.      * @return string 
  275.      */
  276.     public function getFunction ({
  277.         return $this->_function;
  278.     }
  279.     
  280.     /**
  281.      * Returns the class name
  282.      * @return string 
  283.      */
  284.     public function getClass ({
  285.         return $this->_class;
  286.     }
  287.     
  288.     /**
  289.      * Returns the time (in seconds) it took to execute the code from last message
  290.      * @param num $time last message time stamp
  291.      * @return num 
  292.      */
  293.     public function getSeconds ($time=null{
  294.         $this->setSeconds ($time);
  295.         return $this->_seconds;
  296.     }
  297.     
  298. }
  299.  
  300. ?>