示例#1
0
 /**
  * Format a list of records of the same type.
  *
  * @param array $records
  *  A list of arrays or objects.
  * @param array $human_labels
  *  An array that maps the record keys to human names.
  * @return string
  */
 public function formatRecordList($records, $human_labels = array())
 {
     $out = '';
     foreach ($records as $record) {
         foreach ((array) $record as $value) {
             $out .= BashFormatter::flattenValue($value);
             $out .= BashFormatter::FIELD_SEPARATOR;
         }
         // Remove the trailing separator.
         $out = substr($out, 0, strlen($out) - strlen(BashFormatter::FIELD_SEPARATOR));
         $out .= BashFormatter::ROW_SEPARATOR;
     }
     return $out;
 }
示例#2
0
 /**
  * Flattens a value for display
  *
  * @param [string] $output
  */
 private static function flattenValue($value)
 {
     if (is_scalar($value)) {
         return $value;
     }
     $value = (array) $value;
     $output = array();
     foreach ($value as $key => $val) {
         $output[] = $key . ': ' . BashFormatter::flattenValue($val);
     }
     $output = '(' . implode(BashFormatter::VALUE_SEPARATOR, $output) . ')';
     return $output;
 }