Code

Added styles from currently used list.
[gosa.git] / include / class_ConfigManager.inc
1 <?php
3 /**
4  * ConfigManagerException to handle exceptions that happen inside
5  * the config manager module.
6  */
7 class ConfigManagerException extends Exception {
8         public function __construct($message, $code = 0) {
9                 parent::__construct($message, $code);
10         }
11 }
12  
15 /**
16  * ConfigManager loads and manages GOsa session configurations.
17  *
18  * This class should be integrated via Registry.
19  */
20 class ConfigManager {
22         /* Config container */
23         private $config;
24         private $current;
25         private $section;
27         public function __construct(){}
29         /**
30          * Returns a static instance of $class
31          * Creates a new instance of $class if required.
32          * @param string $class
33          * @return obj $$class
34          */
35         public function load($file){
36                 if (!is_readable($file)){
37                         throw new ConfigManagerException(sprintf(_("Can't read configuration file '%s'!"), $file));
38                 }
40                 /* Capture errors - just the first line is interesting */
41                 ob_start(); 
42                 $this->config= parse_ini_file($file, TRUE);
43                 $ret= preg_replace( array('/^.*\nWarning: /', '/\n.*$/'),
44                                     array('', ''),
45                                     ob_get_contents());
46                 ob_end_clean(); 
48                 /* Bail out in case of errors */
49                 if ($ret != ""){
50                         throw new ConfigManagerException($ret);
51                 }
53                 #echo "Test config and load additional configuration data from LDAP\n";
54                 #$this->test_config();
55                 #$this->load_servers();        -> Section servers/...;
56                 #$this->load_plugin_configs(); -> Section pugins/name/value;
58                 #print_r($this->config);
59         }
62         public function save($file){
63                 throw new ConfigManagerException(_("Save not supported yet!"));
64         }
67         public function setSection($name){
68                 if (isset($this->config[$name])){
69                         $this->section= $name;
70                         $this->current= &$this->config[$name];
71                         return TRUE;
72                 } else {
73                         $this->section= "";
74                         $this->current= NULL;
75                         return FALSE;
76                 }
77         }
80         public function getSection(){
81                 return $this->section;
82         }
85         public function getSections(){
86         }
89         public function getValue($name){
90                 if (!$this->current){
91                         throw new ConfigManagerException(_("Can't get value without current section set!"));
92                 }
93                 
94                 if (isset($this->current[$name])){
95                         return $this->current[$name];
96                 } else {
97                         return NULL;
98                 }
99         }
102         public function setValue($section, $value){
103         }
107 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
108 ?>