composer package updates
[openemr.git] / vendor / zendframework / zend-progressbar / src / Upload / UploadProgress.php
blobc4e5d0a57a932c1cdf69c0b3f7b2cc43a0830335
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\ProgressBar\Upload;
12 use Zend\ProgressBar\Exception;
14 /**
15 * Progress Bar Upload Handler for the UploadProgress extension
17 class UploadProgress extends AbstractUploadHandler
19 /**
20 * @param string $id
21 * @return array|bool
22 * @throws Exception\PhpEnvironmentException
24 protected function getUploadProgress($id)
26 if (! $this->isUploadProgressAvailable()) {
27 throw new Exception\PhpEnvironmentException(
28 'UploadProgress extension is not installed'
32 $uploadInfo = uploadprogress_get_info($id);
33 if (! is_array($uploadInfo)) {
34 return false;
37 $status = [
38 'total' => 0,
39 'current' => 0,
40 'rate' => 0,
41 'message' => '',
42 'done' => false
44 $status = $uploadInfo + $status;
45 $status['total'] = $status['bytes_total'];
46 $status['current'] = $status['bytes_uploaded'];
47 $status['rate'] = $status['speed_average'];
48 if ($status['total'] == $status['current']) {
49 $status['done'] = true;
52 return $status;
55 /**
56 * Checks for the UploadProgress extension
58 * @return bool
60 public function isUploadProgressAvailable()
62 return is_callable('uploadprogress_get_info');