fixed debugbar not installed

This commit is contained in:
Edward Yang 2023-03-01 15:22:51 +08:00
parent 2053e6add7
commit c1670c6442
2 changed files with 14 additions and 4 deletions

View File

@ -610,6 +610,16 @@ function create_directories($directoryPath)
}
}
/**
* 是否安装 debugbar
*
* @return bool
*/
function has_debugbar(): bool
{
return class_exists(\Barryvdh\Debugbar\Facades\Debugbar::class);
}
/**
* PHP 代码 hook filter 埋点
*
@ -619,7 +629,7 @@ function create_directories($directoryPath)
*/
function hook_filter($hookKey, $hookValue): mixed
{
if (config('app.debug')) {
if (config('app.debug') && has_debugbar()) {
Debugbar::log('HOOK === hook_filter: ' . $hookKey);
}
@ -634,7 +644,7 @@ function hook_filter($hookKey, $hookValue): mixed
*/
function hook_action($hookKey, $hookValue)
{
if (config('app.debug')) {
if (config('app.debug') && has_debugbar()) {
Debugbar::log('HOOK === hook_action: ' . $hookKey);
}
Eventy::action($hookKey, $hookValue);

View File

@ -57,7 +57,7 @@ class Hook
*/
public function getHook(string $hook, array $params = [], callable $callback = null, string $htmlContent = '')
{
if (config('app.debug')) {
if (config('app.debug') && has_debugbar()) {
Debugbar::log("HOOK === @hook: {$hook}");
}
return $this->get($hook, $params, $callback, $htmlContent);
@ -73,7 +73,7 @@ class Hook
*/
public function getWrapper(string $hook, array $params = [], callable $callback = null, string $htmlContent = '')
{
if (config('app.debug')) {
if (config('app.debug') && has_debugbar()) {
Debugbar::log("HOOK === @hookwrapper: {$hook}");
}
return $this->get($hook, $params, $callback, $htmlContent);