AdapterAbstract.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_Serializer
  17. * @subpackage Adapter
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** @see Zend_Serializer_Adapter_AdapterInterface */
  23. require_once 'Zend/Serializer/Adapter/AdapterInterface.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Serializer
  27. * @subpackage Adapter
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. abstract class Zend_Serializer_Adapter_AdapterAbstract implements Zend_Serializer_Adapter_AdapterInterface
  32. {
  33. /**
  34. * Serializer options
  35. *
  36. * @var array
  37. */
  38. protected $_options = array();
  39. /**
  40. * Constructor
  41. *
  42. * @param array|Zend_Config $opts Serializer options
  43. */
  44. public function __construct($opts = array())
  45. {
  46. $this->setOptions($opts);
  47. }
  48. /**
  49. * Set serializer options
  50. *
  51. * @param array|Zend_Config $opts Serializer options
  52. * @return Zend_Serializer_Adapter_AdapterAbstract
  53. */
  54. public function setOptions($opts)
  55. {
  56. if ($opts instanceof Zend_Config) {
  57. $opts = $opts->toArray();
  58. } else {
  59. $opts = (array) $opts;
  60. }
  61. foreach ($opts as $k => $v) {
  62. $this->setOption($k, $v);
  63. }
  64. return $this;
  65. }
  66. /**
  67. * Set a serializer option
  68. *
  69. * @param string $name Option name
  70. * @param mixed $value Option value
  71. * @return Zend_Serializer_Adapter_AdapterAbstract
  72. */
  73. public function setOption($name, $value)
  74. {
  75. $this->_options[(string) $name] = $value;
  76. return $this;
  77. }
  78. /**
  79. * Get serializer options
  80. *
  81. * @return array
  82. */
  83. public function getOptions()
  84. {
  85. return $this->_options;
  86. }
  87. /**
  88. * Get a serializer option
  89. *
  90. * @param string $name
  91. * @return mixed
  92. * @throws Zend_Serializer_Exception
  93. */
  94. public function getOption($name)
  95. {
  96. $name = (string) $name;
  97. if (!array_key_exists($name, $this->_options)) {
  98. require_once 'Zend/Serializer/Exception.php';
  99. throw new Zend_Serializer_Exception('Unknown option name "'.$name.'"');
  100. }
  101. return $this->_options[$name];
  102. }
  103. }