Ignore:
Timestamp:
04/12/10 16:21:32 (14 years ago)
Author:
pedroerp
Message:

Ticket #993 - Trocando acessos à GLOBALS por acessos à Settings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/workflow/branches/993/lib/settings/Settings.php

    r2429 r2492  
    2929        private static $_configs = array( 
    3030                'workflow' => array( 
    31                         'intranet_subnetworks' => '', 
    32                         'db' => array( 
     31                        'db_processes' => array( 
    3332                                'name' => '', 
    3433                                'host' => '', 
     
    3837                                'type' => '' 
    3938                        ), 
    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' => '', 
     39                        'db_module' => array( 
     40                                'name' => '', 
     41                                'host' => '', 
     42                                'port' => '', 
    5243                                'user' => '', 
    5344                                'password' => '', 
    54                                 'follow_referrals' => '' 
    55                         ), 
     45                                'type' => '' 
     46                        ), 
     47                        'ldap' => array( 
     48                                'host' => '', 
     49                                'user' => '', 
     50                                'password' => '', 
     51                                'follow_referrals' => '', 
     52                                'user_context' => '', 
     53                                'group_context' => '' 
     54                        ), 
     55                        'preferences' => array( 
     56                                'startpage' => '', 
     57                                'ui_items_per_page' => '', 
     58                                'show_activity_complete_page' => '' 
     59                        ), 
     60                        'intranet_subnetworks' => '', 
     61                        'user_can_clean_instances' => '' 
    5662                ), 
    5763                'expresso' => array( 
     
    6571                        ), 
    6672                        'ldap' => array( 
    67                                 'host' => '' 
    68                         ), 
    69                 ), 
    70                 'process' => array( 
     73                                'host' => '', 
     74                                'user_context' => '', 
     75                                'group_context' => '' 
     76                        ), 
     77                        'user' => array( 
     78                                'account_id' => '', 
     79                                'account_lid' => '', 
     80                                'account_dn' => '', 
     81                                'userid' => '', 
     82                                'passwd' => '', 
     83                                'email' => '' 
     84                        ), 
     85                        'preferences' => array( 
     86                                'lang' => '' 
     87                        ), 
     88                        'webserver_url' => '' 
    7189                ) 
    7290        ); 
     
    92110 
    93111        /** 
    94          * Returns settings. 
     112         * Returns settings. If the hole path has not be setted, return the hole 
     113         * hierarchy under it. 
    95114         * 
    96115         * @param string $args  A variable number of parameters which specify the scope 
     
    105124                $args = func_get_args(); 
    106125 
    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                 } 
     126                /* checking if the key exists */ 
     127                self::_keyExists($args); 
    116128 
    117129                /* check if we already load the settings */ 
     
    123135 
    124136                return $value; 
     137        } 
     138 
     139 
     140        public static function set() { 
     141 
     142                /* getting the variable number of parameters */ 
     143                $args = func_get_args(); 
     144 
     145                /* the last position is always the value that we are trying to set, so pop it */ 
     146                $value = array_pop($args); 
     147 
     148                /* checking if the key exists */ 
     149                self::_keyExists($args); 
     150 
     151                /* check if we already load the settings */ 
     152                if (!self::$_isLoaded) 
     153                        self::_load(); 
     154 
     155                /* retrieving the setting. More 'for' programming. */ 
     156                for ($i=0, $key=&self::$_configs; $i<count($args); $key=&$key[$args[$i++]]); 
     157 
     158                /* updating the value. p.s: $key is a pointer to a $_config node */ 
     159                $key = $value; 
     160                return true; 
     161        } 
     162 
     163        /** 
     164         * Here we check if the configuration was defined into $_configs array. 
     165         * If it does not, an exception will be thrown. 
     166         * 
     167         * @param string $args  A variable number of parameters which specify the scope 
     168         *                                              and the configuration to be retrieved. 
     169         * @access private 
     170         * @return boolean 
     171         * @static 
     172         */ 
     173        private static function _keyExists($path) { 
     174 
     175                /** 
     176                 * p.s: Do not try to understand this piece of code. Just fave faith! It works... 
     177                 */ 
     178                for ($i=0, $sub_array=&self::$_configs; $i<count($path); $sub_array=&$sub_array[$path[$i++]]) { 
     179                        if (!array_key_exists($path[$i], $sub_array)) 
     180                                throw new Exception("Sorry! Setting '".implode("->", $path)."' do not exists."); 
     181                } 
     182                return true; 
    125183        } 
    126184 
     
    143201                self::$_configs['expresso']['db']['type'] = $GLOBALS['phpgw_info']['server']['db_type']; 
    144202 
     203                /* current user information */ 
     204                self::$_configs['expresso']['user']['account_id'] = $GLOBALS['phpgw_info']['user']['account_id']; 
     205                self::$_configs['expresso']['user']['account_lid'] = $GLOBALS['phpgw_info']['user']['account_lid']; 
     206                self::$_configs['expresso']['user']['account_dn'] = $GLOBALS['phpgw_info']['user']['account_dn']; 
     207                self::$_configs['expresso']['user']['userid'] = $GLOBALS['phpgw_info']['user']['userid']; 
     208                self::$_configs['expresso']['user']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd']; 
     209                self::$_configs['expresso']['user']['email'] = $GLOBALS['phpgw_info']['user']['email']; 
     210 
    145211                self::$_configs['expresso']['ldap']['host'] = $GLOBALS['phpgw_info']['server']['ldap_host']; 
     212                self::$_configs['expresso']['ldap']['user_context'] = $GLOBALS['phpgw_info']['server']['ldap_user_context']; 
     213                self::$_configs['expresso']['ldap']['group_context'] = $GLOBALS['phpgw_info']['server']['ldap_group_context']; 
     214 
     215                /* workflow specific preferences */ 
     216                self::$_configs['workflow']['preferences']['startpage'] = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['startpage']; 
     217                self::$_configs['workflow']['preferences']['ui_items_per_page'] = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['ui_items_per_page']; 
     218                self::$_configs['workflow']['preferences']['show_activity_complete_page'] = $GLOBALS['phpgw_info']['user']['preferences']['workflow']['show_activity_complete_page']; 
     219 
     220                /*expresso preferences */ 
     221                self::$_configs['expresso']['preferences']['lang'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; 
     222 
     223                self::$_configs['expresso']['webserver_url'] = $GLOBALS['phpgw_info']['server']['webserver_url']; 
    146224 
    147225                /* loading database settings */ 
     
    151229                self::$_configs['workflow']['intranet_subnetworks'] = $values['intranet_subnetworks']; 
    152230 
    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']; 
     231                self::$_configs['workflow']['db_processes']['name'] = $values['database_name']; 
     232                self::$_configs['workflow']['db_processes']['host'] = $values['database_host']; 
     233                self::$_configs['workflow']['db_processes']['port'] = $values['database_port']; 
     234                self::$_configs['workflow']['db_processes']['admin_user'] = $values['database_admin_user']; 
     235                self::$_configs['workflow']['db_processes']['admin_password'] = $values['database_admin_password']; 
     236                self::$_configs['workflow']['db_processes']['type'] = $values['database_type']; 
     237 
     238                self::$_configs['workflow']['db_module']['name'] = $values['workflow_database_name']; 
     239                self::$_configs['workflow']['db_module']['host'] = $values['workflow_database_host']; 
     240                self::$_configs['workflow']['db_module']['port'] = $values['workflow_database_port']; 
     241                self::$_configs['workflow']['db_module']['user'] = $values['workflow_database_user']; 
     242                self::$_configs['workflow']['db_module']['password'] = $values['workflow_database_password']; 
     243                self::$_configs['workflow']['db_module']['type'] = $values['workflow_database_type']; 
    166244 
    167245                self::$_configs['workflow']['ldap']['host'] = $values['ldap_host']; 
     
    169247                self::$_configs['workflow']['ldap']['password'] = $values['ldap_password']; 
    170248                self::$_configs['workflow']['ldap']['follow_referrals'] = $values['ldap_follow_referrals']; 
     249                self::$_configs['workflow']['ldap']['user_context'] = $values['ldap_user_context']; 
     250                self::$_configs['workflow']['ldap']['group_context'] = $values['ldap_group_context']; 
    171251 
    172252                /* the settings are already loaded. No need to call this method again. */ 
Note: See TracChangeset for help on using the changeset viewer.