Added Route::$cache flag, fixes #3212. Includes tests.
[kohana-core.git] / classes / kohana / config / reader.php
blobbd12858a78710af1f39e6c18e20c6071145b6e83
1 <?php defined('SYSPATH') or die('No direct script access.');
2 /**
3 * Abstract configuration reader. All configuration readers must extend
4 * this class.
6 * @package Kohana
7 * @category Configuration
8 * @author Kohana Team
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;
17 /**
18 * Loads an empty array as the initial configuration and enables array
19 * keys to be used as properties.
21 * @return void
23 public function __construct()
25 parent::__construct(array(), ArrayObject::ARRAY_AS_PROPS);
28 /**
29 * Return the current group in serialized form.
31 * echo $config;
33 * @return string
35 public function __toString()
37 return serialize($this->getArrayCopy());
40 /**
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)
54 if ($config === NULL)
56 return FALSE;
59 // Clone the current object
60 $object = clone $this;
62 // Set the group name
63 $object->_configuration_group = $group;
65 // Swap the array with the actual configuration
66 $object->exchangeArray($config);
68 return $object;
71 /**
72 * Return the raw array that is being used for this object.
74 * $array = $config->as_array();
76 * @return array
78 public function as_array()
80 return $this->getArrayCopy();
83 /**
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
90 * @return mixed
92 public function get($key, $default = NULL)
94 return $this->offsetExists($key) ? $this->offsetGet($key) : $default;
97 /**
98 * Sets a value in the configuration array.
100 * $config->set($key, $new_value);
102 * @param string array key
103 * @param mixed array value
104 * @return $this
106 public function set($key, $value)
108 $this->offsetSet($key, $value);
110 return $this;
113 } // End Kohana_Config_Reader