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