Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Tomáš Pospíšil
tracyBars
Commits
c08ab507
Commit
c08ab507
authored
Apr 02, 2020
by
Tomáš Pospíšil
Browse files
Error counts
parent
cccd3781
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/BarPanel/ErrorCountBar.php
0 → 100644
View file @
c08ab507
<?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'
);
}
}
src/BarPanel/Registrator.php
View file @
c08ab507
...
...
@@ -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
(
...
...
src/templates/database/dbProfiler.tpl
View file @
c08ab507
...
...
@@ -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>
...
...
src/templates/errorCount/errors.tpl
0 → 100644
View file @
c08ab507
<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>
src/templates/errorCount/tab.tpl
0 → 100644
View file @
c08ab507
{
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
}
src/templates/internalSmarty/tab.tpl
View file @
c08ab507
{
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>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment