From 57d7ec8066842feae20eaff5343fb6c6f1aaea17 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 9 Oct 2017 18:33:45 +0200 Subject: [PATCH 01/21] opened 2.7-dev --- composer.json | 2 +- readme.md | 1 + src/Tracy/Debugger/Debugger.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8168015da..d06ea6f25 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "2.7-dev" } } } diff --git a/readme.md b/readme.md index 9b1869783..242a192dc 100644 --- a/readme.md +++ b/readme.md @@ -42,6 +42,7 @@ Alternatively, you can download the whole package or [tracy.phar](https://github | Tracy | PHP | compatible with browsers |-----------|---------------|---------- +| Tracy 2.7 | PHP 7.1 – 7.3 | Chrome 49+, Firefox 45+, MS Edge 14+, Safari 10+ and iOS Safari 10.2+ | Tracy 2.6 | PHP 7.1 – 7.3 | Chrome 49+, Firefox 45+, MS Edge 14+, Safari 10+ and iOS Safari 10.2+ | Tracy 2.5 | PHP 5.4.4 – 7.3 | Chrome 49+, Firefox 45+, MS Edge 12+, Safari 10+ and iOS Safari 10.2+ | Tracy 2.4 | PHP 5.4.4 – 7.2 | Chrome 29+, Firefox 28+, IE 11+ (except AJAX), MS Edge 12+, Safari 9+ and iOS Safari 9.2+ diff --git a/src/Tracy/Debugger/Debugger.php b/src/Tracy/Debugger/Debugger.php index 8571fd5dd..483ab2f6e 100644 --- a/src/Tracy/Debugger/Debugger.php +++ b/src/Tracy/Debugger/Debugger.php @@ -17,7 +17,7 @@ */ class Debugger { - public const VERSION = '2.6.4'; + public const VERSION = '2.7-dev'; /** server modes for Debugger::enable() */ public const From 250c6224926c85199aca34a441858b96bbda2209 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 18 Feb 2019 16:07:58 +0100 Subject: [PATCH 02/21] bar: replaced attribute 'rel' with 'data-tracy-action' for closing & open-to-window links --- src/Tracy/Bar/assets/bar.js | 10 +++++----- src/Tracy/Bar/assets/bar.phtml | 2 +- src/Tracy/Bar/assets/panels.phtml | 4 ++-- tests/Tracy/expected/Debugger.barDump().expect | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Tracy/Bar/assets/bar.js b/src/Tracy/Bar/assets/bar.js index 1efffe2d0..3c25eb79a 100644 --- a/src/Tracy/Bar/assets/bar.js +++ b/src/Tracy/Bar/assets/bar.js @@ -62,9 +62,9 @@ elem.querySelectorAll('.tracy-icons a').forEach((link) => { link.addEventListener('click', (e) => { - if (link.rel === 'close') { + if (link.dataset.tracyAction === 'close') { this.toPeek(); - } else if (link.rel === 'window') { + } else if (link.dataset.tracyAction === 'window') { this.toWindow(); } e.preventDefault(); @@ -258,7 +258,7 @@ initTabs(elem) { elem.querySelectorAll('a').forEach((link) => { link.addEventListener('click', (e) => { - if (link.rel === 'close') { + if (link.dataset.tracyAction === 'close') { this.close(); } else if (link.rel) { @@ -284,7 +284,7 @@ }); link.addEventListener('mouseenter', (e) => { - if (e.buttons || !link.rel || link.rel === 'close' || elem.classList.contains('tracy-dragged')) { + if (e.buttons || !link.rel || elem.classList.contains('tracy-dragged')) { return; } @@ -311,7 +311,7 @@ link.addEventListener('mouseleave', () => { clearTimeout(this.displayTimeout); - if (link.rel && link.rel !== 'close' && !elem.classList.contains('tracy-dragged')) { + if (link.rel && !elem.classList.contains('tracy-dragged')) { Debug.panels[link.rel].blur(); } }); diff --git a/src/Tracy/Bar/assets/bar.phtml b/src/Tracy/Bar/assets/bar.phtml index baac001ba..8fa3a8641 100644 --- a/src/Tracy/Bar/assets/bar.phtml +++ b/src/Tracy/Bar/assets/bar.phtml @@ -32,6 +32,6 @@ namespace Tracy; -
  • ×
  • +
  • ×
  • diff --git a/src/Tracy/Bar/assets/panels.phtml b/src/Tracy/Bar/assets/panels.phtml index 77183bd75..b993aae80 100644 --- a/src/Tracy/Bar/assets/panels.phtml +++ b/src/Tracy/Bar/assets/panels.phtml @@ -18,8 +18,8 @@ use Tracy\Helpers; $icons = '
    - ¤ - × + ¤ + ×
    '; diff --git a/tests/Tracy/expected/Debugger.barDump().expect b/tests/Tracy/expected/Debugger.barDump().expect index 22bf7aff2..7a5a6a8bd 100644 --- a/tests/Tracy/expected/Debugger.barDump().expect +++ b/tests/Tracy/expected/Debugger.barDump().expect @@ -17,6 +17,6 @@ in file %a% on line %d%" data-tracy-href="editor:%a%"> - ¤ - × + ¤ + × From e3996eb2136f808e6777d6aafa928c3e08ce9601 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 3 Mar 2019 19:35:51 +0100 Subject: [PATCH 03/21] Bluescreen: footer is always on bottom --- src/Tracy/BlueScreen/assets/bluescreen.css | 20 ++++++++++++++++--- src/Tracy/BlueScreen/assets/content.phtml | 20 +++++++++---------- .../expected/Debugger.E_ERROR.html.expect | 18 ++++++++--------- .../expected/Debugger.error-in-eval.expect | 18 ++++++++--------- .../expected/Debugger.exception.html.expect | 18 ++++++++--------- .../expected/Debugger.strict.html.expect | 18 ++++++++--------- 6 files changed, 63 insertions(+), 49 deletions(-) diff --git a/src/Tracy/BlueScreen/assets/bluescreen.css b/src/Tracy/BlueScreen/assets/bluescreen.css index 5befb8070..8afa1896d 100644 --- a/src/Tracy/BlueScreen/assets/bluescreen.css +++ b/src/Tracy/BlueScreen/assets/bluescreen.css @@ -36,6 +36,20 @@ padding: 3px; } +.tracy-bs-main { + display: flex; + flex-direction: column; + min-height: 100vh; +} + +.tracy-bs-main.tracy-collapsed { + display: none; +} + +#tracy-bs div.panel:last-of-type { + flex: 1; +} + #tracy-bs-error { background: #CD1818; color: white; @@ -153,7 +167,7 @@ list-style: none; } -#tracy-bs-logo a { +#tracy-bs .footer-logo a { position: absolute; bottom: 0; right: 0; @@ -165,8 +179,8 @@ margin: 0; } -#tracy-bs-logo a:hover, -#tracy-bs-logo a:focus { +#tracy-bs .footer-logo a:hover, +#tracy-bs .footer-logo a:focus { opacity: 1; transition: opacity 0.1s; } diff --git a/src/Tracy/BlueScreen/assets/content.phtml b/src/Tracy/BlueScreen/assets/content.phtml index 2a65aeab1..4879b6f29 100644 --- a/src/Tracy/BlueScreen/assets/content.phtml +++ b/src/Tracy/BlueScreen/assets/content.phtml @@ -28,7 +28,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : ''; ?>
    -
    +
    getMessage()): ?>

    @@ -357,15 +357,15 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : '';
    - - - - +
    >
    diff --git a/tests/Tracy/expected/Debugger.E_ERROR.html.expect b/tests/Tracy/expected/Debugger.E_ERROR.html.expect index d4e2aa276..40df02dc7 100644 --- a/tests/Tracy/expected/Debugger.E_ERROR.html.expect +++ b/tests/Tracy/expected/Debugger.E_ERROR.html.expect @@ -15,7 +15,7 @@
    -
    +

    Error

    @@ -211,14 +211,14 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • CLI%a?%
    • +
    • PHP %a%
    + +
    diff --git a/tests/Tracy/expected/Debugger.error-in-eval.expect b/tests/Tracy/expected/Debugger.error-in-eval.expect index 2cefe40e8..522cc3b2f 100644 --- a/tests/Tracy/expected/Debugger.error-in-eval.expect +++ b/tests/Tracy/expected/Debugger.error-in-eval.expect @@ -15,7 +15,7 @@
    -
    +

    User Error

    @@ -182,14 +182,14 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • CLI%a?%
    • +
    • PHP %a%
    + +
    diff --git a/tests/Tracy/expected/Debugger.exception.html.expect b/tests/Tracy/expected/Debugger.exception.html.expect index 8288a5848..48aac140b 100644 --- a/tests/Tracy/expected/Debugger.exception.html.expect +++ b/tests/Tracy/expected/Debugger.exception.html.expect @@ -15,7 +15,7 @@
    -
    +

    Exception #123

    @@ -178,14 +178,14 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • CLI%a?%
    • +
    • PHP %a%
    + +
    diff --git a/tests/Tracy/expected/Debugger.strict.html.expect b/tests/Tracy/expected/Debugger.strict.html.expect index 7177e07e3..ca53c46e4 100644 --- a/tests/Tracy/expected/Debugger.strict.html.expect +++ b/tests/Tracy/expected/Debugger.strict.html.expect @@ -15,7 +15,7 @@
    -
    +

    Notice

    @@ -185,14 +185,14 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • CLI%a?%
    • +
    • PHP %a%
    + +
    From ee22c3ced6e335936beadaa74b23c091020d4bf9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 9 Mar 2019 01:25:47 +0100 Subject: [PATCH 04/21] BlueScreen: removed source from footer --- src/Tracy/BlueScreen/BlueScreen.php | 1 - src/Tracy/BlueScreen/assets/content.phtml | 2 -- tests/Tracy/expected/Debugger.E_ERROR.html.expect | 1 - tests/Tracy/expected/Debugger.error-in-eval.expect | 1 - tests/Tracy/expected/Debugger.exception.html.expect | 1 - tests/Tracy/expected/Debugger.strict.html.expect | 1 - 6 files changed, 7 deletions(-) diff --git a/src/Tracy/BlueScreen/BlueScreen.php b/src/Tracy/BlueScreen/BlueScreen.php index 429b6081a..671ae9147 100644 --- a/src/Tracy/BlueScreen/BlueScreen.php +++ b/src/Tracy/BlueScreen/BlueScreen.php @@ -116,7 +116,6 @@ private function renderTemplate(\Throwable $exception, string $template, $toScre ); $info = array_filter($this->info); $source = Helpers::getSource(); - $sourceIsUrl = preg_match('#^https?://#', $source); $title = $exception instanceof \ErrorException ? Helpers::errorTypeToString($exception->getSeverity()) : Helpers::getClass($exception); diff --git a/src/Tracy/BlueScreen/assets/content.phtml b/src/Tracy/BlueScreen/assets/content.phtml index 4879b6f29..80b6c79ec 100644 --- a/src/Tracy/BlueScreen/assets/content.phtml +++ b/src/Tracy/BlueScreen/assets/content.phtml @@ -12,7 +12,6 @@ * @param array $info * @param string $title * @param string $source - * @param bool $sourceIsUrl * @param array $lastError * @param array $httpHeaders * @param callable $dump @@ -361,7 +360,6 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : ''; diff --git a/tests/Tracy/expected/Debugger.E_ERROR.html.expect b/tests/Tracy/expected/Debugger.E_ERROR.html.expect index 40df02dc7..987e85150 100644 --- a/tests/Tracy/expected/Debugger.E_ERROR.html.expect +++ b/tests/Tracy/expected/Debugger.E_ERROR.html.expect @@ -215,7 +215,6 @@
    • %a%️
    • Report generated at %a%
    • -
    • CLI%a?%
    • PHP %a%
    diff --git a/tests/Tracy/expected/Debugger.error-in-eval.expect b/tests/Tracy/expected/Debugger.error-in-eval.expect index 522cc3b2f..ef8e08371 100644 --- a/tests/Tracy/expected/Debugger.error-in-eval.expect +++ b/tests/Tracy/expected/Debugger.error-in-eval.expect @@ -186,7 +186,6 @@
    • %a%️
    • Report generated at %a%
    • -
    • CLI%a?%
    • PHP %a%
    diff --git a/tests/Tracy/expected/Debugger.exception.html.expect b/tests/Tracy/expected/Debugger.exception.html.expect index 48aac140b..36283fdd4 100644 --- a/tests/Tracy/expected/Debugger.exception.html.expect +++ b/tests/Tracy/expected/Debugger.exception.html.expect @@ -182,7 +182,6 @@
    • %a%️
    • Report generated at %a%
    • -
    • CLI%a?%
    • PHP %a%
    diff --git a/tests/Tracy/expected/Debugger.strict.html.expect b/tests/Tracy/expected/Debugger.strict.html.expect index ca53c46e4..5314b7337 100644 --- a/tests/Tracy/expected/Debugger.strict.html.expect +++ b/tests/Tracy/expected/Debugger.strict.html.expect @@ -189,7 +189,6 @@
    • %a%️
    • Report generated at %a%
    • -
    • CLI%a?%
    • PHP %a%
    From 1d8b7802aa3589b7de18b635135757de3cdad042 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 16 Jul 2019 00:44:35 +0200 Subject: [PATCH 05/21] Logger: added priority to exception file name --- src/Tracy/Logger/Logger.php | 6 +++--- tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt | 2 +- tests/Tracy/Logger.log().phpt | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Tracy/Logger/Logger.php b/src/Tracy/Logger/Logger.php index 4dea99014..7d06d9d7f 100644 --- a/src/Tracy/Logger/Logger.php +++ b/src/Tracy/Logger/Logger.php @@ -61,7 +61,7 @@ public function log($message, $level = self::INFO) } $exceptionFile = $message instanceof \Throwable - ? $this->getExceptionFile($message) + ? $this->getExceptionFile($message, $level) : null; $line = static::formatLogLine($message, $exceptionFile); $file = $this->directory . '/' . strtolower($level ?: self::INFO) . '.log'; @@ -119,7 +119,7 @@ public static function formatLogLine($message, string $exceptionFile = null): st } - public function getExceptionFile(\Throwable $exception): string + public function getExceptionFile(\Throwable $exception, string $level = self::EXCEPTION): string { while ($exception) { $data[] = [ @@ -135,7 +135,7 @@ public function getExceptionFile(\Throwable $exception): string return $dir . $file; } } - return $dir . 'exception--' . @date('Y-m-d--H-i') . "--$hash.html"; // @ timezone may not be set + return $dir . $level . '--' . @date('Y-m-d--H-i') . "--$hash.html"; // @ timezone may not be set } diff --git a/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt b/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt index a505a6c72..560c4b968 100644 --- a/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt +++ b/tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt @@ -19,5 +19,5 @@ Debugger::$logSeverity = E_NOTICE; $variable = $missingVariable; -Assert::count(1, glob(TEMP_DIR . '/exception*.html')); +Assert::count(1, glob(TEMP_DIR . '/error*.html')); Assert::count(1, glob(TEMP_DIR . '/error.log')); diff --git a/tests/Tracy/Logger.log().phpt b/tests/Tracy/Logger.log().phpt index c8eee25ec..7dfa867b1 100644 --- a/tests/Tracy/Logger.log().phpt +++ b/tests/Tracy/Logger.log().phpt @@ -32,23 +32,23 @@ test(function () { test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_ERROR, __FILE__, __LINE__), 'c'); - Assert::match('[%a%] Fatal Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/c.log')); + Assert::match('[%a%] Fatal Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ c-%a%.html', file_get_contents($logger->directory . '/c.log')); }); test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_WARNING, __FILE__, __LINE__), 'd'); - Assert::match('[%a%] Warning: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/d.log')); + Assert::match('[%a%] Warning: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ d-%a%.html', file_get_contents($logger->directory . '/d.log')); }); test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_COMPILE_ERROR, __FILE__, __LINE__), 'e'); - Assert::match('[%a%] Compile Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/e.log')); + Assert::match('[%a%] Compile Error: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ e-%a%.html', file_get_contents($logger->directory . '/e.log')); }); test(function () { $logger = new Logger(TEMP_DIR); $logger->log(new ErrorException('Msg', 0, E_NOTICE, __FILE__, __LINE__), 'f'); - Assert::match('[%a%] Notice: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ exception-%a%.html', file_get_contents($logger->directory . '/f.log')); + Assert::match('[%a%] Notice: Msg in %a%Logger.log().phpt:%d% @ CLI (PID: %d%): %a% @@ f-%a%.html', file_get_contents($logger->directory . '/f.log')); }); From fdaefa26ce590020c031213830268b601ddd4e0a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 11 Mar 2019 23:57:52 +0100 Subject: [PATCH 06/21] TracyExtension: added getConfigSchema() --- composer.json | 7 +++- src/Bridges/Nette/TracyExtension.php | 57 +++++++++++++++------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/composer.json b/composer.json index d06ea6f25..eebbafc97 100644 --- a/composer.json +++ b/composer.json @@ -20,11 +20,14 @@ "ext-json": "*" }, "require-dev": { - "nette/utils": "^2.4 || ^3.0", - "nette/di": "^2.4 || ~3.0.0", + "nette/utils": "^3.0", + "nette/di": "^3.0", "nette/tester": "^2.2", "psr/log": "^1.0" }, + "conflict": { + "nette/di": "<3.0" + }, "suggest": { "https://nette.org/donate": "Please support Tracy via a donation" }, diff --git a/src/Bridges/Nette/TracyExtension.php b/src/Bridges/Nette/TracyExtension.php index 6b82df021..b2d9102fa 100644 --- a/src/Bridges/Nette/TracyExtension.php +++ b/src/Bridges/Nette/TracyExtension.php @@ -10,6 +10,7 @@ namespace Tracy\Bridges\Nette; use Nette; +use Nette\Schema\Expect; use Tracy; @@ -18,26 +19,6 @@ */ class TracyExtension extends Nette\DI\CompilerExtension { - public $defaults = [ - 'email' => null, - 'fromEmail' => null, - 'logSeverity' => null, - 'editor' => null, - 'browser' => null, - 'errorTemplate' => null, - 'strictMode' => null, - 'showBar' => null, - 'maxLen' => null, - 'maxLength' => null, - 'maxDepth' => null, - 'showLocation' => null, - 'scream' => null, - 'bar' => [], // of class name - 'blueScreen' => [], // of callback - 'editorMapping' => [], - 'netteMailer' => true, - ]; - /** @var bool */ private $debugMode; @@ -52,9 +33,31 @@ public function __construct(bool $debugMode = false, bool $cliMode = false) } + public function getConfigSchema(): Nette\Schema\Schema + { + return Expect::structure([ + 'email' => Expect::email()->dynamic(), + 'fromEmail' => Expect::email()->dynamic(), + 'logSeverity' => Expect::scalar(), + 'editor' => Expect::string()->dynamic(), + 'browser' => Expect::string()->dynamic(), + 'errorTemplate' => Expect::string()->dynamic(), + 'strictMode' => Expect::bool()->dynamic(), + 'showBar' => Expect::bool()->dynamic(), + 'maxLength' => Expect::int()->dynamic(), + 'maxDepth' => Expect::int()->dynamic(), + 'showLocation' => Expect::bool()->dynamic(), + 'scream' => Expect::bool()->dynamic(), + 'bar' => Expect::listOf('class|Nette\DI\Definitions\Statement'), + 'blueScreen' => Expect::listOf('callable'), + 'editorMapping' => Expect::arrayOf('string')->dynamic(), + 'netteMailer' => Expect::bool(true), + ]); + } + + public function loadConfiguration() { - $this->validateConfig($this->defaults); $builder = $this->getContainerBuilder(); $builder->addDefinition($this->prefix('logger')) @@ -74,7 +77,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) $initialize = $class->getMethod('initialize'); $builder = $this->getContainerBuilder(); - $options = $this->config; + $options = (array) $this->config; unset($options['bar'], $options['blueScreen'], $options['netteMailer']); if (isset($options['logSeverity'])) { $res = 0; @@ -94,17 +97,17 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) } $logger = $builder->getDefinition($this->prefix('logger')); - if ($logger->getFactory()->getEntity() !== [Tracy\Debugger::class, 'getLogger']) { + if (!$logger instanceof Nette\DI\ServiceDefinition || $logger->getFactory()->getEntity() !== [Tracy\Debugger::class, 'getLogger']) { $initialize->addBody($builder->formatPhp('Tracy\Debugger::setLogger(?);', [$logger])); } - if ($this->config['netteMailer'] && $builder->getByType(Nette\Mail\IMailer::class)) { + if ($this->config->netteMailer && $builder->getByType(Nette\Mail\IMailer::class)) { $initialize->addBody($builder->formatPhp('Tracy\Debugger::getLogger()->mailer = ?;', [ - [new Nette\DI\Statement(Tracy\Bridges\Nette\MailSender::class, ['fromEmail' => $this->config['fromEmail']]), 'send'], + [new Nette\DI\Statement(Tracy\Bridges\Nette\MailSender::class, ['fromEmail' => $this->config->fromEmail]), 'send'], ])); } if ($this->debugMode) { - foreach ((array) $this->config['bar'] as $item) { + foreach ($this->config->bar as $item) { if (is_string($item) && substr($item, 0, 1) === '@') { $item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]); } elseif (is_string($item)) { @@ -122,7 +125,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) } } - foreach ((array) $this->config['blueScreen'] as $item) { + foreach ($this->config->blueScreen as $item) { $initialize->addBody($builder->formatPhp( '$this->getService(?)->addPanel(?);', Nette\DI\Helpers::filterArguments([$this->prefix('blueScreen'), $item]) From 6060d6c7700451f93fb6b674a3eae694beb8c6c2 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 6 Aug 2019 02:21:48 +0200 Subject: [PATCH 07/21] tested against PHP 7.4 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 22c4a68a1..e9af3075c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4snapshot env: - PHP_BIN=php @@ -69,6 +70,7 @@ jobs: allow_failures: - stage: Static Analysis (informative) - stage: Code Coverage + - php: 7.4snapshot sudo: false From be818cc8882af82122faa19d624492bab43e4bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sat, 10 Aug 2019 22:55:08 +0200 Subject: [PATCH 08/21] Fix PhpStan suggestions --- src/Bridges/Nette/Bridge.php | 8 ++++++-- src/Bridges/Nette/MailSender.php | 1 + src/Bridges/Nette/TracyExtension.php | 11 +++++++---- src/Tracy/Debugger/Debugger.php | 2 +- src/Tracy/Dumper/Dumper.php | 7 ++++--- src/Tracy/Helpers.php | 21 +++++++++++---------- src/Tracy/Logger/Logger.php | 1 - 7 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Bridges/Nette/Bridge.php b/src/Bridges/Nette/Bridge.php index 0221cbe7c..8a4dd4fcf 100644 --- a/src/Bridges/Nette/Bridge.php +++ b/src/Bridges/Nette/Bridge.php @@ -33,6 +33,7 @@ public static function initialize(): void public static function renderLatteError(?\Throwable $e): ?array { + assert(\class_exists(Latte\CompileException::class)); if ($e instanceof Latte\CompileException) { return [ 'tab' => 'Template', @@ -48,7 +49,8 @@ public static function renderLatteError(?\Throwable $e): ?array . '
    ', ]; - } elseif ($e && strpos($file = $e->getFile(), '.latte--')) { + } + if ($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 $templateFile = $m[1]; @@ -68,6 +70,7 @@ public static function renderLatteError(?\Throwable $e): ?array public static function renderLatteUnknownMacro(?\Throwable $e): ?array { + assert(\class_exists(Latte\CompileException::class)); if ( $e instanceof Latte\CompileException && @is_file($e->sourceName) // @ - may trigger error @@ -94,7 +97,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/Bridges/Nette/MailSender.php b/src/Bridges/Nette/MailSender.php index f59f412e7..b4e2b685d 100644 --- a/src/Bridges/Nette/MailSender.php +++ b/src/Bridges/Nette/MailSender.php @@ -39,6 +39,7 @@ public function __construct(Nette\Mail\IMailer $mailer, string $fromEmail = null */ public function send($message, string $email): void { + assert(\class_exists(Nette\Mail\Message::class)); $host = preg_replace('#[^\w.-]+#', '', $_SERVER['HTTP_HOST'] ?? php_uname('n')); $mail = new Nette\Mail\Message; diff --git a/src/Bridges/Nette/TracyExtension.php b/src/Bridges/Nette/TracyExtension.php index b2d9102fa..40702003b 100644 --- a/src/Bridges/Nette/TracyExtension.php +++ b/src/Bridges/Nette/TracyExtension.php @@ -108,10 +108,12 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) if ($this->debugMode) { foreach ($this->config->bar as $item) { - if (is_string($item) && substr($item, 0, 1) === '@') { - $item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]); - } elseif (is_string($item)) { - $item = new Nette\DI\Statement($item); + if (is_string($item)) { + if ($item[0] ?? '' === '@') { + $item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]); + } else { + $item = new Nette\DI\Statement($item); + } } $initialize->addBody($builder->formatPhp( '$this->getService(?)->addPanel(?);', @@ -119,6 +121,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) )); } + assert(\class_exists(Nette\Http\Session::class)); if (!$this->cliMode && ($name = $builder->getByType(Nette\Http\Session::class))) { $initialize->addBody('$this->getService(?)->start();', [$name]); $initialize->addBody('Tracy\Debugger::dispatch();'); diff --git a/src/Tracy/Debugger/Debugger.php b/src/Tracy/Debugger/Debugger.php index 483ab2f6e..0d6b44441 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 d08f913ca..73db4e462 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; } @@ -501,7 +502,7 @@ public static function encodeString(string $s, int $maxLength = null): string static $table; if ($table === null) { foreach (array_merge(range("\x00", "\x1F"), range("\x7F", "\xFF")) as $ch) { - $table[$ch] = '\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT); + $table[$ch] = '\x' . str_pad(dechex(ord((string) $ch)), 2, '0', STR_PAD_LEFT); } $table['\\'] = '\\\\'; $table["\r"] = '\r'; @@ -517,7 +518,7 @@ public static function encodeString(string $s, int $maxLength = null): string $i = $len = 0; $maxI = $maxLength * 4; // max UTF-8 length do { - if (($s[$i] < "\x80" || $s[$i] >= "\xC0") && (++$len > $maxLength) || $i >= $maxI) { + if (($s[$i] < "\x80" || $s[$i] >= "\xC0") && ((++$len > $maxLength) || $i >= $maxI)) { $s = substr($s, 0, $i); $shortened = true; break; @@ -539,7 +540,7 @@ public static function encodeString(string $s, int $maxLength = null): string /** - * @param int|string $k + * @param int|string $key * @return int|string */ private function encodeKey($key) diff --git a/src/Tracy/Helpers.php b/src/Tracy/Helpers.php index 07ae19a70..ad23c8a20 100644 --- a/src/Tracy/Helpers.php +++ b/src/Tracy/Helpers.php @@ -164,10 +164,9 @@ public static function getSource(): string return (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? '') . $_SERVER['REQUEST_URI']; - } else { - return 'CLI (PID: ' . getmypid() . ')' - . ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv'])); } + return 'CLI (PID: ' . getmypid() . ')' + . ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv'])); } @@ -212,10 +211,12 @@ public static function improveException(\Throwable $e): void $ref = new \ReflectionProperty($e, 'message'); $ref->setAccessible(true); $ref->setValue($e, $message); - $e->tracyAction = [ - 'link' => self::editorUri($e->getFile(), $e->getLine(), 'fix', $replace[0], $replace[1]), - 'label' => 'fix it', - ]; + if (property_exists($e, 'tracyAction')) { + $e->tracyAction = [ + 'link' => self::editorUri($e->getFile(), $e->getLine(), 'fix', $replace[0] ?? '', $replace[1] ?? ''), + 'label' => 'fix it', + ]; + } } } @@ -243,14 +244,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 7d06d9d7f..d632cf855 100644 --- a/src/Tracy/Logger/Logger.php +++ b/src/Tracy/Logger/Logger.php @@ -163,7 +163,6 @@ protected function sendEmail($message): void if ( $this->email - && $this->mailer && @filemtime($this->directory . '/email-sent') + $snooze < time() // @ file may not exist && @file_put_contents($this->directory . '/email-sent', 'sent') // @ file may not be writable ) { From dc60c083d4d7bce294fbb7ddfc994475e98f15b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sat, 10 Aug 2019 23:02:34 +0200 Subject: [PATCH 09/21] Helpers: Revert write to undefined propert tracyAction --- src/Tracy/Helpers.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Tracy/Helpers.php b/src/Tracy/Helpers.php index ad23c8a20..7f02d15b7 100644 --- a/src/Tracy/Helpers.php +++ b/src/Tracy/Helpers.php @@ -211,12 +211,10 @@ public static function improveException(\Throwable $e): void $ref = new \ReflectionProperty($e, 'message'); $ref->setAccessible(true); $ref->setValue($e, $message); - if (property_exists($e, 'tracyAction')) { - $e->tracyAction = [ - 'link' => self::editorUri($e->getFile(), $e->getLine(), 'fix', $replace[0] ?? '', $replace[1] ?? ''), - 'label' => 'fix it', - ]; - } + $e->tracyAction = [ + 'link' => self::editorUri($e->getFile(), $e->getLine(), 'fix', $replace[0] ?? '', $replace[1] ?? ''), + 'label' => 'fix it', + ]; } } From 6292e0741f5769c3ffaa13c4b1f6fa306ad0e6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sat, 10 Aug 2019 23:06:11 +0200 Subject: [PATCH 10/21] Bridge: CodeStyle --- src/Bridges/Nette/Bridge.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bridges/Nette/Bridge.php b/src/Bridges/Nette/Bridge.php index 8a4dd4fcf..59e40395b 100644 --- a/src/Bridges/Nette/Bridge.php +++ b/src/Bridges/Nette/Bridge.php @@ -48,7 +48,6 @@ public static function renderLatteError(?\Throwable $e): ?array . BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine) . '
    ', ]; - } if ($e && strpos($file = $e->getFile(), '.latte--')) { $lines = file($file); From ae2c34f376bc953b761d79716a19378eff84bf1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sun, 11 Aug 2019 10:34:18 +0200 Subject: [PATCH 11/21] Composer: Added new dev dependencies --- composer.json | 3 +++ src/Bridges/Nette/Bridge.php | 1 - src/Bridges/Nette/MailSender.php | 1 - src/Bridges/Nette/TracyExtension.php | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index eebbafc97..e9d44e1fe 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,9 @@ "nette/utils": "^3.0", "nette/di": "^3.0", "nette/tester": "^2.2", + "nette/mail": "^3.0", + "nette/http": "^3.0", + "latte/latte": "^2.5", "psr/log": "^1.0" }, "conflict": { diff --git a/src/Bridges/Nette/Bridge.php b/src/Bridges/Nette/Bridge.php index 59e40395b..d600e611a 100644 --- a/src/Bridges/Nette/Bridge.php +++ b/src/Bridges/Nette/Bridge.php @@ -33,7 +33,6 @@ public static function initialize(): void public static function renderLatteError(?\Throwable $e): ?array { - assert(\class_exists(Latte\CompileException::class)); if ($e instanceof Latte\CompileException) { return [ 'tab' => 'Template', diff --git a/src/Bridges/Nette/MailSender.php b/src/Bridges/Nette/MailSender.php index b4e2b685d..f59f412e7 100644 --- a/src/Bridges/Nette/MailSender.php +++ b/src/Bridges/Nette/MailSender.php @@ -39,7 +39,6 @@ public function __construct(Nette\Mail\IMailer $mailer, string $fromEmail = null */ public function send($message, string $email): void { - assert(\class_exists(Nette\Mail\Message::class)); $host = preg_replace('#[^\w.-]+#', '', $_SERVER['HTTP_HOST'] ?? php_uname('n')); $mail = new Nette\Mail\Message; diff --git a/src/Bridges/Nette/TracyExtension.php b/src/Bridges/Nette/TracyExtension.php index 40702003b..1cf0148f8 100644 --- a/src/Bridges/Nette/TracyExtension.php +++ b/src/Bridges/Nette/TracyExtension.php @@ -121,7 +121,6 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) )); } - assert(\class_exists(Nette\Http\Session::class)); if (!$this->cliMode && ($name = $builder->getByType(Nette\Http\Session::class))) { $initialize->addBody('$this->getService(?)->start();', [$name]); $initialize->addBody('Tracy\Debugger::dispatch();'); From 85c9611221f482879abad7fa1ed7f262e5dd496a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sun, 11 Aug 2019 10:42:18 +0200 Subject: [PATCH 12/21] Fix by JanTvrdik suggestions --- src/Tracy/Dumper/Dumper.php | 2 +- src/Tracy/Logger/Logger.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Tracy/Dumper/Dumper.php b/src/Tracy/Dumper/Dumper.php index 73db4e462..ac0497f5c 100644 --- a/src/Tracy/Dumper/Dumper.php +++ b/src/Tracy/Dumper/Dumper.php @@ -502,7 +502,7 @@ public static function encodeString(string $s, int $maxLength = null): string static $table; if ($table === null) { foreach (array_merge(range("\x00", "\x1F"), range("\x7F", "\xFF")) as $ch) { - $table[$ch] = '\x' . str_pad(dechex(ord((string) $ch)), 2, '0', STR_PAD_LEFT); + $table[$ch] = '\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT); } $table['\\'] = '\\\\'; $table["\r"] = '\r'; diff --git a/src/Tracy/Logger/Logger.php b/src/Tracy/Logger/Logger.php index d632cf855..47803c8bb 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 */ @@ -163,6 +163,7 @@ protected function sendEmail($message): void if ( $this->email + && $this->mailer && @filemtime($this->directory . '/email-sent') + $snooze < time() // @ file may not exist && @file_put_contents($this->directory . '/email-sent', 'sent') // @ file may not be writable ) { From 3e52f923a7b512021ac318582dc292a4552110d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sun, 11 Aug 2019 10:47:41 +0200 Subject: [PATCH 13/21] Bridge: Use dev dependency and remove assert --- src/Bridges/Nette/Bridge.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bridges/Nette/Bridge.php b/src/Bridges/Nette/Bridge.php index d600e611a..3ef4dbaff 100644 --- a/src/Bridges/Nette/Bridge.php +++ b/src/Bridges/Nette/Bridge.php @@ -68,7 +68,6 @@ public static function renderLatteError(?\Throwable $e): ?array public static function renderLatteUnknownMacro(?\Throwable $e): ?array { - assert(\class_exists(Latte\CompileException::class)); if ( $e instanceof Latte\CompileException && @is_file($e->sourceName) // @ - may trigger error From 75fc1782e49bf6a2f8b6bb7bfd9adac367b5fe47 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 2 Apr 2020 00:36:44 +0200 Subject: [PATCH 14/21] bar.css: alt colors using transparency --- src/Tracy/Bar/assets/bar.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 5129995a2be3b6f11727e44a2c08fd0cc7146f33 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 2 Apr 2020 02:50:49 +0200 Subject: [PATCH 15/21] BlueScreen: refactoring, added formatMessage() --- src/Tracy/BlueScreen/BlueScreen.php | 43 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Tracy/BlueScreen/BlueScreen.php b/src/Tracy/BlueScreen/BlueScreen.php index abcf63812..ceaa1a6a1 100644 --- a/src/Tracy/BlueScreen/BlueScreen.php +++ b/src/Tracy/BlueScreen/BlueScreen.php @@ -113,23 +113,7 @@ 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 - ); - + $messageHtml = $this->formatMessage($exception); $info = array_filter($this->info); $source = Helpers::getSource(); $title = $exception instanceof \ErrorException @@ -384,4 +368,29 @@ 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'); + + $msg = preg_replace( + '#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\\")*\S"#', + '$0', + $msg + ); + + $msg = preg_replace_callback( + '#\w+\\\\[\w\\\\]+\w#', + function ($m) { + return class_exists($m[0], false) || interface_exists($m[0], false) + ? '' . $m[0] . '' + : $m[0]; + }, + $msg + ); + + return $msg; + } } From 8ba795c9f9a8fde0523bc283054ac631b93b5238 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 2 Apr 2020 02:54:08 +0200 Subject: [PATCH 16/21] BlueScreen::formatMessage() clickable methods & files --- src/Tracy/BlueScreen/BlueScreen.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Tracy/BlueScreen/BlueScreen.php b/src/Tracy/BlueScreen/BlueScreen.php index ceaa1a6a1..463070ef8 100644 --- a/src/Tracy/BlueScreen/BlueScreen.php +++ b/src/Tracy/BlueScreen/BlueScreen.php @@ -375,18 +375,36 @@ 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+\\\\[\w\\\\]+\w)(?:::(\w+))?#', function ($m) { - return class_exists($m[0], false) || interface_exists($m[0], false) - ? '' . $m[0] . '' - : $m[0]; + 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 ); From 982e85e2e31240883ca96fe2baa94bcb2586c038 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 3 Apr 2020 15:02:36 +0200 Subject: [PATCH 17/21] BlueScreen: do not show Enviroment on 'Allowed memory size of *** bytes exhausted' --- src/Tracy/BlueScreen/BlueScreen.php | 1 + src/Tracy/BlueScreen/assets/content.phtml | 2 ++ tests/Tracy/expected/Debugger.E_ERROR.html.expect | 2 +- tests/Tracy/expected/Debugger.error-in-eval.expect | 2 +- tests/Tracy/expected/Debugger.exception.html.expect | 2 +- tests/Tracy/expected/Debugger.strict.html.expect | 2 +- 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Tracy/BlueScreen/BlueScreen.php b/src/Tracy/BlueScreen/BlueScreen.php index 463070ef8..1bc09d551 100644 --- a/src/Tracy/BlueScreen/BlueScreen.php +++ b/src/Tracy/BlueScreen/BlueScreen.php @@ -113,6 +113,7 @@ public function renderToFile(\Throwable $exception, string $file): bool private function renderTemplate(\Throwable $exception, string $template, $toScreen = true): void { + $showEnvironment = strpos($exception->getMessage(), 'Allowed memory size') === false; $messageHtml = $this->formatMessage($exception); $info = array_filter($this->info); $source = Helpers::getSource(); 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/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 @@ -
    +

    Environment

    From d66385c0c26818aeee8cd2004bfaf3e0285f91c6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 6 Apr 2020 15:07:10 +0200 Subject: [PATCH 18/21] readme: info about nginx --- readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 ----- From bf35591deb2060cff1ad98fb0da147652b750ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Tue, 7 Apr 2020 15:57:24 +0200 Subject: [PATCH 19/21] Composer.json: Fix duplicated conflict section --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 07438eacb..58b5aec3f 100644 --- a/composer.json +++ b/composer.json @@ -31,9 +31,6 @@ "conflict": { "nette/di": "<3.0" }, - "conflict": { - "nette/di": "<3.0" - }, "suggest": { "https://nette.org/donate": "Please support Tracy via a donation" }, From 0843462a78e5162759709363496f1924f6fc00f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Tue, 7 Apr 2020 15:59:30 +0200 Subject: [PATCH 20/21] Helpers: Revert --- src/Tracy/Helpers.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Tracy/Helpers.php b/src/Tracy/Helpers.php index 773e95c1c..a43c3d441 100644 --- a/src/Tracy/Helpers.php +++ b/src/Tracy/Helpers.php @@ -163,9 +163,10 @@ public static function getSource(): string return (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? '') . $_SERVER['REQUEST_URI']; + } else { + return 'CLI (PID: ' . getmypid() . ')' + . ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv'])); } - return 'CLI (PID: ' . getmypid() . ')' - . ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv'])); } From 1f4e321a546875f085c2d38c63c3daa10457c01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Tue, 7 Apr 2020 16:01:05 +0200 Subject: [PATCH 21/21] Bridge: Revert --- src/Bridges/Nette/Bridge.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Bridges/Nette/Bridge.php b/src/Bridges/Nette/Bridge.php index 4ca0bf5da..423b04f76 100644 --- a/src/Bridges/Nette/Bridge.php +++ b/src/Bridges/Nette/Bridge.php @@ -47,8 +47,7 @@ public static function renderLatteError(?\Throwable $e): ?array . BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine) . '
    ', ]; - } - if ($e && strpos($file = $e->getFile(), '.latte--')) { + } 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 $templateFile = $m[1];