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