Skip to content

Commit

Permalink
Added helper metjpd fireCallback to XmlNodeList
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Aug 28, 2024
1 parent 8e8b768 commit 519b7b6
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/xml/XmlNodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ public function forEachMax(int $max, $callback, $callBackBefore = null, $callbac
return;
}

if (!is_callable($callback)) {
return;
}

if (is_callable($callBackBefore)) {
call_user_func($callBackBefore);
}
$this->fireCallback($callBackBefore);

$count = 0;

Expand All @@ -99,19 +93,27 @@ public function forEachMax(int $max, $callback, $callBackBefore = null, $callbac
break;
}

if (is_callable($callbackBeforeEach)) {
call_user_func($callbackBeforeEach, $node);
}
$this->fireCallback($callbackBeforeEach, $node);
$this->fireCallback($callback, $node);
$this->fireCallback($callbackAfterEach, $node);
}

call_user_func($callback, $node);
$this->fireCallback($callbackAfter);
}

if (is_callable($callbackAfterEach)) {
call_user_func($callbackAfterEach, $node);
}
/**
* Internal helper function to fire a callback function
*
* @param callable $callback
* @param array ...$args
* @return void
*/
private function fireCallback($callback, ...$args)
{
if (!is_callable($callback)) {
return;
}

if (is_callable($callbackAfter)) {
call_user_func($callbackAfter);
}
call_user_func($callback, ...$args);
}
}

0 comments on commit 519b7b6

Please sign in to comment.