Writer.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_Config
  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. * @category Zend
  23. * @package Zend_Config
  24. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. abstract class Zend_Config_Writer
  28. {
  29. /**
  30. * Option keys to skip when calling setOptions()
  31. *
  32. * @var array
  33. */
  34. protected $_skipOptions = array(
  35. 'options'
  36. );
  37. /**
  38. * Config object to write
  39. *
  40. * @var Zend_Config
  41. */
  42. protected $_config = null;
  43. /**
  44. * Create a new adapter
  45. *
  46. * $options can only be passed as array or be omitted
  47. *
  48. * @param null|array $options
  49. */
  50. public function __construct(array $options = null)
  51. {
  52. if (is_array($options)) {
  53. $this->setOptions($options);
  54. }
  55. }
  56. /**
  57. * Set options via a Zend_Config instance
  58. *
  59. * @param Zend_Config $config
  60. * @return Zend_Config_Writer
  61. */
  62. public function setConfig(Zend_Config $config)
  63. {
  64. $this->_config = $config;
  65. return $this;
  66. }
  67. /**
  68. * Set options via an array
  69. *
  70. * @param array $options
  71. * @return Zend_Config_Writer
  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. * Write a Zend_Config object to it's target
  88. *
  89. * @return void
  90. */
  91. abstract public function write();
  92. }