Skip to content

Commit

Permalink
Merge pull request #199 from WebFiori/dev
Browse files Browse the repository at this point in the history
[Fix] Fix to Ordering Callbacks that are Added During Another Callback Execution
  • Loading branch information
usernane authored Nov 26, 2023
2 parents cb99048 + f1871ff commit 43f9484
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions webfiori/framework/ui/WebPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,7 @@ public function removeChild($node) {
* @since 1.0
*/
public function render(bool $formatted = false, bool $returnResult = false) {
$this->beforeRenderCallbacks->insertionSort(false);

foreach ($this->beforeRenderCallbacks as $callbackObj) {
$callbackObj->call($this);
}
$this->invokeBeforeRender();

if (!$returnResult) {
$formatted = $formatted === true || (defined('WF_VERBOSE') && WF_VERBOSE);
Expand All @@ -771,6 +767,21 @@ public function render(bool $formatted = false, bool $returnResult = false) {

return $this->getDocument();
}
private function invokeBeforeRender(int $current = 0) {
$currentCount = count($this->beforeRenderCallbacks);

if ($currentCount == 0 || $currentCount == $current) {
return;
}
$this->beforeRenderCallbacks->get($current)->call($this);
$newCount = count($this->beforeRenderCallbacks);
if ($newCount != $currentCount) {
$this->beforeRenderCallbacks->insertionSort(false);
$this->invokeBeforeRender();
} else {
$this->invokeBeforeRender($current + 1);
}
}
/**
* Resets page attributes to default values.
*
Expand Down

0 comments on commit 43f9484

Please sign in to comment.