<?php
    
/**
    * A class for showing progress bars in the console.
    */
    
class Console_ProgressBar
    
{
        
/**
        * The progress
        * @var integer
        */
        
private $progress = 0;
        
        
/**
        * The maximum "widgets" the progress bar has to represent
        * @var integer
        */
        
private $max;

        
/**
        * Creates the progress bar object
        *
        * @param int The mximum "widgets" that the progress has to represnt
        * @return obj The Console_ProgressBar object
        */
        
public function __construct($max = 100)
        {
            
$this->max = $max;
        }

        
/**
        * Updates the progress bar
        */
        
public function Update($update = 1)
        {
            
$this->progress += $update;

            
$pc   = ($this->progress / $this->max) * 100;
            
$bars = round(($pc * 50) / 100);

            echo
"\r[" . str_repeat('=', $bars) . '>'. str_repeat(' ', 50 - $bars) . "] " . sprintf('%02d', $pc) . '%';
        }
    }
    
?>