|
1 <?php |
|
2 /** |
|
3 * LICENSE |
|
4 * |
|
5 * This source file is subject to the new BSD license that is bundled |
|
6 * with this package in the file LICENSE.txt. |
|
7 * It is also available through the world-wide-web at this URL: |
|
8 * http://framework.zend.com/license/new-bsd |
|
9 * If you did not receive a copy of the license and are unable to |
|
10 * obtain it through the world-wide-web, please send an email |
|
11 * to license@zend.com so we can send you a copy immediately. |
|
12 * |
|
13 * @category Zend |
|
14 * @package Zend_ProgressBar |
|
15 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
16 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
17 * @version $Id: JsPull.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
18 */ |
|
19 |
|
20 /** |
|
21 * @see Zend_Json |
|
22 */ |
|
23 require_once 'Zend/Json.php'; |
|
24 |
|
25 /** |
|
26 * @see Zend_ProgressBar_Adapter |
|
27 */ |
|
28 require_once 'Zend/ProgressBar/Adapter.php'; |
|
29 |
|
30 /** |
|
31 * Zend_ProgressBar_Adapter_JsPull offers a simple method for updating a |
|
32 * progressbar in a browser. |
|
33 * |
|
34 * @category Zend |
|
35 * @package Zend_ProgressBar |
|
36 * @uses Zend_ProgressBar_Adapter_Interface |
|
37 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
38 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
39 */ |
|
40 class Zend_ProgressBar_Adapter_JsPull extends Zend_ProgressBar_Adapter |
|
41 { |
|
42 /** |
|
43 * Wether to exit after json data send or not |
|
44 * |
|
45 * @var boolean |
|
46 */ |
|
47 protected $_exitAfterSend = true; |
|
48 |
|
49 /** |
|
50 * Set wether to exit after json data send or not |
|
51 * |
|
52 * @param boolean $exitAfterSend |
|
53 * @return Zend_ProgressBar_Adapter_JsPull |
|
54 */ |
|
55 public function setExitAfterSend($exitAfterSend) |
|
56 { |
|
57 $this->_exitAfterSend = $exitAfterSend; |
|
58 } |
|
59 |
|
60 /** |
|
61 * Defined by Zend_ProgressBar_Adapter_Interface |
|
62 * |
|
63 * @param float $current Current progress value |
|
64 * @param float $max Max progress value |
|
65 * @param float $percent Current percent value |
|
66 * @param integer $timeTaken Taken time in seconds |
|
67 * @param integer $timeRemaining Remaining time in seconds |
|
68 * @param string $text Status text |
|
69 * @return void |
|
70 */ |
|
71 public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text) |
|
72 { |
|
73 $arguments = array( |
|
74 'current' => $current, |
|
75 'max' => $max, |
|
76 'percent' => ($percent * 100), |
|
77 'timeTaken' => $timeTaken, |
|
78 'timeRemaining' => $timeRemaining, |
|
79 'text' => $text, |
|
80 'finished' => false |
|
81 ); |
|
82 |
|
83 $data = Zend_Json::encode($arguments); |
|
84 |
|
85 // Output the data |
|
86 $this->_outputData($data); |
|
87 } |
|
88 |
|
89 /** |
|
90 * Defined by Zend_ProgressBar_Adapter_Interface |
|
91 * |
|
92 * @return void |
|
93 */ |
|
94 public function finish() |
|
95 { |
|
96 $data = Zend_Json::encode(array('finished' => true)); |
|
97 |
|
98 $this->_outputData($data); |
|
99 } |
|
100 |
|
101 /** |
|
102 * Outputs given data the user agent. |
|
103 * |
|
104 * This split-off is required for unit-testing. |
|
105 * |
|
106 * @param string $data |
|
107 * @return void |
|
108 */ |
|
109 protected function _outputData($data) |
|
110 { |
|
111 echo $data; |
|
112 |
|
113 if ($this->_exitAfterSend) { |
|
114 exit; |
|
115 } |
|
116 } |
|
117 } |