diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/src/Tracy/Debug.php b/src/Tracy/Debug.php new file mode 100644 index 000000000..ed7ab1a26 --- /dev/null +++ b/src/Tracy/Debug.php @@ -0,0 +1,448 @@ +level)) { + error_reporting($config->level); + } + + if (isset($config->display)) { + self::$display = (bool) $config->display; + ini_set('display_errors', self::$display ? '1' : '0'); // for fatal errors + } + + if (isset($config->html)) { + self::$html = (bool) $config->html; + } + + if (isset($config->logDir)) { + self::$logDir = Environment::expand($config->logDir); + ini_set('log_errors', self::$logDir ? '1' : '0'); // for fatal errors + ini_set('error_log', self::$logDir . '/php.error.log'); + } + + if (isset($config->email)) { + self::$email = (string) $config->email; + } + + if (isset($config->emailSubject)) { + self::$emailSubject = (string) $config->emailSubject; + } + + if (self::$email || self::$display || self::$logDir) { + self::enable(); + } + } + + + + /********************* useful tools ****************d*g**/ + + + + /** + * Dumps information about a variable in readable format. + * + * @param mixed variable to dump. + * @param bool return output instead of printing it? + * @return string + */ + public static function dump($var, $return = FALSE) + { + ob_start(); + var_dump($var); + $output = ob_get_clean(); + + if (self::$html) { + $output = htmlspecialchars($output, ENT_NOQUOTES); + $output = preg_replace('#\]=>\n\ +([a-z]+)#i', '] => $1', $output); + $output = preg_replace('#^([a-z]+)#i', '$1', $output); + $output = "
$output\n"; + } else { + $output = preg_replace('#\]=>\n\ +#i', '] => ', $output) . "\n"; + } + + if (!$return) echo $output; + + return $output; + } + + + + /** + * Starts/stops stopwatch. + * @return elapsed seconds + */ + public static function timer() + { + static $time = 0; + $now = microtime(TRUE); + $delta = $now - $time; + $time = $now; + return $delta; + } + + + + /********************* error and exception reporing ****************d*g**/ + + + + /** + * Register error handler routine. + * @param int error_reporting level + * @return void + */ + public static function enable($level = NULL) + { + /* + if (self::$display === NULL) { + require_once dirname(__FILE__) . '/Environment.php'; + self::$display = Environment::getName() !== Environment::PRODUCTION; + } + */ + + if ($level !== NULL) error_reporting($level); + set_error_handler(array(__CLASS__, 'errorHandler')); + set_exception_handler(array(__CLASS__, 'exceptionHandler')); // buggy in PHP 5.2.1 + self::$enabled = TRUE; + } + + + + /** + * Unregister error handler routine. + * @return void + */ + public static function disable() + { + if (self::$enabled) { + restore_error_handler(); + restore_exception_handler(); + self::$enabled = FALSE; + } + } + + + + /** + * Unregister error handler routine. + * @return void + */ + public static function isEnabled() + { + return self::$enabled; + } + + + + /** + * Debug exception handler. + * + * @param Exception + * @return void + */ + public static function exceptionHandler(Exception $exception) + { + self::disable(); + + if (self::$html) { + self::handleMessage(self::blueScreen($exception)); + } else { + self::handleMessage($exception->__toString() . "\nPHP version " . PHP_VERSION . "\nNette Framework version 0.7\n"); + } + + exit; + } + + + + /** + * Debug error handler. + * + * @param int level of the error raised + * @param string error message + * @param string file that the error was raised in + * @param int line number the error was raised at + * @param array an array of variables that existed in the scope the error was triggered in + * @return void + */ + public static function errorHandler($code, $message, $file, $line, $context) + { + $fatals = array( + E_ERROR => 'Fatal error', // unfortunately not catchable + E_CORE_ERROR => 'Fatal core rrror', // not catchable + E_COMPILE_ERROR => 'Fatal compile error', // unfortunately not catchable + E_USER_ERROR => 'Fatal error', + E_PARSE => 'Parse error', // unfortunately not catchable + E_RECOVERABLE_ERROR => 'Catchable fatal error', // since PHP 5.2 + ); + + if (isset($fatals[$code])) { + self::disable(); + + $trace = debug_backtrace(); + array_shift($trace); + $type = $fatals[$code]; + + if (self::$html) { + self::handleMessage(self::blueScreen(NULL, $type, $code, $message, $file, $line, $trace, $context)); + } else { + self::handleMessage("$type '$message' in $file on line $line\nPHP version " . PHP_VERSION . "\nNette Framework version 0.7\n"); + } + + exit; + } + + if (($code & error_reporting()) === $code) { + $types = array( + E_WARNING => 'Warning', + E_CORE_WARNING => 'Core warning', // not catchable + E_COMPILE_WARNING => 'Compile warning', // not catchable + E_USER_WARNING => 'Warning', + E_NOTICE => 'Notice', + E_USER_NOTICE => 'Notice', + E_STRICT => 'Strict standards', + E_DEPRECATED => 'Deprecated', + ); + $type = isset($types[$code]) ? $types[$code] : 'Unknown error'; + + if (self::$html) { + $message = "$type: $message in $file on line $line\n
File: Line:
+ + $s) {
+ $s = rtrim($s);
+ if (strlen($s) > 100) $s = substr($s, 0, 100) . '...';
+ if ($n === $line) {
+ printf("Line %s: %s\n", $n, htmlSpecialChars($s));
+ } else {
+ printf("Line %s: %s\n", $n, htmlSpecialChars($s));
+ }
+ }
+ ?>
+
+
+
+
+
+
+
+ + + + + ', htmlSpecialChars(basename($row['file'])), ' (', $row['line'], ')' ?> + + + <PHP inner-code> + + + source ▶ + + + + + (arguments ▶) +
+ + +', (isset($params[$k]) ? '$' . $params[$k]->name : "#$k"), ' | '; + echo '', self::safedump($v, isset($params[$k]) ? $params[$k]->name : NULL), ' |
$s) {
+ $s = rtrim($s);
+ if (strlen($s) > 100) $s = substr($s, 0, 100) . '...';
+ if ($n === $line) {
+ printf("Line %s: %s\n", $n, htmlSpecialChars($s));
+ } else {
+ printf("Line %s: %s\n", $n, htmlSpecialChars($s));
+ }
+ }
+ ?>
+
+
+ $', htmlspecialchars($k), ' | ', self::safedump($v, $k), ' |
', htmlspecialchars($k), ' | ', self::safedump($v, $k), ' |
', htmlspecialchars($v), ' | '; + } + ?> +
empty
+ +', htmlspecialchars($k), ' | ', self::dump($v, TRUE), ' |
__toString()) ?>+ + + + + + + + getCause()): ?> + +
__toString()) ?>+ + + + + + + + +
', htmlspecialchars($k), ' | ', htmlspecialchars($v), ' |
empty
+ +', htmlspecialchars($k), ' | ', self::dump($v, TRUE), ' |
'; + ?>+ +
no headers
+ + + + +string(20) "<a href="#">test</a>"
+
+array(5) { + [0] => int(10) + [1] => float(20.2) + [2] => bool(true) + [3] => NULL + [4] => string(5) "hello" +} ++
object(stdClass)#1 (2) { + ["item1"] => array(5) { + [0] => int(10) + [1] => float(20.2) + [2] => bool(true) + [3] => NULL + [4] => string(5) "hello" + } + ["item2"] => string(5) "hello" +} ++
The my exception
+File: D:\Web\nette\_trunk\tests\Debug\test.exception.html.php Line: 29
+ +Line 24: }
+Line 25:
+Line 26:
+Line 27: function third($arg1)
+Line 28: {
+Line 29: throw new Exception('The my exception', 123);
+Line 30: }
+Line 31:
+Line 32:
+Line 33: first(10, 'any string');
+
+ + + Debug/test.exception.html.php (23) + source ▶ + third + (arguments ▶) +
+ +$arg1 | array(3) { + [0] => int(1) + [1] => int(2) + [2] => int(3) +} ++ |
Line 18:
+Line 19:
+Line 20:
+Line 21: function second($arg1, $arg2)
+Line 22: {
+Line 23: third(array(1, 2, 3));
+Line 24: }
+Line 25:
+Line 26:
+Line 27: function third($arg1)
+
+
+ + + Debug/test.exception.html.php (16) + source ▶ + second + (arguments ▶) +
+ +$arg1 | bool(true)
+
+ |
$arg2 | bool(false)
+
+ |
Line 11:
+Line 12: define('MY_CONST', 123);
+Line 13:
+Line 14: function first($arg1, $arg2)
+Line 15: {
+Line 16: second(TRUE, FALSE);
+Line 17: }
+Line 18:
+Line 19:
+Line 20:
+
+
+ + + Debug/test.exception.html.php (33) + source ▶ + first + (arguments ▶) +
+ +$arg1 | int(10)
+
+ |
$arg2 | string(10) "any string"
+
+ |
Line 28: {
+Line 29: throw new Exception('The my exception', 123);
+Line 30: }
+Line 31:
+Line 32:
+Line 33: first(10, 'any string');
+
+
+ MY_CONST | int(123)
+
+ |
D:\Web\nette\_trunk\tests\Debug\test.exception.html.php |
D:\Web\_php\tools.debug.php |
D:\Web\nette\_trunk\Nette\Debug.php |
D:\Web\nette\_trunk\Nette\Version.php |
D:\Web\nette\_trunk\Nette\templates\Debug.phtml |
D:\Web\nette\_trunk\Nette\templates\Debug.openpanel.phtml |
D:\Web\nette\_trunk\Nette\templates\Debug.closepanel.phtml |
ALLUSERSPROFILE | string(22) "C:\Documents\All Users"
+
+ |
APPDATA | string(40) "C:\Documents\Administrator\Data aplikací"
+
+ |
CLIENTNAME | string(7) "Console"
+
+ |
CommonProgramFiles | string(29) "C:\Program Files\Common Files"
+
+ |
COMPUTERNAME | string(7) "JAMESON"
+
+ |
ComSpec | string(27) "C:\WINDOWS\system32\cmd.exe"
+
+ |
FARHOME | string(20) "C:\Program Files\Far"
+
+ |
FARLANG | string(7) "English"
+
+ |
FP_NO_HOST_CHECK | string(2) "NO"
+
+ |
HOMEDRIVE | string(2) "C:"
+
+ |
HOMEPATH | string(24) "\Documents\Administrator"
+
+ |
LOGONSERVER | string(9) "\\JAMESON"
+
+ |
NUMBER_OF_PROCESSORS | string(1) "2"
+
+ |
OPENSSL_CONF | string(40) "C:\Program Files\OpenSSL\bin\openssl.cnf"
+
+ |
OS | string(10) "Windows_NT"
+
+ |
Path | string(74) "C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\NC;c:\PHP\PHP5;"
+
+ |
PATHEXT | string(48) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"
+
+ |
PROCESSOR_ARCHITECTURE | string(3) "x86"
+
+ |
PROCESSOR_IDENTIFIER | string(46) "x86 Family 6 Model 23 Stepping 6, GenuineIntel"
+
+ |
PROCESSOR_LEVEL | string(1) "6"
+
+ |
PROCESSOR_REVISION | string(4) "1706"
+
+ |
ProgramFiles | string(16) "C:\Program Files"
+
+ |
PROMPT | string(4) "$P$G"
+
+ |
SESSIONNAME | string(7) "Console"
+
+ |
SystemDrive | string(2) "C:"
+
+ |
SystemRoot | string(10) "C:\WINDOWS"
+
+ |
TEMP | string(7) "c:\Temp"
+
+ |
TMP | string(7) "c:\Temp"
+
+ |
USERDOMAIN | string(7) "JAMESON"
+
+ |
USERNAME | string(13) "Administrator"
+
+ |
USERPROFILE | string(26) "C:\Documents\Administrator"
+
+ |
windir | string(10) "C:\WINDOWS"
+
+ |
PHP_SELF | string(23) "test.exception.html.php"
+
+ |
SCRIPT_NAME | string(23) "test.exception.html.php"
+
+ |
SCRIPT_FILENAME | string(23) "test.exception.html.php"
+
+ |
PATH_TRANSLATED | string(23) "test.exception.html.php"
+
+ |
DOCUMENT_ROOT | string(0) ""
+
+ |
REQUEST_TIME | int(1208551088)
+
+ |
argv | array(1) { + [0] => string(23) "test.exception.html.php" +} ++ |
argc | int(1)
+
+ |
exception 'Exception' with message 'The my exception' in D:\Web\nette\_trunk\tests\Debug\test.exception.html.php:29 +Stack trace: +#0 D:\Web\nette\_trunk\tests\Debug\test.exception.html.php(23): third(Array) +#1 D:\Web\nette\_trunk\tests\Debug\test.exception.html.php(16): second(true, false) +#2 D:\Web\nette\_trunk\tests\Debug\test.exception.html.php(33): first(10, 'any string') +#3 {main}+
empty
+empty
+empty
+no headers
+The my error
+File: D:\Web\nette\_trunk\tests\Debug\test.filter.php Line: 19
+ +Line 14: $struct = (object) array(
+Line 15: 'arr' => array(
+Line 16: 'password' => 'druhe heslo',
+Line 17: ),
+Line 18: );
+Line 19: trigger_error('The my error', E_USER_ERROR);
+Line 20: }
+Line 21:
+Line 22:
+Line 23:
+
+ + + Debug/test.filter.php (19) + source ▶ + trigger_error + (arguments ▶) +
+ +#0 | string(12) "The my error"
+
+ |
#1 | int(256)
+
+ |
Line 14: $struct = (object) array(
+Line 15: 'arr' => array(
+Line 16: 'password' => 'druhe heslo',
+Line 17: ),
+Line 18: );
+Line 19: trigger_error('The my error', E_USER_ERROR);
+Line 20: }
+Line 21:
+Line 22:
+Line 23:
+
+
+ + + Debug/test.filter.php (24) + source ▶ + first + (arguments ▶) +
+ +$user | string(4) "root"
+
+ |
$pass | *** hidden *** |
Line 19: trigger_error('The my error', E_USER_ERROR);
+Line 20: }
+Line 21:
+Line 22:
+Line 23:
+Line 24: first('root', 'prvni heslo');
+
+
+ $user | string(4) "root"
+
+ |
$pass | *** hidden *** |
$struct | object(stdClass)#1 (1) { + ["arr"] => array(1) { + ["password"] => string (?) *** hidden *** + } +} ++ |
PASS | *** hidden *** |
D:\Web\nette\_trunk\tests\Debug\test.filter.php |
D:\Web\_php\tools.debug.php |
D:\Web\nette\_trunk\Nette\Debug.php |
D:\Web\nette\_trunk\Nette\Version.php |
D:\Web\nette\_trunk\Nette\templates\Debug.phtml |
D:\Web\nette\_trunk\Nette\templates\Debug.openpanel.phtml |
D:\Web\nette\_trunk\Nette\templates\Debug.closepanel.phtml |
ALLUSERSPROFILE | string(22) "C:\Documents\All Users"
+
+ |
APPDATA | string(40) "C:\Documents\Administrator\Data aplikací"
+
+ |
CLIENTNAME | string(7) "Console"
+
+ |
CommonProgramFiles | string(29) "C:\Program Files\Common Files"
+
+ |
COMPUTERNAME | string(7) "JAMESON"
+
+ |
ComSpec | string(27) "C:\WINDOWS\system32\cmd.exe"
+
+ |
FARHOME | string(20) "C:\Program Files\Far"
+
+ |
FARLANG | string(7) "English"
+
+ |
FP_NO_HOST_CHECK | string(2) "NO"
+
+ |
HOMEDRIVE | string(2) "C:"
+
+ |
HOMEPATH | string(24) "\Documents\Administrator"
+
+ |
LOGONSERVER | string(9) "\\JAMESON"
+
+ |
NUMBER_OF_PROCESSORS | string(1) "2"
+
+ |
OPENSSL_CONF | string(40) "C:\Program Files\OpenSSL\bin\openssl.cnf"
+
+ |
OS | string(10) "Windows_NT"
+
+ |
Path | string(115) "C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\NC;c:\PHP\PHP5;;C:\Program Files\Common Files\Ahead\Lib\"
+
+ |
PATHEXT | string(48) ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH"
+
+ |
PROCESSOR_ARCHITECTURE | string(3) "x86"
+
+ |
PROCESSOR_IDENTIFIER | string(46) "x86 Family 6 Model 23 Stepping 6, GenuineIntel"
+
+ |
PROCESSOR_LEVEL | string(1) "6"
+
+ |
PROCESSOR_REVISION | string(4) "1706"
+
+ |
ProgramFiles | string(16) "C:\Program Files"
+
+ |
PROMPT | string(4) "$P$G"
+
+ |
SESSIONNAME | string(7) "Console"
+
+ |
SystemDrive | string(2) "C:"
+
+ |
SystemRoot | string(10) "C:\WINDOWS"
+
+ |
TEMP | string(7) "c:\Temp"
+
+ |
TMP | string(7) "c:\Temp"
+
+ |
USERDOMAIN | string(7) "JAMESON"
+
+ |
USERNAME | string(13) "Administrator"
+
+ |
USERPROFILE | string(26) "C:\Documents\Administrator"
+
+ |
windir | string(10) "C:\WINDOWS"
+
+ |
PHP_SELF | string(15) "test.filter.php"
+
+ |
SCRIPT_NAME | string(15) "test.filter.php"
+
+ |
SCRIPT_FILENAME | string(15) "test.filter.php"
+
+ |
PATH_TRANSLATED | string(15) "test.filter.php"
+
+ |
DOCUMENT_ROOT | string(0) ""
+
+ |
REQUEST_TIME | int(1208356603)
+
+ |
argv | array(1) { + [0] => string(15) "test.filter.php" +} ++ |
argc | int(1)
+
+ |
empty
+empty
+empty
+no headers
+