Skip to content

Commit

Permalink
Events orchestrator patch.
Browse files Browse the repository at this point in the history
Changelog excerpt:
- Added guard to the events orchestrator to prevent infinite looping via
  recursive event firing from within handlers.
  • Loading branch information
Maikuolan committed Aug 27, 2023
1 parent a10def9 commit d30b14e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ found at:
- [2023.08.18; Maikuolan]: Improved tests and documentation for the operation
handler.

- [2023.08.28; Maikuolan]: Added guard to the events orchestrator to prevent
infinite looping via recursive event firing from within handlers.

=== Version/Release 1.9.7 ===
PATCH RELEASE.

Expand Down
6 changes: 4 additions & 2 deletions src/Events.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Events orchestrator (last modified: 2023.08.16).
* Events orchestrator (last modified: 2023.08.28).
*
* This file is a part of the "common classes package", utilised by a number of
* packages and projects, including CIDRAM and phpMussel.
Expand Down Expand Up @@ -99,12 +99,14 @@ public function destroyEvent($Event)
*/
public function fireEvent($Event, $Data = '')
{
if (!isset($this->Handlers[$Event], $this->Status[$Event])) {
if (!isset($this->Handlers[$Event], $this->Status[$Event]) || isset($this->Status[$Event]['In Progress'])) {
return false;
}
$this->Status[$Event]['In Progress'] = true;
foreach ($this->Handlers[$Event] as $Handler) {
$Handler($Data);
}
unset($this->Status[$Event]['In Progress']);
return true;
}

Expand Down

0 comments on commit d30b14e

Please sign in to comment.