Source for file Extension.class.php

Documentation is available at Extension.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 - Extension
  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 - Extension
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Interface_Debug_Server_Report");
  34.  
  35. class Gumbo_Debug_Server_Extension implements Gumbo_Interface_Debug_Server_Report {
  36.     
  37.     /** @var string $_ext Extension Name (if null, returns all) */
  38.     private $_ext;
  39.     /** @var bool $_display_func if to display Extension functions */
  40.     private $_display_func = false;
  41.     
  42.     
  43.     
  44.     /**
  45.      * Constructor
  46.      * @param string $ext Extension Name
  47.      * @param bool $func display Extension functions
  48.      */
  49.     public function __construct ($ext=null$func=false{
  50.         if (!is_null ($ext)) $this->setExtension ($ext)}
  51.         $this->setDisplayFunctions ($func);
  52.     }
  53.     
  54.     
  55.     
  56.     /** ACTION METHODS **/
  57.     /**
  58.      * Runs the Report
  59.      * @return string 
  60.      */
  61.     public function run ({
  62.         $txt "<div class=\"debug\">\n";
  63.         
  64.         if ($this->getExtension ()) {
  65.             $txt .= "\t<ul>Extension: " $this->getExtension ("\n";
  66.             foreach (get_extension_funcs ($this->getExtension ()) as $func{
  67.                 $txt .= "\t\t<li>{$func}</li>\n";
  68.             }
  69.         else {
  70.             $txt .= "\t<ul>Loaded Extensions\n";
  71.             foreach (get_loaded_extensions (as $val{
  72.                 $txt .= "\t\t<li>{$val}";
  73.                 if ($this->getDisplayFunctions ()) {
  74.                     $txt .= "\n\t\t\t<ul>\n";
  75.                     foreach (get_extension_funcs ($valas $func{
  76.                         $txt .= "\t\t\t\t<li>{$func}</li>\n";
  77.                     }
  78.                     $txt .= "\t\t\t</ul>";
  79.                 }
  80.                 $txt .= "</li>\n";
  81.             }
  82.         }
  83.         
  84.         $txt .= "\t</ul>\n";
  85.         $txt .= "</div>\n\n";
  86.         
  87.         return $txt;
  88.     }
  89.     
  90.     /**
  91.      * Resets the Report
  92.      * @postcondition !getExtension()
  93.      * @postcondition !getDisplayFunctions()
  94.      */
  95.     public function reset ({
  96.         $this->_ext = null;
  97.         $this->_display_func = false;
  98.     }
  99.     
  100.     
  101.     
  102.     /** MUTATOR METHODS **/
  103.     /**
  104.      * Sets the Extension
  105.      * @precondition extension_loaded()
  106.      * @postcondition getDisplayFunctions()
  107.      * @param string $ext 
  108.      * @throws Gumbo_Exception
  109.      */
  110.     public function setExtension ($ext{
  111.         try {
  112.             // verify precondition
  113.             if (!is_string ($ext)) {
  114.                 throw new Gumbo_Exception ("Invalid Argument 'ext:str' => {$ext}:gettype ($ext));
  115.             }
  116.             if (!extension_loaded ($ext)) {
  117.                 throw new Gumbo_Exception ("Extension Not Loaded: {$ext}");
  118.             }
  119.             
  120.             $this->_ext = $ext;
  121.             $this->setDisplayFunctions (true);
  122.         catch (Gumbo_Exception $e{
  123.             $e->setFunction (__METHOD__);
  124.             gumbo_trigger ($e);
  125.         }
  126.     }
  127.     
  128.     /**
  129.      * Sets to display Extension Functions
  130.      * @param bool $disp 
  131.      * @throws Gumbo_Exception
  132.      */
  133.     public function setDisplayFunctions ($disp{
  134.         try {
  135.             // verify precondition
  136.             if (!is_bool ($disp)) {
  137.                 throw new Gumbo_Exception ("Invalid Argument 'disp:bool' => {$disp}:gettype ($disp));
  138.             }
  139.             
  140.             $this->_display_func = $disp;
  141.         catch (Gumbo_Exception $e{
  142.             $e->setFunction (__METHOD__);
  143.             gumbo_trigger ($e);
  144.         }
  145.     }
  146.     
  147.     
  148.     
  149.     /** ACCESSOR METHODS **/
  150.     /**
  151.      * Returns the Extension Name
  152.      * @return string 
  153.      */
  154.     public function getExtension ({
  155.         return $this->_ext;
  156.     }
  157.     
  158.     /**
  159.      * Returns if displaying Extension functions
  160.      * @return bool 
  161.      */
  162.     public function getDisplayFunctions ({
  163.         return $this->_display_func;
  164.     }
  165.     
  166. }
  167.  
  168. ?>