Adding extra charsets for ActionMailer unit tests, if you're looking to parse incomin...
[akelos.git] / lib / AkConfig.php
blob6d05d4e548fe21c8f2262323ed62940ed9885041
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4 // WARNING THIS CODE IS EXPERIMENTAL
6 // +----------------------------------------------------------------------+
7 // | Akelos Framework - http://www.akelos.org |
8 // +----------------------------------------------------------------------+
9 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
10 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
11 // +----------------------------------------------------------------------+
13 /**
14 * @package ActiveSupport
15 * @subpackage Experimental
16 * @author Bermi Ferrer <bermi a.t akelos c.om>
17 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
18 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
21 class AkConfig
23 var $_settings = array();
24 var $scope = 'core';
25 var $default_options = array('storage'=>'AkPhpConfigFile');
26 var $options = array();
27 var $Storage;
29 function AkConfig()
31 $options = func_get_args();
32 $this->options = array_merge($this->default_options, $this->options);
34 if(empty($this->Storage)){
35 $storage_class_name = $this->options['storage'];
36 require_once(AK_LIB_DIR.DS.'AkConfig'.DS.$this->options['storage'].'.php');
37 $this->Storage =& new $storage_class_name();
41 function set($attribute, $value)
43 $scope = $this->scope;
44 if(strstr('/',$attribute)){
45 list($scope, $attribute) = explode('/', $attribute);
46 }elseif($this->getType() == 'plugin'){
47 return $this->set($this->getPluginName().'/'.$attribute, $value);
49 return $this->_set($scope, $attribute, $value);
52 function _set($scope, $attribute, $value)
54 $this->_saveAfterExecution();
55 $this->_settings[$scope][$attribute] = $value;
58 function loadAttributes()
60 $this->_settings = $this->Storage->getAll();
63 function get($attribute)
65 $scope = $this->scope;
66 if(strstr('/',$attribute)){
67 list($scope, $attribute) = explode('/', $attribute);
68 }elseif($this->getType() == 'plugin'){
69 return $this->get($this->getPluginName().'/'.$attribute, $value);
71 return $this->_get($scope, $attribute);
74 function _get($scope, $attribute)
76 return isset($this->_settings[$scope][$attribute]) ? $this->_settings[$scope][$attribute] : false;
79 function _saveAfterExecution($action)
81 static $registered;
82 if(!isset($registered)){
83 $registered = true;
84 register_shutdown_function(array(&$this,'saveAll'));
88 function saveAll()
90 $this->Storage->save($this->_settings);