1 <?php
defined('SYSPATH') or die('No direct script access.');
3 * Abstract configuration reader. All configuration readers must extend
7 * @category Configuration
9 * @copyright (c) 2008-2010 Kohana Team
10 * @license http://kohanaframework.org/license
12 abstract class Kohana_Config_Reader
extends ArrayObject
{
14 // Configuration group name
15 protected $_configuration_group;
18 * Loads an empty array as the initial configuration and enables array
19 * keys to be used as properties.
23 public function __construct()
25 parent
::__construct(array(), ArrayObject
::ARRAY_AS_PROPS
);
29 * Return the current group in serialized form.
35 public function __toString()
37 return serialize($this->getArrayCopy());
41 * Loads a configuration group.
43 * $config->load($name, $array);
45 * This method must be extended by all readers. After the group has been
46 * loaded, call `parent::load($group, $config)` for final preparation.
48 * @param string configuration group name
49 * @param array configuration array
50 * @return $this a clone of this object
52 public function load($group, array $config = NULL)
59 // Clone the current object
60 $object = clone $this;
63 $object->_configuration_group
= $group;
65 // Swap the array with the actual configuration
66 $object->exchangeArray($config);
72 * Return the raw array that is being used for this object.
74 * $array = $config->as_array();
78 public function as_array()
80 return $this->getArrayCopy();
84 * Get a variable from the configuration or return the default value.
86 * $value = $config->get($key);
88 * @param string array key
89 * @param mixed default value
92 public function get($key, $default = NULL)
94 return $this->offsetExists($key) ?
$this->offsetGet($key) : $default;
98 * Sets a value in the configuration array.
100 * $config->set($key, $new_value);
102 * @param string array key
103 * @param mixed array value
106 public function set($key, $value)
108 $this->offsetSet($key, $value);
113 } // End Kohana_Config_Reader