2.6 KiB
Debug - debugging
App\Helpers\Debug - structured data of the public Debug Toolbar,
legacy dumps, time/memory measurements and SQL error output.
use App\Helpers\Debug;
Public Debug Toolbar
###panel($var, $label = '')
Stores the value only for the duration of the current request and displays it in AVE Public Debug → Data. Prints nothing in HTML and returns the original meaning.
Debug::panel($document, 'Документ после обработки');
Debug::panel($filters, 'Фильтры каталога');
The panel displays the signature, type, value tree, file and call string. Enabling, rights and security rules are described in the section Public Debugging.
Legacy dumps
###echo($var, $exit = false, $bg = null, $echo = true)
Readable variable output; $exit = true - stop execution after output.
Debug::echo($data); // посмотреть
Debug::echo($data, true); // посмотреть и die()
print(...), exp(...), _($var)
Various formats for direct HTML output. Don't use them on a public page: the visitor can see the diagnostics.
###dump(...)
Writes an HTML dump to the root debug.html; This is not a Toolbar tab.
Performance measurements
startTime($name = '') / endTime($name = '') - code section timer.
startMemory($name = '') / endMemory($name = '') - memory measurement.
benchmark(callable $callable, array $params = []) — run and measure the call.
elapsed($start) — elapsed time from the mark.
getStatistic($type = null) - statistics (time/memory/number of requests).
Debug::startTime('render');
$html = renderPage();
Debug::endTime('render'); // выведет длительность
$res = Debug::benchmark(function () { return heavyQuery(); });
Errors and tracing
| Method | Destination |
|---|---|
errorMsg(string $msg) |
Show error message. |
errorSql($header, $sql, $caller = null, $exit = false) |
Nicely display the SQL error. |
dumpTrace() / debugBacktrace() |
Stack trace. |
fileLines($filepath, $line, $highlight = true, $padding = 3) |
A file fragment around a line. |
Recipes
View controller input without changing the answer:
Debug::panel(Request::all(), 'HTTP-вход контроллера');
Find bottleneck:
Debug::startTime('audit');
$report = Model::audit();
Debug::endTime('audit');
Remove temporary HTML dumps and noisy panel() calls before committing. Never
Do not pass passwords, tokens, or payment keys to the debugger.