Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / core / outputformat / variables.inc
1 <?php
2
3 /**
4  * Output formatter 'variables'
5  *
6  * @param $data
7  *   The $data parameter is expected to be a nested array of key / value pairs.
8  *   The top-level key becomes the variable name, $metadata['variable-name'],
9  *   and the key on the inner-level items becomes the array label,
10  *   $metadata['label'].  These items are then rendered by the 'var_export' formatter.
11  * @param $metadata
12  *   Unused.
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=variables:
22  *
23  *   $a['b'] = 2;
24  *   $a['c'] = 3;
25  *   $d['e'] = 5;
26  *   $d['f'] = 6;
27  */
28 class drush_outputformat_variables extends drush_outputformat {
29   function validate() {
30     $metadata = $this->engine_config;
31     $this->sub_engine = drush_load_engine('outputformat', 'var_export', $metadata);
32     if (!is_object($this->sub_engine)) {
33       return FALSE;
34     }
35     return TRUE;
36   }
37
38   function format($data, $metadata) {
39     $output = '';
40     if (is_array($data)) {
41       foreach ($data as $variable_name => $section) {
42         foreach ($section as $label => $value) {
43           $metameta = array(
44             'variable-name' => $variable_name,
45             'label' => $label,
46           );
47           $formatted_item = $this->sub_engine->process($value, $metameta);
48           if ($formatted_item === FALSE) {
49             return FALSE;
50           }
51           $output .= $formatted_item;
52           $output .= "\n";
53           }
54       }
55     }
56     return $output;
57   }
58 }