You are here

protected static function WebformLogicHelper::trackRecursion in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Utility/WebformLogicHelper.php \Drupal\webform\Utility\WebformLogicHelper::trackRecursion()

Track recursions by counting how many times a value is called.

Parameters

string $value: A string value typically a token.

bool $increment: TRUE to increment tracking and FALSE to deincrement tracking.

Return value

bool FALSE when recursion is detected.

2 calls to WebformLogicHelper::trackRecursion()
WebformLogicHelper::startRecursionTracking in src/Utility/WebformLogicHelper.php
Start recursion tracking.
WebformLogicHelper::stopRecursionTracking in src/Utility/WebformLogicHelper.php
Stop recursion tracking.

File

src/Utility/WebformLogicHelper.php, line 28

Class

WebformLogicHelper
Provides helper to handle logic related issues.

Namespace

Drupal\webform\Utility

Code

protected static function trackRecursion($value, $increment = TRUE) {
  self::$recursionTracker += [
    $value => 0,
  ];
  if (self::$recursionTracker[$value] === FALSE) {
    return FALSE;
  }
  if ($increment) {
    self::$recursionTracker[$value]++;
    if (self::$recursionTracker[$value] > 100) {

      // Cancel processing by setting the recursion tracker value to FALSE.
      self::$recursionTracker[$value] = FALSE;
      throw new \LogicException(sprintf('The "%s" is being called recursively.', $value));
    }
  }
  else {
    self::$recursionTracker[$value]--;
  }
}