You are here

class WebformLogicHelper in Webform 8.5

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

Provides helper to handle logic related issues.

Hierarchy

Expanded class hierarchy of WebformLogicHelper

2 files declare their use of WebformLogicHelper
webform.tokens.inc in ./webform.tokens.inc
Builds placeholder replacement tokens for webforms and submissions.
WebformTwigExtension.php in src/Twig/WebformTwigExtension.php

File

src/Utility/WebformLogicHelper.php, line 8

Namespace

Drupal\webform\Utility
View source
class WebformLogicHelper {

  /**
   * Track recursions.
   *
   * @var array
   */
  private static $recursionTracker = [];

  /**
   * Track recursions by counting how many times a value is called.
   *
   * @param string $value
   *   A string value typically a token.
   * @param bool $increment
   *   TRUE to increment tracking and FALSE to deincrement tracking.
   *
   * @return bool
   *   FALSE when recursion is detected.
   */
  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]--;
    }
  }

  /**
   * Start recursion tracking.
   *
   * @param string $value
   *   A string value typically a token.
   *
   * @return bool
   *   FALSE when recursion is detected.
   */
  public static function startRecursionTracking($value) {
    return self::trackRecursion($value, TRUE);
  }

  /**
   * Stop recursion tracking.
   *
   * @param string $value
   *   A string value typically a token.
   *
   * @return bool
   *   FALSE when recursion is detected.
   */
  public static function stopRecursionTracking($value) {
    return self::trackRecursion($value, FALSE);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebformLogicHelper::$recursionTracker private static property Track recursions.
WebformLogicHelper::startRecursionTracking public static function Start recursion tracking.
WebformLogicHelper::stopRecursionTracking public static function Stop recursion tracking.
WebformLogicHelper::trackRecursion protected static function Track recursions by counting how many times a value is called.