Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
allow_failures:
- stage: Static Analysis (informative)
- stage: Code Coverage
- php: 7.4snapshot


sudo: false
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----

Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/Nette/Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static function renderLatteError(?\Throwable $e): ?array
. BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine)
. '</div></pre>',
];

} 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
Expand Down Expand Up @@ -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] . '('),
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Bar/assets/bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ body#tracy-debug { /* in popup window */
}

#tracy-debug tr:nth-child(2n) td {
background: #F7F0CB;
background: #00000005;
}

#tracy-debug td,
Expand Down
62 changes: 45 additions & 17 deletions src/Tracy/BlueScreen/BlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"#',
'<i>$0</i>',
$messageHtml
);
$messageHtml = preg_replace_callback(
'#\w+\\\\[\w\\\\]+\w#',
function ($m) {
return class_exists($m[0], false) || interface_exists($m[0], false)
? '<a href="' . Helpers::escapeHtml(Helpers::editorUri((new \ReflectionClass($m[0]))->getFileName())) . '">' . $m[0] . '</a>'
: $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
Expand Down Expand Up @@ -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"#',
'<i>$0</i>',
$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 '<a href="' . Helpers::escapeHtml(Helpers::editorUri($r->getFileName(), $r->getStartLine())) . '">' . $m[0] . '</a>';
},
$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])
? '<a href="' . Helpers::escapeHtml(Helpers::editorUri($m[1], isset($m[2]) ? (int) $m[2] : null)) . '">' . $m[0] . '</a>'
: $m[0];
},
$msg
);

return $msg;
}
}
2 changes: 2 additions & 0 deletions src/Tracy/BlueScreen/assets/content.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : '';
<?php endforeach ?>


<?php if ($showEnvironment):?>
<div class="panel">
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Environment</a></h2>

Expand Down Expand Up @@ -271,6 +272,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : '';
echo preg_replace('#^.+<body>|</body>.+\z#s', '', $phpinfo) ?>
</div>
</div></div>
<?php endif ?>


<?php if (PHP_SAPI === 'cli'): ?>
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Debugger/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/Tracy/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Tracy/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
Expand Down Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Tracy/Logger/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/expected/Debugger.E_ERROR.html.expect
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@



<div class="panel">
<div class="panel">
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Environment</a></h2>

<div class="tracy-collapsed inner">
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/expected/Debugger.error-in-eval.expect
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@



<div class="panel">
<div class="panel">
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Environment</a></h2>

<div class="tracy-collapsed inner">
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/expected/Debugger.exception.html.expect
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@



<div class="panel">
<div class="panel">
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Environment</a></h2>

<div class="tracy-collapsed inner">
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/expected/Debugger.strict.html.expect
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@



<div class="panel">
<div class="panel">
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Environment</a></h2>

<div class="tracy-collapsed inner">
Expand Down