string.inc

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

Classes

Namesort descending Description
drush_outputformat_string Output formatter 'string'

File

commands/core/outputformat/string.inc
View source
  1. <?php
  2. /**
  3. * Output formatter 'string'
  4. *
  5. * @param $data
  6. * The render data may be either a string or an array
  7. * string - printed as-is, without quotes
  8. * array - the value of the first item in the array is printed as-is
  9. * @param $metadata
  10. * 'label' - If present, prints "label: " prior to the data
  11. *
  12. * Code:
  13. *
  14. * return DRUSH_VERSION;
  15. *
  16. * Output with --format=string:
  17. *
  18. * 6.0-dev
  19. */
  20. class drush_outputformat_string extends drush_outputformat {
  21. function format($data, $metadata) {
  22. // If the data is an array, print the value of the first item.
  23. if (is_array($data)) {
  24. if (count($data) > 1) {
  25. return $this->format_error("Multiple rows provided where only one is allowed.");
  26. }
  27. if (!empty($data)) {
  28. $data = reset($data);
  29. }
  30. if (is_array($data)) {
  31. return $this->format_error("Array provided where a string is required.");
  32. }
  33. }
  34. return (string)$data;
  35. }
  36. }