Implement \Countable for \WP_CLI\Iterators\CSV#5282
Conversation
This makes it possible to start a progress bar for a CSV file: ```php $iterator = new \WP_CLI\Iterators\CSV( $csv_file ); $progress = \WP_CLI\Utils\make_progress_bar( 'Processing list', count( $iterator ) ); ``` The use of `SplFileObject` avoids reading the entire file to memory.
|
Not sure what the build failure is now... |
|
Seems to be signature changes due to refactoring in Core trunk. I'll take a look at fixing this. |
|
Tried to fix the build failure through #5283, let's see what Travis thinks of my approach. |
There was a problem hiding this comment.
Great to have the count() here. However, I don't think it's a good idea to combine two different ways of reading from the file in a same class.
Instead of storing the filename as a property and then using SplFileObject for the count only, it might make sense to convert everything to use SplFileObject and store that object as a property instead. It will overall end up producing simpler code and not introduce inconsistencies between these two read mechanisms.
Using the SplFileObject makes total sense here for the count, but is there a valid reason for not just using it all the way?
To avoid an unnecessary refactor. I suspect it makes zero functional difference that two separate approaches are used. |
|
Can you pull latest |
Yep, done. |
This makes it possible to start a progress bar for a CSV file:
The use of
SplFileObjectavoids reading the entire file to memory.