[2418] | 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 | /** |
---|
[2429] | 13 | * General settings class. This class should be used to centralize all settings |
---|
| 14 | * used by the module. |
---|
[2418] | 15 | * |
---|
| 16 | * @package Settings |
---|
| 17 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 18 | * @author Pedro Eugênio Rocha - pedro.eugenio.rocha@gmail.com |
---|
| 19 | */ |
---|
| 20 | class 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 |
---|
[2429] | 27 | * @static |
---|
[2418] | 28 | */ |
---|
| 29 | private static $_configs = array( |
---|
| 30 | 'workflow' => array( |
---|
| 31 | 'intranet_subnetworks' => '', |
---|
| 32 | 'db' => array( |
---|
| 33 | 'name' => '', |
---|
| 34 | 'host' => '', |
---|
| 35 | 'port' => '', |
---|
| 36 | 'admin_user' => '', |
---|
| 37 | 'admin_password' => '', |
---|
| 38 | 'type' => '' |
---|
| 39 | ), |
---|
| 40 | 'galaxia' => array( |
---|
| 41 | 'db' => array( |
---|
| 42 | 'name' => '', |
---|
| 43 | 'host' => '', |
---|
| 44 | 'port' => '', |
---|
| 45 | 'user' => '', |
---|
| 46 | 'password' => '', |
---|
| 47 | 'type' => '' |
---|
| 48 | ) |
---|
| 49 | ), |
---|
| 50 | 'ldap' => array( |
---|
| 51 | 'host' => '', |
---|
| 52 | 'user' => '', |
---|
| 53 | 'password' => '', |
---|
| 54 | 'follow_referrals' => '' |
---|
| 55 | ), |
---|
| 56 | ), |
---|
| 57 | 'expresso' => array( |
---|
| 58 | 'db' => array( |
---|
| 59 | 'name' => '', |
---|
| 60 | 'host' => '', |
---|
| 61 | 'port' => '', |
---|
| 62 | 'user' => '', |
---|
| 63 | 'password' => '', |
---|
| 64 | 'type' => '' |
---|
| 65 | ), |
---|
| 66 | 'ldap' => array( |
---|
| 67 | 'host' => '' |
---|
| 68 | ), |
---|
| 69 | ), |
---|
| 70 | 'process' => array( |
---|
| 71 | ) |
---|
| 72 | ); |
---|
| 73 | |
---|
[2429] | 74 | /** |
---|
| 75 | * @var boolean $_isLoaded Stores whether the settings are loaded or not. |
---|
| 76 | * @access private |
---|
| 77 | * @static |
---|
| 78 | */ |
---|
| 79 | private static $_isLoaded = false; |
---|
[2418] | 80 | |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * Constructor. Just disabling direct instantiation. |
---|
| 84 | * |
---|
| 85 | * @access public |
---|
| 86 | * @return void |
---|
| 87 | */ |
---|
| 88 | public function __construct() { |
---|
| 89 | throw new Exception("Oops! Static only class."); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | * Returns settings. |
---|
| 95 | * |
---|
| 96 | * @param string $args A variable number of parameters which specify the scope |
---|
| 97 | * and the configuration to be retrieved. |
---|
| 98 | * @access public |
---|
| 99 | * @return string |
---|
| 100 | * @static |
---|
| 101 | */ |
---|
| 102 | public static function get() { |
---|
| 103 | |
---|
| 104 | /* getting the variable number of parameters */ |
---|
| 105 | $args = func_get_args(); |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * Here we check if the configuration was defined into $_configs array. |
---|
| 109 | * If it does not, an exception will be thrown. |
---|
| 110 | * p.s. Do not try to understand this piece of code. Just fave faith! It works... |
---|
| 111 | */ |
---|
| 112 | for ($i=0, $sub_array=&self::$_configs; $i<count($args); $sub_array=&$sub_array[$args[$i++]]) { |
---|
| 113 | if (!array_key_exists($args[$i], $sub_array)) |
---|
| 114 | throw new Exception("Sorry! Setting '".implode("->", $args)."' do not exists."); |
---|
| 115 | } |
---|
| 116 | |
---|
[2429] | 117 | /* check if we already load the settings */ |
---|
| 118 | if (!self::$_isLoaded) |
---|
| 119 | self::_load(); |
---|
[2418] | 120 | |
---|
| 121 | /* retrieving the setting. More 'for' programming. */ |
---|
| 122 | for ($i=0, $value=&self::$_configs; $i<count($args); $value=&$value[$args[$i++]]); |
---|
| 123 | |
---|
| 124 | return $value; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
[2429] | 128 | /** |
---|
| 129 | * Loads settings into $_configs private array. |
---|
| 130 | * |
---|
| 131 | * @access private |
---|
| 132 | * @return void |
---|
| 133 | * @static |
---|
| 134 | */ |
---|
| 135 | private static function _load() { |
---|
[2418] | 136 | |
---|
[2429] | 137 | /* loading global variables into $_configs */ |
---|
[2418] | 138 | self::$_configs['expresso']['db']['name'] = $GLOBALS['phpgw_info']['server']['db_name']; |
---|
| 139 | self::$_configs['expresso']['db']['host'] = $GLOBALS['phpgw_info']['server']['db_host']; |
---|
| 140 | self::$_configs['expresso']['db']['port'] = $GLOBALS['phpgw_info']['server']['db_port']; |
---|
| 141 | self::$_configs['expresso']['db']['user'] = $GLOBALS['phpgw_info']['server']['db_user']; |
---|
| 142 | self::$_configs['expresso']['db']['password'] = $GLOBALS['phpgw_info']['server']['db_pass']; |
---|
| 143 | self::$_configs['expresso']['db']['type'] = $GLOBALS['phpgw_info']['server']['db_type']; |
---|
| 144 | |
---|
| 145 | self::$_configs['expresso']['ldap']['host'] = $GLOBALS['phpgw_info']['server']['ldap_host']; |
---|
| 146 | |
---|
[2429] | 147 | /* loading database settings */ |
---|
| 148 | $config = &Factory::newInstance('config', 'workflow'); |
---|
| 149 | $values = $config->read_repository(); |
---|
[2418] | 150 | |
---|
| 151 | self::$_configs['workflow']['intranet_subnetworks'] = $values['intranet_subnetworks']; |
---|
| 152 | |
---|
| 153 | self::$_configs['workflow']['db']['name'] = $values['database_name']; |
---|
| 154 | self::$_configs['workflow']['db']['host'] = $values['database_host']; |
---|
| 155 | self::$_configs['workflow']['db']['port'] = $values['database_port']; |
---|
| 156 | self::$_configs['workflow']['db']['admin_user'] = $values['database_admin_user']; |
---|
| 157 | self::$_configs['workflow']['db']['admin_password'] = $values['database_admin_password']; |
---|
| 158 | self::$_configs['workflow']['db']['type'] = $values['database_type']; |
---|
| 159 | |
---|
| 160 | self::$_configs['workflow']['galaxia']['db']['name'] = $values['workflow_database_name']; |
---|
| 161 | self::$_configs['workflow']['galaxia']['db']['host'] = $values['workflow_database_host']; |
---|
| 162 | self::$_configs['workflow']['galaxia']['db']['port'] = $values['workflow_database_port']; |
---|
| 163 | self::$_configs['workflow']['galaxia']['db']['user'] = $values['workflow_database_user']; |
---|
| 164 | self::$_configs['workflow']['galaxia']['db']['password'] = $values['workflow_database_password']; |
---|
| 165 | self::$_configs['workflow']['galaxia']['db']['type'] = $values['workflow_database_type']; |
---|
| 166 | |
---|
| 167 | self::$_configs['workflow']['ldap']['host'] = $values['ldap_host']; |
---|
| 168 | self::$_configs['workflow']['ldap']['user'] = $values['ldap_user']; |
---|
| 169 | self::$_configs['workflow']['ldap']['password'] = $values['ldap_password']; |
---|
| 170 | self::$_configs['workflow']['ldap']['follow_referrals'] = $values['ldap_follow_referrals']; |
---|
| 171 | |
---|
[2429] | 172 | /* the settings are already loaded. No need to call this method again. */ |
---|
| 173 | self::$_isLoaded = true; |
---|
[2418] | 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | ?> |
---|