From 33ef22b488454fd09800567db14aca571a8eba76 Mon Sep 17 00:00:00 2001
From: David Grudl
Date: Tue, 2 Nov 2010 03:29:19 +0100
Subject: [PATCH] fixed compatibility with Nette / RobotLoader
---
dibi/libs/DibiConnection.php | 1 +
examples/Nette/Debug.php | 206 +++++++++++++++++++----------------
2 files changed, 111 insertions(+), 96 deletions(-)
diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php
index 167eb800..92ee03ec 100644
--- a/dibi/libs/DibiConnection.php
+++ b/dibi/libs/DibiConnection.php
@@ -111,6 +111,7 @@ class DibiConnection extends DibiObject
}
if (!empty($profilerCfg['run'])) {
+ class_exists('dibi'); // ensure dibi.php is processed
$class = isset($profilerCfg['class']) ? $profilerCfg['class'] : 'DibiProfiler';
if (!class_exists($class)) {
throw new DibiException("Unable to create instance of dibi profiler '$class'.");
diff --git a/examples/Nette/Debug.php b/examples/Nette/Debug.php
index a137459a..26447f38 100644
--- a/examples/Nette/Debug.php
+++ b/examples/Nette/Debug.php
@@ -26,26 +26,21 @@ DETECT=NULL;public
static$strictMode=FALSE;public
static$scream=FALSE;public
static$onFatalError=array();public
+static$logDirectory;public
+static$email;public
static$mailer=array(__CLASS__,'defaultMailer');public
-static$emailSnooze=172800;private
-static$enabled=FALSE;private
-static$logFile;private
-static$logHandle;private
-static$sendEmails;private
-static$emailHeaders=array('To'=>'','From'=>'noreply@%host%','X-Mailer'=>'Nette Framework','Subject'=>'PHP: An error occurred on the server %host%','Body'=>'[%date%] %message%');public
+static$emailSnooze=172800;public
+static$editor='editor://open/?file=%file&line=%line';private
+static$enabled=FALSE;public
static$showBar=TRUE;private
static$panels=array();private
static$dumps;private
-static$errors;public
-static$counters=array();const
-INFO='INFO';const
-ERROR='ERROR';const
-LOG='LOG';const
-WARN='WARN';const
-TRACE='TRACE';const
-EXCEPTION='EXCEPTION';const
-GROUP_START='GROUP_START';const
-GROUP_END='GROUP_END';final
+static$errors;const
+DEBUG='debug';const
+INFO='info';const
+WARNING='warning';const
+ERROR='error';const
+CRITICAL='critical';final
public
function
__construct(){throw
@@ -53,7 +48,7 @@ new
LogicException("Cannot instantiate static class ".get_class($this));}public
static
function
-_init(){self::$time=microtime(TRUE);self::$consoleMode=PHP_SAPI==='cli';self::$productionMode=self::DETECT;if(self::$consoleMode){self::$source=empty($_SERVER['argv'])?'cli':'cli: '.$_SERVER['argv'][0];}else{self::$firebugDetected=isset($_SERVER['HTTP_USER_AGENT'])&&strpos($_SERVER['HTTP_USER_AGENT'],'FirePHP/');self::$ajaxDetected=isset($_SERVER['HTTP_X_REQUESTED_WITH'])&&$_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';if(isset($_SERVER['REQUEST_URI'])){self::$source=(isset($_SERVER['HTTPS'])&&strcasecmp($_SERVER['HTTPS'],'off')?'https://':'http://').(isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:(isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:'')).$_SERVER['REQUEST_URI'];}}$tab=array(__CLASS__,'renderTab');$panel=array(__CLASS__,'renderPanel');self::addPanel(new
+_init(){self::$time=microtime(TRUE);self::$consoleMode=PHP_SAPI==='cli';self::$productionMode=self::DETECT;if(self::$consoleMode){self::$source=empty($_SERVER['argv'])?'cli':'cli: '.$_SERVER['argv'][0];}else{self::$firebugDetected=isset($_SERVER['HTTP_X_FIRELOGGER']);self::$ajaxDetected=isset($_SERVER['HTTP_X_REQUESTED_WITH'])&&$_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';if(isset($_SERVER['REQUEST_URI'])){self::$source=(isset($_SERVER['HTTPS'])&&strcasecmp($_SERVER['HTTPS'],'off')?'https://':'http://').(isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:(isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:'')).$_SERVER['REQUEST_URI'];}}$tab=array(__CLASS__,'renderTab');$panel=array(__CLASS__,'renderPanel');self::addPanel(new
DebugPanel('time',$tab,$panel));self::addPanel(new
DebugPanel('memory',$tab,$panel));self::addPanel(new
DebugPanel('errors',$tab,$panel));self::addPanel(new
@@ -74,57 +69,63 @@ function
timer($name=NULL){static$time=array();$now=microtime(TRUE);$delta=isset($time[$name])?$now-$time[$name]:0;$time[$name]=$now;return$delta;}public
static
function
-enable($mode=NULL,$logFile=NULL,$email=NULL){error_reporting(E_ALL|E_STRICT);if(is_bool($mode)){self::$productionMode=$mode;}elseif(is_string($mode)){$mode=preg_split('#[,\s]+#',$mode);}if(is_array($mode)){self::$productionMode=!isset($_SERVER['REMOTE_ADDR'])||!in_array($_SERVER['REMOTE_ADDR'],$mode,TRUE);}if(self::$productionMode===self::DETECT){if(class_exists('Environment')){self::$productionMode=Environment::isProduction();}elseif(isset($_SERVER['SERVER_ADDR'])||isset($_SERVER['LOCAL_ADDR'])){$addr=isset($_SERVER['SERVER_ADDR'])?$_SERVER['SERVER_ADDR']:$_SERVER['LOCAL_ADDR'];$oct=explode('.',$addr);self::$productionMode=$addr!=='::1'&&(count($oct)!==4||($oct[0]!=='10'&&$oct[0]!=='127'&&($oct[0]!=='172'||$oct[1]<16||$oct[1]>31)&&($oct[0]!=='169'||$oct[1]!=='254')&&($oct[0]!=='192'||$oct[1]!=='168')));}else{self::$productionMode=!self::$consoleMode;}}if(self::$productionMode&&$logFile!==FALSE){self::$logFile='log/php_error.log';if(class_exists('Environment')){if(is_string($logFile)){self::$logFile=Environment::expand($logFile);}else
-try{self::$logFile=Environment::expand('%logDir%/php_error.log');}catch(InvalidStateException$e){}}elseif(is_string($logFile)){self::$logFile=$logFile;}ini_set('error_log',self::$logFile);}if(function_exists('ini_set')){ini_set('display_errors',!self::$productionMode);ini_set('html_errors',FALSE);ini_set('log_errors',FALSE);}elseif(ini_get('display_errors')!=!self::$productionMode&&ini_get('display_errors')!==(self::$productionMode?'stderr':'stdout')){throw
+enable($mode=NULL,$logDirectory=NULL,$email=NULL){error_reporting(E_ALL|E_STRICT);if(is_bool($mode)){self::$productionMode=$mode;}elseif(is_string($mode)){$mode=preg_split('#[,\s]+#',$mode);}if(is_array($mode)){self::$productionMode=!isset($_SERVER['REMOTE_ADDR'])||!in_array($_SERVER['REMOTE_ADDR'],$mode,TRUE);}if(self::$productionMode===self::DETECT){if(class_exists('Environment')){self::$productionMode=Environment::isProduction();}elseif(isset($_SERVER['SERVER_ADDR'])||isset($_SERVER['LOCAL_ADDR'])){$addrs=array();if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){$addrs=preg_split('#,\s*#',$_SERVER['HTTP_X_FORWARDED_FOR']);}if(isset($_SERVER['REMOTE_ADDR'])){$addrs[]=$_SERVER['REMOTE_ADDR'];}$addrs[]=isset($_SERVER['SERVER_ADDR'])?$_SERVER['SERVER_ADDR']:$_SERVER['LOCAL_ADDR'];self::$productionMode=FALSE;foreach($addrs
+as$addr){$oct=explode('.',$addr);if($addr!=='::1'&&(count($oct)!==4||($oct[0]!=='10'&&$oct[0]!=='127'&&($oct[0]!=='172'||$oct[1]<16||$oct[1]>31)&&($oct[0]!=='169'||$oct[1]!=='254')&&($oct[0]!=='192'||$oct[1]!=='168')))){self::$productionMode=TRUE;break;}}}else{self::$productionMode=!self::$consoleMode;}}if(is_string($logDirectory)||$logDirectory===FALSE){self::$logDirectory=$logDirectory;}else{self::$logDirectory=defined('APP_DIR')?APP_DIR.'/../log':getcwd().'/log';}if(self::$logDirectory){ini_set('error_log',self::$logDirectory.'/php_error.log');}if(function_exists('ini_set')){ini_set('display_errors',!self::$productionMode);ini_set('html_errors',FALSE);ini_set('log_errors',FALSE);}elseif(ini_get('display_errors')!=!self::$productionMode&&ini_get('display_errors')!==(self::$productionMode?'stderr':'stdout')){throw
new
-NotSupportedException('Function ini_set() must be enabled.');}self::$sendEmails=self::$logFile&&$email;if(self::$sendEmails){if(is_string($email)){self::$emailHeaders['To']=$email;}elseif(is_array($email)){self::$emailHeaders=$email+self::$emailHeaders;}}if(!defined('E_DEPRECATED')){define('E_DEPRECATED',8192);}if(!defined('E_USER_DEPRECATED')){define('E_USER_DEPRECATED',16384);}register_shutdown_function(array(__CLASS__,'_shutdownHandler'));set_exception_handler(array(__CLASS__,'_exceptionHandler'));set_error_handler(array(__CLASS__,'_errorHandler'));self::$enabled=TRUE;}public
+NotSupportedException('Function ini_set() must be enabled.');}if($email){if(!is_string($email)){throw
+new
+InvalidArgumentException('E-mail address must be a string.');}self::$email=$email;}if(!defined('E_DEPRECATED')){define('E_DEPRECATED',8192);}if(!defined('E_USER_DEPRECATED')){define('E_USER_DEPRECATED',16384);}if(!self::$enabled){register_shutdown_function(array(__CLASS__,'_shutdownHandler'));set_exception_handler(array(__CLASS__,'_exceptionHandler'));set_error_handler(array(__CLASS__,'_errorHandler'));self::$enabled=TRUE;}}public
static
function
isEnabled(){return
self::$enabled;}public
static
function
-log($message,$priority=self::INFO){if(!self::$logFile){return;}if($message
+log($message,$priority=self::INFO){if(self::$logDirectory===FALSE){return;}elseif(!self::$logDirectory){throw
+new
+InvalidStateException('Logging directory is not specified in Debug::$logDirectory.');}elseif(!is_dir(self::$logDirectory)){throw
+new
+DirectoryNotFoundException("Directory '".self::$logDirectory."' is not found or is not directory.");}if($message
instanceof
Exception){$exception=$message;$message="PHP Fatal error: ".($message
instanceof
-FatalErrorException?$exception->getMessage():"Uncaught exception ".get_class($exception)." with message '".$exception->getMessage()."'")." in ".$exception->getFile().":".$exception->getLine();}error_log(@date('[Y-m-d H-i-s] ').trim($message).(self::$source?' @ '.self::$source:'').PHP_EOL,3,self::$logFile);if($priority===self::ERROR&&self::$sendEmails&&@filemtime(self::$logFile.'.email-sent')+self::$emailSnooze
as$key=>$row){if(isset($row['file'])&&strpos($row['file'],$expandPath)!==0){$expanded=$key;break;}}}?>
getFile())):?>
- File: getFile())?> Line: getLine()?>
+ File: rawurlencode($ex->getFile()),'%line'=>$ex->getLine()))),'">'?>
+ getFile()),(self::$editor?'':'')?> Line: getLine()?>
getFile(),$ex->getLine())?>
@@ -208,12 +212,14 @@ htmlspecialchars($ex->getFile())?> Line:
as$key=>$row):?>
-
- ',htmlSpecialChars(basename($row['file'])),' (',$row['line'],')'?>
+
+ rawurlencode($row['file']),'%line'=>$row['line']))).'"':' title="">
+ ',htmlSpecialChars(basename($row['file'])),'',(self::$editor?'':''),' (',$row['line'],')'?>
- <PHP inner-code>
+ inner-code
')">source ►
@@ -399,7 +405,7 @@ htmlSpecialChars(Framework::REVISION)?>)
-
+