OSDN Git Service

move iterators to separate namespace
authorscribu <mail@scribu.net>
Sun, 14 Apr 2013 19:11:05 +0000 (22:11 +0300)
committerscribu <mail@scribu.net>
Sun, 14 Apr 2013 19:11:05 +0000 (22:11 +0300)
php/WP_CLI/Iterators/CSV.php [moved from php/WP_CLI/CSVIterator.php with 95% similarity]
php/WP_CLI/Iterators/Exception.php [new file with mode: 0644]
php/WP_CLI/Iterators/Query.php [moved from php/WP_CLI/QueryIterator.php with 86% similarity]
php/WP_CLI/Iterators/Table.php [moved from php/WP_CLI/TableIterator.php with 86% similarity]
php/commands/role.php
php/commands/search-replace.php
php/commands/user.php

similarity index 95%
rename from php/WP_CLI/CSVIterator.php
rename to php/WP_CLI/Iterators/CSV.php
index 46a3bf9..dde3fb5 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 
-namespace WP_CLI;
+namespace WP_CLI\Iterators;
 
-class CSVIterator implements \Iterator {
+class CSV implements \Iterator {
 
        const ROW_SIZE = 4096;
 
diff --git a/php/WP_CLI/Iterators/Exception.php b/php/WP_CLI/Iterators/Exception.php
new file mode 100644 (file)
index 0000000..e7320e0
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+
+namespace WP_CLI\Iterators;
+
+class Exception extends \RuntimeException {}
+
similarity index 86%
rename from php/WP_CLI/QueryIterator.php
rename to php/WP_CLI/Iterators/Query.php
index 3962d11..1954586 100644 (file)
@@ -1,13 +1,13 @@
 <?php
 
-namespace WP_CLI;
+namespace WP_CLI\Iterators;
 
 /**
  * Iterates over results of a query, split into many queries via LIMIT and OFFSET
  *
  * @source https://gist.github.com/4060005
  */
-class QueryIterator implements \Iterator {
+class Query implements \Iterator {
 
        private $limit = 500;
        private $query = '';
@@ -24,7 +24,7 @@ class QueryIterator implements \Iterator {
         *
         * This will loop over all users, but will retrieve them 100 by 100:
         * <code>
-        * foreach( new QueryIterator( array( 'query' => 'SELECT * FROM users', 'limit' => 100 ) ) as $user ) {
+        * foreach( new Iterators\Query( array( 'query' => 'SELECT * FROM users', 'limit' => 100 ) ) as $user ) {
         *     tickle( $user );
         * }
         * </code>
@@ -49,7 +49,7 @@ class QueryIterator implements \Iterator {
                $this->results = $this->db->get_results( $query );
                if ( !$this->results ) {
                        if ( $this->db->last_error ) {
-                               throw new QueryIteratorException( 'Database error: '.$this->db->last_error );
+                               throw new Iterators\Exception( 'Database error: '.$this->db->last_error );
                        } else {
                                return false;
                        }
@@ -96,5 +96,3 @@ class QueryIterator implements \Iterator {
        }
 }
 
-class QueryIteratorException extends \RuntimeException {}
-
similarity index 86%
rename from php/WP_CLI/TableIterator.php
rename to php/WP_CLI/Iterators/Table.php
index ef8bf89..fb807d0 100644 (file)
@@ -1,23 +1,23 @@
 <?php
 
-namespace WP_CLI;
+namespace WP_CLI\Iterators;
 
 /**
  * @source https://gist.github.com/4060005
  */
-class TableIterator extends QueryIterator {
+class Table extends Iterators\Query {
 
        /**
         * Creates an iterator over a database table
         *
         * <code>
-        * foreach( new TableIterator( array( 'table' => $wpdb->posts, 'fields' => array( 'ID', 'post_content' ) ) ) as $post ) {
+        * foreach( new Iterators\Table( array( 'table' => $wpdb->posts, 'fields' => array( 'ID', 'post_content' ) ) ) as $post ) {
         *     count_words_for( $post->ID, $post->post_content );
         * }
         * </code>
         *
         * <code>
-        * foreach( new TableIterator( array( 'table' => $wpdb->posts, 'where' => 'ID = 8 OR post_status = "publish"' ) ) as $post ) {
+        * foreach( new Iterators\Table( array( 'table' => $wpdb->posts, 'where' => 'ID = 8 OR post_status = "publish"' ) ) as $post ) {
         *     …
         * }
         * </code>
index 8f2e076..88c43b0 100644 (file)
@@ -109,4 +109,4 @@ class Role_Command extends WP_CLI_Command {
        }
 }
 
-WP_CLI::add_command( 'role', 'Role_Command' );
\ No newline at end of file
+WP_CLI::add_command( 'role', 'Role_Command' );
index f46cc27..607ccd2 100644 (file)
@@ -62,7 +62,7 @@ class Search_Replace_Command extends WP_CLI_Command {
                        'limit' => 1000
                );
 
-               $it = new \WP_CLI\TableIterator( $args );
+               $it = new \WP_CLI\Iterators\Table( $args );
 
                $count = 0;
 
index f867204..b2fdc79 100644 (file)
@@ -300,7 +300,7 @@ class User_Command extends \WP_CLI\CommandWithDBObject {
 
                $filename = $args[0];
 
-               foreach ( new \WP_CLI\CSVIterator( $filename ) as $i => $new_user ) {
+               foreach ( new \WP_CLI\Iterators\CSV( $filename ) as $i => $new_user ) {
                        $defaults = array(
                                'role' => get_option('default_role'),
                                'user_pass' => wp_generate_password(),