var_export.inc

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

Classes

Namesort descending Description
drush_outputformat_var_export Output formatter 'var_export'

File

commands/core/outputformat/var_export.inc
View source
  1. <?php
  2. /**
  3. * Output formatter 'var_export'
  4. *
  5. * Note: this class is also used by format 'config'
  6. *
  7. * @param $data
  8. * The $data parameter is rendered with the php var_export() function
  9. * @param $metadata
  10. * 'label' - If present, prints "$variable['label'] = " prior to the data
  11. * 'variable-name' - If present, provides an alternate name for $variable
  12. * when labels are in use.
  13. *
  14. * Code:
  15. *
  16. * return array(
  17. * "a" => array("b" => 2, "c" => 3),
  18. * "d" => array("e" => 5, "f" => 6)
  19. * );
  20. *
  21. * Output with --format=var_export:
  22. *
  23. * array (
  24. * 'a' =>
  25. * array (
  26. * 'b' => 2,
  27. * 'c' => 3,
  28. * ),
  29. * 'd' =>
  30. * array (
  31. * 'e' => 5,
  32. * 'f' => 6,
  33. * ),
  34. * )
  35. *
  36. * Output with --format=config: (list of export)
  37. *
  38. * $config['a'] = array (
  39. * 'b' => 2,
  40. * 'c' => 3,
  41. * );
  42. * $config['d'] = array (
  43. * 'e' => 5,
  44. * 'f' => 6,
  45. * );
  46. */
  47. class drush_outputformat_var_export extends drush_outputformat {
  48. function format($input, $metadata) {
  49. if (isset($metadata['label'])) {
  50. $variable_name = isset($metadata['variable-name']) ? $metadata['variable-name'] : 'variables';
  51. $variable_name = preg_replace("/[^a-zA-Z0-9_-]/", "", str_replace(' ', '_', $variable_name));
  52. $label = $metadata['label'];
  53. $label_template = (isset($metadata['label-template'])) ? $metadata['label-template'] : '$!variable["!label"] = !value;';
  54. $output = dt($label_template, array('!variable' => $variable_name, '!label' => $label, '!value' => var_export($input, TRUE)));
  55. }
  56. else {
  57. $output = drush_var_export($input);
  58. }
  59. return $output;
  60. }
  61. }