From e1a4d1b3cc3d275d3c3deef18370141902d28f97 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Fri, 7 Jul 2023 09:57:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20blade=20hook=20=E4=BC=98?= =?UTF-8?q?=E5=85=88=E7=BA=A7=E8=A2=AB=E8=A6=86=E7=9B=96=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Hook/Hook.php | 23 +++++++++++++---------- beike/Hook/HookServiceProvider.php | 8 +++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/beike/Hook/Hook.php b/beike/Hook/Hook.php index e4394720..3386b125 100644 --- a/beike/Hook/Hook.php +++ b/beike/Hook/Hook.php @@ -49,10 +49,10 @@ class Hook } /** - * @param string $hook - * @param array $params + * @param string $hook + * @param array $params * @param callable|null $callback - * @param string $htmlContent + * @param string $htmlContent * @return string|void|null */ public function getHook(string $hook, array $params = [], callable $callback = null, string $htmlContent = '') @@ -64,12 +64,11 @@ class Hook return $this->get($hook, $params, $callback, $htmlContent); } - /** - * @param string $hook - * @param array $params + * @param string $hook + * @param array $params * @param callable|null $callback - * @param string $htmlContent + * @param string $htmlContent * @return string|void|null */ public function getWrapper(string $hook, array $params = [], callable $callback = null, string $htmlContent = '') @@ -114,11 +113,15 @@ class Hook $priority = null; } + if (isset($this->watch[$hook][$priority])) { + $priority++; + } + $this->watch[$hook][$priority] = [ 'function' => $function, 'caller' => [ - //'file' => $caller['file'], - //'line' => $caller['line'], + 'file' => $caller['file'], + 'line' => $caller['line'], 'class' => Arr::get($caller, 'class'), ], ]; @@ -192,7 +195,7 @@ class Hook * Return a new callback object. * * @param callable $callback function - * @param array $params parameters + * @param array $params parameters * * @return Callback */ diff --git a/beike/Hook/HookServiceProvider.php b/beike/Hook/HookServiceProvider.php index 9c7297cf..326ea2dc 100644 --- a/beike/Hook/HookServiceProvider.php +++ b/beike/Hook/HookServiceProvider.php @@ -19,7 +19,6 @@ class HookServiceProvider extends ServiceProvider }); } - public function boot() { $this->bootHookDirectives(); @@ -33,7 +32,7 @@ class HookServiceProvider extends ServiceProvider protected function bootHookDirectives() { Blade::directive('hook', function ($parameter) { - $parameter = trim($parameter, '()'); + $parameter = trim($parameter, '()'); $parameters = explode(',', $parameter); $name = trim($parameters[0], "'"); @@ -51,7 +50,6 @@ class HookServiceProvider extends ServiceProvider }); } - /** * 添加 blade wrapper hook 标签 * @@ -60,9 +58,9 @@ class HookServiceProvider extends ServiceProvider protected function bootWrapperHookDirectives() { Blade::directive('hookwrapper', function ($parameter) { - $parameter = trim($parameter, '()'); + $parameter = trim($parameter, '()'); $parameters = explode(',', $parameter); - $name = trim($parameters[0], "'"); + $name = trim($parameters[0], "'"); return '