Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposer: Fix TypeError in $name argument. #422

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f2dedf9
Dumper: HTML rendering is now based on model created for JavaScript
dg May 19, 2020
16ef5e2
Dumper: refactoring of dump*() methods, renamed to render*()
dg Apr 13, 2020
7186a07
Dumper: encodeString() & truncateString() moved to Helpers
dg Apr 13, 2020
077b302
Dumper: divided into new classes Describer, Exposer & Renderer
dg May 19, 2020
ad71d62
Describer: refactoring of toJson() method into describe*() methods
dg May 19, 2020
2b5765a
Dumper: dumps zval references
dg May 19, 2020
e1ff575
Describer: referenced arrays are stored in snapshot, used for array r…
dg May 19, 2020
acd6007
Dumper: hash highlighting on mouseover
dg Apr 10, 2020
402b5d2
Exposer: added exposeObject() & addProperty(), decodes visibility of …
dg Apr 14, 2020
34de727
Dumper: property visibility is displayed using CSS as pub/pro/pri
dg May 19, 2020
cb735df
Dumper: shows 'pub' to distinguish between public and dynamic properties
dg May 19, 2020
f390715
Dumper: distinguishes virtual property, resources are virtual
dg May 19, 2020
f2fb71b
Dumper: changed '=>' to ':' as key separator for objects & resources
dg May 19, 2020
031d0f2
Dumper: reduced chars allowed in unquoted key
dg Apr 21, 2020
bdf3fcd
Dumper: added hover effect for guide lines
dg Apr 14, 2020
46bb13f
Dumper: added option to limit max items in array/objects
dg May 19, 2020
906e65b
Dumper: shows declaring class of private properties as tooltip
dg May 19, 2020
88b5793
Dumper: json_encode is not escaping UTF-8 & slashes
dg May 19, 2020
d67b824
Dumper: uses unicode ellipsis
dg May 19, 2020
5e65e16
Dumper: removed [] and {} around ellipsis
dg May 19, 2020
8ea6f0c
test: multiline strings converted to NOWDOC
dg May 19, 2020
4eb9425
Dumper: strings are quoted in single quotes
dg May 19, 2020
e6be83a
Helpers::escapeHtml() escapes quote as '
dg Apr 19, 2020
7f20909
Helpers::encodeString() returns HTML
dg May 19, 2020
73f8ad9
Dumper: clever way of displaying strings and escaped sequences
dg May 19, 2020
10f7cbd
Dumper: length of strings are displayed in tooltip in bytes or unicod…
dg May 19, 2020
ce741a2
Dumper: preserves the ends of truncated strings
dg Apr 21, 2020
8309084
Dumper: changed new-lines processing distribution
dg May 19, 2020
f298dcf
Dumper: array keys are either numbers or quoted strings
dg May 19, 2020
d78a09b
Dumper: changed 'array ()' to 'array (0)'
dg May 19, 2020
d6af4d7
Toggle: Alt-click to toggle all child nodes recursively
dg Apr 14, 2020
1700315
Toggle: added tooltip about Alt-click
dg Apr 15, 2020
ccf87c9
Dumper: added tooltips about Ctrl-click
dg Apr 15, 2020
5d49d24
Debugger::dump(), $maxDepth, $maxLength and $showLocation and moved t…
dg Apr 25, 2020
67400bd
added Dumper::$useColors, detection moved to Helpers::detectColors()
dg May 5, 2020
a087908
Helpers::detectColors() supports https://no-color.org & sapi_windows_…
dg May 5, 2020
cc03c08
Dumper: in CLI outputs to STDOUT to bypass output buffering
dg Apr 28, 2020
77ef32d
removed unused class
dg Apr 28, 2020
753b7d7
js: removed IIFE wrap
dg May 19, 2020
35e6020
dumper.js inited after DOMContentLoaded
dg Apr 26, 2020
c0e5d0b
Helpers: added minifyCss & minifyJs
dg Apr 28, 2020
414ab1d
Dumper: renders HTML style & script on the first call
dg Apr 28, 2020
ea57a93
code improvements
dg Apr 26, 2020
4586608
Dumper\Value: added TYPE_* consts
dg May 19, 2020
a5e885f
Dumper: structures are dumped only once, added 'see above'
dg May 19, 2020
3d149ec
Dumper: added 'see below'
dg May 19, 2020
02d29b5
Dumper: default max depth changed to 7
dg May 6, 2020
a267850
dumper.css: word-break: break-all
dg May 13, 2020
ecc00eb
Dumper, TracyExtension added $maxItems & $keyToHide
dg Apr 25, 2020
17094a2
Helpers::fixEncoding() replaced with JSON_INVALID_UTF8_SUBSTITUTE
dg May 16, 2020
e0d8945
Dumper: Value can be used in keys of properties
dg May 19, 2020
64c39fa
Dumper: supports objects without 'id' for custom objects
dg Apr 21, 2020
ab24fdb
Dumper: Value::$collapsed control whether custom object is collapsed
dg May 19, 2020
351f9c2
Dumper: improved dumping of closures
dg May 19, 2020
153a385
Dumper: added support for ArrayObject properties [Closes #413]
dg May 19, 2020
75edc96
Dumper: added support for DOM [Closes #319]
dg May 19, 2020
ecf2c04
css: pre.tracy-dump => .tracy-dump
dg May 6, 2020
483a036
Dumper: added themes 'light' & 'dark'
dg May 18, 2020
a3a53b5
updated examples
dg May 14, 2020
c829248
Exposer: Fix TypeError in $name argument.
janbarasek May 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Expand Up @@ -6,7 +6,6 @@ module.exports = {
'ecmaVersion': 6
},
'globals': {
'Tracy': true
},
'extends': 'eslint:recommended',
'rules': {
Expand Down
3 changes: 2 additions & 1 deletion examples/assets/style.css
Expand Up @@ -17,8 +17,9 @@ h1 {
color: #036;
}

pre.tracy-dump {
pre.tracy-dump--light {
border: 1px solid silver;
border-radius: 4px;
padding: 1em;
margin: 1em 0;
}
Expand Down
33 changes: 17 additions & 16 deletions examples/dump.php
Expand Up @@ -4,11 +4,7 @@

require __DIR__ . '/../src/tracy.php';

use Tracy\Debugger;

// For security reasons, Tracy is visible only on localhost.
// You may force Tracy to run in development mode by passing the Debugger::DEVELOPMENT instead of Debugger::DETECT.
Debugger::enable(Debugger::DETECT, __DIR__ . '/log');
use Tracy\Dumper;

?>
<!DOCTYPE html><link rel="stylesheet" href="assets/style.css">
Expand All @@ -17,6 +13,14 @@

<?php

// options:
// Dumper::$maxDepth = 7; // how many nested levels of array/object properties display
// Dumper::$maxLength = 150; // how long strings display
// Dumper::$maxItems = 100; // how many items in array/object display
// Dumper::$keysToHide = []; // sensitive keys not displayed
// Dumper::$theme = 'dark'; // theme light or dark


class Test
{
public $x = [10, null];
Expand All @@ -28,23 +32,20 @@ class Test

$arr = [10, 20.2, true, null, 'hello', (object) null, [], fopen(__FILE__, 'r')];

$obj = new Test;


dump('<a href="#">test</a>');

dump($arr);

dump($obj);


echo "<h2>With location</h2>\n";

Debugger::$showLocation = true;
Dumper::$showLocation = true;

dump($arr);


if (Debugger::$productionMode) {
echo '<p><b>For security reasons, Tracy is visible only on localhost. Look into the source code to see how to enable Tracy.</b></p>';
}
echo "<h2>Dark theme</h2>\n";

Dumper::$theme = 'dark';

$obj = new Test;

dump($obj);
23 changes: 14 additions & 9 deletions readme.md
Expand Up @@ -255,27 +255,32 @@ Every debugging developer is a good friend with the function `var_dump`, which l
$arr = [10, 20.2, true, null, 'hello'];

dump($arr);
// or Tracy\Debugger::dump($arr);
// or Tracy\Dumper::dump($arr);
```

generates the output:

![dump](https://nette.github.io/tracy/images/tracy-dump.png)

You can also change the nesting depth by `Debugger::$maxDepth` and displayed strings length by `Debugger::$maxLength`. Naturally, lower values accelerate Tracy rendering.
You can also change the nesting depth by `Dumper::$maxDepth`, displayed strings length by `Dumper::$maxLength` and other options. Naturally, lower values accelerate Tracy rendering.

```php
Debugger::$maxDepth = 2; // default: 3
Debugger::$maxLength = 50; // default: 150
use Tracy\Dumper;

Dumper::$maxDepth = 2; // default: 7
Dumper::$maxLength = 50; // default: 150
Dumper::$maxItems = 50; // default: 100
Dumper::$keysToHide = ['password']; // default: []
Dumper::$theme = 'dark'; // default: light
```

The `dump()` function can display other useful information. `Tracy\Dumper::LOCATION_SOURCE` adds a tooltip with path to the file, where the function was called. `Tracy\Dumper::LOCATION_LINK` adds a link to the file. `Tracy\Dumper::LOCATION_CLASS` adds a tooltip to every dumped object containing path to the file, in which the object's class is defined. All these constants can be set in `Debugger::$showLocation` variable before calling the `dump()`. You can set multiple values at once using the `|` operator.
The `dump()` function can display other useful information. `Tracy\Dumper::LOCATION_SOURCE` adds a tooltip with path to the file, where the function was called. `Tracy\Dumper::LOCATION_LINK` adds a link to the file. `Tracy\Dumper::LOCATION_CLASS` adds a tooltip to every dumped object containing path to the file, in which the object's class is defined. All these constants can be set in `Dumper::$showLocation` variable before calling the `dump()`. You can set multiple values at once using the `|` operator.

```php
Debugger::$showLocation = Tracy\Dumper::LOCATION_SOURCE; // Shows path to where the dump() was called
Debugger::$showLocation = Tracy\Dumper::LOCATION_CLASS | Tracy\Dumper::LOCATION_LINK; // Shows both paths to the classes and link to where the dump() was called
Debugger::$showLocation = false; // Hides additional location information
Debugger::$showLocation = true; // Shows all additional location information
Dumper::$showLocation = Tracy\Dumper::LOCATION_SOURCE; // Shows path to where the dump() was called
Dumper::$showLocation = Tracy\Dumper::LOCATION_CLASS | Tracy\Dumper::LOCATION_LINK; // Shows both paths to the classes and link to where the dump() was called
Dumper::$showLocation = false; // Hides additional location information
Dumper::$showLocation = true; // Shows all additional location information
```

Very handy alternative to `dump()` is `dumpe()` (ie. dump and exit) and `bdump()`. This allows us to dump variables in Debugger Bar. This is useful, because dumps don't mess up the output and we can also add a title to the dump.
Expand Down
15 changes: 13 additions & 2 deletions src/Bridges/Nette/TracyExtension.php
Expand Up @@ -46,6 +46,9 @@ public function getConfigSchema(): Nette\Schema\Schema
'showBar' => Expect::bool()->dynamic(),
'maxLength' => Expect::int()->dynamic(),
'maxDepth' => Expect::int()->dynamic(),
'maxItems' => Expect::int()->dynamic(),
'keysToHide' => Expect::array()->dynamic(),
'theme' => Expect::string()->dynamic(),
'showLocation' => Expect::bool()->dynamic(),
'scream' => Expect::bool()->dynamic(),
'bar' => Expect::listOf('string|Nette\DI\Definitions\Statement'),
Expand Down Expand Up @@ -88,9 +91,17 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
}
foreach ($options as $key => $value) {
if ($value !== null) {
$key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
static $tbl = [
'maxLength' => 'Dumper::$maxLength',
'maxDepth' => 'Dumper::$maxDepth',
'maxItems' => 'Dumper::$maxItems',
'keysToHide' => 'Dumper::$keysToHide',
'theme' => 'Dumper::$theme',
'showLocation' => 'Dumper::$showLocation',
'fromEmail' => 'Debugger::getLogger()->fromEmail',
];
$initialize->addBody($builder->formatPhp(
'Tracy\Debugger::' . $key . ' = ?;',
'Tracy\\' . ($tbl[$key] ?? 'Debugger::$' . $key) . ' = ?;',
Nette\DI\Helpers::filterArguments([$value])
));
}
Expand Down
22 changes: 12 additions & 10 deletions src/Tracy/Bar/Bar.php
Expand Up @@ -122,12 +122,12 @@ private function renderHtml(string $type, string $suffix = ''): array
$panels = $this->renderPanels($suffix);

return [
'bar' => Helpers::fixEncoding(Helpers::capture(function () use ($type, $panels) {
'bar' => Helpers::capture(function () use ($type, $panels) {
require __DIR__ . '/assets/bar.phtml';
})),
'panels' => Helpers::fixEncoding(Helpers::capture(function () use ($type, $panels) {
}),
'panels' => Helpers::capture(function () use ($type, $panels) {
require __DIR__ . '/assets/panels.phtml';
})),
}),
];
}

Expand Down Expand Up @@ -198,12 +198,12 @@ public function dispatchAssets(): bool
}
if ($session) {
$method = $m[1] ? 'loadAjax' : 'init';
echo "Tracy.Debug.$method(", json_encode($session['content'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), ');';
echo "Tracy.Debug.$method(", json_encode($session['content'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE), ');';
$session = null;
}
$session = &$_SESSION['_tracy']['bluescreen'][$m[2]];
if ($session) {
echo 'Tracy.BlueScreen.loadAjax(', json_encode($session['content'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), ');';
echo 'Tracy.BlueScreen.loadAjax(', json_encode($session['content'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE), ');';
$session = null;
}
return true;
Expand All @@ -219,7 +219,8 @@ private function renderAssets(): void
__DIR__ . '/assets/bar.css',
__DIR__ . '/../Toggle/toggle.css',
__DIR__ . '/../TableSort/table-sort.css',
__DIR__ . '/../Dumper/assets/dumper.css',
__DIR__ . '/../Dumper/assets/dumper-light.css',
__DIR__ . '/../Dumper/assets/dumper-dark.css',
__DIR__ . '/../BlueScreen/assets/bluescreen.css',
], Debugger::$customCssFiles));

Expand All @@ -229,16 +230,17 @@ private function renderAssets(): void
var el = document.createElement('style');
el.setAttribute('nonce', document.currentScript.getAttribute('nonce') || document.currentScript.nonce);
el.className='tracy-debug';
el.textContent=" . json_encode(preg_replace('#\s+#u', ' ', implode($css))) . ";
el.textContent=" . json_encode(Helpers::minifyCss(implode($css))) . ";
document.head.appendChild(el);})
();\n";

array_map('readfile', array_merge([
array_map(function ($file) { echo '(function(){', Helpers::minifyJs(file_get_contents($file)), '})();'; }, [
__DIR__ . '/assets/bar.js',
__DIR__ . '/../Toggle/toggle.js',
__DIR__ . '/../TableSort/table-sort.js',
__DIR__ . '/../Dumper/assets/dumper.js',
__DIR__ . '/../BlueScreen/assets/bluescreen.js',
], Debugger::$customJsFiles));
]);
array_map('readfile', Debugger::$customJsFiles);
}
}
50 changes: 44 additions & 6 deletions src/Tracy/Bar/assets/bar.css
Expand Up @@ -352,23 +352,27 @@ body#tracy-debug .tracy-panel { /* in popup window */


/* dump */
#tracy-debug pre.tracy-dump div {
#tracy-debug .tracy-dump--light div {
padding-left: 3ex;
}

#tracy-debug pre.tracy-dump div div {
#tracy-debug .tracy-dump--light div div {
border-left: 1px solid rgba(0, 0, 0, .1);
margin-left: .5ex;
}

#tracy-debug pre.tracy-dump {
#tracy-debug .tracy-dump--light div div:hover {
border-left-color: rgba(0, 0, 0, .25);
}

#tracy-debug .tracy-dump--light {
background: #FDF5CE;
padding: .4em .7em;
border: 1px dotted silver;
overflow: auto;
}

#tracy-debug table pre.tracy-dump {
#tracy-debug table .tracy-dump--light {
padding: 0;
margin: 0;
border: none;
Expand All @@ -383,6 +387,13 @@ body#tracy-debug .tracy-panel { /* in popup window */
color: #35D;
}

#tracy-debug .tracy-dump-virtual span,
#tracy-debug .tracy-dump-dynamic span,
#tracy-debug .tracy-dump-string span {
font-size: 80%;
color: rgba(0, 0, 0, 0.5);
}

#tracy-debug .tracy-dump-number {
color: #090;
}
Expand All @@ -392,15 +403,42 @@ body#tracy-debug .tracy-panel { /* in popup window */
color: #850;
}

#tracy-debug .tracy-dump-visibility,
#tracy-debug .tracy-dump-virtual {
font-style: italic;
}

#tracy-debug .tracy-dump-public::after {
content: ' pub';
}

#tracy-debug .tracy-dump-protected::after {
content: ' pro';
}

#tracy-debug .tracy-dump-private::after {
content: ' pri';
}

#tracy-debug .tracy-dump-public::after,
#tracy-debug .tracy-dump-protected::after,
#tracy-debug .tracy-dump-private::after,
#tracy-debug .tracy-dump-hash {
font-size: 85%; color: #999;
font-size: 85%;
color: rgba(0, 0, 0, 0.5);
}

#tracy-debug .tracy-dump-indent {
display: none;
}

#tracy-debug .tracy-dump-highlight {
background: #C22;
color: white;
border-radius: 2px;
padding: 0 2px;
margin: 0 -2px;
}


/* toggle */
#tracy-debug .tracy-toggle:after {
Expand Down