/drush7/commands/core/outputformat/print_r.inc
Pascal | 51 lines | 40 code | 1 blank | 10 comment | 3 complexity | d9d7eb04bed7d9d23b9e222f9ca082b5 MD5 | raw file
Possible License(s): MIT
- <?php
- /**
- * Output formatter 'print-r'
- *
- * @param $data
- * The $data parameter is rendered with the php print_r function
- * @param $metadata
- * 'label' - If present, prints "label: " prior to the data
- *
- * Code:
- *
- * return array(
- * "a" => array("b" => 2, "c" => 3),
- * "d" => array("e" => 5, "f" => 6)
- * );
- *
- * Output with --format=print-r:
- *
- * Array
- * (
- * [a] => Array
- * (
- * [b] => 2
- * [c] => 3
- * )
- *
- * [d] => Array
- * (
- * [e] => 5
- * [f] => 6
- * )
- * )
- */
- class drush_outputformat_print_r extends drush_outputformat {
- function format($input, $metadata) {
- if (is_string($input)) {
- $output = '"' . $input . '"';
- }
- elseif (is_array($input) || is_object($input)) {
- $output = print_r($input, TRUE);
- }
- else {
- $output = $input;
- }
- if (isset($metadata['label'])) {
- $output = $metadata['label'] . ': ' . $output;
- }
- return $output;
- }
- }