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
10 namespace Zend\ProgressBar\Adapter
;
15 * Zend\ProgressBar\Adapter\JsPush offers a simple method for updating a
16 * progressbar in a browser.
18 class JsPush
extends AbstractAdapter
21 * Name of the JavaScript method to call on update
25 protected $updateMethodName = 'Zend\ProgressBar\ProgressBar\Update';
28 * Name of the JavaScript method to call on finish
32 protected $finishMethodName;
35 * Set the update method name
37 * @param string $methodName
38 * @return \Zend\ProgressBar\Adapter\JsPush
40 public function setUpdateMethodName($methodName)
42 $this->updateMethodName
= $methodName;
48 * Set the finish method name
50 * @param string $methodName
51 * @return \Zend\ProgressBar\Adapter\JsPush
53 public function setFinishMethodName($methodName)
55 $this->finishMethodName
= $methodName;
61 * Defined by Zend\ProgressBar\Adapter\AbstractAdapter
63 * @param float $current Current progress value
64 * @param float $max Max progress value
65 * @param float $percent Current percent value
66 * @param int $timeTaken Taken time in seconds
67 * @param int $timeRemaining Remaining time in seconds
68 * @param string $text Status text
71 public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text)
74 'current' => $current,
76 'percent' => ($percent * 100),
77 'timeTaken' => $timeTaken,
78 'timeRemaining' => $timeRemaining,
82 $data = '<script type="text/javascript">'
83 . 'parent.' . $this->updateMethodName
. '(' . Json
::encode($arguments) . ');'
87 $this->_outputData($data);
91 * Defined by Zend\ProgressBar\Adapter\AbstractAdapter
95 public function finish()
97 if ($this->finishMethodName
=== null) {
101 $data = '<script type="text/javascript">'
102 . 'parent.' . $this->finishMethodName
. '();'
105 $this->_outputData($data);
109 * Outputs given data the user agent.
111 * This split-off is required for unit-testing.
113 * @param string $data
116 // @codingStandardsIgnoreStart
117 protected function _outputData($data)
119 // @codingStandardsIgnoreEnd
120 // 1024 padding is required for Safari, while 256 padding is required
121 // for Internet Explorer. The <br /> is required so Safari actually
122 // executes the <script />
123 echo str_pad($data . '<br />', 1024, ' ', STR_PAD_RIGHT
) . "\n";