PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/drush7/commands/core/outputformat/print_r.inc

https://bitbucket.org/kbasarab/kbasarab_vim
Pascal | 51 lines | 40 code | 1 blank | 10 comment | 3 complexity | d9d7eb04bed7d9d23b9e222f9ca082b5 MD5 | raw file
Possible License(s): MIT
  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. }