PluginProbe
ManageWP Worker / 4.9.29
ManageWP Worker v4.9.29
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Progress / Abstract.php

Abstract.php in ManageWP Worker 4.9.29, at src/MWP/Progress/Abstract.php

78 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <contact@managewp.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 abstract class MWP_Progress_Abstract implements MWP_Progress_CurlCallbackInterface
12 {
13 private $threshold;
14
15 private $lastYield;
16
17 protected function getThreshold()
18 {
19 return $this->threshold;
20 }
21
22 protected function setThreshold($threshold)
23 {
24 $this->threshold = $threshold;
25 }
26
27 protected function yieldCallback()
28 {
29 if (time() - $this->lastYield >= $this->threshold) {
30 $this->lastYield = time();
31
32 return true;
33 }
34
35 return false;
36 }
37
38 protected function formatBytes($bytes)
39 {
40 $bytes = (int) $bytes;
41
42 if ($bytes > 1024 * 1024 * 1024) {
43 return round($bytes / 1024 / 1024 / 1024, 2).' GB';
44 } elseif ($bytes > 1024 * 1024) {
45 return round($bytes / 1024 / 1024, 2).' MB';
46 } elseif ($bytes > 1024) {
47 return round($bytes / 1024, 2).' KB';
48 }
49
50 return $bytes.' B';
51 }
52
53 protected function calculateOffset($curl)
54 {
55 /** @handled function */
56 $info = curl_getinfo($curl);
57
58 $url = parse_url($info['url']);
59
60 if (!isset($url['query'])) {
61 return 0;
62 }
63
64 parse_str($url['query'], $query);
65
66 if (!isset($query['offset'])) {
67 return 0;
68 }
69
70 return (int) $query['offset'];
71 }
72
73 public function getCallback()
74 {
75 return array($this, 'callback');
76 }
77 }
78