function backendCase::parse

4.x backendTest.php backendCase::parse($string)
1 call to backendCase::parse()

File

tests/backendTest.php, line 67

Class

backendCase

Code

function parse($string) {
  $regex = sprintf(self::DRUSH_BACKEND_OUTPUT_DELIMITER, '(.*)');
  preg_match("/$regex/s", $string, $match);
  if ($match[1]) {
    // we have our JSON encoded string
    $output = $match[1];
    // remove the match we just made and any non printing characters
    $string = trim(str_replace(sprintf(self::DRUSH_BACKEND_OUTPUT_DELIMITER, $match[1]), '', $string));
  }

  if ($output) {
    $data = json_decode($output, TRUE);
    if (is_array($data)) {
      return $data;
    }
  }
  return $string;
}