<?php
    
/**
    * o------------------------------------------------------------------------------o
    * | This package is licensed under the Phpguru license 2008. A quick summary is  |
    * | that the code is free to use for non-commercial purposes. For commercial     |
    * | purposes of any kind there is a small license fee to pay. You can read more  |
    * | at:                                                                          |
    * |                  http://www.phpguru.org/static/license.html                  |
    * o------------------------------------------------------------------------------o
    *
    * © Copyright 2008 Richard Heyes
    */

    /**
    * 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) . '%';
        }
    }
    
?>