|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_ProgressBar |
|
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: Adapter.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * Abstract class for Zend_ProgressBar_Adapters |
|
24 * |
|
25 * @category Zend |
|
26 * @package Zend_ProgressBar |
|
27 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
28 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
29 */ |
|
30 abstract class Zend_ProgressBar_Adapter |
|
31 { |
|
32 /** |
|
33 * Option keys to skip when calling setOptions() |
|
34 * |
|
35 * @var array |
|
36 */ |
|
37 protected $_skipOptions = array( |
|
38 'options', |
|
39 'config', |
|
40 ); |
|
41 |
|
42 /** |
|
43 * Create a new adapter |
|
44 * |
|
45 * $options may be either be an array or a Zend_Config object which |
|
46 * specifies adapter related options. |
|
47 * |
|
48 * @param null|array|Zend_Config $options |
|
49 */ |
|
50 public function __construct($options = null) |
|
51 { |
|
52 if (is_array($options)) { |
|
53 $this->setOptions($options); |
|
54 } elseif ($options instanceof Zend_Config) { |
|
55 $this->setConfig($options); |
|
56 } |
|
57 } |
|
58 |
|
59 /** |
|
60 * Set options via a Zend_Config instance |
|
61 * |
|
62 * @param Zend_Config $config |
|
63 * @return Zend_ProgressBar_Adapter |
|
64 */ |
|
65 public function setConfig(Zend_Config $config) |
|
66 { |
|
67 $this->setOptions($config->toArray()); |
|
68 |
|
69 return $this; |
|
70 } |
|
71 |
|
72 /** |
|
73 * Set options via an array |
|
74 * |
|
75 * @param array $options |
|
76 * @return Zend_ProgressBar_Adapter |
|
77 */ |
|
78 public function setOptions(array $options) |
|
79 { |
|
80 foreach ($options as $key => $value) { |
|
81 if (in_array(strtolower($key), $this->_skipOptions)) { |
|
82 continue; |
|
83 } |
|
84 |
|
85 $method = 'set' . ucfirst($key); |
|
86 if (method_exists($this, $method)) { |
|
87 $this->$method($value); |
|
88 } |
|
89 } |
|
90 |
|
91 return $this; |
|
92 } |
|
93 |
|
94 /** |
|
95 * Notify the adapter about an update |
|
96 * |
|
97 * @param float $current Current progress value |
|
98 * @param float $max Max progress value |
|
99 * @param float $percent Current percent value |
|
100 * @param integer $timeTaken Taken time in seconds |
|
101 * @param integer $timeRemaining Remaining time in seconds |
|
102 * @param string $text Status text |
|
103 * @return void |
|
104 */ |
|
105 abstract public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text); |
|
106 |
|
107 /** |
|
108 * Called when the progress is explicitly finished |
|
109 * |
|
110 * @return void |
|
111 */ |
|
112 abstract public function finish(); |
|
113 } |