import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
* @package Zend_ProgressBar
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ProgressBar.php 12296 2008-11-05 11:26:37Z dasprid $
|
||||
* @version $Id: ProgressBar.php 14519 2009-03-27 20:45:32Z dasprid $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -33,14 +33,14 @@ class Zend_ProgressBar
|
||||
* @var float
|
||||
*/
|
||||
protected $_min;
|
||||
|
||||
|
||||
/**
|
||||
* Max value
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $_max;
|
||||
|
||||
|
||||
/**
|
||||
* Current value
|
||||
*
|
||||
@ -68,14 +68,14 @@ class Zend_ProgressBar
|
||||
* @var Zend_ProgressBar_Adapter
|
||||
*/
|
||||
protected $_adapter;
|
||||
|
||||
|
||||
/**
|
||||
* Namespace for keeping the progressbar persistent
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_persistenceNamespace = null;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new progressbar backend.
|
||||
*
|
||||
@ -86,30 +86,30 @@ class Zend_ProgressBar
|
||||
* @throws Zend_ProgressBar_Exception When $min is greater than $max
|
||||
*/
|
||||
public function __construct(Zend_ProgressBar_Adapter $adapter, $min = 0, $max = 100, $persistenceNamespace = null)
|
||||
{
|
||||
{
|
||||
// Check min/max values and set them
|
||||
if ($min > $max) {
|
||||
require_once 'Zend/ProgressBar/Exception.php';
|
||||
throw new Zend_ProgressBar_Exception('$max must be greater than $min');
|
||||
}
|
||||
|
||||
|
||||
$this->_min = (float) $min;
|
||||
$this->_max = (float) $max;
|
||||
$this->_current = (float) $min;
|
||||
|
||||
|
||||
// See if we have to open a session namespace
|
||||
if ($persistenceNamespace !== null) {
|
||||
require_once 'Zend/Session/Namespace.php';
|
||||
|
||||
|
||||
$this->_persistenceNamespace = new Zend_Session_Namespace($persistenceNamespace);
|
||||
}
|
||||
|
||||
|
||||
// Set adapter
|
||||
$this->_adapter = $adapter;
|
||||
|
||||
// Track the start time
|
||||
$this->_startTime = time();
|
||||
|
||||
|
||||
// See If a persistenceNamespace exists and handle accordingly
|
||||
if ($this->_persistenceNamespace !== null) {
|
||||
if (isset($this->_persistenceNamespace->isSet)) {
|
||||
@ -126,7 +126,7 @@ class Zend_ProgressBar
|
||||
$this->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current adapter
|
||||
*
|
||||
@ -136,7 +136,7 @@ class Zend_ProgressBar
|
||||
{
|
||||
return $this->_adapter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the progressbar
|
||||
*
|
||||
@ -150,7 +150,7 @@ class Zend_ProgressBar
|
||||
if ($value !== null) {
|
||||
$this->_current = min($this->_max, max($this->_min, $value));
|
||||
}
|
||||
|
||||
|
||||
// Update text if given
|
||||
if ($text !== null) {
|
||||
$this->_statusText = $text;
|
||||
@ -163,21 +163,25 @@ class Zend_ProgressBar
|
||||
}
|
||||
|
||||
// Calculate percent
|
||||
$percent = (float) ($this->_current - $this->_min) / ($this->_max - $this->_min);
|
||||
if ($this->_min === $this->_max) {
|
||||
$percent = false;
|
||||
} else {
|
||||
$percent = (float) ($this->_current - $this->_min) / ($this->_max - $this->_min);
|
||||
}
|
||||
|
||||
// Calculate ETA
|
||||
$timeTaken = time() - $this->_startTime;
|
||||
|
||||
if ($percent === .0) {
|
||||
|
||||
if ($percent === .0 || $percent === false) {
|
||||
$timeRemaining = null;
|
||||
} else {
|
||||
$timeRemaining = round(((1 / $percent) * $timeTaken) - $timeTaken);
|
||||
}
|
||||
|
||||
|
||||
// Poll the adapter
|
||||
$this->_adapter->notify($this->_current, $this->_max, $percent, $timeTaken, $timeRemaining, $this->_statusText);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the progressbar to the next value
|
||||
*
|
||||
@ -185,10 +189,10 @@ class Zend_ProgressBar
|
||||
* @return void
|
||||
*/
|
||||
public function next($diff = 1, $text = null)
|
||||
{
|
||||
{
|
||||
$this->update(max($this->_min, min($this->_max, $this->_current + $diff)), $text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call the adapters finish() behaviour
|
||||
*
|
||||
@ -199,7 +203,7 @@ class Zend_ProgressBar
|
||||
if ($this->_persistenceNamespace !== null) {
|
||||
unset($this->_persistenceNamespace->isSet);
|
||||
}
|
||||
|
||||
|
||||
$this->_adapter->finish();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user