File indexing completed on 2025-01-26 05:25:25
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Serializer 0017 * @subpackage Adapter 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** @see Zend_Serializer_Adapter_AdapterInterface */ 0024 // require_once 'Zend/Serializer/Adapter/AdapterInterface.php'; 0025 0026 /** 0027 * @category Zend 0028 * @package Zend_Serializer 0029 * @subpackage Adapter 0030 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0031 * @license http://framework.zend.com/license/new-bsd New BSD License 0032 */ 0033 abstract class Zend_Serializer_Adapter_AdapterAbstract implements Zend_Serializer_Adapter_AdapterInterface 0034 { 0035 /** 0036 * Serializer options 0037 * 0038 * @var array 0039 */ 0040 protected $_options = array(); 0041 0042 /** 0043 * Constructor 0044 * 0045 * @param array|Zend_Config $opts Serializer options 0046 */ 0047 public function __construct($opts = array()) 0048 { 0049 $this->setOptions($opts); 0050 } 0051 0052 /** 0053 * Set serializer options 0054 * 0055 * @param array|Zend_Config $opts Serializer options 0056 * @return Zend_Serializer_Adapter_AdapterAbstract 0057 */ 0058 public function setOptions($opts) 0059 { 0060 if ($opts instanceof Zend_Config) { 0061 $opts = $opts->toArray(); 0062 } else { 0063 $opts = (array) $opts; 0064 } 0065 0066 foreach ($opts as $k => $v) { 0067 $this->setOption($k, $v); 0068 } 0069 return $this; 0070 } 0071 0072 /** 0073 * Set a serializer option 0074 * 0075 * @param string $name Option name 0076 * @param mixed $value Option value 0077 * @return Zend_Serializer_Adapter_AdapterAbstract 0078 */ 0079 public function setOption($name, $value) 0080 { 0081 $this->_options[(string) $name] = $value; 0082 return $this; 0083 } 0084 0085 /** 0086 * Get serializer options 0087 * 0088 * @return array 0089 */ 0090 public function getOptions() 0091 { 0092 return $this->_options; 0093 } 0094 0095 /** 0096 * Get a serializer option 0097 * 0098 * @param string $name 0099 * @return mixed 0100 * @throws Zend_Serializer_Exception 0101 */ 0102 public function getOption($name) 0103 { 0104 $name = (string) $name; 0105 if (!array_key_exists($name, $this->_options)) { 0106 // require_once 'Zend/Serializer/Exception.php'; 0107 throw new Zend_Serializer_Exception('Unknown option name "'.$name.'"'); 0108 } 0109 0110 return $this->_options[$name]; 0111 } 0112 }