diff --git a/composer.json b/composer.json index 8168015da..3b370c2fd 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,13 @@ }, "require-dev": { "nette/utils": "^2.4 || ^3.0", - "nette/di": "^2.4 || ~3.0.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" }, @@ -35,7 +38,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "3.0-dev" } } } diff --git a/readme.md b/readme.md index 9b1869783..929c8cd16 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 3.0 (dev) | 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/Bridges/Nette/TracyExtension.php b/src/Bridges/Nette/TracyExtension.php index 6b82df021..d5bfbd0b6 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'), + '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]) diff --git a/src/Bridges/Psr/PsrToTracyLoggerAdapter.php b/src/Bridges/Psr/PsrToTracyLoggerAdapter.php index 71bc7003b..2b9e77b9e 100644 --- a/src/Bridges/Psr/PsrToTracyLoggerAdapter.php +++ b/src/Bridges/Psr/PsrToTracyLoggerAdapter.php @@ -38,7 +38,7 @@ public function __construct(Psr\Log\LoggerInterface $psrLogger) } - public function log($value, $priority = self::INFO) + public function log($value, string $priority = self::INFO) { if ($value instanceof \Throwable) { $message = Tracy\Helpers::getClass($value) . ': ' . $value->getMessage() . ($value->getCode() ? ' #' . $value->getCode() : '') . ' in ' . $value->getFile() . ':' . $value->getLine(); diff --git a/src/Tracy/Bar/Bar.php b/src/Tracy/Bar/Bar.php index e105a505c..6eaff2a27 100644 --- a/src/Tracy/Bar/Bar.php +++ b/src/Tracy/Bar/Bar.php @@ -144,7 +144,7 @@ private function renderPanels(string $suffix = ''): array foreach ($this->panels as $id => $panel) { $idHtml = preg_replace('#[^a-z0-9]+#i', '-', $id) . $suffix; try { - $tab = (string) $panel->getTab(); + $tab = $panel->getTab(); $panelHtml = $tab ? $panel->getPanel() : null; } catch (\Throwable $e) { diff --git a/src/Tracy/Bar/IBarPanel.php b/src/Tracy/Bar/IBarPanel.php index 51cfc7f34..9e259b285 100644 --- a/src/Tracy/Bar/IBarPanel.php +++ b/src/Tracy/Bar/IBarPanel.php @@ -20,11 +20,11 @@ interface IBarPanel * Renders HTML code for custom tab. * @return string */ - function getTab(); + function getTab(): ?string; /** * Renders HTML code for custom panel. * @return string */ - function getPanel(); + function getPanel(): ?string; } 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/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/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..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 @@ -28,7 +27,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : ''; ?>
    -
    +
    getMessage()): ?>

    @@ -357,15 +356,14 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : '';
    - - - - +
    >
    diff --git a/src/Tracy/Debugger/Debugger.php b/src/Tracy/Debugger/Debugger.php index 78a6f51ef..f2b266d13 100644 --- a/src/Tracy/Debugger/Debugger.php +++ b/src/Tracy/Debugger/Debugger.php @@ -17,7 +17,7 @@ */ class Debugger { - public const VERSION = '2.6.3'; + public const VERSION = '3.0-dev'; /** server modes for Debugger::enable() */ public const diff --git a/src/Tracy/Logger/FireLogger.php b/src/Tracy/Logger/FireLogger.php index 6e618b809..8a4414511 100644 --- a/src/Tracy/Logger/FireLogger.php +++ b/src/Tracy/Logger/FireLogger.php @@ -32,7 +32,7 @@ class FireLogger implements ILogger * Sends message to FireLogger console. * @param mixed $message */ - public function log($message, $priority = self::DEBUG): bool + public function log($message, string $priority = self::DEBUG): bool { if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) { return false; diff --git a/src/Tracy/Logger/ILogger.php b/src/Tracy/Logger/ILogger.php index d260936c3..53fec1a60 100644 --- a/src/Tracy/Logger/ILogger.php +++ b/src/Tracy/Logger/ILogger.php @@ -23,5 +23,5 @@ interface ILogger EXCEPTION = 'exception', CRITICAL = 'critical'; - function log($value, $priority = self::INFO); + function log($value, string $priority = self::INFO); } diff --git a/src/Tracy/Logger/Logger.php b/src/Tracy/Logger/Logger.php index b247e82c5..476a00ded 100644 --- a/src/Tracy/Logger/Logger.php +++ b/src/Tracy/Logger/Logger.php @@ -52,7 +52,7 @@ public function __construct(?string $directory, $email = null, BlueScreen $blueS * @param string $priority one of constant ILogger::INFO, WARNING, ERROR (sends email), EXCEPTION (sends email), CRITICAL (sends email) * @return string|null logged error filename */ - public function log($message, $priority = self::INFO) + public function log($message, string $priority = self::INFO): ?string { if (!$this->directory) { throw new \LogicException('Logging directory is not specified.'); diff --git a/src/Tracy/shortcuts.php b/src/Tracy/shortcuts.php index f110f228a..bc46a31f0 100644 --- a/src/Tracy/shortcuts.php +++ b/src/Tracy/shortcuts.php @@ -44,3 +44,15 @@ function bdump($var) return $var; } } + +if (!function_exists('cdump')) { + /** + * Tracy\Debugger::fireLog() shortcut. + * @tracySkipLocation + */ + function cdump($var) + { + Tracy\Debugger::fireLog(...func_get_args()); + return $var; + } +} diff --git a/tests/Tracy.Bridges/TracyExtension.services.phpt b/tests/Tracy.Bridges/TracyExtension.services.phpt index 0e314039d..a3806a10c 100644 --- a/tests/Tracy.Bridges/TracyExtension.services.phpt +++ b/tests/Tracy.Bridges/TracyExtension.services.phpt @@ -16,7 +16,7 @@ require __DIR__ . '/../bootstrap.php'; class CustomLogger implements ILogger { - public function log($value, $priority = self::INFO) + public function log($value, string $priority = self::INFO) { } } diff --git a/tests/Tracy.Bridges/TracyToPsrLoggerAdapter.phpt b/tests/Tracy.Bridges/TracyToPsrLoggerAdapter.phpt index c010d2d08..115de84ff 100644 --- a/tests/Tracy.Bridges/TracyToPsrLoggerAdapter.phpt +++ b/tests/Tracy.Bridges/TracyToPsrLoggerAdapter.phpt @@ -19,7 +19,7 @@ class DummyTracyLogger implements ILogger public $entries = []; - public function log($value, $priority = self::INFO) + public function log($value, string $priority = self::INFO) { $this->entries[] = [$priority, $value]; } diff --git a/tests/Tracy/Logger.extensible.phpt b/tests/Tracy/Logger.extensible.phpt index 6226fac3b..ff42c3c85 100644 --- a/tests/Tracy/Logger.extensible.phpt +++ b/tests/Tracy/Logger.extensible.phpt @@ -19,7 +19,7 @@ class CustomLogger extends Logger public $collector = []; - public function log($value, $priority = self::INFO): ?string + public function log($value, string $priority = self::INFO): ?string { $exceptionFile = $value instanceof \Exception ? $this->logException($value) : null; diff --git a/tests/Tracy/expected/Debugger.E_ERROR.html.expect b/tests/Tracy/expected/Debugger.E_ERROR.html.expect index d4e2aa276..987e85150 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,13 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • PHP %a%
    + +
    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%"> - ¤ - × + ¤ + ×
    diff --git a/tests/Tracy/expected/Debugger.error-in-eval.expect b/tests/Tracy/expected/Debugger.error-in-eval.expect index 2cefe40e8..ef8e08371 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,13 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • PHP %a%
    + +
    diff --git a/tests/Tracy/expected/Debugger.exception.html.expect b/tests/Tracy/expected/Debugger.exception.html.expect index 8288a5848..36283fdd4 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,13 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • PHP %a%
    + +
    diff --git a/tests/Tracy/expected/Debugger.strict.html.expect b/tests/Tracy/expected/Debugger.strict.html.expect index 7177e07e3..5314b7337 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,13 @@ - -
      -
    • %a%️
    • -
    • Report generated at %a%
    • -
    • CLI%a?%
    • -
    • PHP %a%
    - - +
    +
      +
    • %a%️
    • +
    • Report generated at %a%
    • +
    • PHP %a%
    + +