class WebformLogicHelper in Webform 8.5
Same name and namespace in other branches
- 6.x src/Utility/WebformLogicHelper.php \Drupal\webform\Utility\WebformLogicHelper
Provides helper to handle logic related issues.
Hierarchy
- class \Drupal\webform\Utility\WebformLogicHelper
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\UtilityView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WebformLogicHelper:: |
private static | property | Track recursions. | |
WebformLogicHelper:: |
public static | function | Start recursion tracking. | |
WebformLogicHelper:: |
public static | function | Stop recursion tracking. | |
WebformLogicHelper:: |
protected static | function | Track recursions by counting how many times a value is called. |