function drush_outputformat::process

8.0.x outputformat.drush.inc drush_outputformat::process($input, $metadata = array())
6.x outputformat.drush.inc drush_outputformat::process($input, $metadata = array())
7.x outputformat.drush.inc drush_outputformat::process($input, $metadata = array())
master outputformat.drush.inc drush_outputformat::process($input, $metadata = array())

Perform pre-processing and then format() the $input.

File

commands/core/outputformat.drush.inc, line 407
Core drush output formats.

Class

drush_outputformat
Interface for output format engines.

Code

function process($input, $metadata = array()) {
  $metadata = array_merge_recursive($metadata, $this->engine_config);
  if (isset($metadata['private-fields']) && is_array($input)) {
    if (!drush_get_option('show-passwords', FALSE)) {
      if (!is_array($metadata['private-fields'])) {
        $metadata['private-fields'] = array($metadata['private-fields']);
      }
      foreach ($metadata['private-fields'] as $private) {
        drush_unset_recursive($input, $private);
      }
    }
  }
  if (isset($metadata[$this->engine . '-metadata'])) {
    $engine_specific_metadata = $metadata[$this->engine . '-metadata'];
    unset($metadata[$this->engine . '-metadata']);
    $metadata = array_merge($metadata, $engine_specific_metadata);
  }
  if ((drush_get_context('DRUSH_PIPE')) && (isset($metadata['pipe-metadata']))) {
    $pipe_specific_metadata = $metadata['pipe-metadata'];
    unset($metadata['pipe-metadata']);
    $metadata = array_merge($metadata, $pipe_specific_metadata);
  }
  $machine_parsable = $this->engine_config['engine-info']['machine-parsable'];
  $formatter_type = $machine_parsable ? 'parsable' : 'formatted';
  if ((!$machine_parsable) && is_bool($input)) {
    $input = $input ? 'TRUE' : 'FALSE';
  }

  // Run $input through any filters that are specified for this formatter.
  if (isset($metadata[$formatter_type . '-filter'])) {
    $filters = $metadata[$formatter_type . '-filter'];
    if (!is_array($filters)) {
      $filters = array($filters);
    }
    foreach ($filters as $filter) {
      if (function_exists($filter)) {
        $input = $filter($input, $metadata);
      }
    }
  }
  if (isset($metadata['field-labels'])) {
    foreach (drush_hide_output_fields() as $hidden_field) {
      unset($metadata['field-labels'][$hidden_field]);
    }
  }
  return $this->format($input, $metadata);
}