You are here

public function TokenReplacerBase::object_to_array in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 src/Token/TokenReplacerBase.php \Drupal\forena\Token\TokenReplacerBase::object_to_array()

Convert an object into an array

Parameters

mixed $data: Iterates the object and builds an array of strings from it. If the object appears to be an xml object and has an attributes method, do the same for it.

File

src/Token/TokenReplacerBase.php, line 142
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

TokenReplacerBase

Namespace

Drupal\forena\Token

Code

public function object_to_array($data) {
  if (is_object($data)) {
    $ar = array();
    foreach ($data as $key => $value) {
      $ar[$key] = (string) $value;
    }
    if (method_exists($data, 'attributes')) {
      foreach ($data
        ->attributes() as $key => $value) {
        $ar[$key] = (string) $value;
      }
    }
    return $ar;
  }
  else {
    return $data;
  }
}