web/lib/Zend/Config/Writer.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_Config
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: Writer.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @category   Zend
       
    24  * @package    Zend_Config
       
    25  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    26  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    27  */
       
    28 abstract class Zend_Config_Writer
       
    29 {
       
    30     /**
       
    31      * Option keys to skip when calling setOptions()
       
    32      *
       
    33      * @var array
       
    34      */
       
    35     protected $_skipOptions = array(
       
    36         'options'
       
    37     );
       
    38 
       
    39     /**
       
    40      * Config object to write
       
    41      *
       
    42      * @var Zend_Config
       
    43      */
       
    44     protected $_config = null;
       
    45 
       
    46     /**
       
    47      * Create a new adapter
       
    48      *
       
    49      * $options can only be passed as array or be omitted
       
    50      *
       
    51      * @param null|array $options
       
    52      */
       
    53     public function __construct(array $options = null)
       
    54     {
       
    55         if (is_array($options)) {
       
    56             $this->setOptions($options);
       
    57         }
       
    58     }
       
    59 
       
    60     /**
       
    61      * Set options via a Zend_Config instance
       
    62      *
       
    63      * @param  Zend_Config $config
       
    64      * @return Zend_Config_Writer
       
    65      */
       
    66     public function setConfig(Zend_Config $config)
       
    67     {
       
    68         $this->_config = $config;
       
    69 
       
    70         return $this;
       
    71     }
       
    72 
       
    73     /**
       
    74      * Set options via an array
       
    75      *
       
    76      * @param  array $options
       
    77      * @return Zend_Config_Writer
       
    78      */
       
    79     public function setOptions(array $options)
       
    80     {
       
    81         foreach ($options as $key => $value) {
       
    82             if (in_array(strtolower($key), $this->_skipOptions)) {
       
    83                 continue;
       
    84             }
       
    85 
       
    86             $method = 'set' . ucfirst($key);
       
    87             if (method_exists($this, $method)) {
       
    88                 $this->$method($value);
       
    89             }
       
    90         }
       
    91 
       
    92         return $this;
       
    93     }
       
    94 
       
    95     /**
       
    96      * Write a Zend_Config object to it's target
       
    97      *
       
    98      * @return void
       
    99      */
       
   100     abstract public function write();
       
   101 }