Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • Bar
  • BlueScreen
  • Debugger
  • Dumper
  • FireLogger
  • Helpers
  • Logger
  • OutputDebugger

Interfaces

  • IBarPanel
  • ILogger
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Tracy (http://tracy.nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Tracy;
  9: 
 10: use Tracy;
 11: 
 12: 
 13: /**
 14:  * Rendering helpers for Debugger.
 15:  *
 16:  * @author     David Grudl
 17:  */
 18: class Helpers
 19: {
 20: 
 21:     /**
 22:      * Returns HTML link to editor.
 23:      * @return string
 24:      */
 25:     public static function editorLink($file, $line = NULL)
 26:     {
 27:         if ($editor = self::editorUri($file, $line)) {
 28:             $dir = dirname(strtr($file, '/', DIRECTORY_SEPARATOR));
 29:             $base = isset($_SERVER['SCRIPT_FILENAME'])
 30:                 ? dirname(dirname(strtr($_SERVER['SCRIPT_FILENAME'], '/', DIRECTORY_SEPARATOR)))
 31:                 : dirname($dir);
 32:             if (substr($dir, 0, strlen($base)) === $base) {
 33:                 $dir = '...' . substr($dir, strlen($base));
 34:             }
 35:             return self::formatHtml('<a href="%" title="%">%<b>%</b>%</a>',
 36:                 $editor,
 37:                 $file . ($line ? ":$line" : ''),
 38:                 rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR,
 39:                 basename($file),
 40:                 $line ? ":$line" : ''
 41:             );
 42:         } else {
 43:             return self::formatHtml('<span>%</span>', $file . ($line ? ":$line" : ''));
 44:         }
 45:     }
 46: 
 47: 
 48:     /**
 49:      * Returns link to editor.
 50:      * @return string
 51:      */
 52:     public static function editorUri($file, $line = NULL)
 53:     {
 54:         if (Debugger::$editor && $file && is_file($file)) {
 55:             return strtr(Debugger::$editor, array('%file' => rawurlencode($file), '%line' => $line ? (int) $line : ''));
 56:         }
 57:     }
 58: 
 59: 
 60:     public static function formatHtml($mask)
 61:     {
 62:         $args = func_get_args();
 63:         return preg_replace_callback('#%#', function() use (& $args, & $count) {
 64:             return htmlspecialchars($args[++$count], ENT_IGNORE | ENT_QUOTES, 'UTF-8');
 65:         }, $mask);
 66:     }
 67: 
 68: 
 69:     public static function findTrace(array $trace, $method, & $index = NULL)
 70:     {
 71:         $m = explode('::', $method);
 72:         foreach ($trace as $i => $item) {
 73:             if (isset($item['function']) && $item['function'] === end($m)
 74:                 && isset($item['class']) === isset($m[1])
 75:                 && (!isset($item['class']) || $item['class'] === $m[0] || $m[0] === '*' || is_subclass_of($item['class'], $m[0]))
 76:             ) {
 77:                 $index = $i;
 78:                 return $item;
 79:             }
 80:         }
 81:     }
 82: 
 83: 
 84:     /** @internal */
 85:     public static function fixStack($exception)
 86:     {
 87:         if (function_exists('xdebug_get_function_stack')) {
 88:             $stack = array();
 89:             foreach (array_slice(array_reverse(xdebug_get_function_stack()), 2, -1) as $row) {
 90:                 $frame = array(
 91:                     'file' => $row['file'],
 92:                     'line' => $row['line'],
 93:                     'function' => isset($row['function']) ? $row['function'] : '*unknown*',
 94:                     'args' => array(),
 95:                 );
 96:                 if (!empty($row['class'])) {
 97:                     $frame['type'] = isset($row['type']) && $row['type'] === 'dynamic' ? '->' : '::';
 98:                     $frame['class'] = $row['class'];
 99:                 }
100:                 $stack[] = $frame;
101:             }
102:             $ref = new \ReflectionProperty('Exception', 'trace');
103:             $ref->setAccessible(TRUE);
104:             $ref->setValue($exception, $stack);
105:         }
106:         return $exception;
107:     }
108: 
109: 
110:     /** @internal */
111:     public static function fixEncoding($s)
112:     {
113:         if (PHP_VERSION_ID < 50400) {
114:             return @iconv('UTF-16', 'UTF-8//IGNORE', iconv('UTF-8', 'UTF-16//IGNORE', $s)); // intentionally @
115:         } else {
116:             return htmlspecialchars_decode(htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
117:         }
118:     }
119: 
120: 
121:     /** @internal */
122:     public static function errorTypeToString($type)
123:     {
124:         $types = array(
125:             E_ERROR => 'Fatal Error',
126:             E_USER_ERROR => 'User Error',
127:             E_RECOVERABLE_ERROR => 'Recoverable Error',
128:             E_CORE_ERROR => 'Core Error',
129:             E_COMPILE_ERROR => 'Compile Error',
130:             E_PARSE => 'Parse Error',
131:             E_WARNING => 'Warning',
132:             E_CORE_WARNING => 'Core Warning',
133:             E_COMPILE_WARNING => 'Compile Warning',
134:             E_USER_WARNING => 'User Warning',
135:             E_NOTICE => 'Notice',
136:             E_USER_NOTICE => 'User Notice',
137:             E_STRICT => 'Strict standards',
138:             E_DEPRECATED => 'Deprecated',
139:             E_USER_DEPRECATED => 'User Deprecated',
140:         );
141:         return isset($types[$type]) ? $types[$type] : 'Unknown error';
142:     }
143: 
144: 
145:     /** @internal */
146:     public static function getSource()
147:     {
148:         if (isset($_SERVER['REQUEST_URI'])) {
149:             return (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://')
150:                 . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')
151:                 . $_SERVER['REQUEST_URI'];
152:         } else {
153:             return empty($_SERVER['argv']) ? 'CLI' : 'CLI: ' . implode(' ', $_SERVER['argv']);
154:         }
155:     }
156: 
157: }
158: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0