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