You are here

public function RulesConditionalWhile::evaluate in Conditional Rules 8

Same name and namespace in other branches
  1. 7 includes/rules_conditional.plugin.inc \RulesConditionalWhile::evaluate()

File

includes/rules_conditional.plugin.inc, line 431
Rules plugin implementation.

Class

RulesConditionalWhile
While loop.

Code

public function evaluate(RulesState $state) {
  $iteration = 0;
  $maxIterations = variable_get('rules_conditional_max_iterations', RULES_CONDITIONAL_MAX_ITERATIONS);
  while ($iteration < $maxIterations && $this
    ->canEvaluate($state)) {

    // Use a separate state so variables are available in the loop only.
    $clonedState = clone $state;
    parent::evaluate($clonedState);
    $iteration++;

    // Retrieve variables.
    foreach ($state->variables as $key => &$value) {
      if (array_key_exists($key, $clonedState->variables)) {
        $value = $clonedState->variables[$key];
      }
    }
  }
}