From: scribu Date: Sun, 14 Apr 2013 19:11:05 +0000 (+0300) Subject: move iterators to separate namespace X-Git-Tag: v0.10.0~115^2~4 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0b52bebd0c6c1a3a4bcd4ed3846e4c03e9aed67c;p=wvm%2Fwvm.git move iterators to separate namespace --- diff --git a/php/WP_CLI/CSVIterator.php b/php/WP_CLI/Iterators/CSV.php similarity index 95% rename from php/WP_CLI/CSVIterator.php rename to php/WP_CLI/Iterators/CSV.php index 46a3bf9c..dde3fb51 100644 --- a/php/WP_CLI/CSVIterator.php +++ b/php/WP_CLI/Iterators/CSV.php @@ -1,8 +1,8 @@ - * 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 ); * } * @@ -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 {} - diff --git a/php/WP_CLI/TableIterator.php b/php/WP_CLI/Iterators/Table.php similarity index 86% rename from php/WP_CLI/TableIterator.php rename to php/WP_CLI/Iterators/Table.php index ef8bf890..fb807d0a 100644 --- a/php/WP_CLI/TableIterator.php +++ b/php/WP_CLI/Iterators/Table.php @@ -1,23 +1,23 @@ - * 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 ); * } * * * - * 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 ) { * … * } * diff --git a/php/commands/role.php b/php/commands/role.php index 8f2e0765..88c43b0d 100644 --- a/php/commands/role.php +++ b/php/commands/role.php @@ -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' ); diff --git a/php/commands/search-replace.php b/php/commands/search-replace.php index f46cc279..607ccd28 100644 --- a/php/commands/search-replace.php +++ b/php/commands/search-replace.php @@ -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; diff --git a/php/commands/user.php b/php/commands/user.php index f867204e..b2fdc791 100644 --- a/php/commands/user.php +++ b/php/commands/user.php @@ -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(),