Source for file File.class.php

Documentation is available at File.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 File 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 File Report Class
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Debug_Report");
  34. gumbo_load ("Date");
  35.  
  36.     
  37.     /** @var string $_file Debug File */
  38.     private $_file;
  39.     
  40.     
  41.     
  42.     /**
  43.      * Constructor
  44.      * @param string $file (full path)
  45.      */
  46.     public function __construct ($file=null) {
  47.         if (defined ("GUMBO_DEBUG_FILE")) { $this->setFile (GUMBO_DEBUG_FILE); }
  48.         if (!is_null ($file)) { $this->setFile ($file); }
  49.     }
  50.     
  51.     
  52.     
  53.     /** ACTION METHODS **/
  54.     /**
  55.      * Runs the Report
  56.      * @param num $start_time initial start time of script debugger
  57.      * @throws Gumbo_Exception
  58.      * @uses Gumbo_Date
  59.      */
  60.     public function run ($start_time=null) {
  61.         try {
  62.             // verify precondition
  63.             if (!$this->getFile ()) {
  64.                 throw new Gumbo_Exception ("Debug File Undefined");
  65.             }
  66.             
  67.             $fp = @fopen ($this->getFile (), "a+");
  68.             $date = new Gumbo_Date ();
  69.             fwrite ($fp, "\n" . $date->get () . "\n");
  70.             
  71.             foreach ($this->getMessages () as $mess) {
  72.                 $mess->setSeconds ($start_time);
  73.                 
  74.                 $txt = $mess->getSeconds () . "||" . $mess->getMessage () . "||";
  75.                 $txt .= $mess->getFile () . "||" . $mess->getLine () . "||";
  76.                 $txt .= $mess->getFunction () . "||" . $mess->getClass () . "\n";
  77.                 fwrite ($fp, $txt);
  78.                 
  79.                 $start_time = $mess->getTime ();
  80.             }
  81.             
  82.             fwrite ($fp, "\n");
  83.             fclose ($fp);
  84.         } catch (Gumbo_Exception $e) {
  85.             $e->setFunction (__METHOD__);
  86.             gumbo_trigger ($e);
  87.         }
  88.     }
  89.     
  90.     
  91.     
  92.     /** MUTATOR METHODS **/
  93.     /**
  94.      * Sets the Debug File Path
  95.      * @param string $file 
  96.      * @throws Gumbo_Exception
  97.      */
  98.     public function setFile ($file) {
  99.         try {
  100.             // verify precondition
  101.             if (!is_string ($file)) {
  102.                 throw new Gumbo_Exception ("Invalid Argument 'file:str' => {$file}:" . gettype ($file));
  103.             }
  104.             
  105.             $this->_file = $file;
  106.         } catch (Gumbo_Exception $e) {
  107.             $e->setFunction (__METHOD__);
  108.             gumbo_trigger ($e);
  109.         }
  110.     }
  111.     
  112.     
  113.     
  114.     /** ACCESSOR METHODS **/
  115.     /**
  116.      * Returns the Debug File name
  117.      * @return string 
  118.      */
  119.     public function getFile () {
  120.         return $this->_file;
  121.     }
  122.     
  123. }
  124.  
  125. ?>