Source for file Info.class.php

Documentation is available at Info.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 - Info
  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 - Info
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Interface_Debug_Server_Report");
  34.  
  35. class Gumbo_Debug_Server_Info implements Gumbo_Interface_Debug_Server_Report {
  36.     
  37.     /** @var int $_mode combined values of INFO_* constants for viewing PHP details */
  38.     private $_mode = 127;
  39.     
  40.     
  41.     
  42.     /**
  43.      * Constructor
  44.      * @param int $mode INFO_* Mode
  45.      */
  46.     public function __construct ($mode=null{
  47.         if (!is_null ($mode)) $this->setMode ($mode)}
  48.     }
  49.     
  50.     
  51.     
  52.     /** ACTION METHODS **/
  53.     /**
  54.      * Runs the Report
  55.      * @return string 
  56.      */
  57.     public function run ({
  58.         return phpinfo ($this->getMode ());
  59.     }
  60.     
  61.     /**
  62.      * Adds to the current Information Mode
  63.      * @param int $num 
  64.      * @throws Gumbo_Exception
  65.      */
  66.     public function addMode ($num{
  67.         try {
  68.             // verify precondition
  69.             if (!is_numeric ($num)) {
  70.                 throw new Gumbo_Exception ("Invalid Argument 'num:num' => {$num}:gettype ($num));
  71.             }
  72.             if ($num < -|| $num 127{
  73.                 throw new Gumbo_Exception ("Out Of Range '-1 <= num <= 127' => {$num}");
  74.             }
  75.             
  76.             if ($num == -1{
  77.                 $this->_mode = 127;
  78.                 return;
  79.             }
  80.             
  81.             // check if proper number is given
  82.             switch ($num{
  83.                 case INFO_GENERAL break;
  84.                 case INFO_CREDITS break;
  85.                 case INFO_CONFIGURATION break;
  86.                 case INFO_MODULES break;
  87.                 case INFO_ENVIRONMENT break;
  88.                 case INFO_VARIABLES break;
  89.                 case INFO_LICENSE break;
  90.                 default : throw new Gumbo_Exception ("Invalid INFO_Constant: {$num}");
  91.             }
  92.             
  93.             // check if mode is already set
  94.             if ($num $this->getMode ()) {
  95.                 return;
  96.             }
  97.             
  98.             $this->_mode += $num;
  99.         catch (Gumbo_Exception $e{
  100.             $e->setFunction (__METHOD__);
  101.             gumbo_trigger ($e);
  102.         }
  103.     }
  104.     
  105.     /**
  106.      * Removes an Information Mode
  107.      * @param int $num 
  108.      * @throws Gumbo_Exception
  109.      */
  110.     public function removeMode ($num{
  111.         try {
  112.             // verify precondition
  113.             if (!is_int ($num)) {
  114.                 throw new Gumbo_Exception ("Invalid Argument 'num:int' => {$num}:gettype ($num));
  115.             }
  116.             if ($num < -|| $num 127{
  117.                 throw new Gumbo_Exception ("Out Of Range '-1 <= num <= 127' => {$num}");
  118.             }
  119.             
  120.             if ($num == -1{
  121.                 $this->_mode = 127;
  122.                 return;
  123.             }
  124.             
  125.             // check if proper number is given
  126.             switch ($num{
  127.                 case INFO_GENERAL break;
  128.                 case INFO_CREDITS break;
  129.                 case INFO_CONFIGURATION break;
  130.                 case INFO_MODULES break;
  131.                 case INFO_ENVIRONMENT break;
  132.                 case INFO_VARIABLES break;
  133.                 case INFO_LICENSE break;
  134.                 default : throw new Gumbo_Exception ("Invalid INFO_Constant: {$num}");
  135.             }
  136.             
  137.             // check if mode is already set
  138.             if (!($num $this->getMode ())) {
  139.                 return;
  140.             }
  141.             
  142.             $this->_mode -= $num;
  143.         catch (Gumbo_Exception $e{
  144.             $e->setFunction (__METHOD__);
  145.             gumbo_trigger ($e);
  146.         }
  147.     }
  148.     
  149.     
  150.     
  151.     /** MUTATOR METHODS **/
  152.     /**
  153.      * Sets the INFO_* mode
  154.      * @param int $mode 
  155.      * @throws Gumbo_Exception
  156.      */
  157.     public function setMode ($mode{
  158.         try {
  159.             // verify precondition
  160.             if (!is_int ($mode)) {
  161.                 throw new Gumbo_Exception ("Invalid Argument 'mode:int' => {$mode}:gettype ($mode));
  162.             }
  163.             if ($mode < -|| $mode 127{
  164.                 throw new Gumbo_Exception ("Out Of Range '-1 <= mode <= 127' => {$mode}");
  165.             }
  166.             
  167.             $this->_mode = $mode;
  168.         catch (Gumbo_Exception $e{
  169.             $e->setFunction (__METHOD__);
  170.             gumbo_trigger ($e);
  171.         }
  172.     }
  173.     
  174.     
  175.     
  176.     /** ACCESSOR METHODS **/
  177.     /**
  178.      * Returns the INFO_* Mode value
  179.      * @return int 
  180.      */
  181.     public function getMode ({
  182.         if ($this->_mode == 127{
  183.             return -1;
  184.         }
  185.         return $this->_mode;
  186.     }
  187.     
  188. }
  189.  
  190. ?>