includes/debugger/debugConsole.functions.php
author Dan
Fri, 05 Oct 2007 01:57:00 -0400
changeset 161 e1a22031b5bd
parent 1 fe660c52c48f
permissions -rw-r--r--
Major revamps to the template parser. Fixed a few security holes that could allow PHP to be injected in untimely places in TPL code. Improved Ux for XSS attempt in tplWikiFormat. Documented many functions. Backported much cleaner parser from 2.0 branch. Beautified a lot of code in the depths of the template class. Pretty much a small-scale Extreme Makeover.

<?php
/**
 * debugConsole functions
 *
 * @author Andreas Demmer <info@debugconsole.de>
 * @see <http://www.debugconsole.de>
 * @version 1.0.0
 * @package debugConsole_1.2.1
 */

/**
 * show debug info of a variable in debugConsole,
 * add own text for documentation or hints
 * 
 * @param mixed $variable
 * @param string $text
 */
function dc_dump($variable, $text) {
  if(!defined('ENANO_DEBUG')) return false;
	$debugConsole = debugConsoleLoader();
	
	if (is_object($debugConsole)) {
		$debugConsole->dump($variable, $text);
	}
}

/**
 * watch value changes of a variable in debugConsole
 *
 * @param string $variableName
 */
function dc_watch($variableName) {
  if(!defined('ENANO_DEBUG')) return false;
	$debugConsole = debugConsoleLoader();
	
	if (is_object($debugConsole)) {
		$debugConsole->watchVariable($variableName);
	}
}

/**
 * show checkpoint info in debugConsole to make sure
 * that a certain program line has been passed
 *
 * @param string $message
 */
function dc_here($message = NULL) {
  if(!defined('ENANO_DEBUG')) return false;
	$debugConsole = debugConsoleLoader();
	
	if (is_object($debugConsole)) {
		(bool)$message ? $debugConsole->passedCheckpoint($message) : $debugConsole->passedCheckpoint();
	}
}

/**
 * starts a new timer clock and returns its handle
 *
 * @return mixed
 * @param string $comment
 */
function dc_start_timer($comment) {
  if(!defined('ENANO_DEBUG')) return false;
	$debugConsole = debugConsoleLoader();
	
	if (is_object($debugConsole)) {
		return $debugConsole->startTimer($comment);
	}
}

/**
 * stops and shows a certain timer clock in debugConsole
 *
 * @return bool
 * @param string $timerHandle
 */
function dc_stop_timer($timerHandle) {
  if(!defined('ENANO_DEBUG')) return false;
	$debugConsole = debugConsoleLoader();
	
	if (is_object($debugConsole)) {
		return $debugConsole->stopTimer($timerHandle);
	}
}

/**
 * singleton loader for debugConsole
 * DO NOT USE, private to debugConsole functions
 *
 * @return mixed
 */
function debugConsoleLoader() {
	static $debugConsole;
	static $access = 'unset';

	$config = $GLOBALS['_debugConsoleConfig'];
	
	/* obey access restrictions */
	if (gettype($access) != 'bool') {
		if ($config['active']) {
			if ($config['restrictions']['restrictAccess']) {
				if (in_array($_SERVER['REMOTE_ADDR'], $config['restrictions']['allowedClientAdresses'])) {
					$access = TRUE;
				} else {
					$access = FALSE;
				}
			} else {
				$access = TRUE;
			}
		} else {
			$access = FALSE;
		}
	}
	
	/* access granted */
	if ($access) {
		if (!is_object($debugConsole)) {
			$debugConsole = new debugConsole();
		}
	} else {
		$debugConsole = FALSE;
	}
	
	return $debugConsole;
}
?>