public static function renderException($e)
 {
     if (!$e instanceof \PDOException) {
         return;
     }
     if (isset($e->queryString)) {
         $sql = $e->queryString;
     } elseif ($item = Nette\Diagnostics\Helpers::findTrace($e->getTrace(), 'PDO::prepare')) {
         $sql = $item['args'][0];
     }
     return isset($sql) ? array('tab' => 'SQL', 'panel' => Helpers::dumpSql($sql)) : NULL;
 }
 /**
  * Dumps information about a variable in readable format.
  * @param  mixed  variable to dump
  * @param  bool   return output instead of printing it? (bypasses $productionMode)
  * @return mixed  variable itself or dump
  */
 public static function dump($var, $return = FALSE)
 {
     if (!$return && self::$productionMode) {
         return $var;
     }
     $output = "<pre class=\"nette-dump\">" . Helpers::htmlDump($var) . "</pre>\n";
     if (!$return) {
         $trace = debug_backtrace(FALSE);
         $i = Helpers::findTrace($trace, 'dump') ? 1 : 0;
         if (isset($trace[$i]['file'], $trace[$i]['line']) && is_file($trace[$i]['file'])) {
             $lines = file($trace[$i]['file']);
             preg_match('#dump\\((.*)\\)#', $lines[$trace[$i]['line'] - 1], $m);
             $output = substr_replace($output, ' title="' . htmlspecialchars((isset($m[0]) ? "{$m['0']} \n" : '') . "in file {$trace[$i]['file']} on line {$trace[$i]['line']}") . '"', 4, 0);
             if (self::$showLocation) {
                 $output = substr_replace($output, ' <small>in ' . Helpers::editorLink($trace[$i]['file'], $trace[$i]['line']) . ":{$trace[$i]['line']}</small>", -8, 0);
             }
         }
     }
     if (self::$consoleMode) {
         if (self::$consoleColors && substr(getenv('TERM'), 0, 5) === 'xterm') {
             $output = preg_replace_callback('#<span class="php-(\\w+)">|</span>#', function ($m) {
                 return "[" . (isset($m[1], Debugger::$consoleColors[$m[1]]) ? Debugger::$consoleColors[$m[1]] : '0') . "m";
             }, $output);
         }
         $output = htmlspecialchars_decode(strip_tags($output), ENT_QUOTES);
     }
     if ($return) {
         return $output;
     } else {
         echo $output;
         return $var;
     }
 }
Exemple #3
0
catchError(&$error){if(!self::$enabled&&self::$lastError!==FALSE){restore_error_handler();}$error=self::$lastError;self::$lastError=FALSE;return(bool)$error;}static
function
dump($var,$return=FALSE){if(!$return&&self::$productionMode){return$var;}$output="<pre class=\"nette-dump\">".Helpers::htmlDump($var)."</pre>\n";if(!$return){$trace=debug_backtrace(FALSE);$i=Helpers::findTrace($trace,'dump')?1:0;if(isset($trace[$i]['file'],$trace[$i]['line'])&&is_file($trace[$i]['file'])){$lines=file($trace[$i]['file']);preg_match('#dump\((.*)\)#',$lines[$trace[$i]['line']-1],$m);$output=substr_replace($output,' title="'.htmlspecialchars((isset($m[0])?"$m[0] \n":'')."in file {$trace[$i]['file']} on line {$trace[$i]['line']}").'"',4,0);if(self::$showLocation){$output=substr_replace($output,' <small>in '.Helpers::editorLink($trace[$i]['file'],$trace[$i]['line']).":{$trace[$i]['line']}</small>",-8,0);}}}if(self::$consoleMode){if(self::$consoleColors&&substr(PHP_OS,0,3)!=='WIN'){$output=preg_replace_callback('#<span class="php-(\w+)">|</span>#',function($m){return"\033[".(isset($m[1],Debugger::$consoleColors[$m[1]])?Debugger::$consoleColors[$m[1]]:'0')."m";},$output);}$output=htmlspecialchars_decode(strip_tags($output),ENT_QUOTES);}if($return){return$output;}else{echo$output;return$var;}}static
Exemple #4
0
 /**
  * Handler to catch warnings and notices.
  * @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 bool   FALSE to call normal error handler, NULL otherwise
  * @throws ErrorException
  * @internal
  */
 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) {
         // tryError mode
         self::$lastError = new \ErrorException($message, 0, $severity, $file, $line);
         return NULL;
     }
     if ($severity === E_RECOVERABLE_ERROR || $severity === E_USER_ERROR) {
         if (Helpers::findTrace(debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : FALSE), '*::__toString')) {
             $previous = isset($context['e']) && $context['e'] instanceof \Exception ? $context['e'] : NULL;
             $e = new ErrorException($message, 0, $severity, $file, $line, $previous);
             $e->context = $context;
             self::_exceptionHandler($e);
         }
         $e = new ErrorException($message, 0, $severity, $file, $line);
         $e->context = $context;
         throw $e;
     } elseif (($severity & error_reporting()) !== $severity) {
         return FALSE;
         // calls normal error handler to fill-in error_get_last()
     } elseif (!self::$productionMode && (is_bool(self::$strictMode) ? self::$strictMode : (self::$strictMode & $severity) === $severity)) {
         $e = new ErrorException($message, 0, $severity, $file, $line);
         $e->context = $context;
         self::_exceptionHandler($e);
     }
     $message = 'PHP ' . (isset(self::$errorTypes[$severity]) ? self::$errorTypes[$severity] : 'Unknown error') . ": {$message}";
     $count =& self::getBar()->getPanel(__CLASS__ . ':errors')->data["{$file}|{$line}|{$message}"];
     if ($count++) {
         // repeated error
         return NULL;
     } elseif (self::$productionMode) {
         self::log("{$message} in {$file}:{$line}", self::ERROR);
         return NULL;
     } else {
         self::fireLog(new ErrorException($message, 0, $severity, $file, $line));
         return self::isHtmlMode() ? NULL : FALSE;
         // FALSE calls normal error handler
     }
 }
Exemple #5
0
 /**
  * Dumps information about a variable in readable format.
  * @param  mixed  variable to dump
  * @param  bool   return output instead of printing it? (bypasses $productionMode)
  * @return mixed  variable itself or dump
  */
 public static function dump($var, $return = FALSE)
 {
     if (!$return && self::$productionMode) {
         return $var;
     }
     $output = "<pre class=\"nette-dump\">" . Helpers::htmlDump($var) . "</pre>\n";
     if (!$return) {
         $trace = debug_backtrace();
         $i = Helpers::findTrace($trace, 'dump') ? 1 : 0;
         if (isset($trace[$i]['file'], $trace[$i]['line']) && is_file($trace[$i]['file'])) {
             $lines = file($trace[$i]['file']);
             preg_match('#dump\\((.*)\\)#', $lines[$trace[$i]['line'] - 1], $m);
             $output = substr_replace($output, ' title="' . htmlspecialchars((isset($m[0]) ? "{$m['0']} \n" : '') . "in file {$trace[$i]['file']} on line {$trace[$i]['line']}") . '"', 4, 0);
             if (self::$showLocation) {
                 $output = substr_replace($output, ' <small>in ' . Helpers::editorLink($trace[$i]['file'], $trace[$i]['line']) . ":{$trace[$i]['line']}</small>", -8, 0);
             }
         }
     }
     if (self::$consoleMode) {
         $output = htmlspecialchars_decode(strip_tags($output), ENT_QUOTES);
     }
     if ($return) {
         return $output;
     } else {
         echo $output;
         return $var;
     }
 }