OSDN Git Service

Reverse parameter order in output_csv() utility
authorscribu <mail@scribu.net>
Sun, 3 Feb 2013 20:37:16 +0000 (22:37 +0200)
committerscribu <mail@scribu.net>
Sun, 3 Feb 2013 20:37:39 +0000 (22:37 +0200)
... so that $headers can actually be optional.

Also fix coding standards violations.

php/commands/user.php
php/utils.php

index 21f3916..7ded949 100644 (file)
@@ -34,12 +34,12 @@ class User_Command extends \WP_CLI\CommandWithDBObject {
                }
 
                $fields = array(
-                               'ID',
-                               'user_login',
-                               'display_name',
-                               'user_email',
-                               'user_registered'
-                       );
+                       'ID',
+                       'user_login',
+                       'display_name',
+                       'user_email',
+                       'user_registered'
+               );
 
                switch( $params['format'] ) {
                        case 'table':
@@ -77,10 +77,9 @@ class User_Command extends \WP_CLI\CommandWithDBObject {
                                if ( 'json' == $params['format'] )
                                        echo json_encode( $output_users );
                                else
-                                       WP_CLI\Utils\output_csv( $fields, $output_users );
+                                       WP_CLI\Utils\output_csv( $output_users, $fields );
                                break;
                }
-
        }
 
        /**
index fa878df..4e06615 100644 (file)
@@ -236,25 +236,26 @@ function recursive_unserialize_replace( $from = '', $to = '', $data = '', $seria
 /**
  * Output data as CSV
  *
- * @param array  $headers    Headers for the CSV (optional)
- * @param array  $data       Data for each row
+ * @param array  $rows       Array of rows to output
+ * @param array  $headers    List of CSV columns (optional)
  */
-function output_csv( $headers = array(), $data = array() ) {
+function output_csv( $rows, $headers = array() ) {
 
        // Prepare the headers if they were specified
        if ( ! empty( $headers ) )
                fputcsv( STDOUT, $headers );
 
-       foreach( $data as $row ) {
-               $row = (array)$row;
+       foreach ( $rows as $row ) {
+               $row = (array) $row;
 
                if ( ! empty( $headers ) ) {
                        $build_row = array();
-                       foreach( $headers as $key ) {
-                               $build_row[] = $row[$key];
+                       foreach ( $headers as $key ) {
+                               $build_row[] = $row[ $key ];
                        }
                        $row = $build_row;
                }
                fputcsv( STDOUT, $row );
        }
 }
+