Packages

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • DebugBar
  • DebugBlueScreen
  • Debugger
  • DebugHelpers
  • FireLogger
  • Logger

Interfaces

  • IBarPanel
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Diagnostics
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Debugger: displays and logs errors.
 17:  *
 18:  * Behavior is determined by two factors: mode & output
 19:  * - modes: production / development
 20:  * - output: HTML / AJAX / CLI / other (e.g. XML)
 21:  *
 22:  * @author     David Grudl
 23:  * @package Nette\Diagnostics
 24:  */
 25: final class Debugger
 26: {
 27:     /** @var bool in production mode is suppressed any debugging output */
 28:     public static $productionMode;
 29: 
 30:     /** @var bool in console mode is omitted HTML output */
 31:     public static $consoleMode;
 32: 
 33:     /** @var int timestamp with microseconds of the start of the request */
 34:     public static $time;
 35: 
 36:     /** @var bool is AJAX request detected? */
 37:     private static $ajaxDetected;
 38: 
 39:     /** @var string  requested URI or command line */
 40:     public static $source;
 41: 
 42:     /** @var string URL pattern mask to open editor */
 43:     public static $editor = 'editor://open/?file=%file&line=%line';
 44: 
 45:     /** @var string command to open browser (use 'start ""' in Windows) */
 46:     public static $browser;
 47: 
 48:     /********************* Debugger::dump() ****************d*g**/
 49: 
 50:     /** @var int  how many nested levels of array/object properties display {@link Debugger::dump()} */
 51:     public static $maxDepth = 3;
 52: 
 53:     /** @var int  how long strings display {@link Debugger::dump()} */
 54:     public static $maxLen = 150;
 55: 
 56:     /** @var bool display location? {@link Debugger::dump()} */
 57:     public static $showLocation = FALSE;
 58: 
 59:     /** @var array */
 60:     public static $consoleColors = array(
 61:         'bool' => '1;33',
 62:         'null' => '1;33',
 63:         'int' => '1;36',
 64:         'float' => '1;36',
 65:         'string' => '1;32',
 66:         'array' => '1;31',
 67:         'key' => '1;37',
 68:         'object' => '1;31',
 69:         'visibility' => '1;30',
 70:         'resource' => '1;37',
 71:     );
 72: 
 73:     /********************* errors and exceptions reporting ****************d*g**/
 74: 
 75:     /** server modes {@link Debugger::enable()} */
 76:     const DEVELOPMENT = FALSE,
 77:         PRODUCTION = TRUE,
 78:         DETECT = NULL;
 79: 
 80:     /** @var DebugBlueScreen */
 81:     public static $blueScreen;
 82: 
 83:     /** @var bool|int determines whether any error will cause immediate death; if integer that it's matched against error severity */
 84:     public static $strictMode = FALSE; // $immediateDeath
 85: 
 86:     /** @var bool disables the @ (shut-up) operator so that notices and warnings are no longer hidden */
 87:     public static $scream = FALSE;
 88: 
 89:     /** @var array of callables specifies the functions that are automatically called after fatal error */
 90:     public static $onFatalError = array();
 91: 
 92:     /** @var bool {@link Debugger::enable()} */
 93:     private static $enabled = FALSE;
 94: 
 95:     /** @var mixed {@link Debugger::tryError()} FALSE means catching is disabled */
 96:     private static $lastError = FALSE;
 97: 
 98:     /********************* logging ****************d*g**/
 99: 
100:     /** @var Logger */
101:     public static $logger;
102: 
103:     /** @var FireLogger */
104:     public static $fireLogger;
105: 
106:     /** @var string name of the directory where errors should be logged; FALSE means that logging is disabled */
107:     public static $logDirectory;
108: 
109:     /** @var string email to sent error notifications */
110:     public static $email;
111: 
112:     /** @deprecated */
113:     public static $mailer;
114: 
115:     /** @deprecated */
116:     public static $emailSnooze;
117: 
118:     /********************* debug bar ****************d*g**/
119: 
120:     /** @var DebugBar */
121:     public static $bar;
122: 
123:     /** @var DefaultBarPanel */
124:     private static $errorPanel;
125: 
126:     /** @var DefaultBarPanel */
127:     private static $dumpPanel;
128: 
129:     /********************* Firebug extension ****************d*g**/
130: 
131:     /** {@link Debugger::log()} and {@link Debugger::fireLog()} */
132:     const DEBUG = 'debug',
133:         INFO = 'info',
134:         WARNING = 'warning',
135:         ERROR = 'error',
136:         CRITICAL = 'critical';
137: 
138: 
139: 
140:     /**
141:      * Static class - cannot be instantiated.
142:      */
143:     final public function __construct()
144:     {
145:         throw new StaticClassException;
146:     }
147: 
148: 
149: 
150:     /**
151:      * Static class constructor.
152:      * @internal
153:      */
154:     public static function _init()
155:     {
156:         self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(TRUE);
157:         self::$consoleMode = PHP_SAPI === 'cli';
158:         self::$productionMode = self::DETECT;
159:         if (self::$consoleMode) {
160:             self::$source = empty($_SERVER['argv']) ? 'cli' : 'cli: ' . implode(' ', $_SERVER['argv']);
161:         } else {
162:             self::$ajaxDetected = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
163:             if (isset($_SERVER['REQUEST_URI'])) {
164:                 self::$source = (isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://')
165:                     . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''))
166:                     . $_SERVER['REQUEST_URI'];
167:             }
168:         }
169: 
170:         self::$logger = new Logger;
171:         self::$logDirectory = & self::$logger->directory;
172:         self::$email = & self::$logger->email;
173:         self::$mailer = & self::$logger->mailer;
174:         self::$emailSnooze = & Logger::$emailSnooze;
175: 
176:         self::$fireLogger = new FireLogger;
177: 
178:         self::$blueScreen = new DebugBlueScreen;
179:         self::$blueScreen->addPanel(create_function('$e', '
180:             if ($e instanceof TemplateException) {
181:                 return array(
182:                     \'tab\' => \'Template\',
183:                     \'panel\' => \'<p><b>File:</b> \' . DebugHelpers::editorLink($e->sourceFile, $e->sourceLine)
184:                     . \'&nbsp; <b>Line:</b> \' . ($e->sourceLine ? $e->sourceLine : \'n/a\') . \'</p>\'
185:                     . ($e->sourceLine ? DebugBlueScreen::highlightFile($e->sourceFile, $e->sourceLine) : \'\')
186:                 );
187:             } elseif ($e instanceof NeonException && preg_match(\'#line (\\d+)#\', $e->getMessage(), $m)) {
188:                 if ($item = DebugHelpers::findTrace($e->getTrace(), \'ConfigNeonAdapter::load\')) {
189:                     return array(
190:                         \'tab\' => \'NEON\',
191:                         \'panel\' => \'<p><b>File:</b> \' . DebugHelpers::editorLink($item[\'args\'][0], $m[1]) . \'&nbsp; <b>Line:</b> \' . $m[1] . \'</p>\'
192:                             . DebugBlueScreen::highlightFile($item[\'args\'][0], $m[1])
193:                     );
194:                 } elseif ($item = DebugHelpers::findTrace($e->getTrace(), \'Neon::decode\')) {
195:                     return array(
196:                         \'tab\' => \'NEON\',
197:                         \'panel\' => DebugBlueScreen::highlightPhp($item[\'args\'][0], $m[1])
198:                     );
199:                 }
200:             }
201:         '));
202: 
203:         self::$bar = new DebugBar;
204:         self::$bar->addPanel(new DefaultBarPanel('time'));
205:         self::$bar->addPanel(new DefaultBarPanel('memory'));
206:         self::$bar->addPanel(self::$errorPanel = new DefaultBarPanel('errors')); // filled by _errorHandler()
207:         self::$bar->addPanel(self::$dumpPanel = new DefaultBarPanel('dumps')); // filled by barDump()
208:     }
209: 
210: 
211: 
212:     /********************* errors and exceptions reporting ****************d*g**/
213: 
214: 
215: 
216:     /**
217:      * Enables displaying or logging errors and exceptions.
218:      * @param  mixed         production, development mode, autodetection or IP address(es) whitelist.
219:      * @param  string        error log directory; enables logging in production mode, FALSE means that logging is disabled
220:      * @param  string        administrator email; enables email sending in production mode
221:      * @return void
222:      */
223:     public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
224:     {
225:         error_reporting(E_ALL | E_STRICT);
226: 
227:         // production/development mode detection
228:         if (is_bool($mode)) {
229:             self::$productionMode = $mode;
230: 
231:         } elseif ($mode !== self::DETECT || self::$productionMode === NULL) { // IP addresses or computer names whitelist detection
232:             $list = is_string($mode) ? preg_split('#[,\s]+#', $mode) : (array) $mode;
233:             if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
234:                 $list[] = '127.0.0.1';
235:                 $list[] = '::1';
236:             }
237:             self::$productionMode = !in_array(isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : php_uname('n'), $list, TRUE);
238:         }
239: 
240:         // logging configuration
241:         if (is_string($logDirectory)) {
242:             self::$logDirectory = realpath($logDirectory);
243:             if (self::$logDirectory === FALSE) {
244:                 throw new DirectoryNotFoundException("Directory '$logDirectory' is not found.");
245:             }
246:         } elseif ($logDirectory === FALSE) {
247:             self::$logDirectory = FALSE;
248: 
249:         } elseif (self::$logDirectory === NULL) {
250:             self::$logDirectory = defined('APP_DIR') ? APP_DIR . '/../log' : getcwd() . '/log';
251:         }
252:         if (self::$logDirectory) {
253:             ini_set('error_log', self::$logDirectory . '/php_error.log');
254:         }
255: 
256:         // php configuration
257:         if (function_exists('ini_set')) {
258:             ini_set('display_errors', !self::$productionMode); // or 'stderr'
259:             ini_set('html_errors', FALSE);
260:             ini_set('log_errors', FALSE);
261: 
262:         } elseif (ini_get('display_errors') != !self::$productionMode && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')) { // intentionally ==
263:             throw new NotSupportedException('Function ini_set() must be enabled.');
264:         }
265: 
266:         if ($email) {
267:             if (!is_string($email)) {
268:                 throw new InvalidArgumentException('Email address must be a string.');
269:             }
270:             self::$email = $email;
271:         }
272: 
273:         if (!defined('E_DEPRECATED')) {
274:             define('E_DEPRECATED', 8192);
275:         }
276: 
277:         if (!defined('E_USER_WARNING')) {
278:             define('E_USER_WARNING', 16384);
279:         }
280: 
281:         if (!self::$enabled) {
282:             register_shutdown_function(array(__CLASS__, '_shutdownHandler'));
283:             set_exception_handler(array(__CLASS__, '_exceptionHandler'));
284:             set_error_handler(array(__CLASS__, '_errorHandler'));
285:             self::$enabled = TRUE;
286:         }
287:     }
288: 
289: 
290: 
291:     /**
292:      * Is Debug enabled?
293:      * @return bool
294:      */
295:     public static function isEnabled()
296:     {
297:         return self::$enabled;
298:     }
299: 
300: 
301: 
302:     /**
303:      * Logs message or exception to file (if not disabled) and sends email notification (if enabled).
304:      * @param  string|Exception
305:      * @param  int  one of constant Debugger::INFO, WARNING, ERROR (sends email), CRITICAL (sends email)
306:      * @return string logged error filename
307:      */
308:     public static function log($message, $priority = self::INFO)
309:     {
310:         if (self::$logDirectory === FALSE) {
311:             return;
312: 
313:         } elseif (!self::$logDirectory) {
314:             throw new InvalidStateException('Logging directory is not specified in Debugger::$logDirectory.');
315:         }
316: 
317:         if ($message instanceof Exception) {
318:             $exception = $message;
319:             $message = ($message instanceof FatalErrorException
320:                 ? 'Fatal error: ' . $exception->getMessage()
321:                 : get_class($exception) . ": " . $exception->getMessage())
322:                 . " in " . $exception->getFile() . ":" . $exception->getLine();
323: 
324:             $hash = md5($exception . (method_exists($exception, 'getPrevious') ? $exception->getPrevious() : (isset($exception->previous) ? $exception->previous : '')));
325:             $exceptionFilename = "exception-" . @date('Y-m-d-H-i-s') . "-$hash.html";
326:             foreach (new DirectoryIterator(self::$logDirectory) as $entry) {
327:                 if (strpos($entry, $hash)) {
328:                     $exceptionFilename = $entry;
329:                     $saved = TRUE;
330:                     break;
331:                 }
332:             }
333:         }
334: 
335:         self::$logger->log(array(
336:             @date('[Y-m-d H-i-s]'),
337:             trim($message),
338:             self::$source ? ' @  ' . self::$source : NULL,
339:             !empty($exceptionFilename) ? ' @@  ' . $exceptionFilename : NULL
340:         ), $priority);
341: 
342:         if (!empty($exceptionFilename)) {
343:             $exceptionFilename = self::$logDirectory . '/' . $exceptionFilename;
344:             if (empty($saved) && $logHandle = @fopen($exceptionFilename, 'w')) {
345:                 ob_start(); // double buffer prevents sending HTTP headers in some PHP
346:                 ob_start(create_function('$buffer', 'extract(NCFix::$vars['.NCFix::uses(array('logHandle'=>$logHandle)).'], EXTR_REFS); fwrite($logHandle, $buffer); '), 4096);
347:                 self::$blueScreen->render($exception);
348:                 ob_end_flush();
349:                 ob_end_clean();
350:                 fclose($logHandle);
351:             }
352:             return strtr($exceptionFilename, '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
353:         }
354:     }
355: 
356: 
357: 
358:     /**
359:      * Shutdown handler to catch fatal errors and execute of the planned activities.
360:      * @return void
361:      * @internal
362:      */
363:     public static function _shutdownHandler()
364:     {
365:         if (!self::$enabled) {
366:             return;
367:         }
368: 
369:         // fatal error handler
370:         static $types = array(
371:             E_ERROR => 1,
372:             E_CORE_ERROR => 1,
373:             E_COMPILE_ERROR => 1,
374:             E_PARSE => 1,
375:         );
376:         $error = error_get_last();
377:         if (isset($types[$error['type']])) {
378:             self::_exceptionHandler(new FatalErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'], NULL));
379:         }
380: 
381:         // debug bar (require HTML & development mode)
382:         if (self::$bar && !self::$productionMode && self::isHtmlMode()) {
383:             self::$bar->render();
384:         }
385:     }
386: 
387: 
388: 
389:     /**
390:      * Handler to catch uncaught exception.
391:      * @param  Exception
392:      * @return void
393:      * @internal
394:      */
395:     public static function _exceptionHandler(Exception $exception)
396:     {
397:         if (!headers_sent()) { // for PHP < 5.2.4
398:             $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
399:             header($protocol . ' 500', TRUE, 500);
400:         }
401: 
402:         try {
403:             if (self::$productionMode) {
404:                 try {
405:                     self::log($exception, self::ERROR);
406:                 } catch (Exception $e) {
407:                     echo 'FATAL ERROR: unable to log error';
408:                 }
409: 
410:                 if (self::$consoleMode) {
411:                     echo "ERROR: the server encountered an internal error and was unable to complete your request.\n";
412: 
413:                 } elseif (self::isHtmlMode()) {
414:                     require dirname(__FILE__) . '/templates/error.phtml';
415:                 }
416: 
417:             } else {
418:                 if (self::$consoleMode) { // dump to console
419:                     echo "$exception\n";
420:                     if ($file = self::log($exception)) {
421:                         echo "(stored in $file)\n";
422:                         if (self::$browser) {
423:                             exec(self::$browser . ' ' . escapeshellarg($file));
424:                         }
425:                     }
426: 
427:                 } elseif (self::isHtmlMode()) { // dump to browser
428:                     self::$blueScreen->render($exception);
429:                     if (self::$bar) {
430:                         self::$bar->render();
431:                     }
432: 
433:                 } elseif (!self::fireLog($exception, self::ERROR)) { // AJAX or non-HTML mode
434:                     $file = self::log($exception);
435:                     if (!headers_sent()) {
436:                         header("X-Nette-Error-Log: $file");
437:                     }
438:                 }
439:             }
440: 
441:             foreach (self::$onFatalError as $handler) {
442:                 call_user_func($handler, $exception);
443:             }
444: 
445:         } catch (Exception $e) {
446:             if (self::$productionMode) {
447:                 echo self::isHtmlMode() ? '<meta name=robots content=noindex>FATAL ERROR' : 'FATAL ERROR';
448:             } else {
449:                 echo "FATAL ERROR: thrown ", get_class($e), ': ', $e->getMessage(),
450:                     "\nwhile processing ", get_class($exception), ': ', $exception->getMessage(), "\n";
451:             }
452:         }
453: 
454:         self::$enabled = FALSE; // un-register shutdown function
455:         exit(255);
456:     }
457: 
458: 
459: 
460:     /**
461:      * Handler to catch warnings and notices.
462:      * @param  int    level of the error raised
463:      * @param  string error message
464:      * @param  string file that the error was raised in
465:      * @param  int    line number the error was raised at
466:      * @param  array  an array of variables that existed in the scope the error was triggered in
467:      * @return bool   FALSE to call normal error handler, NULL otherwise
468:      * @throws FatalErrorException
469:      * @internal
470:      */
471:     public static function _errorHandler($severity, $message, $file, $line, $context)
472:     {
473:         if (self::$scream) {
474:             error_reporting(E_ALL | E_STRICT);
475:         }
476: 
477:         if (self::$lastError !== FALSE && ($severity & error_reporting()) === $severity) { // tryError mode
478:             self::$lastError = new ErrorException($message, 0, $severity, $file, $line);
479:             return NULL;
480:         }
481: 
482:         if ($severity === E_RECOVERABLE_ERROR || $severity === E_USER_ERROR) {
483:             throw new FatalErrorException($message, 0, $severity, $file, $line, $context);
484: 
485:         } elseif (($severity & error_reporting()) !== $severity) {
486:             return FALSE; // calls normal error handler to fill-in error_get_last()
487: 
488:         } elseif (!self::$productionMode && (is_bool(self::$strictMode) ? self::$strictMode : ((self::$strictMode & $severity) === $severity))) {
489:             self::_exceptionHandler(new FatalErrorException($message, 0, $severity, $file, $line, $context));
490:         }
491: 
492:         static $types = array(
493:             E_WARNING => 'Warning',
494:             E_COMPILE_WARNING => 'Warning', // currently unable to handle
495:             E_USER_WARNING => 'Warning',
496:             E_NOTICE => 'Notice',
497:             E_USER_NOTICE => 'Notice',
498:             E_STRICT => 'Strict standards',
499:             E_DEPRECATED => 'Deprecated',
500:             E_USER_WARNING => 'Deprecated',
501:         );
502: 
503:         $message = 'PHP ' . (isset($types[$severity]) ? $types[$severity] : 'Unknown error') . ": $message";
504:         $count = & self::$errorPanel->data["$message|$file|$line"];
505: 
506:         if ($count++) { // repeated error
507:             return NULL;
508: 
509:         } elseif (self::$productionMode) {
510:             self::log("$message in $file:$line", self::ERROR);
511:             return NULL;
512: 
513:         } else {
514:             $ok = self::fireLog(new ErrorException($message, 0, $severity, $file, $line), self::WARNING);
515:             return !self::isHtmlMode() || (!self::$bar && !$ok) ? FALSE : NULL;
516:         }
517: 
518:         return FALSE; // call normal error handler
519:     }
520: 
521: 
522: 
523:     /**
524:      * Handles exception thrown in __toString().
525:      * @param  Exception
526:      * @return void
527:      */
528:     public static function toStringException(Exception $exception)
529:     {
530:         if (self::$enabled) {
531:             self::_exceptionHandler($exception);
532:         } else {
533:             trigger_error($exception->getMessage(), E_USER_ERROR);
534:         }
535:     }
536: 
537: 
538: 
539:     /**
540:      * Starts catching potential errors/warnings.
541:      * @return void
542:      */
543:     public static function tryError()
544:     {
545:         if (!self::$enabled && self::$lastError === FALSE) {
546:             set_error_handler(array(__CLASS__, '_errorHandler'));
547:         }
548:         self::$lastError = NULL;
549:     }
550: 
551: 
552: 
553:     /**
554:      * Returns catched error/warning message.
555:      * @param  ErrorException  catched error
556:      * @return bool
557:      */
558:     public static function catchError(& $error)
559:     {
560:         if (!self::$enabled && self::$lastError !== FALSE) {
561:             restore_error_handler();
562:         }
563:         $error = self::$lastError;
564:         self::$lastError = FALSE;
565:         return (bool) $error;
566:     }
567: 
568: 
569: 
570:     /********************* useful tools ****************d*g**/
571: 
572: 
573: 
574:     /**
575:      * Dumps information about a variable in readable format.
576:      * @param  mixed  variable to dump
577:      * @param  bool   return output instead of printing it? (bypasses $productionMode)
578:      * @return mixed  variable itself or dump
579:      */
580:     public static function dump($var, $return = FALSE)
581:     {
582:         if (!$return && self::$productionMode) {
583:             return $var;
584:         }
585: 
586:         $output = "<pre class=\"nette-dump\">" . DebugHelpers::htmlDump($var) . "</pre>\n";
587: 
588:         if (!$return) {
589:             $trace = PHP_VERSION_ID < 50205 ? debug_backtrace() :debug_backtrace(FALSE);
590:             $i = DebugHelpers::findTrace($trace, 'dump') ? 1 : 0;
591:             if (isset($trace[$i]['file'], $trace[$i]['line']) && is_file($trace[$i]['file'])) {
592:                 $lines = file($trace[$i]['file']);
593:                 preg_match('#dump\((.*)\)#', $lines[$trace[$i]['line'] - 1], $m);
594:                 $output = substr_replace(
595:                     $output,
596:                     ' title="' . htmlspecialchars((isset($m[0]) ? "$m[0] \n" : '') . "in file {$trace[$i]['file']} on line {$trace[$i]['line']}") . '"',
597:                     4, 0);
598: 
599:                 if (self::$showLocation) {
600:                     $output = substr_replace(
601:                         $output,
602:                         ' <small>in ' . DebugHelpers::editorLink($trace[$i]['file'], $trace[$i]['line']) . ":{$trace[$i]['line']}</small>",
603:                         -8, 0);
604:                 }
605:             }
606:         }
607: 
608:         if (self::$consoleMode) {
609:             if (self::$consoleColors && substr(getenv('TERM'), 0, 5) === 'xterm') {
610:                 $output = preg_replace_callback('#<span class="php-(\w+)">|</span>#', create_function('$m', '
611:                     return "\\033[" . (isset($m[1], Debugger::$consoleColors[$m[1]]) ? Debugger::$consoleColors[$m[1]] : \'0\') . "m";
612:                 '), $output);
613:             }
614:             $output = htmlspecialchars_decode(strip_tags($output), ENT_QUOTES);
615:         }
616: 
617:         if ($return) {
618:             return $output;
619: 
620:         } else {
621:             echo $output;
622:             return $var;
623:         }
624:     }
625: 
626: 
627: 
628:     /**
629:      * Starts/stops stopwatch.
630:      * @param  string  name
631:      * @return float   elapsed seconds
632:      */
633:     public static function timer($name = NULL)
634:     {
635:         static $time = array();
636:         $now = microtime(TRUE);
637:         $delta = isset($time[$name]) ? $now - $time[$name] : 0;
638:         $time[$name] = $now;
639:         return $delta;
640:     }
641: 
642: 
643: 
644:     /**
645:      * Dumps information about a variable in Nette Debug Bar.
646:      * @param  mixed  variable to dump
647:      * @param  string optional title
648:      * @return mixed  variable itself
649:      */
650:     public static function barDump($var, $title = NULL)
651:     {
652:         if (!self::$productionMode) {
653:             $dump = array();
654:             foreach ((is_array($var) ? $var : array('' => $var)) as $key => $val) {
655:                 $dump[$key] = DebugHelpers::clickableDump($val);
656:             }
657:             self::$dumpPanel->data[] = array('title' => $title, 'dump' => $dump);
658:         }
659:         return $var;
660:     }
661: 
662: 
663: 
664:     /**
665:      * Sends message to FireLogger console.
666:      * @param  mixed   message to log
667:      * @return bool    was successful?
668:      */
669:     public static function fireLog($message)
670:     {
671:         if (!self::$productionMode) {
672:             return self::$fireLogger->log($message);
673:         }
674:     }
675: 
676: 
677: 
678:     private static function isHtmlMode()
679:     {
680:         return !self::$ajaxDetected && !self::$consoleMode
681:             && !preg_match('#^Content-Type: (?!text/html)#im', implode("\n", headers_list()));
682:     }
683: 
684: 
685: 
686:     /** @deprecated */
687:     public static function addPanel(IBarPanel $panel, $id = NULL)
688:     {
689:         return self::$bar->addPanel($panel, $id);
690:     }
691: 
692: }
693: 
Nette Framework 2.0.5 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.7.0