includes/debugger/debugConsole.functions.php
changeset 1 fe660c52c48f
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 <?php
       
     2 /**
       
     3  * debugConsole functions
       
     4  *
       
     5  * @author Andreas Demmer <info@debugconsole.de>
       
     6  * @see <http://www.debugconsole.de>
       
     7  * @version 1.0.0
       
     8  * @package debugConsole_1.2.1
       
     9  */
       
    10 
       
    11 /**
       
    12  * show debug info of a variable in debugConsole,
       
    13  * add own text for documentation or hints
       
    14  * 
       
    15  * @param mixed $variable
       
    16  * @param string $text
       
    17  */
       
    18 function dc_dump($variable, $text) {
       
    19   if(!defined('ENANO_DEBUG')) return false;
       
    20 	$debugConsole = debugConsoleLoader();
       
    21 	
       
    22 	if (is_object($debugConsole)) {
       
    23 		$debugConsole->dump($variable, $text);
       
    24 	}
       
    25 }
       
    26 
       
    27 /**
       
    28  * watch value changes of a variable in debugConsole
       
    29  *
       
    30  * @param string $variableName
       
    31  */
       
    32 function dc_watch($variableName) {
       
    33   if(!defined('ENANO_DEBUG')) return false;
       
    34 	$debugConsole = debugConsoleLoader();
       
    35 	
       
    36 	if (is_object($debugConsole)) {
       
    37 		$debugConsole->watchVariable($variableName);
       
    38 	}
       
    39 }
       
    40 
       
    41 /**
       
    42  * show checkpoint info in debugConsole to make sure
       
    43  * that a certain program line has been passed
       
    44  *
       
    45  * @param string $message
       
    46  */
       
    47 function dc_here($message = NULL) {
       
    48   if(!defined('ENANO_DEBUG')) return false;
       
    49 	$debugConsole = debugConsoleLoader();
       
    50 	
       
    51 	if (is_object($debugConsole)) {
       
    52 		(bool)$message ? $debugConsole->passedCheckpoint($message) : $debugConsole->passedCheckpoint();
       
    53 	}
       
    54 }
       
    55 
       
    56 /**
       
    57  * starts a new timer clock and returns its handle
       
    58  *
       
    59  * @return mixed
       
    60  * @param string $comment
       
    61  */
       
    62 function dc_start_timer($comment) {
       
    63   if(!defined('ENANO_DEBUG')) return false;
       
    64 	$debugConsole = debugConsoleLoader();
       
    65 	
       
    66 	if (is_object($debugConsole)) {
       
    67 		return $debugConsole->startTimer($comment);
       
    68 	}
       
    69 }
       
    70 
       
    71 /**
       
    72  * stops and shows a certain timer clock in debugConsole
       
    73  *
       
    74  * @return bool
       
    75  * @param string $timerHandle
       
    76  */
       
    77 function dc_stop_timer($timerHandle) {
       
    78   if(!defined('ENANO_DEBUG')) return false;
       
    79 	$debugConsole = debugConsoleLoader();
       
    80 	
       
    81 	if (is_object($debugConsole)) {
       
    82 		return $debugConsole->stopTimer($timerHandle);
       
    83 	}
       
    84 }
       
    85 
       
    86 /**
       
    87  * singleton loader for debugConsole
       
    88  * DO NOT USE, private to debugConsole functions
       
    89  *
       
    90  * @return mixed
       
    91  */
       
    92 function debugConsoleLoader() {
       
    93 	static $debugConsole;
       
    94 	static $access = 'unset';
       
    95 
       
    96 	$config = $GLOBALS['_debugConsoleConfig'];
       
    97 	
       
    98 	/* obey access restrictions */
       
    99 	if (gettype($access) != 'bool') {
       
   100 		if ($config['active']) {
       
   101 			if ($config['restrictions']['restrictAccess']) {
       
   102 				if (in_array($_SERVER['REMOTE_ADDR'], $config['restrictions']['allowedClientAdresses'])) {
       
   103 					$access = TRUE;
       
   104 				} else {
       
   105 					$access = FALSE;
       
   106 				}
       
   107 			} else {
       
   108 				$access = TRUE;
       
   109 			}
       
   110 		} else {
       
   111 			$access = FALSE;
       
   112 		}
       
   113 	}
       
   114 	
       
   115 	/* access granted */
       
   116 	if ($access) {
       
   117 		if (!is_object($debugConsole)) {
       
   118 			$debugConsole = new debugConsole();
       
   119 		}
       
   120 	} else {
       
   121 		$debugConsole = FALSE;
       
   122 	}
       
   123 	
       
   124 	return $debugConsole;
       
   125 }
       
   126 ?>