You are here

protected function FrxSyntaxEngine::get_value in Forena Reports 7

Same name and namespace in other branches
  1. 6.2 FrxSyntaxEngine.inc \FrxSyntaxEngine::get_value()
  2. 6 FrxSyntaxEngine.inc \FrxSyntaxEngine::get_value()
  3. 7.2 FrxSyntaxEngine.inc \FrxSyntaxEngine::get_value()
  4. 7.3 FrxSyntaxEngine.inc \FrxSyntaxEngine::get_value()
  5. 7.4 FrxSyntaxEngine.inc \FrxSyntaxEngine::get_value()

Get the value from the data. This is used by token_replace method to extract the data based on the path provided.

Parameters

$data:

$key:

Return value

unknown_type

1 call to FrxSyntaxEngine::get_value()
FrxSyntaxEngine::replace in ./FrxSyntaxEngine.inc

File

./FrxSyntaxEngine.inc, line 92
FrXSytnaxEngine defines how regular expression procesing/token substitution takes place. It includes support for passing in a formatter oobject that will escape strings properly before substituting them.

Class

FrxSyntaxEngine

Code

protected function get_value($key, $raw = FALSE) {
  $retvar = '';

  // Determne which $data var we're going to get
  $data = array();
  if ($this->data_stack) {
    $i = count($this->data_stack) - 1;
    $data = $this->data_stack[$i];
  }

  // Determine if we have a . syntax for the id.
  if ($key) {
    @(list($id, $path) = explode('.', $key, 2));
    if ($data && isset($this->data_sources[$id])) {
      $data = $this->data_sources[$id];
      $key = $path;
    }
  }
  if (is_array($data)) {
    $retvar = @$data[$key];
  }
  elseif (is_object($data)) {
    if (strpos($key, '=') === 0) {
      $retvar = $this
        ->simplexml_evaluate($data, ltrim($key, '='));
    }
    else {
      $rows = $data
        ->xpath($key);
      $x = '';
      if ($rows) {
        $x = $rows[0];
      }
      if ($x) {
        $retvar = $x
          ->asXML();
      }

      // Check to see if there are child nodes
      // If so use asXML otherwise string cast.
      if ($retvar && strpos($retvar, '<') !== FALSE) {

        // Find the end of the first tag.
        $p = strpos($retvar, '>');
        $retvar = substr_replace($retvar, '', 0, $p + 1);
        $p = strrpos($retvar, '<', -1);
        $retvar = substr_replace($retvar, '', $p, strlen($retvar) - $p);
      }
      else {
        $retvar = (string) $x;
      }
    }
  }

  // Call the formatter object if neccessary
  $f = $this->formatter;
  if (!$raw && is_object($f) && method_exists($f, 'format')) {
    $retvar = $f
      ->format($retvar, $key, $data);
  }
  $retvar = trim($retvar);
  return $retvar;
}