From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- library/vendor/Zend/ProgressBar.php | 207 ++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 library/vendor/Zend/ProgressBar.php (limited to 'library/vendor/Zend/ProgressBar.php') diff --git a/library/vendor/Zend/ProgressBar.php b/library/vendor/Zend/ProgressBar.php new file mode 100644 index 0000000..60804ee --- /dev/null +++ b/library/vendor/Zend/ProgressBar.php @@ -0,0 +1,207 @@ + $max) { + 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) { + + $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)) { + $this->_startTime = $this->_persistenceNamespace->startTime; + $this->_current = $this->_persistenceNamespace->current; + $this->_statusText = $this->_persistenceNamespace->statusText; + } else { + $this->_persistenceNamespace->isSet = true; + $this->_persistenceNamespace->startTime = $this->_startTime; + $this->_persistenceNamespace->current = $this->_current; + $this->_persistenceNamespace->statusText = $this->_statusText; + } + } else { + $this->update(); + } + } + + /** + * Get the current adapter + * + * @return Zend_ProgressBar_Adapter + */ + public function getAdapter() + { + return $this->_adapter; + } + + /** + * Update the progressbar + * + * @param float $value + * @param string $text + * @return void + */ + public function update($value = null, $text = null) + { + // Update value if given + if ($value !== null) { + $this->_current = min($this->_max, max($this->_min, $value)); + } + + // Update text if given + if ($text !== null) { + $this->_statusText = $text; + } + + // See if we have to update a namespace + if ($this->_persistenceNamespace !== null) { + $this->_persistenceNamespace->current = $this->_current; + $this->_persistenceNamespace->statusText = $this->_statusText; + } + + // Calculate percent + 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 || $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 + * + * @param string $text + * @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 + * + * @return void + */ + public function finish() + { + if ($this->_persistenceNamespace !== null) { + unset($this->_persistenceNamespace->isSet); + } + + $this->_adapter->finish(); + } +} -- cgit v1.2.3