First Commit

This commit is contained in:
marco
2026-09-01 10:46:29 -03:00
commit bf96b77e9c
10000 changed files with 3508600 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace Kernel;
class HookManager
{
protected array $actions = [];
protected array $filters = [];
public function addAction(string $hook, callable $listener, int $priority = 10): void
{
$this->actions[$hook][$priority][] = $listener;
}
public function doAction(string $hook, ...$args): void
{
if (!isset($this->actions[$hook])) {
return;
}
ksort($this->actions[$hook]);
foreach ($this->actions[$hook] as $listeners) {
foreach ($listeners as $listener) {
$listener(...$args);
}
}
}
public function addFilter(string $hook, callable $listener, int $priority = 10): void
{
$this->filters[$hook][$priority][] = $listener;
}
public function applyFilters(string $hook, $value, ...$args)
{
if (!isset($this->filters[$hook])) {
return $value;
}
ksort($this->filters[$hook]);
foreach ($this->filters[$hook] as $listeners) {
foreach ($listeners as $listener) {
$value = $listener($value, ...$args);
}
}
return $value;
}
}