You are here

public function RulesPlugin::setUpState in Rules 7.2

Sets up the execution state for the given arguments.

3 calls to RulesPlugin::setUpState()
RulesAbstractPlugin::executeByArgs in includes/rules.core.inc
Execute the configuration by passing arguments in a single array.
RulesContainerPlugin::executeByArgs in includes/rules.core.inc
Executes container with the given arguments.
RulesEventSet::executeByArgs in includes/rules.plugins.inc
Executes container with the given arguments.

File

includes/rules.core.inc, line 720
Rules base classes and interfaces needed for any rule evaluation.

Class

RulesPlugin
Base class for rules plugins.

Code

public function setUpState(array $args) {
  $state = new RulesState();
  $vars = $this
    ->setUpVariables();

  // Fix numerically indexed args to start with 0.
  if (!isset($args[rules_array_key($vars)])) {
    $args = array_values($args);
  }
  $offset = 0;
  foreach (array_keys($vars) as $i => $name) {
    $info = $vars[$name];
    if (!empty($info['handler']) || isset($info['parameter']) && $info['parameter'] === FALSE) {
      $state
        ->addVariable($name, NULL, $info);

      // Count the variables that are not passed as parameters.
      $offset++;
    }
    elseif (isset($args[$i - $offset])) {
      $state
        ->addVariable($name, $args[$i - $offset], $info);
    }
    elseif (isset($args[$name])) {
      $state
        ->addVariable($name, $args[$name], $info);
    }
    elseif (empty($info['optional']) && $info['type'] != 'hidden') {
      throw new RulesEvaluationException('Argument %name is missing.', array(
        '%name' => $name,
      ), $this, RulesLog::ERROR);
    }
  }
  return $state;
}