From 0de947883b1f02459f1b9d30f726b768aff9790e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 21 Apr 2011 01:52:02 +0200 Subject: [PATCH] updated for Nette 2.0 beta --- dibi/dibi.php | 8 +- dibi/libs/DibiException.php | 39 +- dibi/libs/DibiProfiler.php | 44 +- examples/Nette/{Debug.php => Debugger.php} | 608 +++++++++++---------- examples/Nette/netterobots.txt | 1 - examples/nette-debug-and-exceptions.php | 10 +- examples/nette-debug-and-variables.php | 12 +- 7 files changed, 358 insertions(+), 364 deletions(-) rename examples/Nette/{Debug.php => Debugger.php} (76%) delete mode 100644 examples/Nette/netterobots.txt diff --git a/dibi/dibi.php b/dibi/dibi.php index 82344b36..96e2b3fe 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -26,11 +26,11 @@ if (version_compare(PHP_VERSION, '5.2.0', '<')) { /** * Compatibility with Nette */ -if (interface_exists('Nette\\IDebugPanel')) { - class_alias('Nette\\IDebugPanel', 'IDebugPanel'); +if (interface_exists('Nette\Diagnostics\IBarPanel')) { + class_alias('Nette\Diagnostics\IBarPanel', 'IBarPanel'); -} elseif (!interface_exists('IDebugPanel')) { - interface IDebugPanel {} +} elseif (!interface_exists('IBarPanel')) { + interface IBarPanel {} } diff --git a/dibi/libs/DibiException.php b/dibi/libs/DibiException.php index 67d57775..7d4e1f2c 100644 --- a/dibi/libs/DibiException.php +++ b/dibi/libs/DibiException.php @@ -29,7 +29,7 @@ if (!defined('NETTE')) { * * @author David Grudl */ -class DibiException extends Exception implements IDebugPanel +class DibiException extends Exception { /** @var string */ private $sql; @@ -68,43 +68,6 @@ class DibiException extends Exception implements IDebugPanel return parent::__toString() . ($this->sql ? "\nSQL: " . $this->sql : ''); } - - - /********************* interface Nette\IDebugPanel ****************d*g**/ - - - - /** - * Returns HTML code for custom tab. - * @return mixed - */ - public function getTab() - { - return 'SQL'; - } - - - - /** - * Returns HTML code for custom panel. - * @return mixed - */ - public function getPanel() - { - return $this->sql ? dibi::dump($this->sql, TRUE) : NULL; - } - - - - /** - * Returns panel ID. - * @return string - */ - public function getId() - { - return __CLASS__; - } - } diff --git a/dibi/libs/DibiProfiler.php b/dibi/libs/DibiProfiler.php index 00c8bec4..cc33e7f7 100644 --- a/dibi/libs/DibiProfiler.php +++ b/dibi/libs/DibiProfiler.php @@ -22,7 +22,7 @@ * * @author David Grudl */ -class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel +class DibiProfiler extends DibiObject implements IDibiProfiler, IBarPanel { /** maximum number of rows */ static public $maxQueries = 30; @@ -52,12 +52,17 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel public function __construct(array $config) { - if (is_callable('Nette\Debug::addPanel')) { - call_user_func('Nette\Debug::addPanel', $this); - } elseif (is_callable('NDebug::addPanel')) { - NDebug::addPanel($this); - } elseif (is_callable('Debug::addPanel')) { - Debug::addPanel($this); + if (is_callable('Nette\Diagnostics\Debugger::enable')) { + eval('$tmp = Nette\Diagnostics\Debugger::$bar;'); + $tmp->addPanel($this); + eval('$tmp = Nette\Diagnostics\Debugger::$blueScreen;'); + $tmp->addPanel(array($this, 'renderException'), __CLASS__); + } elseif (is_callable('NDebugger::enable')) { + NDebugger::$bar->addPanel($this); + NDebugger::$blueScreen->addPanel(array($this, 'renderException'), __CLASS__); + } elseif (is_callable('Debugger::enable')) { + Debugger::$bar->addPanel($this); + Debugger::$blueScreen->addPanel(array($this, 'renderException'), __CLASS__); } $this->useFirebug = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'FirePHP/'); @@ -77,6 +82,18 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel + public function renderException($e) + { + if ($e instanceof DibiException && $e->getSql()) { + return array( + 'tab' => 'SQL', + 'panel' => dibi::dump($e->getSql(), TRUE), + ); + } + } + + + /** * @param string filename * @return DibiProfiler provides a fluent interface @@ -242,7 +259,7 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel - /********************* interface Nette\IDebugPanel ****************d*g**/ + /********************* interface Nette\Diagnostics\IBarPanel ****************d*g**/ @@ -308,15 +325,4 @@ class DibiProfiler extends DibiObject implements IDibiProfiler, IDebugPanel '; } - - - /** - * Returns panel ID. - * @return string - */ - public function getId() - { - return get_class($this); - } - } diff --git a/examples/Nette/Debug.php b/examples/Nette/Debugger.php similarity index 76% rename from examples/Nette/Debug.php rename to examples/Nette/Debugger.php index b400a559..1872014f 100644 --- a/examples/Nette/Debug.php +++ b/examples/Nette/Debugger.php @@ -1,4 +1,4 @@ -data=&self::$errors;self::addPanel(new -DebugPanel('dumps',$tab,$panel));}public -static -function -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 127.0.0.1 ::1");}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)){self::$logDirectory=realpath($logDirectory);if(self::$logDirectory===FALSE){throw -new -DirectoryNotFoundException("Directory '$logDirectory' is not found.");}}elseif($logDirectory===FALSE){self::$logDirectory=FALSE;}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.');}if($email){if(!is_string($email)){throw -new -InvalidArgumentException('Email 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::$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::$logDirectory.'/'.strtolower($priority).'.log');if(($priority===self::ERROR||$priority===self::CRITICAL)&&self::$email&&@filemtime(self::$logDirectory.'/email-sent')+self::$emailSnoozegetPrevious():(isset($exception->previous)?$exception->previous:'')));foreach(new -DirectoryIterator(self::$logDirectory)as$entry){if(strpos($entry,$hash)){$skip=TRUE;break;}}if(empty($skip)&&$logHandle=@fopen(self::$logDirectory."/exception ".@date('Y-m-d H-i-s')." $hash.html",'w')){ob_start();ob_start(create_function('$buffer','extract(NClosureFix::$vars['.NClosureFix::uses(array('logHandle'=>$logHandle)).'], EXTR_REFS); fwrite($logHandle, $buffer); '),1);DebugHelpers::renderBlueScreen($exception);ob_end_flush();ob_end_clean();fclose($logHandle);}}}public -static -function -_shutdownHandler(){static$types=array(E_ERROR=>1,E_CORE_ERROR=>1,E_COMPILE_ERROR=>1,E_PARSE=>1);$error=error_get_last();if(isset($types[$error['type']])){self::_exceptionHandler(new -FatalErrorException($error['message'],0,$error['type'],$error['file'],$error['line'],NULL));return;}if(self::$showBar&&!self::$productionMode&&!self::$ajaxDetected&&!self::$consoleMode&&(!preg_match('#^Content-Type: (?!text/html)#im',implode("\n",headers_list())))){DebugHelpers::renderDebugBar(self::$panels);}}public -static -function -_exceptionHandler(Exception$exception){if(!headers_sent()){header('HTTP/1.1 500 Internal Server Error');}$htmlMode=!self::$ajaxDetected&&!preg_match('#^Content-Type: (?!text/html)#im',implode("\n",headers_list()));try{if(self::$productionMode){self::log($exception,self::ERROR);if(self::$consoleMode){echo"ERROR: the server encountered an internal error and was unable to complete your request.\n";}elseif($htmlMode){echo"\n\n";echo"\n\n";echo"Server Error\n\n

Server Error

\n\n

We're sorry! The server encountered an internal error and was unable to complete your request. Please try again later.

\n\n

error 500

";}}else{if(self::$consoleMode){echo"$exception\n";}elseif($htmlMode){DebugHelpers::renderBlueScreen($exception);}elseif(!self::fireLog($exception,self::ERROR)){self::log($exception);}}foreach(self::$onFatalError -as$handler){call_user_func($handler,$exception);}}catch(Exception$e){echo"\nNette\\Debug FATAL ERROR: thrown ",get_class($e),': ',$e->getMessage(),"\nwhile processing ",get_class($exception),': ',$exception->getMessage(),"\n";exit;}}public -static -function -_errorHandler($severity,$message,$file,$line,$context){if(self::$lastError!==FALSE){self::$lastError=new -ErrorException($message,0,$severity,$file,$line);return -NULL;}if(self::$scream){error_reporting(E_ALL|E_STRICT);}if($severity===E_RECOVERABLE_ERROR||$severity===E_USER_ERROR){throw -new -FatalErrorException($message,0,$severity,$file,$line,$context);}elseif(($severity&error_reporting())!==$severity){return -FALSE;}elseif(self::$strictMode&&!self::$productionMode){self::_exceptionHandler(new -FatalErrorException($message,0,$severity,$file,$line,$context));exit;}static$types=array(E_WARNING=>'Warning',E_COMPILE_WARNING=>'Warning',E_USER_WARNING=>'Warning',E_NOTICE=>'Notice',E_USER_NOTICE=>'Notice',E_STRICT=>'Strict standards',E_DEPRECATED=>'Deprecated',E_USER_DEPRECATED=>'Deprecated');$message='PHP '.(isset($types[$severity])?$types[$severity]:'Unknown error').": $message";$count=&self::$errors["$message|$file|$line"];if($count++){return -NULL;}elseif(self::$productionMode){self::log("$message in $file:$line",self::ERROR);return -NULL;}else{$ok=self::fireLog(new -ErrorException($message,0,$severity,$file,$line),self::WARNING);return -self::$consoleMode||(!self::$showBar&&!$ok)?FALSE:NULL;}return -FALSE;}public -static -function -processException(Exception$exception){trigger_error(__METHOD__.'() is deprecated; use '.__CLASS__.'::log($exception, Debug::ERROR) instead.',E_USER_WARNING);self::log($exception,self::ERROR);}public -static -function -toStringException(Exception$exception){if(self::$enabled){self::_exceptionHandler($exception);}else{trigger_error($exception->getMessage(),E_USER_ERROR);}exit;}public -static -function -tryError(){if(!self::$enabled&&self::$lastError===FALSE){set_error_handler(array(__CLASS__,'_errorHandler'));}self::$lastError=NULL;}public -static -function -catchError(&$error){if(!self::$enabled&&self::$lastError!==FALSE){restore_error_handler();}$error=self::$lastError;self::$lastError=FALSE;return(bool)$error;}private -static -function -defaultMailer($message){$host=isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:(isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:'');$parts=str_replace(array("\r\n","\n"),array("\n",PHP_EOL),array('headers'=>"From: noreply@$host\nX-Mailer: Nette Framework\n",'subject'=>"PHP: An error occurred on the server $host",'body'=>"[".@date('Y-m-d H:i:s')."] $message"));mail(self::$email,$parts['subject'],$parts['body'],$parts['headers']);}public -static -function -dump($var,$return=FALSE){if(!$return&&self::$productionMode){return$var;}$output="
".DebugHelpers::htmlDump($var)."
\n";if(!$return&&self::$showLocation){$trace=debug_backtrace();$i=isset($trace[1]['class'])&&$trace[1]['class']===__CLASS__?1:0;if(isset($trace[$i]['file'],$trace[$i]['line'])){$output=substr_replace($output,' '.htmlspecialchars("in file {$trace[$i]['file']} on line {$trace[$i]['line']}",ENT_NOQUOTES).'',-8,0);}}if(self::$consoleMode){$output=htmlspecialchars_decode(strip_tags($output),ENT_NOQUOTES);}if($return){return$output;}else{echo$output;return$var;}}public -static -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 -addPanel(IDebugPanel$panel){self::$panels[]=$panel;}public -static -function -barDump($var,$title=NULL){if(!self::$productionMode){$dump=array();foreach((is_array($var)?$var:array(''=>$var))as$key=>$val){$dump[$key]=DebugHelpers::clickableDump($val);}self::$panels[3]->data[]=array('title'=>$title,'dump'=>$dump);}return$var;}public -static -function -fireLog($message){if(self::$productionMode){return;}elseif(!self::$firebugDetected||headers_sent()){return -FALSE;}static$payload=array('logs'=>array());$item=array('name'=>'PHP','level'=>'debug','order'=>count($payload['logs']),'time'=>str_pad(number_format((microtime(TRUE)-self::$time)*1000,1,'.',' '),8,'0',STR_PAD_LEFT).' ms','template'=>'','message'=>'','style'=>'background:#767ab6');$args=func_get_args();if(isset($args[0])&&is_string($args[0])){$item['template']=array_shift($args);}if(isset($args[0])&&$args[0]instanceof -Exception){$e=array_shift($args);$trace=$e->getTrace();if(isset($trace[0]['class'])&&$trace[0]['class']===__CLASS__&&($trace[0]['function']==='_shutdownHandler'||$trace[0]['function']==='_errorHandler')){unset($trace[0]);}$item['exc_info']=array($e->getMessage(),$e->getFile(),array());$item['exc_frames']=array();foreach($trace -as$frame){$frame+=array('file'=>NULL,'line'=>NULL,'class'=>NULL,'type'=>NULL,'function'=>NULL,'object'=>NULL,'args'=>NULL);$item['exc_info'][2][]=array($frame['file'],$frame['line'],"$frame[class]$frame[type]$frame[function]",$frame['object']);$item['exc_frames'][]=$frame['args'];}$file=str_replace(dirname(dirname(dirname($e->getFile()))),"\xE2\x80\xA6",$e->getFile());$item['template']=($e -instanceof -ErrorException?'':get_class($e).': ').$e->getMessage().($e->getCode()?' #'.$e->getCode():'').' in '.$file.':'.$e->getLine();array_unshift($trace,array('file'=>$e->getFile(),'line'=>$e->getLine()));}else{$trace=debug_backtrace();if(isset($trace[0]['class'])&&$trace[0]['class']===__CLASS__&&($trace[0]['function']==='_shutdownHandler'||$trace[0]['function']==='_errorHandler')){unset($trace[0]);}}if(isset($args[0])&&in_array($args[0],array(self::DEBUG,self::INFO,self::WARNING,self::ERROR,self::CRITICAL),TRUE)){$item['level']=array_shift($args);}$item['args']=$args;foreach($trace -as$frame){if(isset($frame['file'])&&is_file($frame['file'])){$item['pathname']=$frame['file'];$item['lineno']=$frame['line'];break;}}$payload['logs'][]=DebugHelpers::jsonDump($item,-1);foreach(str_split(base64_encode(@json_encode($payload)),4990)as$k=>$v){header("FireLogger-de11e-$k:$v");}return -TRUE;}}class -FatalErrorException -extends -Exception{private$severity;public -function -__construct($message,$code,$severity,$file,$line,$context){parent::__construct($message,$code);$this->severity=$severity;$this->file=$file;$this->line=$line;$this->context=$context;}public -function -getSeverity(){return$this->severity;}}interface -IDebugPanel{function +interface +IBarPanel{function getTab();function -getPanel();function -getId();}class -DebugPanel -implements -IDebugPanel{private$id;private$tabCb;private$panelCb;public$data;public +getPanel();}class +DebugBar{private$panels=array();public function -__construct($id,$tabCb,$panelCb){$this->id=$id;$this->tabCb=$tabCb;$this->panelCb=$panelCb;}public +addPanel(IBarPanel$panel,$id=NULL){if($id===NULL){$c=0;do{$id=get_class($panel).($c++?"-$c":'');}while(isset($this->panels[$id]));}$this->panels[$id]=$panel;}public function -getId(){return$this->id;}public +render(){$panels=array();foreach($this->panels +as$id=>$panel){try{$panels[]=array('id'=>preg_replace('#[^a-z0-9]+#i','-',$id),'tab'=>$tab=(string)$panel->getTab(),'panel'=>$tab?(string)$panel->getPanel():NULL);}catch(Exception$e){$panels[]=array('id'=>"error-$id",'tab'=>"Error: $id",'panel'=>nl2br(htmlSpecialChars((string)$e)));}}?> + + + + + + +  + + + + + + + + + +$panel):if(!$panel['panel'])continue;?> +
+
+ +
+ ¤ + × +
+
+
+ + +
+
+
    + + +
  • ',trim($panel['tab']),'';endif?>
  • + +
  • ×
  • +
+
+
+ + + +
+ + + + +tabCb,$this->id,$this->data);return -ob_get_clean();}public +addPanel($panel,$id=NULL){if($id===NULL){$this->panels[]=$panel;}else{$this->panels[$id]=$panel;}}public function -getPanel(){ob_start();call_user_func($this->panelCb,$this->id,$this->data);return -ob_get_clean();}}final -class -DebugHelpers{public -static -function -renderBlueScreen(Exception$exception){if(class_exists('Environment',FALSE)){$application=Environment::getContext()->hasService('Nette\\Application\\Application',TRUE)?Environment::getContext()->getService('Nette\\Application\\Application'):NULL;}static$errorTypes=array(E_ERROR=>'Fatal Error',E_USER_ERROR=>'User Error',E_RECOVERABLE_ERROR=>'Recoverable Error',E_CORE_ERROR=>'Core Error',E_COMPILE_ERROR=>'Compile Error',E_PARSE=>'Parse Error',E_WARNING=>'Warning',E_CORE_WARNING=>'Core Warning',E_COMPILE_WARNING=>'Compile Warning',E_USER_WARNING=>'User Warning',E_NOTICE=>'Notice',E_USER_NOTICE=>'User Notice',E_STRICT=>'Strict',E_DEPRECATED=>'Deprecated',E_USER_DEPRECATED=>'User Deprecated');$title=($exception +render(Exception$exception){if(class_exists('Environment',FALSE)){$application=Environment::getContext()->hasService('Nette\\Application\\Application',TRUE)?Environment::getContext()->getService('Nette\\Application\\Application'):NULL;}$panels=$this->panels;static$errorTypes=array(E_ERROR=>'Fatal Error',E_USER_ERROR=>'User Error',E_RECOVERABLE_ERROR=>'Recoverable Error',E_CORE_ERROR=>'Core Error',E_COMPILE_ERROR=>'Compile Error',E_PARSE=>'Parse Error',E_WARNING=>'Warning',E_CORE_WARNING=>'Core Warning',E_COMPILE_WARNING=>'Compile Warning',E_USER_WARNING=>'User Warning',E_NOTICE=>'Notice',E_USER_NOTICE=>'User Notice',E_STRICT=>'Strict',E_DEPRECATED=>'Deprecated',E_USER_DEPRECATED=>'User Deprecated');$title=($exception instanceof -FatalErrorException&&isset($errorTypes[$exception->getSeverity()]))?$errorTypes[$exception->getSeverity()]:get_class($exception);$expandPath=NETTE_DIR.DIRECTORY_SEPARATOR;$counter=0;if(headers_sent()){echo'';}?> +FatalErrorException&&isset($errorTypes[$exception->getSeverity()]))?$errorTypes[$exception->getSeverity()]:get_class($exception);$expandPath=NETTE_DIR.DIRECTORY_SEPARATOR;$counter=0;?> + @@ -216,17 +165,17 @@ htmlspecialchars($ex->getMessage())?>

- getTab())&&($panel=$ex->getPanel())):?> + +

+htmlSpecialChars($panel['tab'])?>
- +
- + @@ -238,17 +187,17 @@ as$key=>$row){if(isset($row['file'])&&strpos($row['file'],$expandPath)!==0){$exp

Source file

-

File: getFile(),$ex->getLine())),'">'?> +

File: getFile(),$ex->getLine())),'">'?> getFile()),(Debug::$editor?'':'')?>   Line: getLine()?>

+htmlspecialchars($ex->getFile()),(Debugger::$editor?'':'')?>   Line: getLine()?>

getFile(),$ex->getLine())?>
+self::highlightFile($ex->getFile(),$ex->getLine())?>
- +

Call stack

@@ -261,10 +210,10 @@ as$key=>$row):?> title=" title=""> ',htmlSpecialChars(basename($row['file'])),'',(Debug::$editor?'':''),' (',$row['line'],')'?> +htmlSpecialChars(basename(dirname($row['file']))),'/',htmlSpecialChars(basename($row['file'])),'',(Debugger::$editor?'':''),' (',$row['line'],')'?> inner-code @@ -293,7 +242,7 @@ DebugHelpers::clickableDump($v);echo"\n";}?>
 id="netteBsSrc">
+self::highlightFile($row['file'],$row['line'])?> @@ -438,14 +387,14 @@ htmlspecialchars($s),'
';?>
    -
  • Report generated at
  • - +
  • Report generated at
  • +
  • - +htmlSpecialChars(Debugger::$source)?>"> +
  • +htmlSpecialChars(Debugger::$source)?>
  • PHP
  • @@ -466,123 +415,39 @@ bs.onclick=function(b){b=b||window.event;for(var a=b.target||b.srcElement;a&&a.t $panel){$panels[$key]=array('id'=>preg_replace('#[^a-z0-9]+#i','-',$panel->getId()),'tab'=>$tab=(string)$panel->getTab(),'panel'=>$tab?(string)$panel->getPanel():NULL);}?> - - - - - - -  - - - - - - - - - -$panel):?> -
    -
    -
    -
    - ¤ - × -
    -
    -
    - - -
    -
    -
      - - -
    • ',trim($panel['tab']),'';endif?>
    • - -
    • ×
    • -
    -
    -
    - - - -
    - - - - -',$source[1]);array_unshift($source,NULL);$i=$start;while(--$i>=1){if(preg_match('#.*(]*>)#',$source[$i],$m)){if($m[1]!==''){$spans++;$out.=$m[1];}break;}}$source=array_slice($source,$start,$count,TRUE);end($source);$numWidth=strlen((string)key($source));foreach($source +as$n=>$s){$spans+=substr_count($s,']+>#',$s,$tags);if($n===$line){$out.=sprintf("%{$numWidth}s: %s\n%s",$n,strip_tags($s),implode('',$tags[0]));}else{$out.=sprintf("%{$numWidth}s: %s\n",$n,$s);}}return$out.str_repeat('',$spans).'';}}final +class +DefaultBarPanel +implements +IBarPanel{private$id;public$data;public function -renderTab($id,$data){switch($id){case'time':?> +__construct($id){$this->id=$id;}public +function +getTab(){ob_start();$data=$this->data;if($this->id==='time'){?> ms - +number_format((microtime(TRUE)-Debugger::$time)*1000,1,'.',' ')?> ms +id==='memory'){?> MB - +id==='dumps'&&$this->data){?> variables - +id==='errors'&&$this->data){?> errors - - +getPanel(){ob_start();$data=$this->data;if($this->id==='dumps'){?> +

    Dumped variables

    -
    +
    @@ -603,8 +468,7 @@ htmlspecialchars($key)?>
    - +id==='errors'){?>

    Errors

    @@ -618,32 +482,194 @@ as$item=>$count):list($message,$file,$line)=explode('|',$item)?> 2?'nette-alt':''?>">
    ':''),htmlspecialchars(($relative?str_replace($relative,"...",$file):$file)),':',$line,(Debug::$editor?'':'')?>
    +htmlspecialchars($message),' in ',(Debugger::$editor?'':''),htmlspecialchars(($relative?str_replace($relative,"...",$file):$file)),':',$line,(Debugger::$editor?'':'')?> -
    array());public static function -highlightFile($file,$line,$count=15){if(function_exists('ini_set')){ini_set('highlight.comment','#999; font-style: italic');ini_set('highlight.default','#000');ini_set('highlight.html','#06B');ini_set('highlight.keyword','#D24; font-weight: bold');ini_set('highlight.string','#080');}$start=max(1,$line-floor($count/2));$source=@file_get_contents($file);if(!$source)return;$source=explode("\n",highlight_string($source,TRUE));$spans=1;$out=$source[0];$source=explode('
    ',$source[1]);array_unshift($source,NULL);$i=$start;while(--$i>=1){if(preg_match('#.*(]*>)#',$source[$i],$m)){if($m[1]!==''){$spans++;$out.=$m[1];}break;}}$source=array_slice($source,$start,$count,TRUE);end($source);$numWidth=strlen((string)key($source));foreach($source -as$n=>$s){$spans+=substr_count($s,']+>#',$s,$tags);if($n===$line){$out.=sprintf("%{$numWidth}s: %s\n%s",$n,strip_tags($s),implode('',$tags[0]));}else{$out.=sprintf("%{$numWidth}s: %s\n",$n,$s);}}return$out.str_repeat('',$spans).'';}public +log($message,$priority=self::DEBUG){if(!isset($_SERVER['HTTP_X_FIRELOGGER'])||headers_sent()){return +FALSE;}$item=array('name'=>'PHP','level'=>$priority,'order'=>count(self::$payload['logs']),'time'=>str_pad(number_format((microtime(TRUE)-Debugger::$time)*1000,1,'.',' '),8,'0',STR_PAD_LEFT).' ms','template'=>'','message'=>'','style'=>'background:#767ab6');$args=func_get_args();if(isset($args[0])&&is_string($args[0])){$item['template']=array_shift($args);}if(isset($args[0])&&$args[0]instanceof +Exception){$e=array_shift($args);$trace=$e->getTrace();if(isset($trace[0]['class'])&&$trace[0]['class']===__CLASS__&&($trace[0]['function']==='_shutdownHandler'||$trace[0]['function']==='_errorHandler')){unset($trace[0]);}$item['exc_info']=array($e->getMessage(),$e->getFile(),array());$item['exc_frames']=array();foreach($trace +as$frame){$frame+=array('file'=>NULL,'line'=>NULL,'class'=>NULL,'type'=>NULL,'function'=>NULL,'object'=>NULL,'args'=>NULL);$item['exc_info'][2][]=array($frame['file'],$frame['line'],"$frame[class]$frame[type]$frame[function]",$frame['object']);$item['exc_frames'][]=$frame['args'];}$file=str_replace(dirname(dirname(dirname($e->getFile()))),"\xE2\x80\xA6",$e->getFile());$item['template']=($e +instanceof +ErrorException?'':get_class($e).': ').$e->getMessage().($e->getCode()?' #'.$e->getCode():'').' in '.$file.':'.$e->getLine();array_unshift($trace,array('file'=>$e->getFile(),'line'=>$e->getLine()));}else{$trace=debug_backtrace();if(isset($trace[0]['class'])&&$trace[0]['class']===__CLASS__&&($trace[0]['function']==='_shutdownHandler'||$trace[0]['function']==='_errorHandler')){unset($trace[0]);}}if(isset($args[0])&&in_array($args[0],array(self::DEBUG,self::INFO,self::WARNING,self::ERROR,self::CRITICAL),TRUE)){$item['level']=array_shift($args);}$item['args']=$args;foreach($trace +as$frame){if(isset($frame['file'])&&is_file($frame['file'])){$item['pathname']=$frame['file'];$item['lineno']=$frame['line'];break;}}self::$payload['logs'][]=self::jsonDump($item,-1);foreach(str_split(base64_encode(@json_encode(self::$payload)),4990)as$k=>$v){header("FireLogger-de11e-$k:$v");}return +TRUE;}private +static +function +jsonDump(&$var,$level=0){if(is_bool($var)||is_null($var)||is_int($var)||is_float($var)){return$var;}elseif(is_string($var)){if(Debugger::$maxLen&&strlen($var)>Debugger::$maxLen){$var=substr($var,0,Debugger::$maxLen)." \xE2\x80\xA6 ";}return@iconv('UTF-16','UTF-8//IGNORE',iconv('UTF-8','UTF-16//IGNORE',$var));}elseif(is_array($var)){static$marker;if($marker===NULL)$marker=uniqid("\x00",TRUE);if(isset($var[$marker])){return"\xE2\x80\xA6RECURSION\xE2\x80\xA6";}elseif($level&$v){if($k!==$marker)$res[self::jsonDump($k)]=self::jsonDump($v,$level+1);}unset($var[$marker]);return$res;}else{return" \xE2\x80\xA6 ";}}elseif(is_object($var)){$arr=(array)$var;static$list=array();if(in_array($var,$list,TRUE)){return"\xE2\x80\xA6RECURSION\xE2\x80\xA6";}elseif($level'(object) '.get_class($var));foreach($arr +as$k=>&$v){if($k[0]==="\x00"){$k=substr($k,strrpos($k,"\x00")+1);}$res[self::jsonDump($k)]=self::jsonDump($v,$level+1);}array_pop($list);return$res;}else{return" \xE2\x80\xA6 ";}}elseif(is_resource($var)){return"resource ".get_resource_type($var);}else{return"unknown type";}}}final +class +DebugHelpers{public static function editorLink($file,$line){return -strtr(Debug::$editor,array('%file'=>rawurlencode($file),'%line'=>$line));}public +strtr(Debugger::$editor,array('%file'=>rawurlencode($file),'%line'=>$line));}public static function -htmlDump(&$var,$level=0){static$tableUtf,$tableBin,$reBinary='#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u';if($tableUtf===NULL){foreach(range("\x00","\xFF")as$ch){if(ord($ch)<32&&strpos("\r\n\t",$ch)===FALSE)$tableUtf[$ch]=$tableBin[$ch]='\\x'.str_pad(dechex(ord($ch)),2,'0',STR_PAD_LEFT);elseif(ord($ch)<127)$tableUtf[$ch]=$tableBin[$ch]=$ch;else{$tableUtf[$ch]=$ch;$tableBin[$ch]='\\x'.dechex(ord($ch));}}$tableBin["\\"]='\\\\';$tableBin["\r"]='\\r';$tableBin["\n"]='\\n';$tableBin["\t"]='\\t';$tableUtf['\\x']=$tableBin['\\x']='\\\\x';}if(is_bool($var)){return($var?'TRUE':'FALSE')."\n";}elseif($var===NULL){return"NULL\n";}elseif(is_int($var)){return"$var\n";}elseif(is_float($var)){$var=(string)$var;if(strpos($var,'.')===FALSE)$var.='.0';return"$var\n";}elseif(is_string($var)){if(Debug::$maxLen&&strlen($var)>Debug::$maxLen){$s=htmlSpecialChars(substr($var,0,Debug::$maxLen),ENT_NOQUOTES).' ... ';}else{$s=htmlSpecialChars($var,ENT_NOQUOTES);}$s=strtr($s,preg_match($reBinary,$s)||preg_last_error()?$tableBin:$tableUtf);$len=strlen($var);return"\"$s\"".($len>1?" ($len)":"")."\n";}elseif(is_array($var)){$s="array(".count($var).") ";$space=str_repeat($space1=' ',$level);$brackets=range(0,count($var)-1)===array_keys($var)?"[]":"{}";static$marker;if($marker===NULL)$marker=uniqid("\x00",TRUE);if(empty($var)){}elseif(isset($var[$marker])){$brackets=$var[$marker];$s.="$brackets[0] *RECURSION* $brackets[1]";}elseif($level$brackets[0]\n";$var[$marker]=$brackets;foreach($var -as$k=>&$v){if($k===$marker)continue;$k=is_int($k)?$k:'"'.strtr($k,preg_match($reBinary,$k)||preg_last_error()?$tableBin:$tableUtf).'"';$s.="$space$space1$k => ".self::htmlDump($v,$level+1);}unset($var[$marker]);$s.="$space$brackets[1]";}else{$s.="$brackets[0] ... $brackets[1]";}return$s."\n";}elseif(is_object($var)){$arr=(array)$var;$s="".get_class($var)."(".count($arr).") ";$space=str_repeat($space1=' ',$level);static$list=array();if(empty($arr)){}elseif(in_array($var,$list,TRUE)){$s.="{ *RECURSION* }";}elseif($level{\n";$list[]=$var;foreach($arr -as$k=>&$v){$m='';if($k[0]==="\x00"){$m=$k[1]==='*'?' protected':' private';$k=substr($k,strrpos($k,"\x00")+1);}$k=strtr($k,preg_match($reBinary,$k)||preg_last_error()?$tableBin:$tableUtf);$s.="$space$space1\"$k\"$m => ".self::htmlDump($v,$level+1);}array_pop($list);$s.="$space}";}else{$s.="{ ... }";}return$s."\n";}elseif(is_resource($var)){return"".get_resource_type($var)." resource\n";}else{return"unknown type\n";}}public -static -function -jsonDump(&$var,$level=0){if(is_bool($var)||is_null($var)||is_int($var)||is_float($var)){return$var;}elseif(is_string($var)){if(Debug::$maxLen&&strlen($var)>Debug::$maxLen){$var=substr($var,0,Debug::$maxLen)." \xE2\x80\xA6 ";}return@iconv('UTF-16','UTF-8//IGNORE',iconv('UTF-8','UTF-16//IGNORE',$var));}elseif(is_array($var)){static$marker;if($marker===NULL)$marker=uniqid("\x00",TRUE);if(isset($var[$marker])){return"\xE2\x80\xA6RECURSION\xE2\x80\xA6";}elseif($level&$v){if($k!==$marker)$res[self::jsonDump($k)]=self::jsonDump($v,$level+1);}unset($var[$marker]);return$res;}else{return" \xE2\x80\xA6 ";}}elseif(is_object($var)){$arr=(array)$var;static$list=array();if(in_array($var,$list,TRUE)){return"\xE2\x80\xA6RECURSION\xE2\x80\xA6";}elseif($level'(object) '.get_class($var));foreach($arr -as$k=>&$v){if($k[0]==="\x00"){$k=substr($k,strrpos($k,"\x00")+1);}$res[self::jsonDump($k)]=self::jsonDump($v,$level+1);}array_pop($list);return$res;}else{return" \xE2\x80\xA6 ";}}elseif(is_resource($var)){return"resource ".get_resource_type($var);}else{return"unknown type";}}public +htmlDump(&$var,$level=0){static$tableUtf,$tableBin,$reBinary='#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u';if($tableUtf===NULL){foreach(range("\x00","\xFF")as$ch){if(ord($ch)<32&&strpos("\r\n\t",$ch)===FALSE){$tableUtf[$ch]=$tableBin[$ch]='\\x'.str_pad(dechex(ord($ch)),2,'0',STR_PAD_LEFT);}elseif(ord($ch)<127){$tableUtf[$ch]=$tableBin[$ch]=$ch;}else{$tableUtf[$ch]=$ch;$tableBin[$ch]='\\x'.dechex(ord($ch));}}$tableBin["\\"]='\\\\';$tableBin["\r"]='\\r';$tableBin["\n"]='\\n';$tableBin["\t"]='\\t';$tableUtf['\\x']=$tableBin['\\x']='\\\\x';}if(is_bool($var)){return($var?'TRUE':'FALSE')."\n";}elseif($var===NULL){return"NULL\n";}elseif(is_int($var)){return"$var\n";}elseif(is_float($var)){$var=var_export($var,TRUE);if(strpos($var,'.')===FALSE)$var.='.0';return"$var\n";}elseif(is_string($var)){if(Debugger::$maxLen&&strlen($var)>Debugger::$maxLen){$s=htmlSpecialChars(substr($var,0,Debugger::$maxLen),ENT_NOQUOTES).' ... ';}else{$s=htmlSpecialChars($var,ENT_NOQUOTES);}$s=strtr($s,preg_match($reBinary,$s)||preg_last_error()?$tableBin:$tableUtf);$len=strlen($var);return"\"$s\"".($len>1?" ($len)":"")."\n";}elseif(is_array($var)){$s="array(".count($var).") ";$space=str_repeat($space1=' ',$level);$brackets=range(0,count($var)-1)===array_keys($var)?"[]":"{}";static$marker;if($marker===NULL)$marker=uniqid("\x00",TRUE);if(empty($var)){}elseif(isset($var[$marker])){$brackets=$var[$marker];$s.="$brackets[0] *RECURSION* $brackets[1]";}elseif($level$brackets[0]\n";$var[$marker]=$brackets;foreach($var +as$k=>&$v){if($k===$marker)continue;$k=is_int($k)?$k:'"'.htmlSpecialChars(strtr($k,preg_match($reBinary,$k)||preg_last_error()?$tableBin:$tableUtf)).'"';$s.="$space$space1$k => ".self::htmlDump($v,$level+1);}unset($var[$marker]);$s.="$space$brackets[1]";}else{$s.="$brackets[0] ... $brackets[1]";}return$s."\n";}elseif(is_object($var)){$arr=(array)$var;$s="".get_class($var)."(".count($arr).") ";$space=str_repeat($space1=' ',$level);static$list=array();if(empty($arr)){}elseif(in_array($var,$list,TRUE)){$s.="{ *RECURSION* }";}elseif($level{\n";$list[]=$var;foreach($arr +as$k=>&$v){$m='';if($k[0]==="\x00"){$m=$k[1]==='*'?' protected':' private';$k=substr($k,strrpos($k,"\x00")+1);}$k=htmlSpecialChars(strtr($k,preg_match($reBinary,$k)||preg_last_error()?$tableBin:$tableUtf));$s.="$space$space1\"$k\"$m => ".self::htmlDump($v,$level+1);}array_pop($list);$s.="$space}";}else{$s.="{ ... }";}return$s."\n";}elseif(is_resource($var)){return"".htmlSpecialChars(get_resource_type($var))." resource\n";}else{return"unknown type\n";}}public static function clickableDump($dump){return'
    '.preg_replace_callback('#^( *)((?>[^(]{1,200}))\((\d+)\) #m',create_function('$m','
    -				return "$m[1]$m[2]($m[3]) " . (trim($m[1]) || $m[3] < 7 ? \' \' : \' \');
    -			'),self::htmlDump($dump)).'
    ';}}Debug::_init();if(!function_exists('dump')){function -dump($var){foreach($args=func_get_args()as$arg)Debug::dump($arg);return$var;}} \ No newline at end of file + return "$m[1]$m[2]($m[3]) " + . (trim($m[1]) || $m[3] < 7 + ? \' \' + : \' \'); + '),self::htmlDump($dump)).'';}}class +Logger{const +DEBUG='debug',INFO='info',WARNING='warning',ERROR='error',CRITICAL='critical';public +static$emailSnooze=172800;public$mailer=array(__CLASS__,'defaultMailer');public$directory;public$email;public +function +log($message,$priority=self::INFO){if(!is_dir($this->directory)){throw +new +DirectoryNotFoundException("Directory '$this->directory' is not found or is not directory.");}if(is_array($message)){$message=implode(' ',$message);}$res=error_log(trim($message).PHP_EOL,3,$this->directory.'/'.strtolower($priority).'.log');if(($priority===self::ERROR||$priority===self::CRITICAL)&&$this->email&&@filemtime($this->directory.'/email-sent')+self::$emailSnoozedirectory.'/email-sent','sent')){call_user_func($this->mailer,$message,$this->email);}return$res;}private +static +function +defaultMailer($message,$email){$host=isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:(isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:'');$parts=str_replace(array("\r\n","\n"),array("\n",PHP_EOL),array('headers'=>"From: noreply@$host\nX-Mailer: Nette Framework\n",'subject'=>"PHP: An error occurred on the server $host",'body'=>"[".@date('Y-m-d H:i:s')."] $message"));mail($email,$parts['subject'],$parts['body'],$parts['headers']);}}final +class +Debugger{public +static$productionMode;public +static$consoleMode;public +static$time;private +static$ajaxDetected;public +static$source;public +static$editor='editor://open/?file=%file&line=%line';public +static$maxDepth=3;public +static$maxLen=150;public +static$showLocation=FALSE;const +DEVELOPMENT=FALSE,PRODUCTION=TRUE,DETECT=NULL;public +static$blueScreen;public +static$strictMode=FALSE;public +static$scream=FALSE;public +static$onFatalError=array();private +static$enabled=FALSE;private +static$lastError=FALSE;public +static$logger;public +static$fireLogger;public +static$logDirectory;public +static$email;public +static$mailer;public +static$emailSnooze;public +static$bar;private +static$errorPanel;private +static$dumpPanel;const +DEBUG='debug',INFO='info',WARNING='warning',ERROR='error',CRITICAL='critical';final +public +function +__construct(){throw +new +StaticClassException;}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: '.implode(' ',$_SERVER['argv']);}else{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'];}}self::$logger=new +Logger;self::$logger->directory=&self::$logDirectory;self::$logger->email=&self::$email;self::$logger->mailer=&self::$mailer;Logger::$emailSnooze=&self::$emailSnooze;self::$fireLogger=new +FireLogger;self::$blueScreen=new +DebugBlueScreen;self::$blueScreen->addPanel(create_function('$e',' + if ($e instanceof TemplateException) { + $link = DebugHelpers::editorLink($e->sourceFile, $e->sourceLine); + return array( + \'tab\' => \'Template\', + \'panel\' => \'

    File: \' . ($link ? \'\' : \'\') . htmlspecialchars($e->sourceFile) . ($link ? \'\' : \'\') + . \'  Line: \' . ($e->sourceLine ? $e->sourceLine : \'n/a\') . \'

    \' + . ($e->sourceLine ? \'
    \' . DebugBlueScreen::highlightFile($e->sourceFile, $e->sourceLine) . \'
    \' : \'\') + ); + } + '));self::$bar=new +DebugBar;self::$bar->addPanel(new +DefaultBarPanel('time'));self::$bar->addPanel(new +DefaultBarPanel('memory'));self::$bar->addPanel(self::$errorPanel=new +DefaultBarPanel('errors'));self::$bar->addPanel(self::$dumpPanel=new +DefaultBarPanel('dumps'));}public +static +function +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 127.0.0.1 ::1");}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)){self::$logDirectory=realpath($logDirectory);if(self::$logDirectory===FALSE){throw +new +DirectoryNotFoundException("Directory '$logDirectory' is not found.");}}elseif($logDirectory===FALSE){self::$logDirectory=FALSE;}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.');}if($email){if(!is_string($email)){throw +new +InvalidArgumentException('Email 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::$logDirectory===FALSE){return;}elseif(!self::$logDirectory){throw +new +InvalidStateException('Logging directory is not specified in Debugger::$logDirectory.');}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();$hash=md5($exception.(method_exists($exception,'getPrevious')?$exception->getPrevious():(isset($exception->previous)?$exception->previous:'')));$exceptionFilename="exception ".@date('Y-m-d H-i-s')." $hash.html";foreach(new +DirectoryIterator(self::$logDirectory)as$entry){if(strpos($entry,$hash)){$exceptionFilename=NULL;break;}}}self::$logger->log(array(@date('[Y-m-d H-i-s]'),$message,self::$source?' @ '.self::$source:NULL,!empty($exceptionFilename)?' @@ '.$exceptionFilename:NULL),$priority);if(!empty($exceptionFilename)&&$logHandle=@fopen(self::$logDirectory.'/'.$exceptionFilename,'w')){ob_start();ob_start(create_function('$buffer','extract(NClosureFix::$vars['.NClosureFix::uses(array('logHandle'=>$logHandle)).'], EXTR_REFS); fwrite($logHandle, $buffer); '),1);self::$blueScreen->render($exception);ob_end_flush();ob_end_clean();fclose($logHandle);}}public +static +function +_shutdownHandler(){static$types=array(E_ERROR=>1,E_CORE_ERROR=>1,E_COMPILE_ERROR=>1,E_PARSE=>1);$error=error_get_last();if(isset($types[$error['type']])){self::_exceptionHandler(new +FatalErrorException($error['message'],0,$error['type'],$error['file'],$error['line'],NULL));}if(self::$bar&&!self::$productionMode&&!self::$ajaxDetected&&!self::$consoleMode&&!preg_match('#^Content-Type: (?!text/html)#im',implode("\n",headers_list()))){self::$bar->render();}}public +static +function +_exceptionHandler(Exception$exception){if(!headers_sent()){header('HTTP/1.1 500 Internal Server Error');}$htmlMode=!self::$ajaxDetected&&!preg_match('#^Content-Type: (?!text/html)#im',implode("\n",headers_list()));try{if(self::$productionMode){self::log($exception,self::ERROR);if(self::$consoleMode){echo"ERROR: the server encountered an internal error and was unable to complete your request.\n";}elseif($htmlMode){?> + + + + + +Server Error + +

    Server Error

    + +

    We're sorry! The server encountered an internal error and was unable to complete your request. Please try again later.

    + +

    error 500

    +render($exception);if(self::$bar){self::$bar->render();}}elseif(!self::fireLog($exception,self::ERROR)){self::log($exception);}}foreach(self::$onFatalError +as$handler){call_user_func($handler,$exception);}}catch(Exception$e){echo"\nNette\\Debug FATAL ERROR: thrown ",get_class($e),': ',$e->getMessage(),"\nwhile processing ",get_class($exception),': ',$exception->getMessage(),"\n";}exit(255);}public +static +function +_errorHandler($severity,$message,$file,$line,$context){if(self::$scream){error_reporting(E_ALL|E_STRICT);}if(self::$lastError!==FALSE&&($severity&error_reporting())===$severity){self::$lastError=new +ErrorException($message,0,$severity,$file,$line);return +NULL;}if($severity===E_RECOVERABLE_ERROR||$severity===E_USER_ERROR){throw +new +FatalErrorException($message,0,$severity,$file,$line,$context);}elseif(($severity&error_reporting())!==$severity){return +FALSE;}elseif(self::$strictMode&&!self::$productionMode){self::_exceptionHandler(new +FatalErrorException($message,0,$severity,$file,$line,$context));}static$types=array(E_WARNING=>'Warning',E_COMPILE_WARNING=>'Warning',E_USER_WARNING=>'Warning',E_NOTICE=>'Notice',E_USER_NOTICE=>'Notice',E_STRICT=>'Strict standards',E_DEPRECATED=>'Deprecated',E_USER_DEPRECATED=>'Deprecated');$message='PHP '.(isset($types[$severity])?$types[$severity]:'Unknown error').": $message";$count=&self::$errorPanel->data["$message|$file|$line"];if($count++){return +NULL;}elseif(self::$productionMode){self::log("$message in $file:$line",self::ERROR);return +NULL;}else{$ok=self::fireLog(new +ErrorException($message,0,$severity,$file,$line),self::WARNING);return +self::$consoleMode||(!self::$bar&&!$ok)?FALSE:NULL;}return +FALSE;}public +static +function +toStringException(Exception$exception){if(self::$enabled){self::_exceptionHandler($exception);}else{trigger_error($exception->getMessage(),E_USER_ERROR);}}public +static +function +tryError(){if(!self::$enabled&&self::$lastError===FALSE){set_error_handler(array(__CLASS__,'_errorHandler'));}self::$lastError=NULL;}public +static +function +catchError(&$error){if(!self::$enabled&&self::$lastError!==FALSE){restore_error_handler();}$error=self::$lastError;self::$lastError=FALSE;return(bool)$error;}public +static +function +dump($var,$return=FALSE){if(!$return&&self::$productionMode){return$var;}$output="
    ".DebugHelpers::htmlDump($var)."
    \n";if(!$return&&self::$showLocation){$trace=debug_backtrace();$i=isset($trace[1]['class'])&&$trace[1]['class']===__CLASS__?1:0;if(isset($trace[$i]['file'],$trace[$i]['line'])){$output=substr_replace($output,' '.htmlspecialchars("in file {$trace[$i]['file']} on line {$trace[$i]['line']}",ENT_NOQUOTES).'',-8,0);}}if(self::$consoleMode){$output=htmlspecialchars_decode(strip_tags($output),ENT_NOQUOTES);}if($return){return$output;}else{echo$output;return$var;}}public +static +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 +barDump($var,$title=NULL){if(!self::$productionMode){$dump=array();foreach((is_array($var)?$var:array(''=>$var))as$key=>$val){$dump[$key]=DebugHelpers::clickableDump($val);}self::$dumpPanel->data[]=array('title'=>$title,'dump'=>$dump);}return$var;}public +static +function +fireLog($message){if(!self::$productionMode){return +self::$fireLogger->log($message);}}public +static +function +addPanel(IBarPanel$panel,$id=NULL){self::$bar->addPanel($panel,$id);}}Debugger::_init(); \ No newline at end of file diff --git a/examples/Nette/netterobots.txt b/examples/Nette/netterobots.txt deleted file mode 100644 index 87b5f596..00000000 --- a/examples/Nette/netterobots.txt +++ /dev/null @@ -1 +0,0 @@ -Disallow: / diff --git a/examples/nette-debug-and-exceptions.php b/examples/nette-debug-and-exceptions.php index 0ca63cd9..426c30b8 100644 --- a/examples/nette-debug-and-exceptions.php +++ b/examples/nette-debug-and-exceptions.php @@ -1,8 +1,8 @@ -

    Nette\Debug & SQL Exceptions | dibi

    +

    Nette Debugger & SQL Exceptions | dibi

    -

    Dibi can display and log exceptions via Nette\Debug, part of Nette Framework.

    +

    Dibi can display and log exceptions via Nette Debugger, part of Nette Framework.

    • Nette Framework: http://nette.org @@ -10,12 +10,12 @@ -

      Nette\Debug & Variables | dibi

      +

      Nette Debugger & Variables | dibi

      -

      Dibi can dump variables via Nette\Debug, part of Nette Framework.

      +

      Dibi can dump variables via Nette Debugger, part of Nette Framework.

      • Nette Framework: http://nette.org @@ -10,12 +10,12 @@