Skip to content

Commit

Permalink
Make sure same hook spot is not triggered while executing
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Aug 26, 2020
1 parent 949e5d8 commit 399e43f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/HookTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,13 @@ public function hook(string $spot, array $args = [], HookBreaker &$brokenBy = nu

$return = [];
if (isset($this->hooks[$spot])) {
krsort($this->hooks[$spot]); // lower priority is called sooner
$hookBackup = $this->hooks[$spot];
ksort($this->hooks[$spot]); // lower priority is called sooner

try {
$bb = $this->_hookActiveSpots[$spot] ?? false;
$this->_hookActiveSpots[$spot] = true;

while ($_data = array_pop($this->hooks[$spot])) {
foreach ($_data as $index => $data) {
foreach ($this->hooks[$spot] as $datas) {
foreach ($datas as $index => $data) {
$return[$index] = $data[0](...array_merge(
[$this],
$args,
Expand All @@ -157,8 +155,7 @@ public function hook(string $spot, array $args = [], HookBreaker &$brokenBy = nu

return $e->getReturnValue();
} finally {
$this->hooks[$spot] = $hookBackup;
$this->_hookActiveSpots[$spot] = $bb;
$this->_hookActiveSpots[$spot] = false;
}
}

Expand Down

0 comments on commit 399e43f

Please sign in to comment.