Commit c08ab507 authored by Tomáš Pospíšil's avatar Tomáš Pospíšil
Browse files

Error counts

parent cccd3781
<?php
declare(strict_types=1);
namespace Praguebest\BarPanel;
use Smarty;
use SmartyException;
use Tracy\IBarPanel;
use Tracy\ILogger;
final class ErrorCountBar implements IBarPanel
{
/**
* @var Smarty
*/
private $smarty;
/**
* @var string
*/
private $errorDir;
/**
* @var array
*/
private $errors;
/**
* @var array
*/
private $infos;
/**
* ErrorCountBar constructor.
* @param $errorDir
* @param Smarty $smarty
*/
public function __construct(string $errorDir, Smarty $smarty)
{
$this->smarty = $smarty;
$this->errorDir = $errorDir;
foreach ([ILogger::CRITICAL, ILogger::EXCEPTION, ILogger::ERROR, ILogger::WARNING] as $errorCode) {
$this->errors[$errorCode] = $this->countFiles($errorCode);
}
foreach ([ILogger::DEBUG, ILogger::INFO] as $errorCode) {
$this->infos[$errorCode] = $this->countFiles($errorCode);
}
}
private function countFiles(string $string): int
{
$files = glob($this->errorDir . DIRECTORY_SEPARATOR . $string . '*.html');
if ($files) {
return count($files);
}
return 0;
}
/**
* Renders HTML code for custom panel.
* @return string
* @throws SmartyException
*/
public function getPanel(): string
{
$this->smarty->assign('errorCount', array_sum($this->errors));
$this->smarty->assign('errors', $this->errors);
$this->smarty->assign('infos', $this->infos);
return $this->smarty->fetch(dirname(__DIR__) . '/templates/errorCount/errors.tpl');
}
/**
* Renders HTML code for custom tab.
* @return string
* @throws SmartyException
*/
public function getTab(): string
{
$this->smarty->assign('errorCount', array_sum($this->errors));
return $this->smarty->fetch(dirname(__DIR__) . '/templates/errorCount/tab.tpl');
}
}
......@@ -68,9 +68,27 @@ final class Registrator
Debugger::$maxDepth = 5;
Debugger::enable('42@84.42.168.182,42@185.156.123.46', realpath($errorDir), Strings::replace($emailDeveloper, '/,;/', ','));
$this->addPanel(
__METHOD__,
function () use ($errorDir) {
return new ErrorCountBar($errorDir, $this->smarty);
}
);
return $this;
}
private function addPanel(string $method, callable $panelCreator): void
{
if (PHP_SAPI !== 'cli' && !array_key_exists($method, $this->registeredPanels) && Debugger::isEnabled()) {
$panel = $panelCreator();
assert($panel instanceof IBarPanel);
$this->registeredPanels[$method] = $panel;
Debugger::getBar()->addPanel($panel);
}
}
public function registerAll(Tools\TraceableSmarty $smarty, WebSwitcherUrls $urls): Registrator
{
if (Debugger::isEnabled()) {
......@@ -98,17 +116,6 @@ final class Registrator
return $this;
}
private function addPanel(string $method, callable $panelCreator): void
{
if (PHP_SAPI !== 'cli' && !array_key_exists($method, $this->registeredPanels) && Debugger::isEnabled()) {
$panel = $panelCreator();
assert($panel instanceof IBarPanel);
$this->registeredPanels[$method] = $panel;
Debugger::getBar()->addPanel($panel);
}
}
public function registerWebswitcher(WebSwitcherUrls $urls): Registrator
{
$this->addPanel(
......
......@@ -31,6 +31,12 @@
<td>{$line['loc'] nofilter}</td>
<td>{$line['name'] nofilter}</td>
</tr>
{if $line@iteration > 5}
<tr>
<td colspan="2">+ {count($call['lines'])-5} more...</td>
</tr>
{break}
{/if}
{/foreach}
</table>
</td>
......
<div class="tracy-inner">
<h1 style="margin: 0;">{$errorCount} errors</h1>
<div class="tracy-inner-container">
<form method="post">
<table>
{foreach $errors as $name => $count}
<tr>
<td>{$name|ucfirst}</td>
<td>{$count}</td>
</tr>
{/foreach}
{foreach $infos as $name => $count}
<tr>
<td>{$name|ucfirst}</td>
<td>{$count}</td>
</tr>
{/foreach}
</table>
</form>
</div>
</div>
{if $errorCount > 0}
<span style="display: inline-block;color: white;padding: 0 5px;background-color: red"><strong>{$errorCount}</strong> errors logged</span>
{else}
<span class="">0 errors</span>
{/if}
{if $countInternalVariables === 0}
<span style="color: gray; text-decoration: line-through">{ldelim}${rdelim} Internal vars</span>
<span class="tracy-label"></span>
<span style="color: gray; text-decoration: line-through">{ldelim}${rdelim}</span>
{else}
{strip}
<span style="color: cadetblue">{ldelim}</span>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment