composer package updates
[openemr.git] / vendor / zendframework / zend-progressbar / src / Adapter / JsPush.php
blob284df2460f8cb1a6b51128c92da1bf7f7a87bca1
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\Adapter;
12 use Zend\Json\Json;
14 /**
15 * Zend\ProgressBar\Adapter\JsPush offers a simple method for updating a
16 * progressbar in a browser.
18 class JsPush extends AbstractAdapter
20 /**
21 * Name of the JavaScript method to call on update
23 * @var string
25 protected $updateMethodName = 'Zend\ProgressBar\ProgressBar\Update';
27 /**
28 * Name of the JavaScript method to call on finish
30 * @var string
32 protected $finishMethodName;
34 /**
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;
44 return $this;
47 /**
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;
57 return $this;
60 /**
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
69 * @return void
71 public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text)
73 $arguments = [
74 'current' => $current,
75 'max' => $max,
76 'percent' => ($percent * 100),
77 'timeTaken' => $timeTaken,
78 'timeRemaining' => $timeRemaining,
79 'text' => $text
82 $data = '<script type="text/javascript">'
83 . 'parent.' . $this->updateMethodName . '(' . Json::encode($arguments) . ');'
84 . '</script>';
86 // Output the data
87 $this->_outputData($data);
90 /**
91 * Defined by Zend\ProgressBar\Adapter\AbstractAdapter
93 * @return void
95 public function finish()
97 if ($this->finishMethodName === null) {
98 return;
101 $data = '<script type="text/javascript">'
102 . 'parent.' . $this->finishMethodName . '();'
103 . '</script>';
105 $this->_outputData($data);
109 * Outputs given data the user agent.
111 * This split-off is required for unit-testing.
113 * @param string $data
114 * @return void
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";
125 flush();
126 ob_flush();