source: sandbox/workflow/branches/993/lib/settings/Settings.php @ 2418

Revision 2418, 5.6 KB checked in by pedroerp, 14 years ago (diff)

Ticket #993 - Versão inicial da classe 'Settings' e substituicao de chamadas 'read_repository'.

Line 
1<?php
2/**************************************************************************\
3* eGroupWare                                                               *
4* http://www.egroupware.org                                                *
5* --------------------------------------------                             *
6*  This program is free software; you can redistribute it and/or modify it *
7*  under the terms of the GNU General Public License as published by the   *
8*  Free Software Foundation; either version 2 of the License, or (at your  *
9*  option) any later version.                                              *
10\**************************************************************************/
11
12/**
13 *
14 *
15 * @package Settings
16 * @license http://www.gnu.org/copyleft/gpl.html GPL
17 * @author Pedro Eugênio Rocha - pedro.eugenio.rocha@gmail.com
18 */
19
20class Settings {
21
22        /**
23         * @var array $_configs Here we should define which settings we are able
24         *                                              to get. The settings not defined here will throw
25         *                                              an exception when someone asks for it.
26         * @access private
27         */
28        private static $_configs = array(
29                'workflow' => array(
30                        'intranet_subnetworks' => '',
31                        'db' => array(
32                                'name' => '',
33                                'host' => '',
34                                'port' => '',
35                                'admin_user' => '',
36                                'admin_password' => '',
37                                'type' => ''
38                        ),
39                        'galaxia' => array(
40                                'db' => array(
41                                        'name' => '',
42                                        'host' => '',
43                                        'port' => '',
44                                        'user' => '',
45                                        'password' => '',
46                                        'type' => ''
47                                )
48                        ),
49                        'ldap' => array(
50                                'host' => '',
51                                'user' => '',
52                                'password' => '',
53                                'follow_referrals' => ''
54                        ),
55                ),
56                'expresso' => array(
57                        'db' => array(
58                                'name' => '',
59                                'host' => '',
60                                'port' => '',
61                                'user' => '',
62                                'password' => '',
63                                'type' => ''
64                        ),
65                        'ldap' => array(
66                                'host' => ''
67                        ),
68                ),
69                'process' => array(
70                )
71        );
72
73        private static $loaded_from_db = false;
74
75
76        /**
77         * Constructor. Just disabling direct instantiation.
78         *
79         * @access public
80         * @return void
81         */
82        public function __construct() {
83                throw new Exception("Oops! Static only class.");
84        }
85
86
87        /**
88         * Returns settings.
89         *
90         * @param string $args  A variable number of parameters which specify the scope
91         *                                              and the configuration to be retrieved.
92         * @access public
93         * @return string
94         * @static
95         */
96        public static function get() {
97
98                /* getting the variable number of parameters */
99                $args = func_get_args();
100
101                /**
102                 * Here we check if the configuration was defined into $_configs array.
103                 * If it does not, an exception will be thrown.
104                 * p.s. Do not try to understand this piece of code. Just fave faith! It works...
105                 */
106                for ($i=0, $sub_array=&self::$_configs; $i<count($args); $sub_array=&$sub_array[$args[$i++]]) {
107                        if (!array_key_exists($args[$i], $sub_array))
108                                throw new Exception("Sorry! Setting '".implode("->", $args)."' do not exists.");
109                }
110
111                /* check if the setting was loaded */
112                $methodName = "populate" . ucfirst(strtolower($args[0]));
113                self::$methodName();
114
115
116                /* retrieving the setting. More 'for' programming. */
117                for ($i=0, $value=&self::$_configs; $i<count($args); $value=&$value[$args[$i++]]);
118
119                return $value;
120        }
121
122
123        public static function load() {
124
125                self::$_configs['expresso']['db']['name'] = $GLOBALS['phpgw_info']['server']['db_name'];
126                self::$_configs['expresso']['db']['host'] = $GLOBALS['phpgw_info']['server']['db_host'];
127                self::$_configs['expresso']['db']['port'] = $GLOBALS['phpgw_info']['server']['db_port'];
128                self::$_configs['expresso']['db']['user'] = $GLOBALS['phpgw_info']['server']['db_user'];
129                self::$_configs['expresso']['db']['password'] = $GLOBALS['phpgw_info']['server']['db_pass'];
130                self::$_configs['expresso']['db']['type'] = $GLOBALS['phpgw_info']['server']['db_type'];
131
132                self::$_configs['expresso']['ldap']['host'] = $GLOBALS['phpgw_info']['server']['ldap_host'];
133        }
134
135        private static function populateWorkflow() {
136
137                $values = self::loadFromDb();
138
139                self::$_configs['workflow']['intranet_subnetworks'] = $values['intranet_subnetworks'];
140
141                self::$_configs['workflow']['db']['name'] = $values['database_name'];
142                self::$_configs['workflow']['db']['host'] = $values['database_host'];
143                self::$_configs['workflow']['db']['port'] = $values['database_port'];
144                self::$_configs['workflow']['db']['admin_user'] = $values['database_admin_user'];
145                self::$_configs['workflow']['db']['admin_password'] = $values['database_admin_password'];
146                self::$_configs['workflow']['db']['type'] = $values['database_type'];
147
148                self::$_configs['workflow']['galaxia']['db']['name'] = $values['workflow_database_name'];
149                self::$_configs['workflow']['galaxia']['db']['host'] = $values['workflow_database_host'];
150                self::$_configs['workflow']['galaxia']['db']['port'] = $values['workflow_database_port'];
151                self::$_configs['workflow']['galaxia']['db']['user'] = $values['workflow_database_user'];
152                self::$_configs['workflow']['galaxia']['db']['password'] = $values['workflow_database_password'];
153                self::$_configs['workflow']['galaxia']['db']['type'] = $values['workflow_database_type'];
154
155                self::$_configs['workflow']['ldap']['host'] = $values['ldap_host'];
156                self::$_configs['workflow']['ldap']['user'] = $values['ldap_user'];
157                self::$_configs['workflow']['ldap']['password'] = $values['ldap_password'];
158                self::$_configs['workflow']['ldap']['follow_referrals'] = $values['ldap_follow_referrals'];
159        }
160
161        private static function populateExpresso() {}
162
163
164        private static function loadFromDb() {
165
166                /* */
167                $config = &Factory::newInstance('config', 'workflow');
168                $values = $config->read_repository();
169
170                /*
171                foreach ($values as $key => $value) {
172                        self::$_configs[$key] = $value;
173                }
174                self::$loaded_from_db = true;
175                */
176                return $values;
177        }
178}
179
180?>
Note: See TracBrowser for help on using the repository browser.