variables.inc

  1. 8.0.x commands/core/outputformat/variables.inc
  2. 6.x commands/core/outputformat/variables.inc
  3. 7.x commands/core/outputformat/variables.inc
  4. master commands/core/outputformat/variables.inc

Classes

Namesort descending Description
drush_outputformat_variables Output formatter 'variables'

File

commands/core/outputformat/variables.inc
View source
  1. <?php
  2. /**
  3. * Output formatter 'variables'
  4. *
  5. * @param $data
  6. * The $data parameter is expected to be a nested array of key / value pairs.
  7. * The top-level key becomes the variable name, $metadata['variable-name'],
  8. * and the key on the inner-level items becomes the array label,
  9. * $metadata['label']. These items are then rendered by the 'var_export' formatter.
  10. * @param $metadata
  11. * Unused.
  12. *
  13. * Code:
  14. *
  15. * return array(
  16. * "a" => array("b" => 2, "c" => 3),
  17. * "d" => array("e" => 5, "f" => 6)
  18. * );
  19. *
  20. * Output with --format=variables:
  21. *
  22. * $a['b'] = 2;
  23. * $a['c'] = 3;
  24. * $d['e'] = 5;
  25. * $d['f'] = 6;
  26. */
  27. class drush_outputformat_variables extends drush_outputformat {
  28. function validate() {
  29. $metadata = $this->engine_config;
  30. $this->sub_engine = drush_load_engine('outputformat', 'var_export', $metadata);
  31. if (!is_object($this->sub_engine)) {
  32. return FALSE;
  33. }
  34. return TRUE;
  35. }
  36. function format($data, $metadata) {
  37. $output = '';
  38. if (is_array($data)) {
  39. foreach ($data as $variable_name => $section) {
  40. foreach ($section as $label => $value) {
  41. $metameta = array(
  42. 'variable-name' => $variable_name,
  43. 'label' => $label,
  44. );
  45. $formatted_item = $this->sub_engine->process($value, $metameta);
  46. if ($formatted_item === FALSE) {
  47. return FALSE;
  48. }
  49. $output .= $formatted_item;
  50. $output .= "\n";
  51. }
  52. }
  53. }
  54. return $output;
  55. }
  56. }