Adapter.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * Abstract class for Zend_ProgressBar_Adapters
  23. *
  24. * @category Zend
  25. * @package Zend_ProgressBar
  26. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. abstract class Zend_ProgressBar_Adapter
  30. {
  31. /**
  32. * Option keys to skip when calling setOptions()
  33. *
  34. * @var array
  35. */
  36. protected $_skipOptions = array(
  37. 'options',
  38. 'config',
  39. );
  40. /**
  41. * Create a new adapter
  42. *
  43. * $options may be either be an array or a Zend_Config object which
  44. * specifies adapter related options.
  45. *
  46. * @param null|array|Zend_Config $options
  47. */
  48. public function __construct($options = null)
  49. {
  50. if (is_array($options)) {
  51. $this->setOptions($options);
  52. } elseif ($options instanceof Zend_Config) {
  53. $this->setConfig($options);
  54. }
  55. }
  56. /**
  57. * Set options via a Zend_Config instance
  58. *
  59. * @param Zend_Config $config
  60. * @return Zend_ProgressBar_Adapter
  61. */
  62. public function setConfig(Zend_Config $config)
  63. {
  64. $this->setOptions($config->toArray());
  65. return $this;
  66. }
  67. /**
  68. * Set options via an array
  69. *
  70. * @param array $options
  71. * @return Zend_ProgressBar_Adapter
  72. */
  73. public function setOptions(array $options)
  74. {
  75. foreach ($options as $key => $value) {
  76. if (in_array(strtolower($key), $this->_skipOptions)) {
  77. continue;
  78. }
  79. $method = 'set' . ucfirst($key);
  80. if (method_exists($this, $method)) {
  81. $this->$method($value);
  82. }
  83. }
  84. return $this;
  85. }
  86. /**
  87. * Notify the adapter about an update
  88. *
  89. * @param float $current Current progress value
  90. * @param float $max Max progress value
  91. * @param float $percent Current percent value
  92. * @param integer $timeTaken Taken time in seconds
  93. * @param integer $timeRemaining Remaining time in seconds
  94. * @param string $text Status text
  95. * @return void
  96. */
  97. abstract public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text);
  98. /**
  99. * Called when the progress is explicitly finished
  100. *
  101. * @return void
  102. */
  103. abstract public function finish();
  104. }