Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/Library/CrudPanel/Hooks/LifecycleHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
final class LifecycleHooks
{
public array $hooks = [];
private array $executedHooks = [];

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

foreach ($hooks as $hook) {
// Create a unique identifier for this controller+hook combination
$hookId = is_null($controller) ? '' : (is_string($controller) ? $controller : $controller::class.'::'.$hook);

// Skip if this hook has already been executed
if (isset($this->executedHooks[$hookId])) {
continue;
}

if (isset($this->hooks[$controller][$hook])) {
foreach ($this->hooks[$controller][$hook] as $callback) {
if ($callback instanceof \Closure) {
$callback(...$parameters);
}
}

$this->executedHooks[$hookId] = true;
}
}
}
Expand Down