function RulesState::get

Gets a variable.

If necessary, the specified handler is invoked to fetch the variable.

Parameters

string $name: The name of the variable to return.

Return value

The variable or a EntityMetadataWrapper containing the variable.

Throws

RulesEvaluationException Throws a RulesEvaluationException in case we have info about the requested variable, but it is not defined.

1 call to RulesState::get()
RulesState::applyDataSelector in includes/rules.state.inc
Returns an entity metadata wrapper as specified in the selector.

File

includes/rules.state.inc, line 154

Class

RulesState
The rules evaluation state.

Code

public function &get($name) {
    if (!array_key_exists($name, $this->variables)) {
        // If there is handler to load the variable, do it now.
        if (!empty($this->info[$name]['handler'])) {
            $data = call_user_func($this->info[$name]['handler'], rules_unwrap_data($this->variables), $name, $this->info[$name]);
            $this->variables[$name] = rules_wrap_data($data, $this->info[$name]);
            $this->info[$name]['handler'] = FALSE;
            if (!isset($data)) {
                throw new RulesEvaluationException('Unable to load variable %name, aborting.', array(
                    '%name' => $name,
                ), NULL, RulesLog::INFO);
            }
        }
        else {
            throw new RulesEvaluationException('Unable to get variable %name, it is not defined.', array(
                '%name' => $name,
            ), NULL, RulesLog::ERROR);
        }
    }
    return $this->variables[$name];
}