Skip to content

Commit 5a2517f

Browse files
pxpmStyleCIBot
andauthored
Fix hooks at setup level (#5818)
Co-authored-by: StyleCI Bot <[email protected]>
1 parent c6bd8ce commit 5a2517f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/app/Library/CrudPanel/Hooks/LifecycleHooks.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
final class LifecycleHooks
88
{
99
public array $hooks = [];
10+
private array $executedHooks = [];
1011

1112
public function hookInto(string|array $hooks, callable $callback): void
1213
{
@@ -23,12 +24,22 @@ public function trigger(string|array $hooks, array $parameters = []): void
2324
$controller = CrudManager::getActiveController() ?? CrudManager::getParentController();
2425

2526
foreach ($hooks as $hook) {
27+
// Create a unique identifier for this controller+hook combination
28+
$hookId = is_null($controller) ? '' : (is_string($controller) ? $controller : $controller::class.'::'.$hook);
29+
30+
// Skip if this hook has already been executed
31+
if (isset($this->executedHooks[$hookId])) {
32+
continue;
33+
}
34+
2635
if (isset($this->hooks[$controller][$hook])) {
2736
foreach ($this->hooks[$controller][$hook] as $callback) {
2837
if ($callback instanceof \Closure) {
2938
$callback(...$parameters);
3039
}
3140
}
41+
42+
$this->executedHooks[$hookId] = true;
3243
}
3344
}
3445
}

0 commit comments

Comments
 (0)