print_r.inc

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

Classes

Namesort descending Description
drush_outputformat_print_r Output formatter 'print-r'

File

commands/core/outputformat/print_r.inc
View source
  1. <?php
  2. /**
  3. * Output formatter 'print-r'
  4. *
  5. * @param $data
  6. * The $data parameter is rendered with the php print_r function
  7. * @param $metadata
  8. * 'label' - If present, prints "label: " prior to the data
  9. *
  10. * Code:
  11. *
  12. * return array(
  13. * "a" => array("b" => 2, "c" => 3),
  14. * "d" => array("e" => 5, "f" => 6)
  15. * );
  16. *
  17. * Output with --format=print-r:
  18. *
  19. * Array
  20. * (
  21. * [a] => Array
  22. * (
  23. * [b] => 2
  24. * [c] => 3
  25. * )
  26. *
  27. * [d] => Array
  28. * (
  29. * [e] => 5
  30. * [f] => 6
  31. * )
  32. * )
  33. */
  34. class drush_outputformat_print_r extends drush_outputformat {
  35. function format($input, $metadata) {
  36. if (is_string($input)) {
  37. $output = '"' . $input . '"';
  38. }
  39. elseif (is_array($input) || is_object($input)) {
  40. $output = print_r($input, TRUE);
  41. }
  42. else {
  43. $output = $input;
  44. }
  45. if (isset($metadata['label'])) {
  46. $output = $metadata['label'] . ': ' . $output;
  47. }
  48. return $output;
  49. }
  50. }