diff --git a/.travis.yml b/.travis.yml index e3ec86b86..e25381f95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,6 +70,7 @@ jobs: allow_failures: - stage: Static Analysis (informative) - stage: Code Coverage + - php: 7.4snapshot sudo: false diff --git a/readme.md b/readme.md index aad616e70..d16a668fc 100644 --- a/readme.md +++ b/readme.md @@ -384,6 +384,22 @@ services: ``` +nginx +----- + +If Tracy does not work on nginx, it is probably misconfigured. If there is something like + +```nginx +try_files $uri $uri/ /index.php; +``` + +change it to + +```nginx +try_files $uri $uri/ /index.php$is_args$args; +``` + + Ports ----- diff --git a/src/Bridges/Nette/Bridge.php b/src/Bridges/Nette/Bridge.php index da9c04f27..423b04f76 100644 --- a/src/Bridges/Nette/Bridge.php +++ b/src/Bridges/Nette/Bridge.php @@ -47,7 +47,6 @@ public static function renderLatteError(?\Throwable $e): ?array . BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine) . '', ]; - } elseif ($e && strpos($file = $e->getFile(), '.latte--')) { $lines = file($file); if (preg_match('#// source: (\S+\.latte)#', $lines[1], $m) && @is_file($m[1])) { // @ - may trigger error @@ -94,7 +93,8 @@ public static function renderMemberAccessException(?\Throwable $e): ?array 'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', '->' . $m[1], '->' . $m[2]), 'label' => 'fix it', ]; - } elseif (preg_match('#Call to undefined (static )?method .+::(\w+)\(\), did you mean (\w+)\(\)?#A', $e->getMessage(), $m)) { + } + if (preg_match('#Call to undefined (static )?method .+::(\w+)\(\), did you mean (\w+)\(\)?#A', $e->getMessage(), $m)) { $operator = $m[1] ? '::' : '->'; return [ 'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', $operator . $m[2] . '(', $operator . $m[3] . '('), diff --git a/src/Tracy/Bar/assets/bar.css b/src/Tracy/Bar/assets/bar.css index 990bff727..7ef98db5d 100644 --- a/src/Tracy/Bar/assets/bar.css +++ b/src/Tracy/Bar/assets/bar.css @@ -95,7 +95,7 @@ body#tracy-debug { /* in popup window */ } #tracy-debug tr:nth-child(2n) td { - background: #F7F0CB; + background: #00000005; } #tracy-debug td, diff --git a/src/Tracy/BlueScreen/BlueScreen.php b/src/Tracy/BlueScreen/BlueScreen.php index abcf63812..1bc09d551 100644 --- a/src/Tracy/BlueScreen/BlueScreen.php +++ b/src/Tracy/BlueScreen/BlueScreen.php @@ -113,23 +113,8 @@ public function renderToFile(\Throwable $exception, string $file): bool private function renderTemplate(\Throwable $exception, string $template, $toScreen = true): void { - $messageHtml = Dumper::encodeString((string) $exception->getMessage(), self::MAX_MESSAGE_LENGTH); - $messageHtml = htmlspecialchars($messageHtml, ENT_SUBSTITUTE, 'UTF-8'); - $messageHtml = preg_replace( - '#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\\")*\S"#', - '$0', - $messageHtml - ); - $messageHtml = preg_replace_callback( - '#\w+\\\\[\w\\\\]+\w#', - function ($m) { - return class_exists($m[0], false) || interface_exists($m[0], false) - ? '' . $m[0] . '' - : $m[0]; - }, - $messageHtml - ); - + $showEnvironment = strpos($exception->getMessage(), 'Allowed memory size') === false; + $messageHtml = $this->formatMessage($exception); $info = array_filter($this->info); $source = Helpers::getSource(); $title = $exception instanceof \ErrorException @@ -384,4 +369,47 @@ public function getDumper(): \Closure ]); }; } + + + private function formatMessage(\Throwable $exception): string + { + $msg = Dumper::encodeString((string) $exception->getMessage(), self::MAX_MESSAGE_LENGTH); + $msg = htmlspecialchars($msg, ENT_SUBSTITUTE, 'UTF-8'); + + // highlight 'string' + $msg = preg_replace( + '#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\\")*\S"#', + '$0', + $msg + ); + + // clickable class & methods + $msg = preg_replace_callback( + '#(\w+\\\\[\w\\\\]+\w)(?:::(\w+))?#', + function ($m) { + if (isset($m[2]) && method_exists($m[1], $m[2])) { + $r = new \ReflectionMethod($m[1], $m[2]); + } elseif (class_exists($m[1], false) || interface_exists($m[1], false)) { + $r = new \ReflectionClass($m[1]); + } else { + return $m[0]; + } + return '' . $m[0] . ''; + }, + $msg + ); + + // clickable file name + $msg = preg_replace_callback( + '#([\w\\\\/.:-]+\.(?:php|phpt|phtml|latte|neon))(?|:(\d+)| on line (\d+))?#', + function ($m) { + return @is_file($m[1]) + ? '' . $m[0] . '' + : $m[0]; + }, + $msg + ); + + return $msg; + } } diff --git a/src/Tracy/BlueScreen/assets/content.phtml b/src/Tracy/BlueScreen/assets/content.phtml index d039539ba..5b2c78ed0 100644 --- a/src/Tracy/BlueScreen/assets/content.phtml +++ b/src/Tracy/BlueScreen/assets/content.phtml @@ -207,6 +207,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : ''; +

Environment

@@ -271,6 +272,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : ''; echo preg_replace('#^.+|.+\z#s', '', $phpinfo) ?>
+ diff --git a/src/Tracy/Debugger/Debugger.php b/src/Tracy/Debugger/Debugger.php index 09150eec7..2016081b2 100644 --- a/src/Tracy/Debugger/Debugger.php +++ b/src/Tracy/Debugger/Debugger.php @@ -27,7 +27,7 @@ class Debugger public const COOKIE_SECRET = 'tracy-debug'; - /** @var bool in production mode is suppressed any debugging output */ + /** @var bool|null in production mode is suppressed any debugging output */ public static $productionMode = self::DETECT; /** @var bool whether to display debug bar in development mode */ diff --git a/src/Tracy/Dumper/Dumper.php b/src/Tracy/Dumper/Dumper.php index fc2ea1b0d..0d574cfed 100644 --- a/src/Tracy/Dumper/Dumper.php +++ b/src/Tracy/Dumper/Dumper.php @@ -179,6 +179,7 @@ private function asHtml($var): string ' title="%in file % on line %" data-tracy-href="%"', "$code\n", $file, $line, Helpers::editorUri($file, $line) ) : null; + $options = []; if (is_array($this->snapshot)) { $options[self::SNAPSHOT] = &$this->snapshot; } diff --git a/src/Tracy/Helpers.php b/src/Tracy/Helpers.php index a61752751..a43c3d441 100644 --- a/src/Tracy/Helpers.php +++ b/src/Tracy/Helpers.php @@ -212,7 +212,7 @@ public static function improveException(\Throwable $e): void $ref->setAccessible(true); $ref->setValue($e, $message); $e->tracyAction = [ - 'link' => self::editorUri($e->getFile(), $e->getLine(), 'fix', $replace[0], $replace[1]), + 'link' => self::editorUri($e->getFile(), $e->getLine(), 'fix', $replace[0] ?? '', $replace[1] ?? ''), 'label' => 'fix it', ]; } @@ -242,14 +242,14 @@ public static function guessClassFile(string $class): ?string $segments = explode(DIRECTORY_SEPARATOR, $class); $res = null; $max = 0; - foreach (get_declared_classes() as $class) { - $parts = explode(DIRECTORY_SEPARATOR, $class); + foreach (get_declared_classes() as $declaredClass) { + $parts = explode(DIRECTORY_SEPARATOR, $declaredClass); foreach ($parts as $i => $part) { if ($part !== $segments[$i] ?? null) { break; } } - if ($i > $max && ($file = (new \ReflectionClass($class))->getFileName())) { + if (isset($i) && $i > $max && ($file = (new \ReflectionClass($declaredClass))->getFileName())) { $max = $i; $res = array_merge(array_slice(explode(DIRECTORY_SEPARATOR, $file), 0, $i - count($parts)), array_slice($segments, $i)); $res = implode(DIRECTORY_SEPARATOR, $res) . '.php'; diff --git a/src/Tracy/Logger/Logger.php b/src/Tracy/Logger/Logger.php index 6f926ce66..d6aec5429 100644 --- a/src/Tracy/Logger/Logger.php +++ b/src/Tracy/Logger/Logger.php @@ -27,7 +27,7 @@ class Logger implements ILogger /** @var mixed interval for sending email is 2 days */ public $emailSnooze = '2 days'; - /** @var callable handler for sending emails */ + /** @var callable|null handler for sending emails */ public $mailer; /** @var BlueScreen|null */ diff --git a/tests/Tracy/expected/Debugger.E_ERROR.html.expect b/tests/Tracy/expected/Debugger.E_ERROR.html.expect index 987e85150..4ba155742 100644 --- a/tests/Tracy/expected/Debugger.E_ERROR.html.expect +++ b/tests/Tracy/expected/Debugger.E_ERROR.html.expect @@ -159,7 +159,7 @@ -
+

Environment

diff --git a/tests/Tracy/expected/Debugger.error-in-eval.expect b/tests/Tracy/expected/Debugger.error-in-eval.expect index ef8e08371..6c92411f4 100644 --- a/tests/Tracy/expected/Debugger.error-in-eval.expect +++ b/tests/Tracy/expected/Debugger.error-in-eval.expect @@ -130,7 +130,7 @@ -
+

Environment

diff --git a/tests/Tracy/expected/Debugger.exception.html.expect b/tests/Tracy/expected/Debugger.exception.html.expect index 36283fdd4..0bea04602 100644 --- a/tests/Tracy/expected/Debugger.exception.html.expect +++ b/tests/Tracy/expected/Debugger.exception.html.expect @@ -126,7 +126,7 @@ -
+

Environment

diff --git a/tests/Tracy/expected/Debugger.strict.html.expect b/tests/Tracy/expected/Debugger.strict.html.expect index 5314b7337..528aeefa6 100644 --- a/tests/Tracy/expected/Debugger.strict.html.expect +++ b/tests/Tracy/expected/Debugger.strict.html.expect @@ -133,7 +133,7 @@ -