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 Server Report - File
  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 Server Report - File
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Interface_Debug_Server_Report");
  34.  
  35. class Gumbo_Debug_Server_File implements Gumbo_Interface_Debug_Server_Report {
  36.     
  37.     /** @var array $_paths list of Paths to remove from return string */
  38.     private $_paths = array ();
  39.     
  40.     
  41.     
  42.     /**
  43.      * Constructor
  44.      * @param arr $args 
  45.      */
  46.     public function __construct ($args=null) {
  47.         $args = func_get_args ();
  48.         call_user_func_array (array ($this, "setPaths"), $args);
  49.     }
  50.     
  51.     
  52.     
  53.     /** ACTION METHODS **/
  54.     /**
  55.      * Runs the Report
  56.      * @return string 
  57.      */
  58.     public function run () {
  59.         $txt .= "<div class=\"debug\">\n";
  60.         $txt .= "\t<ul>Included Files\n";
  61.         foreach (get_included_files () as $val) {
  62.             $txt .= "\t\t<li>{$this->parse ($val)}</li>\n";
  63.         }
  64.         $txt .= "\t</ul>\n";
  65.         $txt .= "</div>\n\n";
  66.         
  67.         return $txt;
  68.     }
  69.     
  70.     /**
  71.      * Parses active Paths from the string
  72.      * @param string $txt 
  73.      * @return string 
  74.      * @throws Gumbo_Exception
  75.      */
  76.     protected function parse ($txt) {
  77.         try {
  78.             // verify precondition
  79.             if (!is_string ($txt)) {
  80.                 throw new Gumbo_Exception ("Invalid Argument 'txt:str' => {$txt}:" . gettype ($txt));
  81.             }
  82.             
  83.             foreach ($this->getPaths () as $path) {
  84.                 $txt = str_replace ($path, "", $txt);
  85.             }
  86.         } catch (Gumbo_Exception $e) {
  87.             $e->setFunction (__METHOD__);
  88.             gumbo_trigger ($e);
  89.         }
  90.         return $txt;
  91.     }
  92.     
  93.     /**
  94.      * Adds a Path
  95.      * @precondition !isPath()
  96.      * @param string $path 
  97.      * @throws Gumbo_Exception
  98.      */
  99.     public function addPath ($path) {
  100.         try {
  101.             // verify precondition
  102.             if (!is_string ($path)) {
  103.                 throw new Gumbo_Exception ("Invalid Argument 'path:str' => {$path}:" . gettype ($path));
  104.             }
  105.             if (!is_dir ($path)) {
  106.                 throw new Gumbo_Exception ("Invalid Directory: {$path}");
  107.             }
  108.             if ($this->isPath ($path)) {
  109.                 throw new Gumbo_Exception ("Path Defined: {$path}");
  110.             }
  111.             
  112.             $this->_paths [] = $path;
  113.         } catch (Gumbo_Exception $e) {
  114.             $e->setFunction (__METHOD__);
  115.             gumbo_trigger ($e);
  116.         }
  117.     }
  118.     
  119.     /**
  120.      * Removes a Path
  121.      * @precondition isPath()
  122.      * @param string $path 
  123.      * @throws Gumbo_Exception
  124.      */
  125.     public function removePath ($path) {
  126.         try {
  127.             // verify precondition
  128.             if (!is_string ($path)) {
  129.                 throw new Gumbo_Exception ("Invalid Argument 'path:str' => {$path}:" . gettype ($path));
  130.             }
  131.             if (!$this->isPath ($path)) {
  132.                 throw new Gumbo_Exception ("Path Undefined: {$path}");
  133.             }
  134.             
  135.             foreach ($this->getPaths () as $key=>$val) {
  136.                 if ($val == $path) {
  137.                     unset ($this->_paths [$key]);
  138.                     break;
  139.                 }
  140.             }
  141.         } catch (Gumbo_Exception $e) {
  142.             $e->setFunction (__METHOD__);
  143.             gumbo_trigger ($e);
  144.         }
  145.     }
  146.     
  147.     /**
  148.      * Resets the Paths
  149.      * @postcondition !getPaths()
  150.      */
  151.     public function resetPaths () {
  152.         $this->_paths = array ();
  153.     }
  154.     
  155.     
  156.     
  157.     /** MUTATOR METHODS **/
  158.     /**
  159.      * Sets the Paths that should be removed from the output
  160.      * @param arr $args 
  161.      */
  162.     public function setPaths ($args=null) {
  163.         if (is_null ($args) || func_num_args () == 0) {
  164.             return;
  165.         }
  166.         
  167.         // check for multiple arguments
  168.         if (func_num_args () > 1) {
  169.             $args = func_get_args ();
  170.         }
  171.         
  172.         // check for an array
  173.         if (is_array ($args)) {
  174.             foreach ($args as $val) {
  175.                 $this->setPaths ($val);
  176.             }
  177.             return;
  178.         }
  179.         
  180.         // add the Path
  181.         $this->addPath ($args);
  182.     }
  183.     
  184.     
  185.     
  186.     /** ACCESSOR METHODS **/
  187.     public function getPaths () {
  188.         return $this->_paths;
  189.     }
  190.     
  191.     /**
  192.      * Returns if a Path exists
  193.      * @param string $path 
  194.      * @return bool 
  195.      * @throws Gumbo_Exception
  196.      */
  197.     public function isPath ($path) {
  198.         $found = false;
  199.         try {
  200.             // verify precondition
  201.             // verify precondition
  202.             if (!is_string ($path)) {
  203.                 throw new Gumbo_Exception ("Invalid Argument 'path:str' => {$path}:" . gettype ($path));
  204.             }
  205.             
  206.             foreach ($this->getPaths () as $val) {
  207.                 if ($val == $path) {
  208.                     $found = true;
  209.                     break;
  210.                 }
  211.             }
  212.         } catch (Gumbo_Exception $e) {
  213.             $e->setFunction (__METHOD__);
  214.             gumbo_trigger ($e);
  215.         }
  216.         return $found;
  217.     }
  218.     
  219. }
  220.  
  221. ?>