From c1670c6442a5035cc6fddb8afe83c3b4b94a8f3f Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 1 Mar 2023 15:22:51 +0800 Subject: [PATCH] fixed debugbar not installed --- beike/Helpers.php | 14 ++++++++++++-- beike/Hook/Hook.php | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/beike/Helpers.php b/beike/Helpers.php index 65d9e235..f619eeb3 100644 --- a/beike/Helpers.php +++ b/beike/Helpers.php @@ -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); diff --git a/beike/Hook/Hook.php b/beike/Hook/Hook.php index 645df776..362bed03 100644 --- a/beike/Hook/Hook.php +++ b/beike/Hook/Hook.php @@ -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);