Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_ProgressBar_Adapter_Console Class Reference
Inheritance diagram for Zend_ProgressBar_Adapter_Console:
Zend_ProgressBar_Adapter

Public Member Functions

 __construct ($options=null)
 
 __destruct ()
 
 setOutputStream ($resource)
 
 getOutputStream ()
 
 setWidth ($width=null)
 
 setElements (array $elements)
 
 setBarLeftChar ($char)
 
 setBarRightChar ($char)
 
 setBarIndicatorChar ($char)
 
 setTextWidth ($width)
 
 setCharset ($charset)
 
 setFinishAction ($action)
 
 notify ($current, $max, $percent, $timeTaken, $timeRemaining, $text)
 
 finish ()
 
- Public Member Functions inherited from Zend_ProgressBar_Adapter
 __construct ($options=null)
 
 setConfig (Zend_Config $config)
 
 setOptions (array $options)
 
 notify ($current, $max, $percent, $timeTaken, $timeRemaining, $text)
 
 finish ()
 

Data Fields

const ELEMENT_PERCENT = 'ELEMENT_PERCENT'
 
const ELEMENT_BAR = 'ELEMENT_BAR'
 
const ELEMENT_ETA = 'ELEMENT_ETA'
 
const ELEMENT_TEXT = 'ELEMENT_TEXT'
 
const FINISH_ACTION_EOL = 'FINISH_ACTION_EOL'
 
const FINISH_ACTION_CLEAR_LINE = 'FINISH_ACTION_CLEAR_LINE'
 
const FINISH_ACTION_NONE = 'FINISH_ACTION_NONE'
 

Protected Member Functions

 _calculateBarWidth ()
 
 _outputData ($data)
 

Protected Attributes

 $_width = null
 
 $_elements
 
 $_finishAction = self::FINISH_ACTION_EOL
 
 $_barWidth
 
 $_barLeftChar = '#'
 
 $_barIndicatorChar = ''
 
 $_barRightChar = '-'
 
 $_outputStream = null
 
 $_textWidth = 20
 
 $_outputStarted = false
 
 $_charset = 'utf-8'
 
- Protected Attributes inherited from Zend_ProgressBar_Adapter
 $_skipOptions
 

Detailed Description

Definition at line 40 of file Console.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Defined by Zend_ProgressBar_Adapter

Parameters
null | array | Zend_Config$options

Definition at line 161 of file Console.php.

162  {
163  // Call parent constructor with options
164  parent::__construct($options);
165 
166  // Check if a width was set, else use auto width
167  if ($this->_width === null) {
168  $this->setWidth();
169  }
170  }

◆ __destruct()

__destruct ( )

Close local stdout, when open

Definition at line 175 of file Console.php.

176  {
177  if ($this->_outputStream !== null) {
178  fclose($this->_outputStream);
179  }
180  }

Member Function Documentation

◆ _calculateBarWidth()

_calculateBarWidth ( )
protected

Calculate the bar width when other elements changed

Returns
void

Definition at line 501 of file Console.php.

502  {
503  if (in_array(self::ELEMENT_BAR, $this->_elements)) {
504  $barWidth = $this->_width;
505 
506  if (in_array(self::ELEMENT_PERCENT, $this->_elements)) {
507  $barWidth -= 4;
508  }
509 
510  if (in_array(self::ELEMENT_ETA, $this->_elements)) {
511  $barWidth -= 12;
512  }
513 
514  if (in_array(self::ELEMENT_TEXT, $this->_elements)) {
515  $barWidth -= $this->_textWidth;
516  }
517 
518  $this->_barWidth = $barWidth - (count($this->_elements) - 1);
519  }
520  }

◆ _outputData()

_outputData (   $data)
protected

Outputs given data to STDOUT.

This split-off is required for unit-testing.

Parameters
string$data
Returns
void

Definition at line 530 of file Console.php.

◆ finish()

finish ( )

Defined by Zend_ProgressBar_Adapter_Interface

Returns
void

Definition at line 474 of file Console.php.

475  {
476  switch ($this->_finishAction) {
478  $this->_outputData(PHP_EOL);
479  break;
480 
482  if ($this->_outputStarted) {
483  $data = str_repeat("\x08", $this->_width)
484  . str_repeat(' ', $this->_width)
485  . str_repeat("\x08", $this->_width);
486 
487  $this->_outputData($data);
488  }
489  break;
490 
492  break;
493  }
494  }

◆ getOutputStream()

getOutputStream ( )

Get the current output stream

Returns
resource

Definition at line 209 of file Console.php.

210  {
211  if ($this->_outputStream === null) {
212  if (!defined('STDOUT')) {
213  $this->_outputStream = fopen('php://stdout', 'w');
214  } else {
215  return STDOUT;
216  }
217  }
218 
219  return $this->_outputStream;
220  }

◆ notify()

notify (   $current,
  $max,
  $percent,
  $timeTaken,
  $timeRemaining,
  $text 
)

Defined by Zend_ProgressBar_Adapter_Interface

Parameters
float$currentCurrent progress value
float$maxMax progress value
float$percentCurrent percent value
integer$timeTakenTaken time in seconds
integer$timeRemainingRemaining time in seconds
string$textStatus text
Returns
void

Definition at line 393 of file Console.php.

394  {
395  // See if we must clear the line
396  if ($this->_outputStarted) {
397  $data = str_repeat("\x08", $this->_width);
398  } else {
399  $data = '';
400  $this->_outputStarted = true;
401  }
402 
403  // Build all elements
404  $renderedElements = array();
405 
406  foreach ($this->_elements as $element) {
407  switch ($element) {
408  case self::ELEMENT_BAR:
409  $visualWidth = $this->_barWidth - 2;
410  $bar = '[';
411 
412  $indicatorWidth = strlen($this->_barIndicatorChar);
413 
414  $doneWidth = min($visualWidth - $indicatorWidth, round($visualWidth * $percent));
415  if ($doneWidth > 0) {
416  $bar .= substr(str_repeat($this->_barLeftChar, ceil($doneWidth / strlen($this->_barLeftChar))), 0, $doneWidth);
417  }
418 
419  $bar .= $this->_barIndicatorChar;
420 
421  $leftWidth = $visualWidth - $doneWidth - $indicatorWidth;
422  if ($leftWidth > 0) {
423  $bar .= substr(str_repeat($this->_barRightChar, ceil($leftWidth / strlen($this->_barRightChar))), 0, $leftWidth);
424  }
425 
426  $bar .= ']';
427 
428  $renderedElements[] = $bar;
429  break;
430 
432  $renderedElements[] = str_pad(round($percent * 100), 3, ' ', STR_PAD_LEFT) . '%';
433  break;
434 
435  case self::ELEMENT_ETA:
436  // In the first 5 seconds we don't get accurate results,
437  // this skipping technique is found in many progressbar
438  // implementations.
439  if ($timeTaken < 5) {
440  $renderedElements[] = str_repeat(' ', 12);
441  break;
442  }
443 
444  if ($timeRemaining === null || $timeRemaining > 86400) {
445  $etaFormatted = '??:??:??';
446  } else {
447  $hours = floor($timeRemaining / 3600);
448  $minutes = floor(($timeRemaining % 3600) / 60);
449  $seconds = ($timeRemaining % 3600 % 60);
450 
451  $etaFormatted = sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
452  }
453 
454  $renderedElements[] = 'ETA ' . $etaFormatted;
455  break;
456 
457  case self::ELEMENT_TEXT:
458  $renderedElements[] = Zend_Text_MultiByte::strPad(substr($text, 0, $this->_textWidth), $this->_textWidth, ' ', STR_PAD_RIGHT, $this->_charset);
459  break;
460  }
461  }
462 
463  $data .= implode(' ', $renderedElements);
464 
465  // Output line data
466  $this->_outputData($data);
467  }
if($this->helper('Magento\Tax\Helper\Data') ->displayFullSummary()) foreach( $block->getTotal() ->getFullInfo() as $info)(isset($info['hidden']) && $info['hidden']) $percent
Definition: tax.phtml:33
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
static strPad($input, $padLength, $padString=' ', $padType=STR_PAD_RIGHT, $charset='utf-8')
Definition: MultiByte.php:104
$element
Definition: element.phtml:12

◆ setBarIndicatorChar()

setBarIndicatorChar (   $char)

Set the indicator character for the bar

Parameters
string$char
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 327 of file Console.php.

328  {
329  $this->_barIndicatorChar = (string) $char;
330 
331  return $this;
332  }

◆ setBarLeftChar()

setBarLeftChar (   $char)

Set the left-hand character for the bar

Parameters
string$char
Exceptions
Zend_ProgressBar_Adapter_ExceptionWhen character is empty
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 290 of file Console.php.

291  {
292  if (empty($char)) {
293  #require_once 'Zend/ProgressBar/Adapter/Exception.php';
294  throw new Zend_ProgressBar_Adapter_Exception('Character may not be empty');
295  }
296 
297  $this->_barLeftChar = (string) $char;
298 
299  return $this;
300  }

◆ setBarRightChar()

setBarRightChar (   $char)

Set the right-hand character for the bar

Parameters
string$char
Exceptions
Zend_ProgressBar_Adapter_ExceptionWhen character is empty
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 309 of file Console.php.

310  {
311  if (empty($char)) {
312  #require_once 'Zend/ProgressBar/Adapter/Exception.php';
313  throw new Zend_ProgressBar_Adapter_Exception('Character may not be empty');
314  }
315 
316  $this->_barRightChar = (string) $char;
317 
318  return $this;
319  }

◆ setCharset()

setCharset (   $charset)

Set the charset of the text element

Parameters
string$charset

Definition at line 354 of file Console.php.

355  {
356  $this->_charset = $charset;
357  }

◆ setElements()

setElements ( array  $elements)

Set the elements to display with the progressbar

Parameters
array$elements
Exceptions
Zend_ProgressBar_Adapter_ExceptionWhen an invalid element is foudn in the array
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 264 of file Console.php.

265  {
266  $allowedElements = array(self::ELEMENT_PERCENT,
267  self::ELEMENT_BAR,
268  self::ELEMENT_ETA,
269  self::ELEMENT_TEXT);
270 
271  if (count(array_diff($elements, $allowedElements)) > 0) {
272  #require_once 'Zend/ProgressBar/Adapter/Exception.php';
273  throw new Zend_ProgressBar_Adapter_Exception('Invalid element found in $elements array');
274  }
275 
276  $this->_elements = $elements;
277 
278  $this->_calculateBarWidth();
279 
280  return $this;
281  }

◆ setFinishAction()

setFinishAction (   $action)

Set the finish action

Parameters
string$action
Exceptions
Zend_ProgressBar_Adapter_ExceptionWhen an invalid action is specified
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 366 of file Console.php.

367  {
368  $allowedActions = array(self::FINISH_ACTION_CLEAR_LINE,
369  self::FINISH_ACTION_EOL,
370  self::FINISH_ACTION_NONE);
371 
372  if (!in_array($action, $allowedActions)) {
373  #require_once 'Zend/ProgressBar/Adapter/Exception.php';
374  throw new Zend_ProgressBar_Adapter_Exception('Invalid finish action specified');
375  }
376 
377  $this->_finishAction = $action;
378 
379  return $this;
380  }

◆ setOutputStream()

setOutputStream (   $resource)

Set a different output-stream

Parameters
string$resource
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 188 of file Console.php.

189  {
190  $stream = @fopen($resource, 'w');
191 
192  if ($stream === false) {
193  #require_once 'Zend/ProgressBar/Adapter/Exception.php';
194  throw new Zend_ProgressBar_Adapter_Exception('Unable to open stream');
195  }
196 
197  if ($this->_outputStream !== null) {
198  fclose($this->_outputStream);
199  }
200 
201  $this->_outputStream = $stream;
202  }
$resource
Definition: bulk.php:12

◆ setTextWidth()

setTextWidth (   $width)

Set the width of the text element

Parameters
integer$width
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 340 of file Console.php.

341  {
342  $this->_textWidth = (int) $width;
343 
344  $this->_calculateBarWidth();
345 
346  return $this;
347  }

◆ setWidth()

setWidth (   $width = null)

Set the width of the progressbar

Parameters
integer$width
Returns
Zend_ProgressBar_Adapter_Console

Definition at line 228 of file Console.php.

229  {
230  if ($width === null || !is_integer($width)) {
231  if (substr(PHP_OS, 0, 3) === 'WIN') {
232  // We have to default to 79 on windows, because the windows
233  // terminal always has a fixed width of 80 characters and the
234  // cursor is counted to the line, else windows would line break
235  // after every update.
236  $this->_width = 79;
237  } else {
238  // Set the default width of 80
239  $this->_width = 80;
240 
241  // Try to determine the width through stty
242  if (preg_match('#\d+ (\d+)#', @shell_exec('stty size'), $match) === 1) {
243  $this->_width = (int) $match[1];
244  } else if (preg_match('#columns = (\d+);#', @shell_exec('stty'), $match) === 1) {
245  $this->_width = (int) $match[1];
246  }
247  }
248  } else {
249  $this->_width = (int) $width;
250  }
251 
252  $this->_calculateBarWidth();
253 
254  return $this;
255  }

Field Documentation

◆ $_barIndicatorChar

$_barIndicatorChar = ''
protected

Definition at line 119 of file Console.php.

◆ $_barLeftChar

$_barLeftChar = '#'
protected

Definition at line 112 of file Console.php.

◆ $_barRightChar

$_barRightChar = '-'
protected

Definition at line 126 of file Console.php.

◆ $_barWidth

$_barWidth
protected

Definition at line 105 of file Console.php.

◆ $_charset

$_charset = 'utf-8'
protected

Definition at line 154 of file Console.php.

◆ $_elements

$_elements
protected
Initial value:
= array(self::ELEMENT_PERCENT,
self::ELEMENT_BAR,
self::ELEMENT_ETA)

Definition at line 89 of file Console.php.

◆ $_finishAction

$_finishAction = self::FINISH_ACTION_EOL
protected

Definition at line 98 of file Console.php.

◆ $_outputStarted

$_outputStarted = false
protected

Definition at line 147 of file Console.php.

◆ $_outputStream

$_outputStream = null
protected

Definition at line 133 of file Console.php.

◆ $_textWidth

$_textWidth = 20
protected

Definition at line 140 of file Console.php.

◆ $_width

$_width = null
protected

Definition at line 82 of file Console.php.

◆ ELEMENT_BAR

const ELEMENT_BAR = 'ELEMENT_BAR'

Visual value of the progress

Definition at line 50 of file Console.php.

◆ ELEMENT_ETA

const ELEMENT_ETA = 'ELEMENT_ETA'

ETA of the progress

Definition at line 55 of file Console.php.

◆ ELEMENT_PERCENT

const ELEMENT_PERCENT = 'ELEMENT_PERCENT'

Percentage value of the progress

Definition at line 45 of file Console.php.

◆ ELEMENT_TEXT

const ELEMENT_TEXT = 'ELEMENT_TEXT'

Text part of the progress

Definition at line 60 of file Console.php.

◆ FINISH_ACTION_CLEAR_LINE

const FINISH_ACTION_CLEAR_LINE = 'FINISH_ACTION_CLEAR_LINE'

Finish action: Clear Line

Definition at line 70 of file Console.php.

◆ FINISH_ACTION_EOL

const FINISH_ACTION_EOL = 'FINISH_ACTION_EOL'

Finish action: End of Line

Definition at line 65 of file Console.php.

◆ FINISH_ACTION_NONE

const FINISH_ACTION_NONE = 'FINISH_ACTION_NONE'

Finish action: None

Definition at line 75 of file Console.php.


The documentation for this class was generated from the following file: