source: sandbox/2.5.1-evolucao/prototype/api/config.php @ 8230

Revision 8230, 2.8 KB checked in by angelo, 10 years ago (diff)

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

Line 
1<?php
2
3namespace prototype\api;
4
5class Config
6{
7        static $register;
8
9        static function module($config , $module = false)
10        {
11                //Todo: registrar na nova api o currentapp
12                if(!$module)
13                                $module =  $_SESSION['flags']['currentapp'];
14 
15                if( !isset( $_SESSION['config'][$module] ) || !isset( $_SESSION['config'][$module][$config] ))
16                                $_SESSION['config'][$module] = parse_ini_file( ROOTPATH."/config/$module.ini", true );
17       
18                return isset($_SESSION['config'][$module][$config]) ? $_SESSION['config'][$module][$config] : false;
19     
20        }
21   
22        static function me($config)
23        {
24       
25                return isset($_SESSION['wallet']['user'][$config]) ? $_SESSION['wallet']['user'][$config] : false;
26        }
27   
28        static function service( $service , $config )
29        {
30                if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] ))
31                                $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true );
32       
33                return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false;
34        }
35   
36        static function get( $concept , $config = false , $module = false )
37        {
38                $load = parse_ini_file( ROOTPATH."/config/$concept.ini", true );
39       
40                if($config === false) return $load;
41       
42                return (isset($load[$config])) ? $load[$config] : false;
43        }
44   
45        static function regSet( $name , $value)
46        {
47                self::$register[$name] = $value;
48        }
49        static function regGet ($name )
50        {
51                return (isset(self::$register[$name]) ? self::$register[$name] : false );
52        }
53
54        static function init( )
55        {
56   
57                if( !defined( 'ROOTPATH' ) )
58                                define( 'ROOTPATH', dirname(__FILE__).'/..' );
59       
60                if ( isset( $_COOKIE[ 'sessionid' ] ) )
61                {
62                                session_id( $_COOKIE[ 'sessionid' ] );
63                                if ( isset($GLOBALS['phpgw']) && !is_null($GLOBALS['phpgw']->session) )
64                                        $GLOBALS['phpgw']->session->sessionid = $_COOKIE[ 'sessionid' ];
65                }
66               
67            if( !isset($_SESSION) )
68            session_start();
69               
70        }
71
72   
73        public static function writeIniFile($assoc_arr, $path, $has_sections)
74        {
75                $content = ''; 
76                self::_writeIniFile($content, $assoc_arr, $has_sections);
77                if( file_put_contents($path, $content) === false)
78                {
79                        trigger_error("Permission failure when trying to write in the file: $path ", E_USER_WARNING);
80                        return false;
81                }
82                return true;
83        }
84
85        private static function _writeIniFile(&$content, $assoc_arr, $has_sections)
86        {
87                foreach ($assoc_arr as $key => $val)
88                {
89                        if (is_array($val))
90                        {
91                                if($has_sections)
92                                {
93                                        $content .= "[$key]\n";
94                                        self::_writeIniFile($content, $val, false);
95                                }
96                                else                           
97                                        foreach($val as $iKey => $iVal)
98                                        {
99                                                if (is_int($iKey))
100                                                        $content .= $key ."[] = $iVal\n";
101                                                else
102                                                        $content .= $key ."[$iKey] = $iVal\n";
103                                        }
104                        }
105                        else
106                                $content .= "$key = $val\n";
107                }
108        }
109
110}
111
112        Config::init();
113       
114
115?>
Note: See TracBrowser for help on using the repository browser.