New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Add an iterate method to the ProgressBar class #29753

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@jvasseur
Copy link
Contributor

jvasseur commented Jan 2, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Add an iterate method to the ProgressBar class that simplify updating the progress bar when iterating over an iterable.

Before:

$bar->start();
foreach ($iterable as $value) {
    // Process $value

    $bar->advance();
}
$bar->finish();

After:

foreach ($bar->iterate($iterable) as $value) {
    // Process $value
}

Additionally if $iterable is countable, the progress bar max step will automatically set to its count. If it isn't countable, nothing is done (instead of setting it to 0) to allow passing a max independently before calling iterate.

I will try to do the doc PR soon.

Show resolved Hide resolved src/Symfony/Component/Console/CHANGELOG.md Outdated

@nicolas-grekas nicolas-grekas added this to the next milestone Jan 3, 2019

@jvasseur

This comment has been minimized.

Copy link
Contributor

jvasseur commented Jan 3, 2019

Updated the code to allow passing $max as a second argument instead of allowing to set the max before calling iterate.

@jvasseur jvasseur force-pushed the jvasseur:progress-iterate branch from e9d3f0b to c5e70ee Jan 4, 2019

@jvasseur jvasseur force-pushed the jvasseur:progress-iterate branch from c5e70ee to 223a232 Jan 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment