Zeta Components Manual :: Docs For Class ezcConsoleProgressbar
ConsoleTools::ezcConsoleProgressbar
Class ezcConsoleProgressbar
Creating and maintaining progress-bars to be printed to the console.
- // Create progress bar itself
- $progress->options->emptyChar = '-';
- $progress->options->progressChar = '#';
- $progress->options->formatString = "Uploading file </tmp/foobar.tar.bz2>: %act%/%max% kb [%bar%]";
- // Perform actions
- $i = 0;
- while ( $i++ < 20 )
- {
- // Do whatever you want to indicate progress for
- // Advance the progressbar by one step ( uploading 5k per run )
- }
- // Finish progress bar and jump to next line.
- $out->outputText( "Successfully uploaded </tmp/foobar.tar.bz2>.\n", 'success' );
Source for this file: /ConsoleTools/src/progressbar.php
Version: | //autogen// |
Properties
int | read/write |
$max
The maximum progress value to reach. |
ezcConsoleProgressbarOptions | read/write |
$options
Contains the options for this class. |
Member Variables
protected int |
$currentStep
= 0
The current step the progress bar should show. |
protected array(string=>int) |
$measures
= array(
Stores the bar utilization. This array saves how much space a specific part of the bar utilizes to not recalculate those on every step. |
protected int |
$numSteps
= 0
The maximum number of steps to go. Calculated once from the settings. |
protected ezcConsoleOutput |
$output
The ezcConsoleOutput object to use. |
protected array(string=>mixed) |
$properties
Container to hold the properties |
protected bool |
$started
= false
Indicates if the starting point for the bar has been stored. Per default this is false to indicate that no start position has been stored, yet. |
protected array(string=>string) |
$valueMap
= array(
Storage for actual values to be replaced in the format string. Actual values are stored here and will be inserted into the bar before printing it. |
Method Summary
public ezcConsoleProgressbar |
__construct(
$outHandler
, $max
, [ $options
= array()] )
Creates a new progress bar. |
public void |
advance(
[ $redraw
= true] , [ $step
= 1] )
Advance the progress bar. |
protected void |
calculateMeasures(
)
Calculate several measures necessary to generate a bar. |
public void |
finish(
)
Finish the progress bar. |
protected void |
generateValues(
)
Generate all values to be replaced in the format string. |
public ezcConsoleProgressbarOptions |
getOptions(
)
Returns the current options. |
protected void |
insertValues(
)
Insert values into bar format string. |
public void |
output(
)
Draw the progress bar. |
public void |
setOptions(
$options
)
Set new options. |
public void |
start(
)
Start the progress bar Starts the progress bar and sticks it to the current line. |
protected void |
stripEscapeSequences(
$str
)
Strip all escape sequences from a string to measure it's size correctly. |
Methods
__construct
Creates a new progress bar.
Parameters:
Name | Type | Description |
---|---|---|
$outHandler |
ezcConsoleOutput | Handler to utilize for output |
$max |
int | Maximum value, where progressbar reaches 100%. |
$options |
array(string=>string) | Options |
advance
Advance the progress bar.
Advances the progress bar by $step steps. Redraws the bar by default, using the ezcConsoleProgressbar::output() method.
Parameters:
Name | Type | Description |
---|---|---|
$redraw |
bool | Whether to redraw the bar immediately. |
$step |
int | How many steps to advance. |
calculateMeasures
Calculate several measures necessary to generate a bar.
finish
Finish the progress bar.
Finishes the bar (jump to 100% if not happened yet,...) and jumps to the next line to allow new output. Also resets the values of the output handler used, if changed.
generateValues
Generate all values to be replaced in the format string.
getOptions
Returns the current options.
Returns the options currently set for this progressbar.
insertValues
Insert values into bar format string.
output
Draw the progress bar.
Prints the progress-bar to the screen. If start() has not been called yet, the current line is used for ezcConsolProgressbar::start().
setOptions
Set new options.
This method allows you to change the options of progressbar.
Parameters:
Name | Type | Description |
---|---|---|
$options |
ezcConsoleProgresbarOptions | The options to set. |
Exceptions:
Type | Description |
---|---|
ezcBaseSettingNotFoundException |
If you tried to set a non-existent option value. |
ezcBaseSettingValueException |
If the value is not valid for the desired option. |
ezcBaseValueException |
If you submit neither an array nor an instance of ezcConsoleProgresbarOptions. |
start
Start the progress bar Starts the progress bar and sticks it to the current line.
No output will be done yet. Call ezcConsoleProgressbar::output() to print the bar.
stripEscapeSequences
Strip all escape sequences from a string to measure it's size correctly.
Parameters:
Name | Type | Description |
---|---|---|
$str |
mixed |