You are here

function rules_variable::get in Rules 6

Gets the actual data. Be sure to keep the reference intact.

Parameters

$load Use the variable handler to load the variable, if necessary.:

Return value

The data or NULL.

File

rules/rules.variables.inc, line 308
Provides functions and classes for handling variables

Class

rules_variable
Handles loading and saving a variable

Code

function &get($load = TRUE) {
  $data = NULL;
  if ($load && !isset($this->data) && function_exists($this->info['handler'])) {

    // Call the handler to get the runtime data.
    $args = rules_get_variables(array_keys($this->_state['variables']), $this->_state, FALSE);
    $data = call_user_func_array($this->info['handler'], $args);
    $this
      ->_set_data($data);
    $this->info['handler'] = '';

    // Do not invoke it twice, if it fails
    rules_log(t('Loaded variable "@arg"', array(
      '@arg' => $this->info['label'],
    )));
  }
  else {
    if (isset($this->data)) {
      $data =& $this->data
        ->get();
    }
  }
  return $data;
}