Passed
Push — 1.0.0-dev ( 8edc19...2b6704 )
by nguereza
03:32
created
tests/tnhfw/functions/FunctionUserAgentTest.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,69 +1,69 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class FunctionUserAgentTest extends TestCase
6
-	{	
5
+    class FunctionUserAgentTest extends TestCase
6
+    {	
7 7
 	
8
-		public static function setUpBeforeClass()
9
-		{
8
+        public static function setUpBeforeClass()
9
+        {
10 10
             require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
11
-		}
11
+        }
12 12
 		
13
-		public function testLoopBack()
14
-		{
15
-			$this->assertEquals('127.0.0.1', get_ip());
16
-		}
13
+        public function testLoopBack()
14
+        {
15
+            $this->assertEquals('127.0.0.1', get_ip());
16
+        }
17 17
         
18 18
         public function testServerRemoteAddr()
19
-		{
19
+        {
20 20
             $ip = '182.23.24.56';
21 21
             $_SERVER['REMOTE_ADDR'] = $ip;
22
-			$this->assertEquals($ip, get_ip());
23
-		}
22
+            $this->assertEquals($ip, get_ip());
23
+        }
24 24
         
25 25
         public function testServerHttpClientIp()
26
-		{
26
+        {
27 27
             $ip = '192.168.24.1';
28 28
             $_SERVER['HTTP_CLIENT_IP'] = $ip;
29
-			$this->assertEquals($ip, get_ip());
30
-		}
29
+            $this->assertEquals($ip, get_ip());
30
+        }
31 31
         
32 32
         public function testServerHttpXForwardedFor()
33
-		{
33
+        {
34 34
             $ip = '172.18.2.1';
35 35
             $_SERVER['HTTP_X_FORWARDED_FOR'] = $ip;
36
-			$this->assertEquals($ip, get_ip());
37
-		}
36
+            $this->assertEquals($ip, get_ip());
37
+        }
38 38
         
39 39
         public function testServerHttpXForwarded()
40
-		{
40
+        {
41 41
             
42 42
             $ip = '12.18.2.1';
43 43
             $_SERVER['HTTP_X_FORWARDED'] = $ip;
44
-			$this->assertEquals($ip, get_ip());
45
-		}
44
+            $this->assertEquals($ip, get_ip());
45
+        }
46 46
         
47 47
         public function testServerHttpForwardedFor()
48
-		{
48
+        {
49 49
             $ip = '198.180.2.1';
50 50
             $_SERVER['HTTP_FORWARDED_FOR'] = $ip;
51
-			$this->assertEquals($ip, get_ip());
52
-		}
51
+            $this->assertEquals($ip, get_ip());
52
+        }
53 53
         
54 54
         public function testServerHttpForwarded()
55
-		{
55
+        {
56 56
             $ip = '220.200.2.1';
57 57
             $_SERVER['HTTP_FORWARDED'] = $ip;
58
-			$this->assertEquals($ip, get_ip());
59
-		}
58
+            $this->assertEquals($ip, get_ip());
59
+        }
60 60
         
61
-         public function testManyIp()
62
-		{
61
+            public function testManyIp()
62
+        {
63 63
             $ips = '20.200.2.1, 192.168.34.4';
64 64
             $ip = '20.200.2.1';
65 65
             $_SERVER['REMOTE_ADDR'] = $ips;
66
-			$this->assertEquals($ip, get_ip());
67
-		}
66
+            $this->assertEquals($ip, get_ip());
67
+        }
68 68
 
69
-	}
70 69
\ No newline at end of file
70
+    }
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
tests/bootstrap.php 2 patches
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -1,287 +1,287 @@
 block discarded – undo
1 1
 <?php
2
-	/**
3
-	 * TNH Framework
4
-	 *
5
-	 * A simple PHP framework using HMVC architecture
6
-	 *
7
-	 * This content is released under the GNU GPL License (GPL)
8
-	 *
9
-	 * Copyright (C) 2017 Tony NGUEREZA
10
-	 *
11
-	 * This program is free software; you can redistribute it and/or
12
-	 * modify it under the terms of the GNU General Public License
13
-	 * as published by the Free Software Foundation; either version 3
14
-	 * of the License, or (at your option) any later version.
15
-	 *
16
-	 * This program is distributed in the hope that it will be useful,
17
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
-	 * GNU General Public License for more details.
20
-	 *
21
-	 * You should have received a copy of the GNU General Public License
22
-	 * along with this program; if not, write to the Free Software
23
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
-	*/
2
+    /**
3
+     * TNH Framework
4
+     *
5
+     * A simple PHP framework using HMVC architecture
6
+     *
7
+     * This content is released under the GNU GPL License (GPL)
8
+     *
9
+     * Copyright (C) 2017 Tony NGUEREZA
10
+     *
11
+     * This program is free software; you can redistribute it and/or
12
+     * modify it under the terms of the GNU General Public License
13
+     * as published by the Free Software Foundation; either version 3
14
+     * of the License, or (at your option) any later version.
15
+     *
16
+     * This program is distributed in the hope that it will be useful,
17
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+     * GNU General Public License for more details.
20
+     *
21
+     * You should have received a copy of the GNU General Public License
22
+     * along with this program; if not, write to the Free Software
23
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
+     */
25 25
 	
26
-	error_reporting(E_ALL | E_STRICT);
27
-	ini_set('display_errors', 1);
26
+    error_reporting(E_ALL | E_STRICT);
27
+    ini_set('display_errors', 1);
28 28
 
29
-	/**
30
-	* the directory separator, under windows it is \ and unix, linux /
31
-	*/
32
-	define('DS', DIRECTORY_SEPARATOR);
29
+    /**
30
+     * the directory separator, under windows it is \ and unix, linux /
31
+     */
32
+    define('DS', DIRECTORY_SEPARATOR);
33 33
 
34
-	/**
35
-	* The root directory of the application.
36
-	*
37
-	* you can place this directory outside of your web directory, for example "/home/your_app", etc.
38
-	*/
39
-	define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS);
34
+    /**
35
+     * The root directory of the application.
36
+     *
37
+     * you can place this directory outside of your web directory, for example "/home/your_app", etc.
38
+     */
39
+    define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS);
40 40
 	
41
-	//tests dir path
42
-	define('TESTS_PATH', dirname(realpath(__FILE__)) . DS);
41
+    //tests dir path
42
+    define('TESTS_PATH', dirname(realpath(__FILE__)) . DS);
43 43
 
44
-	/**
45
-	* The path to the directory.
46
-	*
47
-	* That contains your static files (javascript, css, images, etc.)
48
-	* Note: the path must be relative to the file index.php (the front-end controller).
49
-	*/
50
-	define('ASSETS_PATH', 'assets/');
44
+    /**
45
+     * The path to the directory.
46
+     *
47
+     * That contains your static files (javascript, css, images, etc.)
48
+     * Note: the path must be relative to the file index.php (the front-end controller).
49
+     */
50
+    define('ASSETS_PATH', 'assets/');
51 51
 
52
-	/**
53
-	* The path to the directory of your cache files.
54
-	*
55
-	* This feature is available currently for database and views.
56
-	*/
57
-	define('CACHE_PATH', ROOT_PATH . 'cache' . DS);
52
+    /**
53
+     * The path to the directory of your cache files.
54
+     *
55
+     * This feature is available currently for database and views.
56
+     */
57
+    define('CACHE_PATH', ROOT_PATH . 'cache' . DS);
58 58
 
59
-	/**
60
-	* Custom application path for tests 
61
-	*/
62
-	define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
59
+    /**
60
+     * Custom application path for tests 
61
+     */
62
+    define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
63 63
 
64
-	/**
65
-	* The path to the controller directory of your application.
66
-	*
67
-	* If you already know the MVC architecture you know what a controller means; 
68
-	* it is he who makes the business logic of your application in general.
69
-	*/
70
-	define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS);
64
+    /**
65
+     * The path to the controller directory of your application.
66
+     *
67
+     * If you already know the MVC architecture you know what a controller means; 
68
+     * it is he who makes the business logic of your application in general.
69
+     */
70
+    define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS);
71 71
 
72
-	/**
73
-	* The path to the directory of your model classes of your application. 
74
-	*
75
-	* If you already know the MVC architecture you know what a model means; 
76
-	* it's the one who interacts with the database, in one word persistent data from your application.
77
-	*/
78
-	define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS);
72
+    /**
73
+     * The path to the directory of your model classes of your application. 
74
+     *
75
+     * If you already know the MVC architecture you know what a model means; 
76
+     * it's the one who interacts with the database, in one word persistent data from your application.
77
+     */
78
+    define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS);
79 79
 
80
-	/**
81
-	* The path to the directory of your views.
82
-	*
83
-	* If you already know the MVC architecture you know what a view means, 
84
-	* a view is just a user interface (html page, form, etc.) that is to say 
85
-	* everything displayed in the browser interface, etc.
86
-	*/
87
-	define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS);
80
+    /**
81
+     * The path to the directory of your views.
82
+     *
83
+     * If you already know the MVC architecture you know what a view means, 
84
+     * a view is just a user interface (html page, form, etc.) that is to say 
85
+     * everything displayed in the browser interface, etc.
86
+     */
87
+    define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS);
88 88
 
89
-	/**
90
-	* The path to the configuration directory.
91
-	*
92
-	* That contains most of the configuration files for your 
93
-	* application (database, class loading file, functions, etc.)
94
-	*/
95
-	define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
89
+    /**
90
+     * The path to the configuration directory.
91
+     *
92
+     * That contains most of the configuration files for your 
93
+     * application (database, class loading file, functions, etc.)
94
+     */
95
+    define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
96 96
 
97
-	/** 
98
-	* The core directory
99
-	*
100
-	* It is recommended to put this folder out of the web directory of your server and 
101
-	* you should not change its content because in case of update you could lose the modified files.
102
-	*/
103
-	define('CORE_PATH', ROOT_PATH . 'core' . DS);
97
+    /** 
98
+     * The core directory
99
+     *
100
+     * It is recommended to put this folder out of the web directory of your server and 
101
+     * you should not change its content because in case of update you could lose the modified files.
102
+     */
103
+    define('CORE_PATH', ROOT_PATH . 'core' . DS);
104 104
 	
105
-	/**
106
-	* The path to the directory of core classes that used by the system.
107
-	*
108
-	* It contains PHP classes that are used by the framework internally.
109
-	*/
110
-	define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS);
105
+    /**
106
+     * The path to the directory of core classes that used by the system.
107
+     *
108
+     * It contains PHP classes that are used by the framework internally.
109
+     */
110
+    define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS);
111 111
 	
112
-	/**
113
-	* The path to the directory of core classes for the cache used by the system.
114
-	*
115
-	* It contains PHP classes for the cache drivers.
116
-	*/
117
-	define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS);
112
+    /**
113
+     * The path to the directory of core classes for the cache used by the system.
114
+     *
115
+     * It contains PHP classes for the cache drivers.
116
+     */
117
+    define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS);
118 118
 	
119 119
     /**
120
-	* The path to the directory of core classes for the database used by the system.
121
-	*
122
-	* It contains PHP classes for the database library, drivers, etc.
123
-	*/
124
-	define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS);
120
+     * The path to the directory of core classes for the database used by the system.
121
+     *
122
+     * It contains PHP classes for the database library, drivers, etc.
123
+     */
124
+    define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS);
125 125
     
126
-	/**
127
-	* The path to the directory of core classes for the model used by the system.
128
-	*
129
-	* It contains PHP classes for the models.
130
-	*/
131
-	define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS);
126
+    /**
127
+     * The path to the directory of core classes for the model used by the system.
128
+     *
129
+     * It contains PHP classes for the models.
130
+     */
131
+    define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS);
132 132
 
133
-	/**
134
-	* The path to the directory of functions or helper systems.
135
-	*
136
-	* It contains PHP functions that perform a particular task: character string processing, URL, etc.
137
-	*/
138
-	define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS);
133
+    /**
134
+     * The path to the directory of functions or helper systems.
135
+     *
136
+     * It contains PHP functions that perform a particular task: character string processing, URL, etc.
137
+     */
138
+    define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS);
139 139
 
140
-	/**
141
-	* The path to the core directory of languages files. 
142
-	*
143
-	*/
144
-	define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS);
140
+    /**
141
+     * The path to the core directory of languages files. 
142
+     *
143
+     */
144
+    define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS);
145 145
 
146
-	/**
147
-	* The path to the system library directory.
148
-	*
149
-	* Which contains the libraries most often used in your web application, as for the 
150
-	* core directory it is advisable to put it out of the root directory of your application.
151
-	*/
152
-	define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS);
146
+    /**
147
+     * The path to the system library directory.
148
+     *
149
+     * Which contains the libraries most often used in your web application, as for the 
150
+     * core directory it is advisable to put it out of the root directory of your application.
151
+     */
152
+    define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS);
153 153
 
154
-	/**
155
-	* The path to the system view directory.
156
-	*
157
-	* That contains the views used for the system, such as error messages, and so on.
158
-	*/
159
-	define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS);
154
+    /**
155
+     * The path to the system view directory.
156
+     *
157
+     * That contains the views used for the system, such as error messages, and so on.
158
+     */
159
+    define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS);
160 160
 	
161
-	/**
162
-	* The path to the directory of your PHP personal functions or helper.
163
-	*
164
-	* It contains your PHP functions that perform a particular task: utilities, etc.
165
-	* Note: Do not put your personal functions or helpers in the system functions directory, 
166
-	* because if you update the system you may lose them.
167
-	*/
168
-	define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS);
161
+    /**
162
+     * The path to the directory of your PHP personal functions or helper.
163
+     *
164
+     * It contains your PHP functions that perform a particular task: utilities, etc.
165
+     * Note: Do not put your personal functions or helpers in the system functions directory, 
166
+     * because if you update the system you may lose them.
167
+     */
168
+    define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS);
169 169
 
170
-	/**
171
-	* The path to the app directory of personal language. 
172
-	*
173
-	* This feature is not yet available. 
174
-	* You can help us do this if you are nice or wish to see the developed framework.
175
-	*/
176
-	define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS);
170
+    /**
171
+     * The path to the app directory of personal language. 
172
+     *
173
+     * This feature is not yet available. 
174
+     * You can help us do this if you are nice or wish to see the developed framework.
175
+     */
176
+    define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS);
177 177
 
178
-	/**
179
-	* The path to the directory of your personal libraries
180
-	*
181
-	* It contains your PHP classes, package, etc.
182
-	* Note: you should not put your personal libraries in the system library directory, 
183
-	* because it is recalled in case of updating the system you might have surprises.
184
-	*/
185
-	define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS);
178
+    /**
179
+     * The path to the directory of your personal libraries
180
+     *
181
+     * It contains your PHP classes, package, etc.
182
+     * Note: you should not put your personal libraries in the system library directory, 
183
+     * because it is recalled in case of updating the system you might have surprises.
184
+     */
185
+    define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS);
186 186
 
187
-	/**
188
-	* The path to the directory that contains the log files.
189
-	*
190
-	* Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
191
-	* under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
192
-	* details see the documentation of your web server.
193
-	* Example for Unix or linux with apache web server:
194
-	* # chmod -R 700 /path/to/your/logs/directory/
195
-	* # chown -R www-data:www-data /path/to/your/logs/directory/
196
-	*/
197
-	define('LOGS_PATH', ROOT_PATH . 'logs' . DS);
187
+    /**
188
+     * The path to the directory that contains the log files.
189
+     *
190
+     * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
191
+     * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
192
+     * details see the documentation of your web server.
193
+     * Example for Unix or linux with apache web server:
194
+     * # chmod -R 700 /path/to/your/logs/directory/
195
+     * # chown -R www-data:www-data /path/to/your/logs/directory/
196
+     */
197
+    define('LOGS_PATH', ROOT_PATH . 'logs' . DS);
198 198
 
199
-	/**
200
-	* The path to the modules directory. 
201
-	*
202
-	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
203
-	* in HMVC architecture (hierichical, controllers, models, views).
204
-	*/
205
-	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
199
+    /**
200
+     * The path to the modules directory. 
201
+     *
202
+     * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
203
+     * in HMVC architecture (hierichical, controllers, models, views).
204
+     */
205
+    define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
206 206
 
207
-	/**
208
-	* The path to the directory of sources external to your application.
209
-	*
210
-	* If you have already used "composer" you know what that means.
211
-	*/
212
-	define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
207
+    /**
208
+     * The path to the directory of sources external to your application.
209
+     *
210
+     * If you have already used "composer" you know what that means.
211
+     */
212
+    define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
213 213
 
214
-	/**
215
-	* The front controller of your application.
216
-	*
217
-	* "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
218
-	* your application by using the rewrite module URL of your web server .
219
-	* For example, under apache web server, there is a configuration example file that is located at the root 
220
-	* of your framework folder : "htaccess.txt" rename it to ".htaccess".
221
-	*/
222
-	define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
214
+    /**
215
+     * The front controller of your application.
216
+     *
217
+     * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
218
+     * your application by using the rewrite module URL of your web server .
219
+     * For example, under apache web server, there is a configuration example file that is located at the root 
220
+     * of your framework folder : "htaccess.txt" rename it to ".htaccess".
221
+     */
222
+    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
223 223
 	
224
-	/**
225
-	 * Check if user run the application under CLI
226
-	 */
227
-	define('IS_CLI', stripos('cli', php_sapi_name()) !== false);
224
+    /**
225
+     * Check if user run the application under CLI
226
+     */
227
+    define('IS_CLI', stripos('cli', php_sapi_name()) !== false);
228 228
 
229
-	/**
230
-	* The environment of your application (production, test, development). 
231
-	*
232
-	* if your application is still in development you use the value "development" 
233
-	* so you will have the display of the error messages, etc. 
234
-	* Once you finish the development of your application that is to put it online 
235
-	* you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
236
-	* the loading of the system, will be fast.
237
-	*/
238
-	define('ENVIRONMENT', 'testing');
229
+    /**
230
+     * The environment of your application (production, test, development). 
231
+     *
232
+     * if your application is still in development you use the value "development" 
233
+     * so you will have the display of the error messages, etc. 
234
+     * Once you finish the development of your application that is to put it online 
235
+     * you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
236
+     * the loading of the system, will be fast.
237
+     */
238
+    define('ENVIRONMENT', 'testing');
239 239
 	
240 240
 	
241
-	//Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available
242
-	$_SESSION = array();
241
+    //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available
242
+    $_SESSION = array();
243 243
 	
244
-	//check for composer autoload file if exists include it
245
-	if (file_exists(VENDOR_PATH . 'autoload.php')){
246
-		require_once VENDOR_PATH . 'autoload.php';
244
+    //check for composer autoload file if exists include it
245
+    if (file_exists(VENDOR_PATH . 'autoload.php')){
246
+        require_once VENDOR_PATH . 'autoload.php';
247 247
 		
248
-		//define the class alias for vstream
249
-		class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
250
-		class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
251
-		class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
248
+        //define the class alias for vstream
249
+        class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
250
+        class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
251
+        class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
252 252
 		
253
-	}
253
+    }
254 254
 
255
-	//require autoloader for test
256
-	require_once  'include/autoloader.php';
255
+    //require autoloader for test
256
+    require_once  'include/autoloader.php';
257 257
 	
258 258
 	
259 259
 
260
-	//grap from core/common.php functions and mock some functions for tests
261
-	require_once  'include/common.php';
260
+    //grap from core/common.php functions and mock some functions for tests
261
+    require_once  'include/common.php';
262 262
 	
263
-	//Some utilities functions, classes, etc.
264
-	require_once  'include/testsUtil.php';
263
+    //Some utilities functions, classes, etc.
264
+    require_once  'include/testsUtil.php';
265 265
 	
266
-	/**
267
-	* Setting of the PHP error message handling function
268
-	*/
269
-	set_error_handler('php_error_handler');
266
+    /**
267
+     * Setting of the PHP error message handling function
268
+     */
269
+    set_error_handler('php_error_handler');
270 270
 
271
-	/**
272
-	* Setting of the PHP error exception handling function
273
-	*/
274
-	set_exception_handler('php_exception_handler');
271
+    /**
272
+     * Setting of the PHP error exception handling function
273
+     */
274
+    set_exception_handler('php_exception_handler');
275 275
 
276
-	/**
277
-	 * Setting of the PHP shutdown handling function
278
-	 */
279
-	register_shutdown_function('php_shudown_handler');
276
+    /**
277
+     * Setting of the PHP shutdown handling function
278
+     */
279
+    register_shutdown_function('php_shudown_handler');
280 280
 	
281
-	/**
282
-	* Register the tests autoload
283
-	*/
284
-	spl_autoload_register('tests_autoload');
281
+    /**
282
+     * Register the tests autoload
283
+     */
284
+    spl_autoload_register('tests_autoload');
285 285
 	
286 286
 	
287
-	
288 287
\ No newline at end of file
288
+    
289 289
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	/**
60 60
 	* Custom application path for tests 
61 61
 	*/
62
-	define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
62
+	define('APPS_PATH', TESTS_PATH . 'hmvc' . DS);
63 63
 
64 64
 	/**
65 65
 	* The path to the controller directory of your application.
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
203 203
 	* in HMVC architecture (hierichical, controllers, models, views).
204 204
 	*/
205
-	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
205
+	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS);
206 206
 
207 207
 	/**
208 208
 	* The path to the directory of sources external to your application.
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	$_SESSION = array();
243 243
 	
244 244
 	//check for composer autoload file if exists include it
245
-	if (file_exists(VENDOR_PATH . 'autoload.php')){
245
+	if (file_exists(VENDOR_PATH . 'autoload.php')) {
246 246
 		require_once VENDOR_PATH . 'autoload.php';
247 247
 		
248 248
 		//define the class alias for vstream
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 3 patches
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -1,312 +1,312 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class FileCache implements CacheInterface{
27
+    class FileCache implements CacheInterface{
28 28
 		
29
-		/**
30
-		 * Whether to enable compression of the cache data file.
31
-		 * @var boolean
32
-		 */
33
-		private $compressCacheData = true;
29
+        /**
30
+         * Whether to enable compression of the cache data file.
31
+         * @var boolean
32
+         */
33
+        private $compressCacheData = true;
34 34
 		
35
-		/**
36
-		 * The logger instance
37
-		 * @var Log
38
-		 */
39
-		private $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var Log
38
+         */
39
+        private $logger;
40 40
 		
41 41
 		
42
-		public function __construct(Log $logger = null){
43
-			if(! $this->isSupported()){
44
-				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45
-			}
46
-			/**
47
-	         * instance of the Log class
48
-	         */
49
-	        if(is_object($logger)){
50
-	          $this->logger = $logger;
51
-	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
54
-	            $this->logger->setLogger('Library::FileCache');
55
-	        }
42
+        public function __construct(Log $logger = null){
43
+            if(! $this->isSupported()){
44
+                show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45
+            }
46
+            /**
47
+             * instance of the Log class
48
+             */
49
+            if(is_object($logger)){
50
+                $this->logger = $logger;
51
+            }
52
+            else{
53
+                $this->logger =& class_loader('Log', 'classes');
54
+                $this->logger->setLogger('Library::FileCache');
55
+            }
56 56
 			
57
-			//if Zlib extension is not loaded set compressCacheData to false
58
-			if(! extension_loaded('zlib')){
59
-				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60
-				$this->compressCacheData = false;
61
-			}
62
-		}
57
+            //if Zlib extension is not loaded set compressCacheData to false
58
+            if(! extension_loaded('zlib')){
59
+                $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60
+                $this->compressCacheData = false;
61
+            }
62
+        }
63 63
 
64
-		/**
65
-		 * This is used to get the cache data using the key
66
-		 * @param  string $key the key to identify the cache data
67
-		 * @return mixed      the cache data if exists else return false
68
-		 */
69
-		public function get($key){
70
-			$this->logger->debug('Getting cache data for key ['. $key .']');
71
-			$filePath = $this->getFilePath($key);
72
-			if(! file_exists($filePath)){
73
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
74
-				return false;
75
-			}
76
-			$this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
-			$handle = fopen($filePath,'r');
78
-			if(! is_resource($handle)){
79
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
80
-				return false;
81
-			}
82
-			// Getting a shared lock 
83
-		    flock($handle, LOCK_SH);
84
-		    $data = file_get_contents($filePath);
85
-      		fclose($handle);
86
-      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
-		         // If unserializing somehow didn't work out, we'll delete the file
90
-		         unlink($filePath);
91
-		         return false;
92
-	      	}
93
-	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
-		        // Unlinking when the file was expired
96
-		        unlink($filePath);
97
-		        return false;
98
-		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
-		     	return $data['data'];
102
-		     }
103
-		}
64
+        /**
65
+         * This is used to get the cache data using the key
66
+         * @param  string $key the key to identify the cache data
67
+         * @return mixed      the cache data if exists else return false
68
+         */
69
+        public function get($key){
70
+            $this->logger->debug('Getting cache data for key ['. $key .']');
71
+            $filePath = $this->getFilePath($key);
72
+            if(! file_exists($filePath)){
73
+                $this->logger->info('No cache file found for the key ['. $key .'], return false');
74
+                return false;
75
+            }
76
+            $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
+            $handle = fopen($filePath,'r');
78
+            if(! is_resource($handle)){
79
+                $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
80
+                return false;
81
+            }
82
+            // Getting a shared lock 
83
+            flock($handle, LOCK_SH);
84
+            $data = file_get_contents($filePath);
85
+                fclose($handle);
86
+                $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
+                if (! $data) {
88
+                    $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
89
+                    // If unserializing somehow didn't work out, we'll delete the file
90
+                    unlink($filePath);
91
+                    return false;
92
+                }
93
+                if (time() > $data['expire']) {
94
+                    $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
95
+                // Unlinking when the file was expired
96
+                unlink($filePath);
97
+                return false;
98
+                }
99
+                else{
100
+                    $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101
+                    return $data['data'];
102
+                }
103
+        }
104 104
 
105 105
 
106
-		/**
107
-		 * Save data to the cache
108
-		 * @param string  $key  the key to identify this cache data
109
-		 * @param mixed  $data the cache data
110
-		 * @param integer $ttl  the cache life time
111
-		 * @return boolean true if success otherwise will return false
112
-		 */
113
-		public function set($key, $data, $ttl = 0){
114
-			$expire = time() + $ttl;
115
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116
-			$filePath = $this->getFilePath($key);
117
-			$handle = fopen($filePath,'w');
118
-			if(! is_resource($handle)){
119
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
120
-				return false;
121
-			}
122
-			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
123
-			//Serializing along with the TTL
124
-		    $cacheData = serialize(array(
125
-									'mtime' => time(),
126
-									'expire' => $expire,
127
-									'data' => $data,
128
-									'ttl' => $ttl
129
-									)
130
-								);		   
131
-		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
-		    	fclose($handle);
135
-		    	return false;
136
-		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
-		    	fclose($handle);
140
-				chmod($filePath, 0640);
141
-				return true;
142
-		    }
143
-		}	
106
+        /**
107
+         * Save data to the cache
108
+         * @param string  $key  the key to identify this cache data
109
+         * @param mixed  $data the cache data
110
+         * @param integer $ttl  the cache life time
111
+         * @return boolean true if success otherwise will return false
112
+         */
113
+        public function set($key, $data, $ttl = 0){
114
+            $expire = time() + $ttl;
115
+            $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116
+            $filePath = $this->getFilePath($key);
117
+            $handle = fopen($filePath,'w');
118
+            if(! is_resource($handle)){
119
+                $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
120
+                return false;
121
+            }
122
+            flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
123
+            //Serializing along with the TTL
124
+            $cacheData = serialize(array(
125
+                                    'mtime' => time(),
126
+                                    'expire' => $expire,
127
+                                    'data' => $data,
128
+                                    'ttl' => $ttl
129
+                                    )
130
+                                );		   
131
+            $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
+            if(! $result){
133
+                $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134
+                fclose($handle);
135
+                return false;
136
+            }
137
+            else{
138
+                $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139
+                fclose($handle);
140
+                chmod($filePath, 0640);
141
+                return true;
142
+            }
143
+        }	
144 144
 
145 145
 
146
-		/**
147
-		 * Delete the cache data for given key
148
-		 * @param  string $key the key for cache to be deleted
149
-		 * @return boolean      true if the cache is delete, false if can't delete 
150
-		 * the cache or the cache with the given key not exist
151
-		 */
152
-		public function delete($key){
153
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
154
-			$filePath = $this->getFilePath($key);
155
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
-			if(! file_exists($filePath)){
157
-				$this->logger->info('This cache file does not exists skipping');
158
-				return false;
159
-			}
160
-			else{
161
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
162
-	      		unlink($filePath);
163
-				return true;
164
-			}
165
-		}
146
+        /**
147
+         * Delete the cache data for given key
148
+         * @param  string $key the key for cache to be deleted
149
+         * @return boolean      true if the cache is delete, false if can't delete 
150
+         * the cache or the cache with the given key not exist
151
+         */
152
+        public function delete($key){
153
+            $this->logger->debug('Deleting of cache data for key [' .$key. ']');
154
+            $filePath = $this->getFilePath($key);
155
+            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
+            if(! file_exists($filePath)){
157
+                $this->logger->info('This cache file does not exists skipping');
158
+                return false;
159
+            }
160
+            else{
161
+                $this->logger->info('Found cache file [' .$filePath. '] remove it');
162
+                    unlink($filePath);
163
+                return true;
164
+            }
165
+        }
166 166
 		
167
-		/**
168
-		 * Get the cache information for given key
169
-		 * @param  string $key the key for cache to get the information for
170
-		 * @return boolean|array    the cache information. The associative array and must contains the following information:
171
-		 * 'mtime' => creation time of the cache (Unix timestamp),
172
-		 * 'expire' => expiration time of the cache (Unix timestamp),
173
-		 * 'ttl' => the time to live of the cache in second
174
-		 */
175
-		public function getInfo($key){
176
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
177
-			$filePath = $this->getFilePath($key);
178
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
-			if(! file_exists($filePath)){
180
-				$this->logger->info('This cache file does not exists skipping');
181
-				return false;
182
-			}
183
-			$this->logger->info('Found cache file [' .$filePath. '] check the validity');
184
-      		$data = file_get_contents($filePath);
185
-			$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
186
-			if(! $data){
187
-				$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
188
-				return false;
189
-			}
190
-			$this->logger->info('This cache data is OK check for expire');
191
-			if(isset($data['expire']) && $data['expire'] > time()){
192
-				$this->logger->info('This cache not yet expired return cache informations');
193
-				$info = array(
194
-					'mtime' => $data['mtime'],
195
-					'expire' => $data['expire'],
196
-					'ttl' => $data['ttl']
197
-					);
198
-				return $info;
199
-			}
200
-			$this->logger->info('This cache already expired return false');
201
-			return false;
202
-		}
167
+        /**
168
+         * Get the cache information for given key
169
+         * @param  string $key the key for cache to get the information for
170
+         * @return boolean|array    the cache information. The associative array and must contains the following information:
171
+         * 'mtime' => creation time of the cache (Unix timestamp),
172
+         * 'expire' => expiration time of the cache (Unix timestamp),
173
+         * 'ttl' => the time to live of the cache in second
174
+         */
175
+        public function getInfo($key){
176
+            $this->logger->debug('Getting of cache info for key [' .$key. ']');
177
+            $filePath = $this->getFilePath($key);
178
+            $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
+            if(! file_exists($filePath)){
180
+                $this->logger->info('This cache file does not exists skipping');
181
+                return false;
182
+            }
183
+            $this->logger->info('Found cache file [' .$filePath. '] check the validity');
184
+                $data = file_get_contents($filePath);
185
+            $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
186
+            if(! $data){
187
+                $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
188
+                return false;
189
+            }
190
+            $this->logger->info('This cache data is OK check for expire');
191
+            if(isset($data['expire']) && $data['expire'] > time()){
192
+                $this->logger->info('This cache not yet expired return cache informations');
193
+                $info = array(
194
+                    'mtime' => $data['mtime'],
195
+                    'expire' => $data['expire'],
196
+                    'ttl' => $data['ttl']
197
+                    );
198
+                return $info;
199
+            }
200
+            $this->logger->info('This cache already expired return false');
201
+            return false;
202
+        }
203 203
 
204 204
 
205
-		/**
206
-		 * Used to delete expired cache data
207
-		 */
208
-		public function deleteExpiredCache(){
209
-			$this->logger->debug('Deleting of expired cache files');
210
-			$list = glob(CACHE_PATH . '*.cache');
211
-			if(! $list){
212
-				$this->logger->info('No cache files were found skipping');
213
-			}
214
-			else{
215
-				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
216
-				foreach ($list as $file) {
217
-					$this->logger->debug('Processing the cache file [' . $file . ']');
218
-					$data = file_get_contents($file);
219
-		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
220
-		      		if(! $data){
221
-		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
222
-		      		}
223
-		      		else if(time() > $data['expire']){
224
-		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
225
-		      			unlink($file);
226
-		      		}
227
-		      		else{
228
-		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
229
-		      		}
230
-				}
231
-			}
232
-		}	
205
+        /**
206
+         * Used to delete expired cache data
207
+         */
208
+        public function deleteExpiredCache(){
209
+            $this->logger->debug('Deleting of expired cache files');
210
+            $list = glob(CACHE_PATH . '*.cache');
211
+            if(! $list){
212
+                $this->logger->info('No cache files were found skipping');
213
+            }
214
+            else{
215
+                $this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
216
+                foreach ($list as $file) {
217
+                    $this->logger->debug('Processing the cache file [' . $file . ']');
218
+                    $data = file_get_contents($file);
219
+                        $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
220
+                        if(! $data){
221
+                            $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
222
+                        }
223
+                        else if(time() > $data['expire']){
224
+                            $this->logger->info('The cache data for file [' . $file . '] already expired remove it');
225
+                            unlink($file);
226
+                        }
227
+                        else{
228
+                            $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
229
+                        }
230
+                }
231
+            }
232
+        }	
233 233
 
234
-		/**
235
-		 * Remove all file from cache folder
236
-		 */
237
-		public function clean(){
238
-			$this->logger->debug('Deleting of all cache files');
239
-			$list = glob(CACHE_PATH . '*.cache');
240
-			if(! $list){
241
-				$this->logger->info('No cache files were found skipping');
242
-			}
243
-			else{
244
-				$this->logger->info('Found [' . count($list) . '] cache files to remove');
245
-				foreach ($list as $file) {
246
-					$this->logger->debug('Processing the cache file [' . $file . ']');
247
-					unlink($file);
248
-				}
249
-			}
250
-		}
234
+        /**
235
+         * Remove all file from cache folder
236
+         */
237
+        public function clean(){
238
+            $this->logger->debug('Deleting of all cache files');
239
+            $list = glob(CACHE_PATH . '*.cache');
240
+            if(! $list){
241
+                $this->logger->info('No cache files were found skipping');
242
+            }
243
+            else{
244
+                $this->logger->info('Found [' . count($list) . '] cache files to remove');
245
+                foreach ($list as $file) {
246
+                    $this->logger->debug('Processing the cache file [' . $file . ']');
247
+                    unlink($file);
248
+                }
249
+            }
250
+        }
251 251
 	
252
-	    /**
253
-	     * @return boolean
254
-	     */
255
-	    public function isCompressCacheData(){
256
-	        return $this->compressCacheData;
257
-	    }
252
+        /**
253
+         * @return boolean
254
+         */
255
+        public function isCompressCacheData(){
256
+            return $this->compressCacheData;
257
+        }
258 258
 
259
-	    /**
260
-	     * @param boolean $compressCacheData
261
-	     *
262
-	     * @return object
263
-	     */
264
-	    public function setCompressCacheData($status = true){
265
-			//if Zlib extension is not loaded set compressCacheData to false
266
-			if($status === true && ! extension_loaded('zlib')){
259
+        /**
260
+         * @param boolean $compressCacheData
261
+         *
262
+         * @return object
263
+         */
264
+        public function setCompressCacheData($status = true){
265
+            //if Zlib extension is not loaded set compressCacheData to false
266
+            if($status === true && ! extension_loaded('zlib')){
267 267
 				
268
-				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
269
-				$this->compressCacheData = false;
270
-			}
271
-			else{
272
-				$this->compressCacheData = $status;
273
-			}
274
-			return $this;
275
-	    }
268
+                $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
269
+                $this->compressCacheData = false;
270
+            }
271
+            else{
272
+                $this->compressCacheData = $status;
273
+            }
274
+            return $this;
275
+        }
276 276
 		
277
-		/**
278
-		 * Check whether the cache feature for the handle is supported
279
-		 *
280
-		 * @return bool
281
-		 */
282
-		public function isSupported(){
283
-			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
284
-		}
277
+        /**
278
+         * Check whether the cache feature for the handle is supported
279
+         *
280
+         * @return bool
281
+         */
282
+        public function isSupported(){
283
+            return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
284
+        }
285 285
 
286
-		/**
287
-	     * Return the Log instance
288
-	     * @return object
289
-	     */
290
-	    public function getLogger(){
291
-	      return $this->logger;
292
-	    }
286
+        /**
287
+         * Return the Log instance
288
+         * @return object
289
+         */
290
+        public function getLogger(){
291
+            return $this->logger;
292
+        }
293 293
 
294
-	    /**
295
-	     * Set the log instance
296
-	     * @param Log $logger the log object
297
-	     */
298
-	    public function setLogger(Log $logger){
299
-	      $this->logger = $logger;
300
-	      return $this;
301
-	    }
294
+        /**
295
+         * Set the log instance
296
+         * @param Log $logger the log object
297
+         */
298
+        public function setLogger(Log $logger){
299
+            $this->logger = $logger;
300
+            return $this;
301
+        }
302 302
 		
303
-		/**
304
-		* Get the cache file full path for the given key
305
-		*
306
-		* @param string $key the cache item key
307
-		* @return string the full cache file path for this key
308
-		*/
309
-		private function getFilePath($key){
310
-			return CACHE_PATH . md5($key) . '.cache';
311
-		}
312
-	}
303
+        /**
304
+         * Get the cache file full path for the given key
305
+         *
306
+         * @param string $key the cache item key
307
+         * @return string the full cache file path for this key
308
+         */
309
+        private function getFilePath($key){
310
+            return CACHE_PATH . md5($key) . '.cache';
311
+        }
312
+    }
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class FileCache implements CacheInterface{
27
+	class FileCache implements CacheInterface {
28 28
 		
29 29
 		/**
30 30
 		 * Whether to enable compression of the cache data file.
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
 		private $logger;
40 40
 		
41 41
 		
42
-		public function __construct(Log $logger = null){
43
-			if(! $this->isSupported()){
42
+		public function __construct(Log $logger = null) {
43
+			if (!$this->isSupported()) {
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47 47
 	         * instance of the Log class
48 48
 	         */
49
-	        if(is_object($logger)){
49
+	        if (is_object($logger)) {
50 50
 	          $this->logger = $logger;
51 51
 	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
52
+	        else {
53
+	            $this->logger = & class_loader('Log', 'classes');
54 54
 	            $this->logger->setLogger('Library::FileCache');
55 55
 	        }
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58
-			if(! extension_loaded('zlib')){
58
+			if (!extension_loaded('zlib')) {
59 59
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60 60
 				$this->compressCacheData = false;
61 61
 			}
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 		 * @param  string $key the key to identify the cache data
67 67
 		 * @return mixed      the cache data if exists else return false
68 68
 		 */
69
-		public function get($key){
70
-			$this->logger->debug('Getting cache data for key ['. $key .']');
69
+		public function get($key) {
70
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
71 71
 			$filePath = $this->getFilePath($key);
72
-			if(! file_exists($filePath)){
73
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
72
+			if (!file_exists($filePath)) {
73
+				$this->logger->info('No cache file found for the key [' . $key . '], return false');
74 74
 				return false;
75 75
 			}
76
-			$this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
-			$handle = fopen($filePath,'r');
78
-			if(! is_resource($handle)){
79
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
76
+			$this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid');
77
+			$handle = fopen($filePath, 'r');
78
+			if (!is_resource($handle)) {
79
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
 		    $data = file_get_contents($filePath);
85 85
       		fclose($handle);
86 86
       		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
87
+      		if (!$data) {
88
+      			$this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false');
89 89
 		         // If unserializing somehow didn't work out, we'll delete the file
90 90
 		         unlink($filePath);
91 91
 		         return false;
92 92
 	      	}
93 93
 	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
94
+	      		$this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']');
95 95
 		        // Unlinking when the file was expired
96 96
 		        unlink($filePath);
97 97
 		        return false;
98 98
 		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
99
+		     else {
100
+		     	$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101 101
 		     	return $data['data'];
102 102
 		     }
103 103
 		}
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 		 * @param integer $ttl  the cache life time
111 111
 		 * @return boolean true if success otherwise will return false
112 112
 		 */
113
-		public function set($key, $data, $ttl = 0){
113
+		public function set($key, $data, $ttl = 0) {
114 114
 			$expire = time() + $ttl;
115
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
115
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116 116
 			$filePath = $this->getFilePath($key);
117
-			$handle = fopen($filePath,'w');
118
-			if(! is_resource($handle)){
119
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
117
+			$handle = fopen($filePath, 'w');
118
+			if (!is_resource($handle)) {
119
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
120 120
 				return false;
121 121
 			}
122 122
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 									)
130 130
 								);		   
131 131
 		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
132
+		    if (!$result) {
133
+		    	$this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false');
134 134
 		    	fclose($handle);
135 135
 		    	return false;
136 136
 		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
137
+		    else {
138
+		    	$this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']');
139 139
 		    	fclose($handle);
140 140
 				chmod($filePath, 0640);
141 141
 				return true;
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
 		 * @return boolean      true if the cache is delete, false if can't delete 
150 150
 		 * the cache or the cache with the given key not exist
151 151
 		 */
152
-		public function delete($key){
153
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
152
+		public function delete($key) {
153
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
154 154
 			$filePath = $this->getFilePath($key);
155
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
-			if(! file_exists($filePath)){
155
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
156
+			if (!file_exists($filePath)) {
157 157
 				$this->logger->info('This cache file does not exists skipping');
158 158
 				return false;
159 159
 			}
160
-			else{
161
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
160
+			else {
161
+				$this->logger->info('Found cache file [' . $filePath . '] remove it');
162 162
 	      		unlink($filePath);
163 163
 				return true;
164 164
 			}
@@ -172,23 +172,23 @@  discard block
 block discarded – undo
172 172
 		 * 'expire' => expiration time of the cache (Unix timestamp),
173 173
 		 * 'ttl' => the time to live of the cache in second
174 174
 		 */
175
-		public function getInfo($key){
176
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
175
+		public function getInfo($key) {
176
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
177 177
 			$filePath = $this->getFilePath($key);
178
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
-			if(! file_exists($filePath)){
178
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
179
+			if (!file_exists($filePath)) {
180 180
 				$this->logger->info('This cache file does not exists skipping');
181 181
 				return false;
182 182
 			}
183
-			$this->logger->info('Found cache file [' .$filePath. '] check the validity');
183
+			$this->logger->info('Found cache file [' . $filePath . '] check the validity');
184 184
       		$data = file_get_contents($filePath);
185 185
 			$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
186
-			if(! $data){
186
+			if (!$data) {
187 187
 				$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
188 188
 				return false;
189 189
 			}
190 190
 			$this->logger->info('This cache data is OK check for expire');
191
-			if(isset($data['expire']) && $data['expire'] > time()){
191
+			if (isset($data['expire']) && $data['expire'] > time()) {
192 192
 				$this->logger->info('This cache not yet expired return cache informations');
193 193
 				$info = array(
194 194
 					'mtime' => $data['mtime'],
@@ -205,26 +205,26 @@  discard block
 block discarded – undo
205 205
 		/**
206 206
 		 * Used to delete expired cache data
207 207
 		 */
208
-		public function deleteExpiredCache(){
208
+		public function deleteExpiredCache() {
209 209
 			$this->logger->debug('Deleting of expired cache files');
210 210
 			$list = glob(CACHE_PATH . '*.cache');
211
-			if(! $list){
211
+			if (!$list) {
212 212
 				$this->logger->info('No cache files were found skipping');
213 213
 			}
214
-			else{
214
+			else {
215 215
 				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
216 216
 				foreach ($list as $file) {
217 217
 					$this->logger->debug('Processing the cache file [' . $file . ']');
218 218
 					$data = file_get_contents($file);
219 219
 		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
220
-		      		if(! $data){
220
+		      		if (!$data) {
221 221
 		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
222 222
 		      		}
223
-		      		else if(time() > $data['expire']){
223
+		      		else if (time() > $data['expire']) {
224 224
 		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
225 225
 		      			unlink($file);
226 226
 		      		}
227
-		      		else{
227
+		      		else {
228 228
 		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
229 229
 		      		}
230 230
 				}
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 		/**
235 235
 		 * Remove all file from cache folder
236 236
 		 */
237
-		public function clean(){
237
+		public function clean() {
238 238
 			$this->logger->debug('Deleting of all cache files');
239 239
 			$list = glob(CACHE_PATH . '*.cache');
240
-			if(! $list){
240
+			if (!$list) {
241 241
 				$this->logger->info('No cache files were found skipping');
242 242
 			}
243
-			else{
243
+			else {
244 244
 				$this->logger->info('Found [' . count($list) . '] cache files to remove');
245 245
 				foreach ($list as $file) {
246 246
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	    /**
253 253
 	     * @return boolean
254 254
 	     */
255
-	    public function isCompressCacheData(){
255
+	    public function isCompressCacheData() {
256 256
 	        return $this->compressCacheData;
257 257
 	    }
258 258
 
@@ -261,14 +261,14 @@  discard block
 block discarded – undo
261 261
 	     *
262 262
 	     * @return object
263 263
 	     */
264
-	    public function setCompressCacheData($status = true){
264
+	    public function setCompressCacheData($status = true) {
265 265
 			//if Zlib extension is not loaded set compressCacheData to false
266
-			if($status === true && ! extension_loaded('zlib')){
266
+			if ($status === true && !extension_loaded('zlib')) {
267 267
 				
268 268
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
269 269
 				$this->compressCacheData = false;
270 270
 			}
271
-			else{
271
+			else {
272 272
 				$this->compressCacheData = $status;
273 273
 			}
274 274
 			return $this;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		 *
280 280
 		 * @return bool
281 281
 		 */
282
-		public function isSupported(){
282
+		public function isSupported() {
283 283
 			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
284 284
 		}
285 285
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	     * Return the Log instance
288 288
 	     * @return object
289 289
 	     */
290
-	    public function getLogger(){
290
+	    public function getLogger() {
291 291
 	      return $this->logger;
292 292
 	    }
293 293
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	     * Set the log instance
296 296
 	     * @param Log $logger the log object
297 297
 	     */
298
-	    public function setLogger(Log $logger){
298
+	    public function setLogger(Log $logger) {
299 299
 	      $this->logger = $logger;
300 300
 	      return $this;
301 301
 	    }
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		* @param string $key the cache item key
307 307
 		* @return string the full cache file path for this key
308 308
 		*/
309
-		private function getFilePath($key){
309
+		private function getFilePath($key) {
310 310
 			return CACHE_PATH . md5($key) . '.cache';
311 311
 		}
312 312
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -48,8 +48,7 @@  discard block
 block discarded – undo
48 48
 	         */
49 49
 	        if(is_object($logger)){
50 50
 	          $this->logger = $logger;
51
-	        }
52
-	        else{
51
+	        } else{
53 52
 	            $this->logger =& class_loader('Log', 'classes');
54 53
 	            $this->logger->setLogger('Library::FileCache');
55 54
 	        }
@@ -95,8 +94,7 @@  discard block
 block discarded – undo
95 94
 		        // Unlinking when the file was expired
96 95
 		        unlink($filePath);
97 96
 		        return false;
98
-		     }
99
-		     else{
97
+		     } else{
100 98
 		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101 99
 		     	return $data['data'];
102 100
 		     }
@@ -133,8 +131,7 @@  discard block
 block discarded – undo
133 131
 		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
134 132
 		    	fclose($handle);
135 133
 		    	return false;
136
-		    }
137
-		    else{
134
+		    } else{
138 135
 		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
139 136
 		    	fclose($handle);
140 137
 				chmod($filePath, 0640);
@@ -156,8 +153,7 @@  discard block
 block discarded – undo
156 153
 			if(! file_exists($filePath)){
157 154
 				$this->logger->info('This cache file does not exists skipping');
158 155
 				return false;
159
-			}
160
-			else{
156
+			} else{
161 157
 				$this->logger->info('Found cache file [' .$filePath. '] remove it');
162 158
 	      		unlink($filePath);
163 159
 				return true;
@@ -210,8 +206,7 @@  discard block
 block discarded – undo
210 206
 			$list = glob(CACHE_PATH . '*.cache');
211 207
 			if(! $list){
212 208
 				$this->logger->info('No cache files were found skipping');
213
-			}
214
-			else{
209
+			} else{
215 210
 				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
216 211
 				foreach ($list as $file) {
217 212
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -219,12 +214,10 @@  discard block
 block discarded – undo
219 214
 		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
220 215
 		      		if(! $data){
221 216
 		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
222
-		      		}
223
-		      		else if(time() > $data['expire']){
217
+		      		} else if(time() > $data['expire']){
224 218
 		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
225 219
 		      			unlink($file);
226
-		      		}
227
-		      		else{
220
+		      		} else{
228 221
 		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
229 222
 		      		}
230 223
 				}
@@ -239,8 +232,7 @@  discard block
 block discarded – undo
239 232
 			$list = glob(CACHE_PATH . '*.cache');
240 233
 			if(! $list){
241 234
 				$this->logger->info('No cache files were found skipping');
242
-			}
243
-			else{
235
+			} else{
244 236
 				$this->logger->info('Found [' . count($list) . '] cache files to remove');
245 237
 				foreach ($list as $file) {
246 238
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -267,8 +259,7 @@  discard block
 block discarded – undo
267 259
 				
268 260
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
269 261
 				$this->compressCacheData = false;
270
-			}
271
-			else{
262
+			} else{
272 263
 				$this->compressCacheData = $status;
273 264
 			}
274 265
 			return $this;
Please login to merge, or discard this patch.
core/classes/Router.php 3 patches
Indentation   +610 added lines, -610 removed lines patch added patch discarded remove patch
@@ -1,624 +1,624 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
26
-
27
-	class Router {
28
-		/**
29
-		* @var array $pattern: The list of URIs to validate against
30
-		*/
31
-		private $pattern = array();
32
-
33
-		/**
34
-		* @var array $callback: The list of callback to call
35
-		*/
36
-		private $callback = array();
37
-
38
-		/**
39
-		* @var string $uriTrim: The char to remove from the URIs
40
-		*/
41
-		protected $uriTrim = '/\^$';
42
-
43
-		/**
44
-		* @var string $uri: The route URI to use
45
-		*/
46
-		protected $uri = '';
47
-
48
-		/**
49
-		 * The module name of the current request
50
-		 * @var string
51
-		 */
52
-		protected $module = null;
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+
27
+    class Router {
28
+        /**
29
+         * @var array $pattern: The list of URIs to validate against
30
+         */
31
+        private $pattern = array();
32
+
33
+        /**
34
+         * @var array $callback: The list of callback to call
35
+         */
36
+        private $callback = array();
37
+
38
+        /**
39
+         * @var string $uriTrim: The char to remove from the URIs
40
+         */
41
+        protected $uriTrim = '/\^$';
42
+
43
+        /**
44
+         * @var string $uri: The route URI to use
45
+         */
46
+        protected $uri = '';
47
+
48
+        /**
49
+         * The module name of the current request
50
+         * @var string
51
+         */
52
+        protected $module = null;
53 53
 		
54
-		/**
55
-		 * The controller name of the current request
56
-		 * @var string
57
-		 */
58
-		protected $controller = null;
59
-
60
-		/**
61
-		 * The controller path
62
-		 * @var string
63
-		 */
64
-		protected $controllerPath = null;
65
-
66
-		/**
67
-		 * The method name. The default value is "index"
68
-		 * @var string
69
-		 */
70
-		protected $method = 'index';
71
-
72
-		/**
73
-		 * List of argument to pass to the method
74
-		 * @var array
75
-		 */
76
-		protected $args = array();
77
-
78
-		/**
79
-		 * List of routes configurations
80
-		 * @var array
81
-		 */
82
-		protected $routes = array();
83
-
84
-		/**
85
-		 * The segments array for the current request
86
-		 * @var array
87
-		 */
88
-		protected $segments = array();
89
-
90
-		/**
91
-		 * The logger instance
92
-		 * @var Log
93
-		 */
94
-		private $logger;
95
-
96
-		/**
97
-		 * Construct the new Router instance
98
-		 */
99
-		public function __construct(){
100
-			$this->setLoggerFromParamOrCreateNewInstance(null);
54
+        /**
55
+         * The controller name of the current request
56
+         * @var string
57
+         */
58
+        protected $controller = null;
59
+
60
+        /**
61
+         * The controller path
62
+         * @var string
63
+         */
64
+        protected $controllerPath = null;
65
+
66
+        /**
67
+         * The method name. The default value is "index"
68
+         * @var string
69
+         */
70
+        protected $method = 'index';
71
+
72
+        /**
73
+         * List of argument to pass to the method
74
+         * @var array
75
+         */
76
+        protected $args = array();
77
+
78
+        /**
79
+         * List of routes configurations
80
+         * @var array
81
+         */
82
+        protected $routes = array();
83
+
84
+        /**
85
+         * The segments array for the current request
86
+         * @var array
87
+         */
88
+        protected $segments = array();
89
+
90
+        /**
91
+         * The logger instance
92
+         * @var Log
93
+         */
94
+        private $logger;
95
+
96
+        /**
97
+         * Construct the new Router instance
98
+         */
99
+        public function __construct(){
100
+            $this->setLoggerFromParamOrCreateNewInstance(null);
101 101
 			
102
-			//loading routes for module
103
-			$moduleRouteList = array();
104
-			$modulesRoutes = Module::getModulesRoutes();
105
-			if($modulesRoutes && is_array($modulesRoutes)){
106
-				$moduleRouteList = $modulesRoutes;
107
-				unset($modulesRoutes);
108
-			}
109
-			$this->setRouteConfiguration($moduleRouteList);
110
-			$this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes));
111
-
112
-			//Set route informations
113
-			$this->setRouteConfigurationInfos();
114
-		}
115
-
116
-		/**
117
-		 * Get the route patterns
118
-		 * @return array
119
-		 */
120
-		public function getPattern(){
121
-			return $this->pattern;
122
-		}
123
-
124
-		/**
125
-		 * Get the route callbacks
126
-		 * @return array
127
-		 */
128
-		public function getCallback(){
129
-			return $this->callback;
130
-		}
131
-
132
-	    /**
133
-		 * Get the module name
134
-		 * @return string
135
-		 */
136
-		public function getModule(){
137
-			return $this->module;
138
-		}
102
+            //loading routes for module
103
+            $moduleRouteList = array();
104
+            $modulesRoutes = Module::getModulesRoutes();
105
+            if($modulesRoutes && is_array($modulesRoutes)){
106
+                $moduleRouteList = $modulesRoutes;
107
+                unset($modulesRoutes);
108
+            }
109
+            $this->setRouteConfiguration($moduleRouteList);
110
+            $this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes));
111
+
112
+            //Set route informations
113
+            $this->setRouteConfigurationInfos();
114
+        }
115
+
116
+        /**
117
+         * Get the route patterns
118
+         * @return array
119
+         */
120
+        public function getPattern(){
121
+            return $this->pattern;
122
+        }
123
+
124
+        /**
125
+         * Get the route callbacks
126
+         * @return array
127
+         */
128
+        public function getCallback(){
129
+            return $this->callback;
130
+        }
131
+
132
+        /**
133
+         * Get the module name
134
+         * @return string
135
+         */
136
+        public function getModule(){
137
+            return $this->module;
138
+        }
139 139
 		
140
-		/**
141
-		 * Get the controller name
142
-		 * @return string
143
-		 */
144
-		public function getController(){
145
-			return $this->controller;
146
-		}
147
-
148
-		/**
149
-		 * Get the controller file path
150
-		 * @return string
151
-		 */
152
-		public function getControllerPath(){
153
-			return $this->controllerPath;
154
-		}
155
-
156
-		/**
157
-		 * Get the controller method
158
-		 * @return string
159
-		 */
160
-		public function getMethod(){
161
-			return $this->method;
162
-		}
163
-
164
-		/**
165
-		 * Get the request arguments
166
-		 * @return array
167
-		 */
168
-		public function getArgs(){
169
-			return $this->args;
170
-		}
171
-
172
-		/**
173
-		 * Get the URL segments array
174
-		 * @return array
175
-		 */
176
-		public function getSegments(){
177
-			return $this->segments;
178
-		}
179
-
180
-		/**
181
-	     * Return the Log instance
182
-	     * @return Log
183
-	     */
184
-	    public function getLogger(){
185
-	      return $this->logger;
186
-	    }
187
-
188
-	    /**
189
-	     * Set the log instance
190
-	     * @param Log $logger the log object
191
-		 * @return object
192
-	     */
193
-	    public function setLogger($logger){
194
-	      $this->logger = $logger;
195
-	      return $this;
196
-	    }
197
-
198
-	    /**
199
-		 * Get the route URI
200
-		 * @return string
201
-		 */
202
-		public function getRouteUri(){
203
-			return $this->uri;
204
-		}
205
-
206
-		/**
207
-		* Add the URI and callback to the list of URIs to validate
208
-		*
209
-		* @param string $uri the request URI
210
-		* @param string $callback the callback function
211
-		*
212
-		* @return object the current instance
213
-		*/
214
-		public function add($uri, $callback) {
215
-			$uri = trim($uri, $this->uriTrim);
216
-			if(in_array($uri, $this->pattern)){
217
-				$this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
218
-			}
219
-			$this->pattern[] = $uri;
220
-			$this->callback[] = $callback;
221
-			return $this;
222
-		}
223
-
224
-		/**
225
-		* Remove the route configuration
226
-		*
227
-		* @param string $uri the URI
228
-		*
229
-		* @return object the current instance
230
-		*/
231
-		public function removeRoute($uri) {
232
-			$index  = array_search($uri, $this->pattern, true);
233
-			if($index !== false){
234
-				$this->logger->info('Remove route for uri [' . $uri . '] from the configuration');
235
-				unset($this->pattern[$index]);
236
-				unset($this->callback[$index]);
237
-			}
238
-			return $this;
239
-		}
240
-
241
-
242
-		/**
243
-		* Remove all the routes from the configuration
244
-		*
245
-		* @return object the current instance
246
-		*/
247
-		public function removeAllRoute() {
248
-			$this->logger->info('Remove all routes from the configuration');
249
-			$this->pattern  = array();
250
-			$this->callback = array();
251
-			$this->routes = array();
252
-			return $this;
253
-		}
254
-
255
-
256
-		/**
257
-	     * Set the route URI to use later
258
-	     * @param string $uri the route URI, if is empty will determine automatically
259
-	     * @return object
260
-	     */
261
-	    public function setRouteUri($uri = ''){
262
-	    	$routeUri = '';
263
-	    	if(! empty($uri)){
264
-	    		$routeUri = $uri;
265
-	    	}
266
-	    	//if the application is running in CLI mode use the first argument
267
-			else if(IS_CLI && isset($_SERVER['argv'][1])){
268
-				$routeUri = $_SERVER['argv'][1];
269
-			}
270
-			else if(isset($_SERVER['REQUEST_URI'])){
271
-				$routeUri = $_SERVER['REQUEST_URI'];
272
-			}
273
-			$this->logger->debug('Check if URL suffix is enabled in the configuration');
274
-			//remove url suffix from the request URI
275
-			$suffix = get_config('url_suffix');
276
-			if ($suffix) {
277
-				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
278
-				$routeUri = str_ireplace($suffix, '', $routeUri);
279
-			} 
280
-			if (strpos($routeUri, '?') !== false){
281
-				$routeUri = substr($routeUri, 0, strpos($routeUri, '?'));
282
-			}
283
-			$this->uri = trim($routeUri, $this->uriTrim);
284
-			return $this;
285
-	    }
286
-
287
-	     /**
288
-		 * Set the route segments informations
289
-		 * @param array $segements the route segments information
290
-		 * 
291
-		 * @return object
292
-		 */
293
-		public function setRouteSegments(array $segments = array()){
294
-			if(! empty($segments)){
295
-				$this->segments = $segments;
296
-			} else if (!empty($this->uri)) {
297
-				$this->segments = explode('/', $this->uri);
298
-			}
299
-			$segment = $this->segments;
300
-			$baseUrl = get_config('base_url');
301
-			//check if the app is not in DOCUMENT_ROOT
302
-			if(isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false){
303
-				array_shift($segment);
304
-				$this->segments = $segment;
305
-			}
306
-			$this->logger->debug('Check if the request URI contains the front controller');
307
-			if(isset($segment[0]) && $segment[0] == SELF){
308
-				$this->logger->info('The request URI contains the front controller');
309
-				array_shift($segment);
310
-				$this->segments = $segment;
311
-			}
312
-			return $this;
313
-		}
314
-
315
-		/**
316
-		 * Setting the route parameters like module, controller, method, argument
317
-		 * @return object the current instance
318
-		 */
319
-		public function determineRouteParamsInformation() {
320
-			$this->logger->debug('Routing process start ...');
140
+        /**
141
+         * Get the controller name
142
+         * @return string
143
+         */
144
+        public function getController(){
145
+            return $this->controller;
146
+        }
147
+
148
+        /**
149
+         * Get the controller file path
150
+         * @return string
151
+         */
152
+        public function getControllerPath(){
153
+            return $this->controllerPath;
154
+        }
155
+
156
+        /**
157
+         * Get the controller method
158
+         * @return string
159
+         */
160
+        public function getMethod(){
161
+            return $this->method;
162
+        }
163
+
164
+        /**
165
+         * Get the request arguments
166
+         * @return array
167
+         */
168
+        public function getArgs(){
169
+            return $this->args;
170
+        }
171
+
172
+        /**
173
+         * Get the URL segments array
174
+         * @return array
175
+         */
176
+        public function getSegments(){
177
+            return $this->segments;
178
+        }
179
+
180
+        /**
181
+         * Return the Log instance
182
+         * @return Log
183
+         */
184
+        public function getLogger(){
185
+            return $this->logger;
186
+        }
187
+
188
+        /**
189
+         * Set the log instance
190
+         * @param Log $logger the log object
191
+         * @return object
192
+         */
193
+        public function setLogger($logger){
194
+            $this->logger = $logger;
195
+            return $this;
196
+        }
197
+
198
+        /**
199
+         * Get the route URI
200
+         * @return string
201
+         */
202
+        public function getRouteUri(){
203
+            return $this->uri;
204
+        }
205
+
206
+        /**
207
+         * Add the URI and callback to the list of URIs to validate
208
+         *
209
+         * @param string $uri the request URI
210
+         * @param string $callback the callback function
211
+         *
212
+         * @return object the current instance
213
+         */
214
+        public function add($uri, $callback) {
215
+            $uri = trim($uri, $this->uriTrim);
216
+            if(in_array($uri, $this->pattern)){
217
+                $this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
218
+            }
219
+            $this->pattern[] = $uri;
220
+            $this->callback[] = $callback;
221
+            return $this;
222
+        }
223
+
224
+        /**
225
+         * Remove the route configuration
226
+         *
227
+         * @param string $uri the URI
228
+         *
229
+         * @return object the current instance
230
+         */
231
+        public function removeRoute($uri) {
232
+            $index  = array_search($uri, $this->pattern, true);
233
+            if($index !== false){
234
+                $this->logger->info('Remove route for uri [' . $uri . '] from the configuration');
235
+                unset($this->pattern[$index]);
236
+                unset($this->callback[$index]);
237
+            }
238
+            return $this;
239
+        }
240
+
241
+
242
+        /**
243
+         * Remove all the routes from the configuration
244
+         *
245
+         * @return object the current instance
246
+         */
247
+        public function removeAllRoute() {
248
+            $this->logger->info('Remove all routes from the configuration');
249
+            $this->pattern  = array();
250
+            $this->callback = array();
251
+            $this->routes = array();
252
+            return $this;
253
+        }
254
+
255
+
256
+        /**
257
+         * Set the route URI to use later
258
+         * @param string $uri the route URI, if is empty will determine automatically
259
+         * @return object
260
+         */
261
+        public function setRouteUri($uri = ''){
262
+            $routeUri = '';
263
+            if(! empty($uri)){
264
+                $routeUri = $uri;
265
+            }
266
+            //if the application is running in CLI mode use the first argument
267
+            else if(IS_CLI && isset($_SERVER['argv'][1])){
268
+                $routeUri = $_SERVER['argv'][1];
269
+            }
270
+            else if(isset($_SERVER['REQUEST_URI'])){
271
+                $routeUri = $_SERVER['REQUEST_URI'];
272
+            }
273
+            $this->logger->debug('Check if URL suffix is enabled in the configuration');
274
+            //remove url suffix from the request URI
275
+            $suffix = get_config('url_suffix');
276
+            if ($suffix) {
277
+                $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
278
+                $routeUri = str_ireplace($suffix, '', $routeUri);
279
+            } 
280
+            if (strpos($routeUri, '?') !== false){
281
+                $routeUri = substr($routeUri, 0, strpos($routeUri, '?'));
282
+            }
283
+            $this->uri = trim($routeUri, $this->uriTrim);
284
+            return $this;
285
+        }
286
+
287
+            /**
288
+             * Set the route segments informations
289
+             * @param array $segements the route segments information
290
+             * 
291
+             * @return object
292
+             */
293
+        public function setRouteSegments(array $segments = array()){
294
+            if(! empty($segments)){
295
+                $this->segments = $segments;
296
+            } else if (!empty($this->uri)) {
297
+                $this->segments = explode('/', $this->uri);
298
+            }
299
+            $segment = $this->segments;
300
+            $baseUrl = get_config('base_url');
301
+            //check if the app is not in DOCUMENT_ROOT
302
+            if(isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false){
303
+                array_shift($segment);
304
+                $this->segments = $segment;
305
+            }
306
+            $this->logger->debug('Check if the request URI contains the front controller');
307
+            if(isset($segment[0]) && $segment[0] == SELF){
308
+                $this->logger->info('The request URI contains the front controller');
309
+                array_shift($segment);
310
+                $this->segments = $segment;
311
+            }
312
+            return $this;
313
+        }
314
+
315
+        /**
316
+         * Setting the route parameters like module, controller, method, argument
317
+         * @return object the current instance
318
+         */
319
+        public function determineRouteParamsInformation() {
320
+            $this->logger->debug('Routing process start ...');
321 321
 			
322
-			//determine route parameters using the config
323
-			$this->determineRouteParamsFromConfig();
322
+            //determine route parameters using the config
323
+            $this->determineRouteParamsFromConfig();
324 324
 			
325
-			//if can not determine the module/controller/method via the defined routes configuration we will use
326
-			//the URL like http://domain.com/module/controller/method/arg1/arg2
327
-			if(! $this->controller){
328
-				$this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
329
-				//determine route parameters using the REQUEST_URI param
330
-				$this->determineRouteParamsFromRequestUri();
331
-			}
332
-			//Set the controller file path if not yet set
333
-			$this->setControllerFilePath();
334
-			$this->logger->debug('Routing process end.');
335
-
336
-			return $this;
337
-		}
325
+            //if can not determine the module/controller/method via the defined routes configuration we will use
326
+            //the URL like http://domain.com/module/controller/method/arg1/arg2
327
+            if(! $this->controller){
328
+                $this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
329
+                //determine route parameters using the REQUEST_URI param
330
+                $this->determineRouteParamsFromRequestUri();
331
+            }
332
+            //Set the controller file path if not yet set
333
+            $this->setControllerFilePath();
334
+            $this->logger->debug('Routing process end.');
335
+
336
+            return $this;
337
+        }
338 338
 	
339
-		 /**
340
-		 * Routing the request to the correspondant module/controller/method if exists
341
-		 * otherwise send 404 error.
342
-		 */
343
-	    public function processRequest(){
344
-	    	//Setting the route URI
345
-			$this->setRouteUri();
346
-
347
-			//setting route segments
348
-			$this->setRouteSegments();
349
-
350
-			$this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']' );
351
-
352
-	    	//determine the route parameters information
353
-	    	$this->determineRouteParamsInformation();
354
-
355
-	    	$e404 = false;
356
-	    	$classFilePath = $this->controllerPath;
357
-	    	$controller = ucfirst($this->controller);
358
-	    	$this->logger->info('The routing information are: module [' . $this->module . '], controller [' . $controller . '], method [' . $this->method . '], args [' . stringfy_vars($this->args) . ']');
359
-	    	$this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
339
+            /**
340
+             * Routing the request to the correspondant module/controller/method if exists
341
+             * otherwise send 404 error.
342
+             */
343
+        public function processRequest(){
344
+            //Setting the route URI
345
+            $this->setRouteUri();
346
+
347
+            //setting route segments
348
+            $this->setRouteSegments();
349
+
350
+            $this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']' );
351
+
352
+            //determine the route parameters information
353
+            $this->determineRouteParamsInformation();
354
+
355
+            $e404 = false;
356
+            $classFilePath = $this->controllerPath;
357
+            $controller = ucfirst($this->controller);
358
+            $this->logger->info('The routing information are: module [' . $this->module . '], controller [' . $controller . '], method [' . $this->method . '], args [' . stringfy_vars($this->args) . ']');
359
+            $this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
360 360
 	    	
361
-			if(file_exists($classFilePath)){
362
-				require_once $classFilePath;
363
-				if(! class_exists($controller, false)){
364
-					$e404 = true;
365
-					$this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
366
-				}
367
-				else{
368
-					$controllerInstance = new $controller();
369
-					$controllerMethod = $this->getMethod();
370
-					if(! method_exists($controllerInstance, $controllerMethod)){
371
-						$e404 = true;
372
-						$this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
373
-					}
374
-					else{
375
-						$this->logger->info('Routing data is set correctly now GO!');
376
-						call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
377
-						//render the final page to user
378
-						$this->logger->info('Render the final output to the browser');
379
-						get_instance()->response->renderFinalPage();
380
-					}
381
-				}
382
-			}
383
-			else{
384
-				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
385
-				$e404 = true;
386
-			}
387
-			if($e404){
388
-				if(IS_CLI){
389
-					set_http_status_header(404);
390
-					echo 'Error 404: page not found.';
391
-				} else {
392
-					$response =& class_loader('Response', 'classes');
393
-					$response->send404();
394
-				}
395
-			}
396
-	    }
397
-
398
-
399
-	    /**
400
-	    * Setting the route configuration using the configuration file and additional configuration from param
401
-	    * @param array $overwriteConfig the additional configuration to overwrite with the existing one
402
-	    * @param boolean $useConfigFile whether to use route configuration file
403
-		* @return object
404
-	    */
405
-	    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
406
-	        $route = array();
407
-	        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')){
408
-	            require_once CONFIG_PATH . 'routes.php';
409
-	        }
410
-	        $route = array_merge($route, $overwriteConfig);
411
-	        $this->routes = $route;
412
-	        //if route is empty remove all configuration
413
-	        if(empty($route)){
414
-	        	$this->removeAllRoute();
415
-	        }
416
-			return $this;
417
-	    }
418
-
419
-	     /**
420
-		 * Get the route configuration
421
-		 * @return array
422
-		 */
423
-		public function getRouteConfiguration(){
424
-			return $this->routes;
425
-		}
361
+            if(file_exists($classFilePath)){
362
+                require_once $classFilePath;
363
+                if(! class_exists($controller, false)){
364
+                    $e404 = true;
365
+                    $this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
366
+                }
367
+                else{
368
+                    $controllerInstance = new $controller();
369
+                    $controllerMethod = $this->getMethod();
370
+                    if(! method_exists($controllerInstance, $controllerMethod)){
371
+                        $e404 = true;
372
+                        $this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
373
+                    }
374
+                    else{
375
+                        $this->logger->info('Routing data is set correctly now GO!');
376
+                        call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
377
+                        //render the final page to user
378
+                        $this->logger->info('Render the final output to the browser');
379
+                        get_instance()->response->renderFinalPage();
380
+                    }
381
+                }
382
+            }
383
+            else{
384
+                $this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
385
+                $e404 = true;
386
+            }
387
+            if($e404){
388
+                if(IS_CLI){
389
+                    set_http_status_header(404);
390
+                    echo 'Error 404: page not found.';
391
+                } else {
392
+                    $response =& class_loader('Response', 'classes');
393
+                    $response->send404();
394
+                }
395
+            }
396
+        }
397
+
398
+
399
+        /**
400
+         * Setting the route configuration using the configuration file and additional configuration from param
401
+         * @param array $overwriteConfig the additional configuration to overwrite with the existing one
402
+         * @param boolean $useConfigFile whether to use route configuration file
403
+         * @return object
404
+         */
405
+        public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
406
+            $route = array();
407
+            if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')){
408
+                require_once CONFIG_PATH . 'routes.php';
409
+            }
410
+            $route = array_merge($route, $overwriteConfig);
411
+            $this->routes = $route;
412
+            //if route is empty remove all configuration
413
+            if(empty($route)){
414
+                $this->removeAllRoute();
415
+            }
416
+            return $this;
417
+        }
418
+
419
+            /**
420
+             * Get the route configuration
421
+             * @return array
422
+             */
423
+        public function getRouteConfiguration(){
424
+            return $this->routes;
425
+        }
426 426
 
427 427
 	    
428
-	    /**
429
-	     * Set the controller file path if is not set
430
-	     * @param string $path the file path if is null will using the route 
431
-	     * information
432
-	     *
433
-	     * @return object the current instance
434
-	     */
435
-	    public function setControllerFilePath($path = null){
436
-	    	if($path !== null){
437
-	    		$this->controllerPath = $path;
438
-	    		return $this;
439
-	    	}
440
-	    	//did we set the controller, so set the controller path
441
-			if($this->controller && ! $this->controllerPath){
442
-				$this->logger->debug('Setting the file path for the controller [' . $this->controller . ']');
443
-				$controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->controller) . '.php';
444
-				//if the controller is in module
445
-				if($this->module){
446
-					$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
447
-					if($path !== false){
448
-						$controllerPath = $path;
449
-					}
450
-				}
451
-				$this->controllerPath = $controllerPath;
452
-			}
453
-			return $this;
454
-	    }
455
-
456
-	    /**
457
-	     * Determine the route parameters from route configuration
458
-	     * @return void
459
-	     */
460
-	    protected function determineRouteParamsFromConfig(){
461
-	    	$uri = implode('/', $this->segments);
462
-	    	/*
428
+        /**
429
+         * Set the controller file path if is not set
430
+         * @param string $path the file path if is null will using the route 
431
+         * information
432
+         *
433
+         * @return object the current instance
434
+         */
435
+        public function setControllerFilePath($path = null){
436
+            if($path !== null){
437
+                $this->controllerPath = $path;
438
+                return $this;
439
+            }
440
+            //did we set the controller, so set the controller path
441
+            if($this->controller && ! $this->controllerPath){
442
+                $this->logger->debug('Setting the file path for the controller [' . $this->controller . ']');
443
+                $controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->controller) . '.php';
444
+                //if the controller is in module
445
+                if($this->module){
446
+                    $path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
447
+                    if($path !== false){
448
+                        $controllerPath = $path;
449
+                    }
450
+                }
451
+                $this->controllerPath = $controllerPath;
452
+            }
453
+            return $this;
454
+        }
455
+
456
+        /**
457
+         * Determine the route parameters from route configuration
458
+         * @return void
459
+         */
460
+        protected function determineRouteParamsFromConfig(){
461
+            $uri = implode('/', $this->segments);
462
+            /*
463 463
 	   		* Generics routes patterns
464 464
 	    	*/
465
-			$pattern = array(':num', ':alpha', ':alnum', ':any');
466
-			$replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*');
467
-
468
-			$this->logger->debug(
469
-									'Begin to loop in the predefined routes configuration ' 
470
-									. 'to check if the current request match'
471
-									);
472
-
473
-			// Cycle through the URIs stored in the array
474
-			foreach ($this->pattern as $index => $uriList) {
475
-				$uriList = str_ireplace($pattern, $replace, $uriList);
476
-				// Check for an existant matching URI
477
-				if (preg_match("#^$uriList$#", $uri, $args)) {
478
-					$this->logger->info(
479
-										'Route found for request URI [' . $uri . '] using the predefined configuration '
480
-										. ' [' . $this->pattern[$index] . '] --> [' . $this->callback[$index] . ']'
481
-									);
482
-					array_shift($args);
483
-					//check if this contains an module
484
-					$moduleControllerMethod = explode('#', $this->callback[$index]);
485
-					if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
486
-						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
487
-						$this->module = $moduleControllerMethod[0];
488
-						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
489
-					}
490
-					else{
491
-						$this->logger->info('The current request does not use the module');
492
-						$moduleControllerMethod = explode('@', $this->callback[$index]);
493
-					}
494
-					if(is_array($moduleControllerMethod)){
495
-						if(isset($moduleControllerMethod[0])){
496
-							$this->controller = $moduleControllerMethod[0];	
497
-						}
498
-						if(isset($moduleControllerMethod[1])){
499
-							$this->method = $moduleControllerMethod[1];
500
-						}
501
-						$this->args = $args;
502
-					}
503
-					// stop here
504
-					break;
505
-				}
506
-			}
507
-
508
-			//first if the controller is not set and the module is set use the module name as the controller
509
-			if(! $this->controller && $this->module){
510
-				$this->logger->info(
511
-									'After loop in predefined routes configuration, 
465
+            $pattern = array(':num', ':alpha', ':alnum', ':any');
466
+            $replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*');
467
+
468
+            $this->logger->debug(
469
+                                    'Begin to loop in the predefined routes configuration ' 
470
+                                    . 'to check if the current request match'
471
+                                    );
472
+
473
+            // Cycle through the URIs stored in the array
474
+            foreach ($this->pattern as $index => $uriList) {
475
+                $uriList = str_ireplace($pattern, $replace, $uriList);
476
+                // Check for an existant matching URI
477
+                if (preg_match("#^$uriList$#", $uri, $args)) {
478
+                    $this->logger->info(
479
+                                        'Route found for request URI [' . $uri . '] using the predefined configuration '
480
+                                        . ' [' . $this->pattern[$index] . '] --> [' . $this->callback[$index] . ']'
481
+                                    );
482
+                    array_shift($args);
483
+                    //check if this contains an module
484
+                    $moduleControllerMethod = explode('#', $this->callback[$index]);
485
+                    if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
486
+                        $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
487
+                        $this->module = $moduleControllerMethod[0];
488
+                        $moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
489
+                    }
490
+                    else{
491
+                        $this->logger->info('The current request does not use the module');
492
+                        $moduleControllerMethod = explode('@', $this->callback[$index]);
493
+                    }
494
+                    if(is_array($moduleControllerMethod)){
495
+                        if(isset($moduleControllerMethod[0])){
496
+                            $this->controller = $moduleControllerMethod[0];	
497
+                        }
498
+                        if(isset($moduleControllerMethod[1])){
499
+                            $this->method = $moduleControllerMethod[1];
500
+                        }
501
+                        $this->args = $args;
502
+                    }
503
+                    // stop here
504
+                    break;
505
+                }
506
+            }
507
+
508
+            //first if the controller is not set and the module is set use the module name as the controller
509
+            if(! $this->controller && $this->module){
510
+                $this->logger->info(
511
+                                    'After loop in predefined routes configuration, 
512 512
 									the module name is set but the controller is not set, 
513 513
 									so we will use module as the controller'
514
-								);
515
-				$this->controller = $this->module;
516
-			}
517
-	    }
518
-
519
-	    /**
520
-	     * Determine the route parameters using the server variable "REQUEST_URI"
521
-	     * @return void
522
-	     */
523
-	    protected function determineRouteParamsFromRequestUri(){
524
-	    	$segment = $this->segments;
525
-	    	$nbSegment = count($segment);
526
-			//if segment is null so means no need to perform
527
-			if($nbSegment > 0){
528
-				//get the module list
529
-				$modules = Module::getModuleList();
530
-				//first check if no module
531
-				if(empty($modules)){
532
-					$this->logger->info('No module was loaded will skip the module checking');
533
-					//the application don't use module
534
-					//controller
535
-					if(isset($segment[0])){
536
-						$this->controller = $segment[0];
537
-						array_shift($segment);
538
-					}
539
-					//method
540
-					if(isset($segment[0])){
541
-						$this->method = $segment[0];
542
-						array_shift($segment);
543
-					}
544
-					//args
545
-					$this->args = $segment;
546
-				}
547
-				else{
548
-					$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
549
-					if(in_array($segment[0], $modules)){
550
-						$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
551
-						$this->module = $segment[0];
552
-						array_shift($segment);
553
-						//check if the second arg is the controller from module
554
-						if(isset($segment[0])){
555
-							$this->controller = $segment[0];
556
-							//check if the request use the same module name and controller
557
-							$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
558
-							if(! $path){
559
-								$this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
560
-								$this->controller = $this->module;
561
-							}
562
-							else{
563
-								$this->controllerPath = $path;
564
-								array_shift($segment);
565
-							}
566
-						}
567
-						//check for method
568
-						if(isset($segment[0])){
569
-							$this->method = $segment[0];
570
-							array_shift($segment);
571
-						}
572
-						//the remaining is for args
573
-						$this->args = $segment;
574
-					}
575
-					else{
576
-						$this->logger->info('The current request information is not found in the module list');
577
-						//controller
578
-						if(isset($segment[0])){
579
-							$this->controller = $segment[0];
580
-							array_shift($segment);
581
-						}
582
-						//method
583
-						if(isset($segment[0])){
584
-							$this->method = $segment[0];
585
-							array_shift($segment);
586
-						}
587
-						//args
588
-						$this->args = $segment;
589
-					}
590
-				}
591
-				if(! $this->controller && $this->module){
592
-					$this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
593
-					$this->controller = $this->module;
594
-				}
595
-			}
596
-	    }
597
-
598
-	    /**
599
-	     * Set the route informations using the configuration
600
-	     *
601
-	     * @return object the current instance
602
-	     */
603
-	    protected function setRouteConfigurationInfos(){
604
-	    	//adding route
605
-			foreach($this->routes as $pattern => $callback){
606
-				$this->add($pattern, $callback);
607
-			}
608
-			return $this;
609
-		}
610
-
611
-		/**
612
-	     * Set the Log instance using argument or create new instance
613
-	     * @param object $logger the Log instance if not null
614
-	     */
615
-	    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
616
-	      if ($logger !== null){
617
-	        $this->logger = $logger;
618
-	      }
619
-	      else{
620
-	          $this->logger =& class_loader('Log', 'classes');
621
-	          $this->logger->setLogger('Library::Router');
622
-	      }
623
-	    }
624
-	}
514
+                                );
515
+                $this->controller = $this->module;
516
+            }
517
+        }
518
+
519
+        /**
520
+         * Determine the route parameters using the server variable "REQUEST_URI"
521
+         * @return void
522
+         */
523
+        protected function determineRouteParamsFromRequestUri(){
524
+            $segment = $this->segments;
525
+            $nbSegment = count($segment);
526
+            //if segment is null so means no need to perform
527
+            if($nbSegment > 0){
528
+                //get the module list
529
+                $modules = Module::getModuleList();
530
+                //first check if no module
531
+                if(empty($modules)){
532
+                    $this->logger->info('No module was loaded will skip the module checking');
533
+                    //the application don't use module
534
+                    //controller
535
+                    if(isset($segment[0])){
536
+                        $this->controller = $segment[0];
537
+                        array_shift($segment);
538
+                    }
539
+                    //method
540
+                    if(isset($segment[0])){
541
+                        $this->method = $segment[0];
542
+                        array_shift($segment);
543
+                    }
544
+                    //args
545
+                    $this->args = $segment;
546
+                }
547
+                else{
548
+                    $this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
549
+                    if(in_array($segment[0], $modules)){
550
+                        $this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
551
+                        $this->module = $segment[0];
552
+                        array_shift($segment);
553
+                        //check if the second arg is the controller from module
554
+                        if(isset($segment[0])){
555
+                            $this->controller = $segment[0];
556
+                            //check if the request use the same module name and controller
557
+                            $path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
558
+                            if(! $path){
559
+                                $this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
560
+                                $this->controller = $this->module;
561
+                            }
562
+                            else{
563
+                                $this->controllerPath = $path;
564
+                                array_shift($segment);
565
+                            }
566
+                        }
567
+                        //check for method
568
+                        if(isset($segment[0])){
569
+                            $this->method = $segment[0];
570
+                            array_shift($segment);
571
+                        }
572
+                        //the remaining is for args
573
+                        $this->args = $segment;
574
+                    }
575
+                    else{
576
+                        $this->logger->info('The current request information is not found in the module list');
577
+                        //controller
578
+                        if(isset($segment[0])){
579
+                            $this->controller = $segment[0];
580
+                            array_shift($segment);
581
+                        }
582
+                        //method
583
+                        if(isset($segment[0])){
584
+                            $this->method = $segment[0];
585
+                            array_shift($segment);
586
+                        }
587
+                        //args
588
+                        $this->args = $segment;
589
+                    }
590
+                }
591
+                if(! $this->controller && $this->module){
592
+                    $this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
593
+                    $this->controller = $this->module;
594
+                }
595
+            }
596
+        }
597
+
598
+        /**
599
+         * Set the route informations using the configuration
600
+         *
601
+         * @return object the current instance
602
+         */
603
+        protected function setRouteConfigurationInfos(){
604
+            //adding route
605
+            foreach($this->routes as $pattern => $callback){
606
+                $this->add($pattern, $callback);
607
+            }
608
+            return $this;
609
+        }
610
+
611
+        /**
612
+         * Set the Log instance using argument or create new instance
613
+         * @param object $logger the Log instance if not null
614
+         */
615
+        protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
616
+            if ($logger !== null){
617
+            $this->logger = $logger;
618
+            }
619
+            else{
620
+                $this->logger =& class_loader('Log', 'classes');
621
+                $this->logger->setLogger('Library::Router');
622
+            }
623
+        }
624
+    }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
 		/**
97 97
 		 * Construct the new Router instance
98 98
 		 */
99
-		public function __construct(){
99
+		public function __construct() {
100 100
 			$this->setLoggerFromParamOrCreateNewInstance(null);
101 101
 			
102 102
 			//loading routes for module
103 103
 			$moduleRouteList = array();
104 104
 			$modulesRoutes = Module::getModulesRoutes();
105
-			if($modulesRoutes && is_array($modulesRoutes)){
105
+			if ($modulesRoutes && is_array($modulesRoutes)) {
106 106
 				$moduleRouteList = $modulesRoutes;
107 107
 				unset($modulesRoutes);
108 108
 			}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * Get the route patterns
118 118
 		 * @return array
119 119
 		 */
120
-		public function getPattern(){
120
+		public function getPattern() {
121 121
 			return $this->pattern;
122 122
 		}
123 123
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		 * Get the route callbacks
126 126
 		 * @return array
127 127
 		 */
128
-		public function getCallback(){
128
+		public function getCallback() {
129 129
 			return $this->callback;
130 130
 		}
131 131
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		 * Get the module name
134 134
 		 * @return string
135 135
 		 */
136
-		public function getModule(){
136
+		public function getModule() {
137 137
 			return $this->module;
138 138
 		}
139 139
 		
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 		 * Get the controller name
142 142
 		 * @return string
143 143
 		 */
144
-		public function getController(){
144
+		public function getController() {
145 145
 			return $this->controller;
146 146
 		}
147 147
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		 * Get the controller file path
150 150
 		 * @return string
151 151
 		 */
152
-		public function getControllerPath(){
152
+		public function getControllerPath() {
153 153
 			return $this->controllerPath;
154 154
 		}
155 155
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		 * Get the controller method
158 158
 		 * @return string
159 159
 		 */
160
-		public function getMethod(){
160
+		public function getMethod() {
161 161
 			return $this->method;
162 162
 		}
163 163
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		 * Get the request arguments
166 166
 		 * @return array
167 167
 		 */
168
-		public function getArgs(){
168
+		public function getArgs() {
169 169
 			return $this->args;
170 170
 		}
171 171
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		 * Get the URL segments array
174 174
 		 * @return array
175 175
 		 */
176
-		public function getSegments(){
176
+		public function getSegments() {
177 177
 			return $this->segments;
178 178
 		}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	     * Return the Log instance
182 182
 	     * @return Log
183 183
 	     */
184
-	    public function getLogger(){
184
+	    public function getLogger() {
185 185
 	      return $this->logger;
186 186
 	    }
187 187
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	     * @param Log $logger the log object
191 191
 		 * @return object
192 192
 	     */
193
-	    public function setLogger($logger){
193
+	    public function setLogger($logger) {
194 194
 	      $this->logger = $logger;
195 195
 	      return $this;
196 196
 	    }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		 * Get the route URI
200 200
 		 * @return string
201 201
 		 */
202
-		public function getRouteUri(){
202
+		public function getRouteUri() {
203 203
 			return $this->uri;
204 204
 		}
205 205
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		*/
214 214
 		public function add($uri, $callback) {
215 215
 			$uri = trim($uri, $this->uriTrim);
216
-			if(in_array($uri, $this->pattern)){
216
+			if (in_array($uri, $this->pattern)) {
217 217
 				$this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
218 218
 			}
219 219
 			$this->pattern[] = $uri;
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 		* @return object the current instance
230 230
 		*/
231 231
 		public function removeRoute($uri) {
232
-			$index  = array_search($uri, $this->pattern, true);
233
-			if($index !== false){
232
+			$index = array_search($uri, $this->pattern, true);
233
+			if ($index !== false) {
234 234
 				$this->logger->info('Remove route for uri [' . $uri . '] from the configuration');
235 235
 				unset($this->pattern[$index]);
236 236
 				unset($this->callback[$index]);
@@ -258,26 +258,26 @@  discard block
 block discarded – undo
258 258
 	     * @param string $uri the route URI, if is empty will determine automatically
259 259
 	     * @return object
260 260
 	     */
261
-	    public function setRouteUri($uri = ''){
261
+	    public function setRouteUri($uri = '') {
262 262
 	    	$routeUri = '';
263
-	    	if(! empty($uri)){
263
+	    	if (!empty($uri)) {
264 264
 	    		$routeUri = $uri;
265 265
 	    	}
266 266
 	    	//if the application is running in CLI mode use the first argument
267
-			else if(IS_CLI && isset($_SERVER['argv'][1])){
267
+			else if (IS_CLI && isset($_SERVER['argv'][1])) {
268 268
 				$routeUri = $_SERVER['argv'][1];
269 269
 			}
270
-			else if(isset($_SERVER['REQUEST_URI'])){
270
+			else if (isset($_SERVER['REQUEST_URI'])) {
271 271
 				$routeUri = $_SERVER['REQUEST_URI'];
272 272
 			}
273 273
 			$this->logger->debug('Check if URL suffix is enabled in the configuration');
274 274
 			//remove url suffix from the request URI
275 275
 			$suffix = get_config('url_suffix');
276 276
 			if ($suffix) {
277
-				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
277
+				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']');
278 278
 				$routeUri = str_ireplace($suffix, '', $routeUri);
279 279
 			} 
280
-			if (strpos($routeUri, '?') !== false){
280
+			if (strpos($routeUri, '?') !== false) {
281 281
 				$routeUri = substr($routeUri, 0, strpos($routeUri, '?'));
282 282
 			}
283 283
 			$this->uri = trim($routeUri, $this->uriTrim);
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 		 * 
291 291
 		 * @return object
292 292
 		 */
293
-		public function setRouteSegments(array $segments = array()){
294
-			if(! empty($segments)){
293
+		public function setRouteSegments(array $segments = array()) {
294
+			if (!empty($segments)) {
295 295
 				$this->segments = $segments;
296 296
 			} else if (!empty($this->uri)) {
297 297
 				$this->segments = explode('/', $this->uri);
@@ -299,12 +299,12 @@  discard block
 block discarded – undo
299 299
 			$segment = $this->segments;
300 300
 			$baseUrl = get_config('base_url');
301 301
 			//check if the app is not in DOCUMENT_ROOT
302
-			if(isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false){
302
+			if (isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false) {
303 303
 				array_shift($segment);
304 304
 				$this->segments = $segment;
305 305
 			}
306 306
 			$this->logger->debug('Check if the request URI contains the front controller');
307
-			if(isset($segment[0]) && $segment[0] == SELF){
307
+			if (isset($segment[0]) && $segment[0] == SELF) {
308 308
 				$this->logger->info('The request URI contains the front controller');
309 309
 				array_shift($segment);
310 310
 				$this->segments = $segment;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 			
325 325
 			//if can not determine the module/controller/method via the defined routes configuration we will use
326 326
 			//the URL like http://domain.com/module/controller/method/arg1/arg2
327
-			if(! $this->controller){
327
+			if (!$this->controller) {
328 328
 				$this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
329 329
 				//determine route parameters using the REQUEST_URI param
330 330
 				$this->determineRouteParamsFromRequestUri();
@@ -340,14 +340,14 @@  discard block
 block discarded – undo
340 340
 		 * Routing the request to the correspondant module/controller/method if exists
341 341
 		 * otherwise send 404 error.
342 342
 		 */
343
-	    public function processRequest(){
343
+	    public function processRequest() {
344 344
 	    	//Setting the route URI
345 345
 			$this->setRouteUri();
346 346
 
347 347
 			//setting route segments
348 348
 			$this->setRouteSegments();
349 349
 
350
-			$this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']' );
350
+			$this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']');
351 351
 
352 352
 	    	//determine the route parameters information
353 353
 	    	$this->determineRouteParamsInformation();
@@ -358,20 +358,20 @@  discard block
 block discarded – undo
358 358
 	    	$this->logger->info('The routing information are: module [' . $this->module . '], controller [' . $controller . '], method [' . $this->method . '], args [' . stringfy_vars($this->args) . ']');
359 359
 	    	$this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
360 360
 	    	
361
-			if(file_exists($classFilePath)){
361
+			if (file_exists($classFilePath)) {
362 362
 				require_once $classFilePath;
363
-				if(! class_exists($controller, false)){
363
+				if (!class_exists($controller, false)) {
364 364
 					$e404 = true;
365
-					$this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
365
+					$this->logger->warning('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']');
366 366
 				}
367
-				else{
367
+				else {
368 368
 					$controllerInstance = new $controller();
369 369
 					$controllerMethod = $this->getMethod();
370
-					if(! method_exists($controllerInstance, $controllerMethod)){
370
+					if (!method_exists($controllerInstance, $controllerMethod)) {
371 371
 						$e404 = true;
372 372
 						$this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
373 373
 					}
374
-					else{
374
+					else {
375 375
 						$this->logger->info('Routing data is set correctly now GO!');
376 376
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
377 377
 						//render the final page to user
@@ -380,16 +380,16 @@  discard block
 block discarded – undo
380 380
 					}
381 381
 				}
382 382
 			}
383
-			else{
383
+			else {
384 384
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
385 385
 				$e404 = true;
386 386
 			}
387
-			if($e404){
388
-				if(IS_CLI){
387
+			if ($e404) {
388
+				if (IS_CLI) {
389 389
 					set_http_status_header(404);
390 390
 					echo 'Error 404: page not found.';
391 391
 				} else {
392
-					$response =& class_loader('Response', 'classes');
392
+					$response = & class_loader('Response', 'classes');
393 393
 					$response->send404();
394 394
 				}
395 395
 			}
@@ -402,15 +402,15 @@  discard block
 block discarded – undo
402 402
 	    * @param boolean $useConfigFile whether to use route configuration file
403 403
 		* @return object
404 404
 	    */
405
-	    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
405
+	    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true) {
406 406
 	        $route = array();
407
-	        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')){
407
+	        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')) {
408 408
 	            require_once CONFIG_PATH . 'routes.php';
409 409
 	        }
410 410
 	        $route = array_merge($route, $overwriteConfig);
411 411
 	        $this->routes = $route;
412 412
 	        //if route is empty remove all configuration
413
-	        if(empty($route)){
413
+	        if (empty($route)) {
414 414
 	        	$this->removeAllRoute();
415 415
 	        }
416 416
 			return $this;
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 		 * Get the route configuration
421 421
 		 * @return array
422 422
 		 */
423
-		public function getRouteConfiguration(){
423
+		public function getRouteConfiguration() {
424 424
 			return $this->routes;
425 425
 		}
426 426
 
@@ -432,19 +432,19 @@  discard block
 block discarded – undo
432 432
 	     *
433 433
 	     * @return object the current instance
434 434
 	     */
435
-	    public function setControllerFilePath($path = null){
436
-	    	if($path !== null){
435
+	    public function setControllerFilePath($path = null) {
436
+	    	if ($path !== null) {
437 437
 	    		$this->controllerPath = $path;
438 438
 	    		return $this;
439 439
 	    	}
440 440
 	    	//did we set the controller, so set the controller path
441
-			if($this->controller && ! $this->controllerPath){
441
+			if ($this->controller && !$this->controllerPath) {
442 442
 				$this->logger->debug('Setting the file path for the controller [' . $this->controller . ']');
443 443
 				$controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->controller) . '.php';
444 444
 				//if the controller is in module
445
-				if($this->module){
445
+				if ($this->module) {
446 446
 					$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
447
-					if($path !== false){
447
+					if ($path !== false) {
448 448
 						$controllerPath = $path;
449 449
 					}
450 450
 				}
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	     * Determine the route parameters from route configuration
458 458
 	     * @return void
459 459
 	     */
460
-	    protected function determineRouteParamsFromConfig(){
460
+	    protected function determineRouteParamsFromConfig() {
461 461
 	    	$uri = implode('/', $this->segments);
462 462
 	    	/*
463 463
 	   		* Generics routes patterns
@@ -482,20 +482,20 @@  discard block
 block discarded – undo
482 482
 					array_shift($args);
483 483
 					//check if this contains an module
484 484
 					$moduleControllerMethod = explode('#', $this->callback[$index]);
485
-					if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
485
+					if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) {
486 486
 						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
487 487
 						$this->module = $moduleControllerMethod[0];
488 488
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
489 489
 					}
490
-					else{
490
+					else {
491 491
 						$this->logger->info('The current request does not use the module');
492 492
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
493 493
 					}
494
-					if(is_array($moduleControllerMethod)){
495
-						if(isset($moduleControllerMethod[0])){
494
+					if (is_array($moduleControllerMethod)) {
495
+						if (isset($moduleControllerMethod[0])) {
496 496
 							$this->controller = $moduleControllerMethod[0];	
497 497
 						}
498
-						if(isset($moduleControllerMethod[1])){
498
+						if (isset($moduleControllerMethod[1])) {
499 499
 							$this->method = $moduleControllerMethod[1];
500 500
 						}
501 501
 						$this->args = $args;
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 			}
507 507
 
508 508
 			//first if the controller is not set and the module is set use the module name as the controller
509
-			if(! $this->controller && $this->module){
509
+			if (!$this->controller && $this->module) {
510 510
 				$this->logger->info(
511 511
 									'After loop in predefined routes configuration, 
512 512
 									the module name is set but the controller is not set, 
@@ -520,67 +520,67 @@  discard block
 block discarded – undo
520 520
 	     * Determine the route parameters using the server variable "REQUEST_URI"
521 521
 	     * @return void
522 522
 	     */
523
-	    protected function determineRouteParamsFromRequestUri(){
523
+	    protected function determineRouteParamsFromRequestUri() {
524 524
 	    	$segment = $this->segments;
525 525
 	    	$nbSegment = count($segment);
526 526
 			//if segment is null so means no need to perform
527
-			if($nbSegment > 0){
527
+			if ($nbSegment > 0) {
528 528
 				//get the module list
529 529
 				$modules = Module::getModuleList();
530 530
 				//first check if no module
531
-				if(empty($modules)){
531
+				if (empty($modules)) {
532 532
 					$this->logger->info('No module was loaded will skip the module checking');
533 533
 					//the application don't use module
534 534
 					//controller
535
-					if(isset($segment[0])){
535
+					if (isset($segment[0])) {
536 536
 						$this->controller = $segment[0];
537 537
 						array_shift($segment);
538 538
 					}
539 539
 					//method
540
-					if(isset($segment[0])){
540
+					if (isset($segment[0])) {
541 541
 						$this->method = $segment[0];
542 542
 						array_shift($segment);
543 543
 					}
544 544
 					//args
545 545
 					$this->args = $segment;
546 546
 				}
547
-				else{
547
+				else {
548 548
 					$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
549
-					if(in_array($segment[0], $modules)){
549
+					if (in_array($segment[0], $modules)) {
550 550
 						$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
551 551
 						$this->module = $segment[0];
552 552
 						array_shift($segment);
553 553
 						//check if the second arg is the controller from module
554
-						if(isset($segment[0])){
554
+						if (isset($segment[0])) {
555 555
 							$this->controller = $segment[0];
556 556
 							//check if the request use the same module name and controller
557 557
 							$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
558
-							if(! $path){
558
+							if (!$path) {
559 559
 								$this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
560 560
 								$this->controller = $this->module;
561 561
 							}
562
-							else{
562
+							else {
563 563
 								$this->controllerPath = $path;
564 564
 								array_shift($segment);
565 565
 							}
566 566
 						}
567 567
 						//check for method
568
-						if(isset($segment[0])){
568
+						if (isset($segment[0])) {
569 569
 							$this->method = $segment[0];
570 570
 							array_shift($segment);
571 571
 						}
572 572
 						//the remaining is for args
573 573
 						$this->args = $segment;
574 574
 					}
575
-					else{
575
+					else {
576 576
 						$this->logger->info('The current request information is not found in the module list');
577 577
 						//controller
578
-						if(isset($segment[0])){
578
+						if (isset($segment[0])) {
579 579
 							$this->controller = $segment[0];
580 580
 							array_shift($segment);
581 581
 						}
582 582
 						//method
583
-						if(isset($segment[0])){
583
+						if (isset($segment[0])) {
584 584
 							$this->method = $segment[0];
585 585
 							array_shift($segment);
586 586
 						}
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 						$this->args = $segment;
589 589
 					}
590 590
 				}
591
-				if(! $this->controller && $this->module){
591
+				if (!$this->controller && $this->module) {
592 592
 					$this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
593 593
 					$this->controller = $this->module;
594 594
 				}
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
 	     *
601 601
 	     * @return object the current instance
602 602
 	     */
603
-	    protected function setRouteConfigurationInfos(){
603
+	    protected function setRouteConfigurationInfos() {
604 604
 	    	//adding route
605
-			foreach($this->routes as $pattern => $callback){
605
+			foreach ($this->routes as $pattern => $callback) {
606 606
 				$this->add($pattern, $callback);
607 607
 			}
608 608
 			return $this;
@@ -612,12 +612,12 @@  discard block
 block discarded – undo
612 612
 	     * Set the Log instance using argument or create new instance
613 613
 	     * @param object $logger the Log instance if not null
614 614
 	     */
615
-	    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
616
-	      if ($logger !== null){
615
+	    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
616
+	      if ($logger !== null) {
617 617
 	        $this->logger = $logger;
618 618
 	      }
619
-	      else{
620
-	          $this->logger =& class_loader('Log', 'classes');
619
+	      else {
620
+	          $this->logger = & class_loader('Log', 'classes');
621 621
 	          $this->logger->setLogger('Library::Router');
622 622
 	      }
623 623
 	    }
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -266,8 +266,7 @@  discard block
 block discarded – undo
266 266
 	    	//if the application is running in CLI mode use the first argument
267 267
 			else if(IS_CLI && isset($_SERVER['argv'][1])){
268 268
 				$routeUri = $_SERVER['argv'][1];
269
-			}
270
-			else if(isset($_SERVER['REQUEST_URI'])){
269
+			} else if(isset($_SERVER['REQUEST_URI'])){
271 270
 				$routeUri = $_SERVER['REQUEST_URI'];
272 271
 			}
273 272
 			$this->logger->debug('Check if URL suffix is enabled in the configuration');
@@ -363,15 +362,13 @@  discard block
 block discarded – undo
363 362
 				if(! class_exists($controller, false)){
364 363
 					$e404 = true;
365 364
 					$this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
366
-				}
367
-				else{
365
+				} else{
368 366
 					$controllerInstance = new $controller();
369 367
 					$controllerMethod = $this->getMethod();
370 368
 					if(! method_exists($controllerInstance, $controllerMethod)){
371 369
 						$e404 = true;
372 370
 						$this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
373
-					}
374
-					else{
371
+					} else{
375 372
 						$this->logger->info('Routing data is set correctly now GO!');
376 373
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
377 374
 						//render the final page to user
@@ -379,8 +376,7 @@  discard block
 block discarded – undo
379 376
 						get_instance()->response->renderFinalPage();
380 377
 					}
381 378
 				}
382
-			}
383
-			else{
379
+			} else{
384 380
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
385 381
 				$e404 = true;
386 382
 			}
@@ -486,8 +482,7 @@  discard block
 block discarded – undo
486 482
 						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
487 483
 						$this->module = $moduleControllerMethod[0];
488 484
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
489
-					}
490
-					else{
485
+					} else{
491 486
 						$this->logger->info('The current request does not use the module');
492 487
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
493 488
 					}
@@ -543,8 +538,7 @@  discard block
 block discarded – undo
543 538
 					}
544 539
 					//args
545 540
 					$this->args = $segment;
546
-				}
547
-				else{
541
+				} else{
548 542
 					$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
549 543
 					if(in_array($segment[0], $modules)){
550 544
 						$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
@@ -558,8 +552,7 @@  discard block
 block discarded – undo
558 552
 							if(! $path){
559 553
 								$this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
560 554
 								$this->controller = $this->module;
561
-							}
562
-							else{
555
+							} else{
563 556
 								$this->controllerPath = $path;
564 557
 								array_shift($segment);
565 558
 							}
@@ -571,8 +564,7 @@  discard block
 block discarded – undo
571 564
 						}
572 565
 						//the remaining is for args
573 566
 						$this->args = $segment;
574
-					}
575
-					else{
567
+					} else{
576 568
 						$this->logger->info('The current request information is not found in the module list');
577 569
 						//controller
578 570
 						if(isset($segment[0])){
@@ -615,8 +607,7 @@  discard block
 block discarded – undo
615 607
 	    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
616 608
 	      if ($logger !== null){
617 609
 	        $this->logger = $logger;
618
-	      }
619
-	      else{
610
+	      } else{
620 611
 	          $this->logger =& class_loader('Log', 'classes');
621 612
 	          $this->logger->setLogger('Library::Router');
622 613
 	      }
Please login to merge, or discard this patch.
core/classes/Security.php 3 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -1,157 +1,157 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Security{
27
+    class Security{
28 28
 		
29
-		/**
30
-		 * The logger instance
31
-		 * @var Log
32
-		 */
33
-		private static $logger;
29
+        /**
30
+         * The logger instance
31
+         * @var Log
32
+         */
33
+        private static $logger;
34 34
 
35
-		/**
36
-		 * Get the logger singleton instance
37
-		 * @return Log the logger instance
38
-		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
42
-				self::$logger[0]->setLogger('Library::Security');
43
-			}
44
-			return self::$logger[0];
45
-		}
35
+        /**
36
+         * Get the logger singleton instance
37
+         * @return Log the logger instance
38
+         */
39
+        private static function getLogger(){
40
+            if(self::$logger == null){
41
+                self::$logger[0] =& class_loader('Log', 'classes');
42
+                self::$logger[0]->setLogger('Library::Security');
43
+            }
44
+            return self::$logger[0];
45
+        }
46 46
 
47 47
 
48
-		/**
49
-		 * This method is used to generate the CSRF token
50
-		 * @return string the generated CSRF token
51
-		 */
52
-		public static function generateCSRF(){
53
-			$logger = self::getLogger();
54
-			$logger->debug('Generation of CSRF ...');
48
+        /**
49
+         * This method is used to generate the CSRF token
50
+         * @return string the generated CSRF token
51
+         */
52
+        public static function generateCSRF(){
53
+            $logger = self::getLogger();
54
+            $logger->debug('Generation of CSRF ...');
55 55
 			
56
-			$key = get_config('csrf_key', 'csrf_key');
57
-			$expire = get_config('csrf_expire', 60);
58
-			$keyExpire = 'csrf_expire';
59
-			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
61
-				$logger->info('The CSRF token not yet expire just return it');
62
-				return Session::get($key);
63
-			}
64
-			else{
65
-				$newTime = $currentTime + $expire;
66
-				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
68
-				Session::set($keyExpire, $newTime);
69
-				Session::set($key, $token);
70
-				return Session::get($key);
71
-			}
72
-		}
56
+            $key = get_config('csrf_key', 'csrf_key');
57
+            $expire = get_config('csrf_expire', 60);
58
+            $keyExpire = 'csrf_expire';
59
+            $currentTime = time();
60
+            if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
61
+                $logger->info('The CSRF token not yet expire just return it');
62
+                return Session::get($key);
63
+            }
64
+            else{
65
+                $newTime = $currentTime + $expire;
66
+                $token = sha1(uniqid()) . sha1(uniqid());
67
+                $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
68
+                Session::set($keyExpire, $newTime);
69
+                Session::set($key, $token);
70
+                return Session::get($key);
71
+            }
72
+        }
73 73
 
74
-		/**
75
-		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76
-		 * @return boolean true if valid, false if not valid
77
-		 */
78
-		public static function validateCSRF(){
79
-			$logger = self::getLogger();
80
-			$logger->debug('Validation of CSRF ...');
74
+        /**
75
+         * This method is used to check the CSRF if is valid, not yet expire, etc.
76
+         * @return boolean true if valid, false if not valid
77
+         */
78
+        public static function validateCSRF(){
79
+            $logger = self::getLogger();
80
+            $logger->debug('Validation of CSRF ...');
81 81
 				
82
-			$key = get_config('csrf_key', 'csrf_key');
83
-			$expire = get_config('csrf_expire', 60);
84
-			$keyExpire = 'csrf_expire';
85
-			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
88
-				$logger->warning('The CSRF session data is not valide');
89
-				return false;
90
-			}
91
-			//perform form data
92
-			//need use request->query() for best retrieve
93
-			//super instance
94
-			$obj = & get_instance();
95
-			$token = $obj->request->query($key);
96
-			if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
97
-				$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
98
-				return false;
99
-			}
100
-			$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
101
-			//remove the token from session
102
-			Session::clear($key);
103
-			Session::clear($keyExpire);
104
-			return true;
105
-		}
82
+            $key = get_config('csrf_key', 'csrf_key');
83
+            $expire = get_config('csrf_expire', 60);
84
+            $keyExpire = 'csrf_expire';
85
+            $currentTime = time();
86
+            $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
+            if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
88
+                $logger->warning('The CSRF session data is not valide');
89
+                return false;
90
+            }
91
+            //perform form data
92
+            //need use request->query() for best retrieve
93
+            //super instance
94
+            $obj = & get_instance();
95
+            $token = $obj->request->query($key);
96
+            if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
97
+                $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
98
+                return false;
99
+            }
100
+            $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
101
+            //remove the token from session
102
+            Session::clear($key);
103
+            Session::clear($keyExpire);
104
+            return true;
105
+        }
106 106
 		
107
-		/**
108
-		 * This method is used to check the whitelist IP address access
109
-		 */
110
-		 public static function checkWhiteListIpAccess(){
111
-			$logger = self::getLogger();
112
-			$logger->debug('Validation of the IP address access ...');
113
-			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
114
-			$isEnable = get_config('white_list_ip_enable', false);
115
-			if($isEnable){
116
-				$logger->info('Whitelist IP access is enabled in the configuration');
117
-				$list = get_config('white_list_ip_addresses', array());
118
-				if(! empty($list)){
119
-					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
120
-					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
121
-					$ip = get_ip();
122
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
123
-						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
124
-						//wildcard to access all ip address
125
-						return;
126
-					}
127
-					else{
128
-						// go through all whitelisted ips
129
-						foreach ($list as $ipaddr) {
130
-							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
131
-							$wildcardPosition = strpos($ipaddr, '*');
132
-							if ($wildcardPosition === false) {
133
-								// no wild card in whitelisted ip --continue searching
134
-								continue;
135
-							}
136
-							// cut ip at the position where we got the wild card on the whitelisted ip
137
-							// and add the wold card to get the same pattern
138
-							if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) {
139
-								// f.e. we got
140
-								//  ip "127.0.0.1"
141
-								//  whitelisted ip "127.0.*"
142
-								// then we compared "127.0.*" with "127.0.*"
143
-								// return success
144
-								$logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"');
145
-								return;
146
-							}
147
-						}
148
-						$logger->warning('IP address ' . $ip . ' is not allowed to access to this application');
149
-						show_error('Access to this application is not allowed');
150
-					}
151
-				}
152
-			}
153
-			else{
154
-				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
155
-			}
156
-		 }
157
-	}
107
+        /**
108
+         * This method is used to check the whitelist IP address access
109
+         */
110
+            public static function checkWhiteListIpAccess(){
111
+            $logger = self::getLogger();
112
+            $logger->debug('Validation of the IP address access ...');
113
+            $logger->debug('Check if whitelist IP access is enabled in the configuration ...');
114
+            $isEnable = get_config('white_list_ip_enable', false);
115
+            if($isEnable){
116
+                $logger->info('Whitelist IP access is enabled in the configuration');
117
+                $list = get_config('white_list_ip_addresses', array());
118
+                if(! empty($list)){
119
+                    //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
120
+                    require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
121
+                    $ip = get_ip();
122
+                    if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
123
+                        $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
124
+                        //wildcard to access all ip address
125
+                        return;
126
+                    }
127
+                    else{
128
+                        // go through all whitelisted ips
129
+                        foreach ($list as $ipaddr) {
130
+                            // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
131
+                            $wildcardPosition = strpos($ipaddr, '*');
132
+                            if ($wildcardPosition === false) {
133
+                                // no wild card in whitelisted ip --continue searching
134
+                                continue;
135
+                            }
136
+                            // cut ip at the position where we got the wild card on the whitelisted ip
137
+                            // and add the wold card to get the same pattern
138
+                            if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) {
139
+                                // f.e. we got
140
+                                //  ip "127.0.0.1"
141
+                                //  whitelisted ip "127.0.*"
142
+                                // then we compared "127.0.*" with "127.0.*"
143
+                                // return success
144
+                                $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"');
145
+                                return;
146
+                            }
147
+                        }
148
+                        $logger->warning('IP address ' . $ip . ' is not allowed to access to this application');
149
+                        show_error('Access to this application is not allowed');
150
+                    }
151
+                }
152
+            }
153
+            else{
154
+                $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
155
+            }
156
+            }
157
+    }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Security{
27
+	class Security {
28 28
 		
29 29
 		/**
30 30
 		 * The logger instance
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		 * Get the logger singleton instance
37 37
 		 * @return Log the logger instance
38 38
 		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
39
+		private static function getLogger() {
40
+			if (self::$logger == null) {
41
+				self::$logger[0] = & class_loader('Log', 'classes');
42 42
 				self::$logger[0]->setLogger('Library::Security');
43 43
 			}
44 44
 			return self::$logger[0];
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		 * This method is used to generate the CSRF token
50 50
 		 * @return string the generated CSRF token
51 51
 		 */
52
-		public static function generateCSRF(){
52
+		public static function generateCSRF() {
53 53
 			$logger = self::getLogger();
54 54
 			$logger->debug('Generation of CSRF ...');
55 55
 			
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 			$expire = get_config('csrf_expire', 60);
58 58
 			$keyExpire = 'csrf_expire';
59 59
 			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
60
+			if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63 63
 			}
64
-			else{
64
+			else {
65 65
 				$newTime = $currentTime + $expire;
66 66
 				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
67
+				$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
68 68
 				Session::set($keyExpire, $newTime);
69 69
 				Session::set($key, $token);
70 70
 				return Session::get($key);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76 76
 		 * @return boolean true if valid, false if not valid
77 77
 		 */
78
-		public static function validateCSRF(){
78
+		public static function validateCSRF() {
79 79
 			$logger = self::getLogger();
80 80
 			$logger->debug('Validation of CSRF ...');
81 81
 				
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 			$expire = get_config('csrf_expire', 60);
84 84
 			$keyExpire = 'csrf_expire';
85 85
 			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
86
+			$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
87
+			if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
88 88
 				$logger->warning('The CSRF session data is not valide');
89 89
 				return false;
90 90
 			}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 			//super instance
94 94
 			$obj = & get_instance();
95 95
 			$token = $obj->request->query($key);
96
-			if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
97
-				$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
96
+			if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
97
+				$logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
98 98
 				return false;
99 99
 			}
100
-			$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
100
+			$logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
101 101
 			//remove the token from session
102 102
 			Session::clear($key);
103 103
 			Session::clear($keyExpire);
@@ -107,24 +107,24 @@  discard block
 block discarded – undo
107 107
 		/**
108 108
 		 * This method is used to check the whitelist IP address access
109 109
 		 */
110
-		 public static function checkWhiteListIpAccess(){
110
+		 public static function checkWhiteListIpAccess() {
111 111
 			$logger = self::getLogger();
112 112
 			$logger->debug('Validation of the IP address access ...');
113 113
 			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
114 114
 			$isEnable = get_config('white_list_ip_enable', false);
115
-			if($isEnable){
115
+			if ($isEnable) {
116 116
 				$logger->info('Whitelist IP access is enabled in the configuration');
117 117
 				$list = get_config('white_list_ip_addresses', array());
118
-				if(! empty($list)){
118
+				if (!empty($list)) {
119 119
 					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
120 120
 					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
121 121
 					$ip = get_ip();
122
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
122
+					if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) {
123 123
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
124 124
 						//wildcard to access all ip address
125 125
 						return;
126 126
 					}
127
-					else{
127
+					else {
128 128
 						// go through all whitelisted ips
129 129
 						foreach ($list as $ipaddr) {
130 130
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 					}
151 151
 				}
152 152
 			}
153
-			else{
153
+			else {
154 154
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
155 155
 			}
156 156
 		 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,8 +60,7 @@  discard block
 block discarded – undo
60 60
 			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63
-			}
64
-			else{
63
+			} else{
65 64
 				$newTime = $currentTime + $expire;
66 65
 				$token = sha1(uniqid()) . sha1(uniqid());
67 66
 				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
@@ -123,8 +122,7 @@  discard block
 block discarded – undo
123 122
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
124 123
 						//wildcard to access all ip address
125 124
 						return;
126
-					}
127
-					else{
125
+					} else{
128 126
 						// go through all whitelisted ips
129 127
 						foreach ($list as $ipaddr) {
130 128
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -149,8 +147,7 @@  discard block
 block discarded – undo
149 147
 						show_error('Access to this application is not allowed');
150 148
 					}
151 149
 				}
152
-			}
153
-			else{
150
+			} else{
154 151
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
155 152
 			}
156 153
 		 }
Please login to merge, or discard this patch.
core/functions/function_string.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,71 +1,71 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 *  @file function_string.php
29
-	 *
30
-	 *  This file contains the definition of the functions relating to the processing of strings characters.
31
-	 *
32
-	 *  @package	core
33
-	 *  @author	Tony NGUEREZA
34
-	 *  @copyright	Copyright (c) 2017
35
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
-	 *  @link	http://www.iacademy.cf
37
-	 *  @version 1.0.0
38
-	 *  @since 1.0.0
39
-	 *  @filesource
40
-	 */
27
+    /**
28
+     *  @file function_string.php
29
+     *
30
+     *  This file contains the definition of the functions relating to the processing of strings characters.
31
+     *
32
+     *  @package	core
33
+     *  @author	Tony NGUEREZA
34
+     *  @copyright	Copyright (c) 2017
35
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
+     *  @link	http://www.iacademy.cf
37
+     *  @version 1.0.0
38
+     *  @since 1.0.0
39
+     *  @filesource
40
+     */
41 41
 
42
-	if(! function_exists('get_random_string')){
43
-		/**
44
-		 * Generate a random string
45
-		 * @param  string $type the type of generation. It can take the values: "alpha" for alphabetic characters,
46
-		 * "alnum" for alpha-numeric characters and "num" for numbers.
47
-		 * By default it is "alnum".
48
-		 * @param  integer $length the length of the string to generate. By default it is 10.
49
-		 * @param  boolean $lower if we return the generated string in lowercase (true). By default it's false.
50
-		 * @return string the generated string.
51
-		 */
52
-		function get_random_string($type = 'alnum', $length = 10, $lower = false){
53
-			$chars = array(
54
-							'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
55
-							'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
56
-							'num' => '1234567890'
57
-						);
58
-			$str = null;
59
-			if(isset($chars[$type])){
60
-				$str = $chars[$type];
61
-			}
62
-			$random = null;
63
-			for($i = 0; $i < $length; $i++){
64
-				$random .= $str[mt_rand() % strlen($str)];
65
-			}
66
-			if($lower){
67
-				$random = strtolower($random);
68
-			}
69
-			return $random;
70
-		}
71
-	}
42
+    if(! function_exists('get_random_string')){
43
+        /**
44
+         * Generate a random string
45
+         * @param  string $type the type of generation. It can take the values: "alpha" for alphabetic characters,
46
+         * "alnum" for alpha-numeric characters and "num" for numbers.
47
+         * By default it is "alnum".
48
+         * @param  integer $length the length of the string to generate. By default it is 10.
49
+         * @param  boolean $lower if we return the generated string in lowercase (true). By default it's false.
50
+         * @return string the generated string.
51
+         */
52
+        function get_random_string($type = 'alnum', $length = 10, $lower = false){
53
+            $chars = array(
54
+                            'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
55
+                            'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
56
+                            'num' => '1234567890'
57
+                        );
58
+            $str = null;
59
+            if(isset($chars[$type])){
60
+                $str = $chars[$type];
61
+            }
62
+            $random = null;
63
+            for($i = 0; $i < $length; $i++){
64
+                $random .= $str[mt_rand() % strlen($str)];
65
+            }
66
+            if($lower){
67
+                $random = strtolower($random);
68
+            }
69
+            return $random;
70
+        }
71
+    }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 *  @filesource
40 40
 	 */
41 41
 
42
-	if(! function_exists('get_random_string')){
42
+	if (!function_exists('get_random_string')) {
43 43
 		/**
44 44
 		 * Generate a random string
45 45
 		 * @param  string $type the type of generation. It can take the values: "alpha" for alphabetic characters,
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
 		 * @param  boolean $lower if we return the generated string in lowercase (true). By default it's false.
50 50
 		 * @return string the generated string.
51 51
 		 */
52
-		function get_random_string($type = 'alnum', $length = 10, $lower = false){
52
+		function get_random_string($type = 'alnum', $length = 10, $lower = false) {
53 53
 			$chars = array(
54 54
 							'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
55 55
 							'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
56 56
 							'num' => '1234567890'
57 57
 						);
58 58
 			$str = null;
59
-			if(isset($chars[$type])){
59
+			if (isset($chars[$type])) {
60 60
 				$str = $chars[$type];
61 61
 			}
62 62
 			$random = null;
63
-			for($i = 0; $i < $length; $i++){
63
+			for ($i = 0; $i < $length; $i++) {
64 64
 				$random .= $str[mt_rand() % strlen($str)];
65 65
 			}
66
-			if($lower){
66
+			if ($lower) {
67 67
 				$random = strtolower($random);
68 68
 			}
69 69
 			return $random;
Please login to merge, or discard this patch.
tests/include/testsUtil.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	/**
4
-	* Function to test private & protected method
5
-	*/
6
-	function run_private_protected_method($object, $method, array $args = array()){
7
-		$r = new ReflectionClass(get_class($object));
8
-		$m = $r->getMethod($method);
9
-		$m->setAccessible(true);
10
-		return $m->invokeArgs($object, $args);
11
-	}
3
+    /**
4
+     * Function to test private & protected method
5
+     */
6
+    function run_private_protected_method($object, $method, array $args = array()){
7
+        $r = new ReflectionClass(get_class($object));
8
+        $m = $r->getMethod($method);
9
+        $m->setAccessible(true);
10
+        return $m->invokeArgs($object, $args);
11
+    }
12 12
     
13 13
     /**
14
-	* Function to return the correct database configuration
15
-	*/
14
+     * Function to return the correct database configuration
15
+     */
16 16
     function get_db_config(){
17 17
         return array(
18 18
                     'driver'    =>  'sqlite',
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 	/**
4 4
 	* Function to test private & protected method
5 5
 	*/
6
-	function run_private_protected_method($object, $method, array $args = array()){
6
+	function run_private_protected_method($object, $method, array $args = array()) {
7 7
 		$r = new ReflectionClass(get_class($object));
8 8
 		$m = $r->getMethod($method);
9 9
 		$m->setAccessible(true);
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     /**
14 14
 	* Function to return the correct database configuration
15 15
 	*/
16
-    function get_db_config(){
16
+    function get_db_config() {
17 17
         return array(
18 18
                     'driver'    =>  'sqlite',
19 19
                     'database'  =>  TESTS_PATH . 'assets' . DS . 'db_tests.db',
Please login to merge, or discard this patch.
tests/tnhfw/classes/DBSessionHandlerTest.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -1,222 +1,222 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class DBSessionHandlerTest extends TestCase
6
-	{	
5
+    class DBSessionHandlerTest extends TestCase
6
+    {	
7 7
 	
8
-		private $db = null;
8
+        private $db = null;
9 9
 		
10
-		private $model = null;
10
+        private $model = null;
11 11
 		
12
-		private $secret = 'bXlzZWNyZXQ';
12
+        private $secret = 'bXlzZWNyZXQ';
13 13
 		
14
-		private static $config = null;
14
+        private static $config = null;
15 15
 		
16
-		public function __construct(){
16
+        public function __construct(){
17 17
             $cfg = get_db_config();
18
-			$this->db = new Database($cfg);
18
+            $this->db = new Database($cfg);
19 19
             $qr = new DatabaseQueryRunner($this->db->getPdo());
20 20
             $qr->setBenchmark(new Benchmark());
21 21
             $qr->setDriver('sqlite');
22 22
             $this->db->setQueryRunner($qr);
23
-		}
23
+        }
24 24
 		
25
-		public static function setUpBeforeClass()
26
-		{
27
-			require APPS_MODEL_PATH . 'DBSessionModel.php';
28
-			self::$config = new Config();
29
-			self::$config->init();
30
-		}
25
+        public static function setUpBeforeClass()
26
+        {
27
+            require APPS_MODEL_PATH . 'DBSessionModel.php';
28
+            self::$config = new Config();
29
+            self::$config->init();
30
+        }
31 31
 		
32 32
 		
33
-		public static function tearDownAfterClass()
34
-		{
33
+        public static function tearDownAfterClass()
34
+        {
35 35
 			
36
-		}
36
+        }
37 37
 		
38
-		protected function setUp()
39
-		{
40
-			$this->model = new DBSessionModel($this->db);
38
+        protected function setUp()
39
+        {
40
+            $this->model = new DBSessionModel($this->db);
41 41
             //to prevent old data conflict
42
-			$this->model->truncate();
43
-		}
42
+            $this->model->truncate();
43
+        }
44 44
 
45
-		protected function tearDown()
46
-		{
47
-		}
45
+        protected function tearDown()
46
+        {
47
+        }
48 48
 
49 49
 		
50 50
 		
51
-		public function testUsingSessionConfiguration(){
52
-			//using value in the configuration
53
-			self::$config->set('session_save_path', 'DBSessionModel');
54
-			self::$config->set('session_secret', $this->secret);
55
-			$dbsh = new DBSessionHandler();
56
-			//assign Database instance manually
57
-			$o = &get_instance();
58
-			$o->database = $this->db;
59
-			
60
-			$this->assertTrue($dbsh->open(null, null));
61
-			$this->assertTrue($dbsh->close());
62
-			$this->assertNull($dbsh->read('foo'));
63
-			$this->assertTrue($dbsh->write('foo', '444'));
64
-			$this->assertNotEmpty($dbsh->read('foo'));
65
-			$this->assertEquals($dbsh->read('foo'), '444');
66
-			//do update of existing data
67
-			$this->assertTrue($dbsh->write('foo', '445'));
68
-			$this->assertEquals($dbsh->read('foo'), '445');	
69
-			$this->assertTrue($dbsh->destroy('foo'));
70
-			$this->assertNull($dbsh->read('foo'));
71
-			$this->assertTrue($dbsh->gc(13));
72
-			$encoded = $dbsh->encode('foo');
73
-			$this->assertNotEmpty($encoded);
74
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
75
-		}
76
-		
77
-		public function testWhenDataIsExpired(){
78
-			$dbsh = new DBSessionHandler($this->model);
79
-			$dbsh->setSessionSecret($this->secret);
80
-			
81
-			$this->assertTrue($dbsh->open(null, null));
82
-			$this->assertTrue($dbsh->write('foo', '444'));
83
-			$this->assertNotEmpty($dbsh->read('foo'));
84
-			$this->assertEquals($dbsh->read('foo'), '444');
85
-			//put it in expired
86
-			$this->model->update('foo', array('s_time' => 1234567));
87
-			$this->assertNull($dbsh->read('foo'));
88
-		}
89
-		
90
-		public function testWhenDataAlreadyExistDoUpdate(){
91
-			$dbsh = new DBSessionHandler($this->model);
92
-			$dbsh->setSessionSecret($this->secret);
93
-			
94
-			$this->assertTrue($dbsh->open(null, null));
95
-			$this->assertTrue($dbsh->write('foo', '444'));
96
-			$this->assertNotEmpty($dbsh->read('foo'));
97
-			$this->assertEquals($dbsh->read('foo'), '444');
98
-			//do update of existing data
99
-			$this->assertTrue($dbsh->write('foo', '445'));
100
-			$this->assertEquals($dbsh->read('foo'), '445');	
101
-		}
102
-		
103
-		public function testUsingCustomModelInstance(){
104
-			$dbsh = new DBSessionHandler($this->model);
105
-			$dbsh->setSessionSecret($this->secret);
106
-			
107
-			$this->assertTrue($dbsh->open(null, null));
108
-			$this->assertTrue($dbsh->close());
109
-			$this->assertNull($dbsh->read('foo'));
110
-			$this->assertTrue($dbsh->write('foo', '444'));
111
-			$this->assertNotEmpty($dbsh->read('foo'));
112
-			$this->assertEquals($dbsh->read('foo'), '444');
113
-			//put it in expired
114
-			$this->model->update('foo', array('s_time' => 1234567));
115
-			
116
-			$this->assertNull($dbsh->read('foo'));
117
-			$this->assertTrue($dbsh->write('foo', '444'));
118
-			
119
-			//do update of existing data
120
-			$this->assertTrue($dbsh->write('foo', '445'));
121
-			$this->assertEquals($dbsh->read('foo'), '445');	
122
-			$this->assertTrue($dbsh->destroy('foo'));
123
-			$this->assertNull($dbsh->read('foo'));
124
-			$this->assertTrue($dbsh->gc(13));
125
-			$encoded = $dbsh->encode('foo');
126
-			$this->assertNotEmpty($encoded);
127
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
128
-		}
129
-			
130
-			
131
-		public function testUsingCustomLogInstance(){
132
-			$dbsh = new DBSessionHandler($this->model, new Log());
133
-			$dbsh->setSessionSecret($this->secret);
134
-			
135
-			$this->assertTrue($dbsh->open(null, null));
136
-			$this->assertTrue($dbsh->close());
137
-			$this->assertNull($dbsh->read('foo'));
138
-			$this->assertTrue($dbsh->write('foo', '444'));
139
-			$this->assertNotEmpty($dbsh->read('foo'));
140
-			$this->assertEquals($dbsh->read('foo'), '444');
141
-			//put it in expired
142
-			$this->model->update('foo', array('s_time' => 1234567));
143
-			
144
-			$this->assertNull($dbsh->read('foo'));
145
-			$this->assertTrue($dbsh->write('foo', '444'));
146
-			
147
-			//do update of existing data
148
-			$this->assertTrue($dbsh->write('foo', '445'));
149
-			$this->assertEquals($dbsh->read('foo'), '445');	
150
-			$this->assertTrue($dbsh->destroy('foo'));
151
-			$this->assertNull($dbsh->read('foo'));
152
-			$this->assertTrue($dbsh->gc(13));
153
-			$encoded = $dbsh->encode('foo');
154
-			$this->assertNotEmpty($encoded);
155
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
156
-		}
157
-		
158
-		public function testUsingCustomLoaderInstance(){
159
-			$dbsh = new DBSessionHandler($this->model, null, new Loader());
160
-			$dbsh->setSessionSecret($this->secret);
161
-			
162
-			$this->assertTrue($dbsh->open(null, null));
163
-			$this->assertTrue($dbsh->close());
164
-			$this->assertNull($dbsh->read('foo'));
165
-			$this->assertTrue($dbsh->write('foo', '444'));
166
-			$this->assertNotEmpty($dbsh->read('foo'));
167
-			$this->assertEquals($dbsh->read('foo'), '444');
168
-			//put it in expired
169
-			$this->model->update('foo', array('s_time' => 1234567));
170
-			
171
-			$this->assertNull($dbsh->read('foo'));
172
-			$this->assertTrue($dbsh->write('foo', '444'));
173
-			
174
-			//do update of existing data
175
-			$this->assertTrue($dbsh->write('foo', '445'));
176
-			$this->assertEquals($dbsh->read('foo'), '445');	
177
-			$this->assertTrue($dbsh->destroy('foo'));
178
-			$this->assertNull($dbsh->read('foo'));
179
-			$this->assertTrue($dbsh->gc(13));
180
-			$encoded = $dbsh->encode('foo');
181
-			$this->assertNotEmpty($encoded);
182
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
183
-		}
184
-		
185
-		
186
-		public function testWhenModelInsanceIsNotSet(){
187
-			$dbsh = new DBSessionHandler(null, null, new Loader());
188
-			$dbsh->setSessionSecret($this->secret);
189
-			
190
-			$this->assertTrue($dbsh->open(null, null));
191
-			$this->assertTrue($dbsh->close());
192
-			$this->assertNull($dbsh->read('foo'));
193
-			$this->assertTrue($dbsh->write('foo', '444'));
194
-			$this->assertNotEmpty($dbsh->read('foo'));
195
-			$this->assertEquals($dbsh->read('foo'), '444');
196
-			//put it in expired
197
-			$this->model->update('foo', array('s_time' => 1234567));
198
-			
199
-			$this->assertNull($dbsh->read('foo'));
200
-			$this->assertTrue($dbsh->write('foo', '444'));
201
-			
202
-			//do update of existing data
203
-			$this->assertTrue($dbsh->write('tnh', '445'));
204
-			$this->assertTrue($dbsh->write('foo', '445'));
205
-			$this->assertEquals($dbsh->read('foo'), '445');	
206
-			$this->assertTrue($dbsh->destroy('foo'));
207
-			$this->assertNull($dbsh->read('foo'));
208
-			$this->assertTrue($dbsh->gc(13));
209
-			$encoded = $dbsh->encode('foo');
210
-			$this->assertNotEmpty($encoded);
211
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
212
-		}
213
-		
214
-		public function testWhenModelTableColumnsIsNotSet(){
215
-			//session table is empty
216
-			$this->model->setSessionTableColumns(array());
217
-			$dbsh = new DBSessionHandler($this->model);
218
-			$this->assertTrue($dbsh->open(null, null));
219
-		}
220
-		
221
-		
222
-	}
223 51
\ No newline at end of file
52
+        public function testUsingSessionConfiguration(){
53
+            //using value in the configuration
54
+            self::$config->set('session_save_path', 'DBSessionModel');
55
+            self::$config->set('session_secret', $this->secret);
56
+            $dbsh = new DBSessionHandler();
57
+            //assign Database instance manually
58
+            $o = &get_instance();
59
+            $o->database = $this->db;
60
+			
61
+            $this->assertTrue($dbsh->open(null, null));
62
+            $this->assertTrue($dbsh->close());
63
+            $this->assertNull($dbsh->read('foo'));
64
+            $this->assertTrue($dbsh->write('foo', '444'));
65
+            $this->assertNotEmpty($dbsh->read('foo'));
66
+            $this->assertEquals($dbsh->read('foo'), '444');
67
+            //do update of existing data
68
+            $this->assertTrue($dbsh->write('foo', '445'));
69
+            $this->assertEquals($dbsh->read('foo'), '445');	
70
+            $this->assertTrue($dbsh->destroy('foo'));
71
+            $this->assertNull($dbsh->read('foo'));
72
+            $this->assertTrue($dbsh->gc(13));
73
+            $encoded = $dbsh->encode('foo');
74
+            $this->assertNotEmpty($encoded);
75
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
76
+        }
77
+		
78
+        public function testWhenDataIsExpired(){
79
+            $dbsh = new DBSessionHandler($this->model);
80
+            $dbsh->setSessionSecret($this->secret);
81
+			
82
+            $this->assertTrue($dbsh->open(null, null));
83
+            $this->assertTrue($dbsh->write('foo', '444'));
84
+            $this->assertNotEmpty($dbsh->read('foo'));
85
+            $this->assertEquals($dbsh->read('foo'), '444');
86
+            //put it in expired
87
+            $this->model->update('foo', array('s_time' => 1234567));
88
+            $this->assertNull($dbsh->read('foo'));
89
+        }
90
+		
91
+        public function testWhenDataAlreadyExistDoUpdate(){
92
+            $dbsh = new DBSessionHandler($this->model);
93
+            $dbsh->setSessionSecret($this->secret);
94
+			
95
+            $this->assertTrue($dbsh->open(null, null));
96
+            $this->assertTrue($dbsh->write('foo', '444'));
97
+            $this->assertNotEmpty($dbsh->read('foo'));
98
+            $this->assertEquals($dbsh->read('foo'), '444');
99
+            //do update of existing data
100
+            $this->assertTrue($dbsh->write('foo', '445'));
101
+            $this->assertEquals($dbsh->read('foo'), '445');	
102
+        }
103
+		
104
+        public function testUsingCustomModelInstance(){
105
+            $dbsh = new DBSessionHandler($this->model);
106
+            $dbsh->setSessionSecret($this->secret);
107
+			
108
+            $this->assertTrue($dbsh->open(null, null));
109
+            $this->assertTrue($dbsh->close());
110
+            $this->assertNull($dbsh->read('foo'));
111
+            $this->assertTrue($dbsh->write('foo', '444'));
112
+            $this->assertNotEmpty($dbsh->read('foo'));
113
+            $this->assertEquals($dbsh->read('foo'), '444');
114
+            //put it in expired
115
+            $this->model->update('foo', array('s_time' => 1234567));
116
+			
117
+            $this->assertNull($dbsh->read('foo'));
118
+            $this->assertTrue($dbsh->write('foo', '444'));
119
+			
120
+            //do update of existing data
121
+            $this->assertTrue($dbsh->write('foo', '445'));
122
+            $this->assertEquals($dbsh->read('foo'), '445');	
123
+            $this->assertTrue($dbsh->destroy('foo'));
124
+            $this->assertNull($dbsh->read('foo'));
125
+            $this->assertTrue($dbsh->gc(13));
126
+            $encoded = $dbsh->encode('foo');
127
+            $this->assertNotEmpty($encoded);
128
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
129
+        }
130
+			
131
+			
132
+        public function testUsingCustomLogInstance(){
133
+            $dbsh = new DBSessionHandler($this->model, new Log());
134
+            $dbsh->setSessionSecret($this->secret);
135
+			
136
+            $this->assertTrue($dbsh->open(null, null));
137
+            $this->assertTrue($dbsh->close());
138
+            $this->assertNull($dbsh->read('foo'));
139
+            $this->assertTrue($dbsh->write('foo', '444'));
140
+            $this->assertNotEmpty($dbsh->read('foo'));
141
+            $this->assertEquals($dbsh->read('foo'), '444');
142
+            //put it in expired
143
+            $this->model->update('foo', array('s_time' => 1234567));
144
+			
145
+            $this->assertNull($dbsh->read('foo'));
146
+            $this->assertTrue($dbsh->write('foo', '444'));
147
+			
148
+            //do update of existing data
149
+            $this->assertTrue($dbsh->write('foo', '445'));
150
+            $this->assertEquals($dbsh->read('foo'), '445');	
151
+            $this->assertTrue($dbsh->destroy('foo'));
152
+            $this->assertNull($dbsh->read('foo'));
153
+            $this->assertTrue($dbsh->gc(13));
154
+            $encoded = $dbsh->encode('foo');
155
+            $this->assertNotEmpty($encoded);
156
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
157
+        }
158
+		
159
+        public function testUsingCustomLoaderInstance(){
160
+            $dbsh = new DBSessionHandler($this->model, null, new Loader());
161
+            $dbsh->setSessionSecret($this->secret);
162
+			
163
+            $this->assertTrue($dbsh->open(null, null));
164
+            $this->assertTrue($dbsh->close());
165
+            $this->assertNull($dbsh->read('foo'));
166
+            $this->assertTrue($dbsh->write('foo', '444'));
167
+            $this->assertNotEmpty($dbsh->read('foo'));
168
+            $this->assertEquals($dbsh->read('foo'), '444');
169
+            //put it in expired
170
+            $this->model->update('foo', array('s_time' => 1234567));
171
+			
172
+            $this->assertNull($dbsh->read('foo'));
173
+            $this->assertTrue($dbsh->write('foo', '444'));
174
+			
175
+            //do update of existing data
176
+            $this->assertTrue($dbsh->write('foo', '445'));
177
+            $this->assertEquals($dbsh->read('foo'), '445');	
178
+            $this->assertTrue($dbsh->destroy('foo'));
179
+            $this->assertNull($dbsh->read('foo'));
180
+            $this->assertTrue($dbsh->gc(13));
181
+            $encoded = $dbsh->encode('foo');
182
+            $this->assertNotEmpty($encoded);
183
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
184
+        }
185
+		
186
+		
187
+        public function testWhenModelInsanceIsNotSet(){
188
+            $dbsh = new DBSessionHandler(null, null, new Loader());
189
+            $dbsh->setSessionSecret($this->secret);
190
+			
191
+            $this->assertTrue($dbsh->open(null, null));
192
+            $this->assertTrue($dbsh->close());
193
+            $this->assertNull($dbsh->read('foo'));
194
+            $this->assertTrue($dbsh->write('foo', '444'));
195
+            $this->assertNotEmpty($dbsh->read('foo'));
196
+            $this->assertEquals($dbsh->read('foo'), '444');
197
+            //put it in expired
198
+            $this->model->update('foo', array('s_time' => 1234567));
199
+			
200
+            $this->assertNull($dbsh->read('foo'));
201
+            $this->assertTrue($dbsh->write('foo', '444'));
202
+			
203
+            //do update of existing data
204
+            $this->assertTrue($dbsh->write('tnh', '445'));
205
+            $this->assertTrue($dbsh->write('foo', '445'));
206
+            $this->assertEquals($dbsh->read('foo'), '445');	
207
+            $this->assertTrue($dbsh->destroy('foo'));
208
+            $this->assertNull($dbsh->read('foo'));
209
+            $this->assertTrue($dbsh->gc(13));
210
+            $encoded = $dbsh->encode('foo');
211
+            $this->assertNotEmpty($encoded);
212
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
213
+        }
214
+		
215
+        public function testWhenModelTableColumnsIsNotSet(){
216
+            //session table is empty
217
+            $this->model->setSessionTableColumns(array());
218
+            $dbsh = new DBSessionHandler($this->model);
219
+            $this->assertTrue($dbsh->open(null, null));
220
+        }
221
+		
222
+		
223
+    }
224 224
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 		
14 14
 		private static $config = null;
15 15
 		
16
-		public function __construct(){
16
+		public function __construct() {
17 17
             $cfg = get_db_config();
18 18
 			$this->db = new Database($cfg);
19 19
             $qr = new DatabaseQueryRunner($this->db->getPdo());
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 		
50 50
 		
51
-		public function testUsingSessionConfiguration(){
51
+		public function testUsingSessionConfiguration() {
52 52
 			//using value in the configuration
53 53
 			self::$config->set('session_save_path', 'DBSessionModel');
54 54
 			self::$config->set('session_secret', $this->secret);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
75 75
 		}
76 76
 		
77
-		public function testWhenDataIsExpired(){
77
+		public function testWhenDataIsExpired() {
78 78
 			$dbsh = new DBSessionHandler($this->model);
79 79
 			$dbsh->setSessionSecret($this->secret);
80 80
 			
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			$this->assertNull($dbsh->read('foo'));
88 88
 		}
89 89
 		
90
-		public function testWhenDataAlreadyExistDoUpdate(){
90
+		public function testWhenDataAlreadyExistDoUpdate() {
91 91
 			$dbsh = new DBSessionHandler($this->model);
92 92
 			$dbsh->setSessionSecret($this->secret);
93 93
 			
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			$this->assertEquals($dbsh->read('foo'), '445');	
101 101
 		}
102 102
 		
103
-		public function testUsingCustomModelInstance(){
103
+		public function testUsingCustomModelInstance() {
104 104
 			$dbsh = new DBSessionHandler($this->model);
105 105
 			$dbsh->setSessionSecret($this->secret);
106 106
 			
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		}
129 129
 			
130 130
 			
131
-		public function testUsingCustomLogInstance(){
131
+		public function testUsingCustomLogInstance() {
132 132
 			$dbsh = new DBSessionHandler($this->model, new Log());
133 133
 			$dbsh->setSessionSecret($this->secret);
134 134
 			
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
156 156
 		}
157 157
 		
158
-		public function testUsingCustomLoaderInstance(){
158
+		public function testUsingCustomLoaderInstance() {
159 159
 			$dbsh = new DBSessionHandler($this->model, null, new Loader());
160 160
 			$dbsh->setSessionSecret($this->secret);
161 161
 			
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 		}
184 184
 		
185 185
 		
186
-		public function testWhenModelInsanceIsNotSet(){
186
+		public function testWhenModelInsanceIsNotSet() {
187 187
 			$dbsh = new DBSessionHandler(null, null, new Loader());
188 188
 			$dbsh->setSessionSecret($this->secret);
189 189
 			
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
212 212
 		}
213 213
 		
214
-		public function testWhenModelTableColumnsIsNotSet(){
214
+		public function testWhenModelTableColumnsIsNotSet() {
215 215
 			//session table is empty
216 216
 			$this->model->setSessionTableColumns(array());
217 217
 			$dbsh = new DBSessionHandler($this->model);
Please login to merge, or discard this patch.
core/classes/Loader.php 3 patches
Braces   +15 added lines, -30 removed lines patch added patch discarded remove patch
@@ -107,8 +107,7 @@  discard block
 block discarded – undo
107 107
 			if ($moduleModelFilePath){
108 108
 				$logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
109 109
 				$classFilePath = $moduleModelFilePath;
110
-			}
111
-			else{
110
+			} else{
112 111
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
113 112
 			}
114 113
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
@@ -120,12 +119,10 @@  discard block
 block discarded – undo
120 119
 					$obj->{$instance} = $c;
121 120
 					static::$loaded[$instance] = $class;
122 121
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123
-				}
124
-				else{
122
+				} else{
125 123
 					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
126 124
 				}
127
-			}
128
-			else{
125
+			} else{
129 126
 				show_error('Unable to find the model [' . $class . ']');
130 127
 			}
131 128
 		}
@@ -168,8 +165,7 @@  discard block
 block discarded – undo
168 165
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
169 166
 				$class = ucfirst($class);
170 167
 				$logger->info('This library is a system library');
171
-			}
172
-			else{
168
+			} else{
173 169
 				$logger->info('This library is not a system library');	
174 170
 				//first check if this library is in the module
175 171
 				$libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
@@ -214,8 +210,7 @@  discard block
 block discarded – undo
214 210
 			if ($moduleFunctionPath){
215 211
 				$logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
216 212
 				$functionFilePath = $moduleFunctionPath;
217
-			}
218
-			else{
213
+			} else{
219 214
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220 215
 			}
221 216
 			if (! $functionFilePath){
@@ -234,8 +229,7 @@  discard block
 block discarded – undo
234 229
 				require_once $functionFilePath;
235 230
 				static::$loaded['function_' . $function] = $functionFilePath;
236 231
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237
-			}
238
-			else{
232
+			} else{
239 233
 				show_error('Unable to find helper file [' . $file . ']');
240 234
 			}
241 235
 		}
@@ -268,8 +262,7 @@  discard block
 block discarded – undo
268 262
 			if ($moduleConfigPath){
269 263
 				$logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
270 264
 				$configFilePath = $moduleConfigPath;
271
-			}
272
-			else{
265
+			} else{
273 266
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274 267
 			}
275 268
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
@@ -283,8 +276,7 @@  discard block
 block discarded – undo
283 276
 					$logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
284 277
 					unset($config);
285 278
 				}
286
-			}
287
-			else{
279
+			} else{
288 280
 				show_error('Unable to find config file ['. $configFilePath . ']');
289 281
 			}
290 282
 		}
@@ -323,8 +315,7 @@  discard block
 block discarded – undo
323 315
 			if ($moduleLanguagePath){
324 316
 				$logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
325 317
 				$languageFilePath = $moduleLanguagePath;
326
-			}
327
-			else{
318
+			} else{
328 319
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
329 320
 			}
330 321
 			if (! $languageFilePath){
@@ -377,8 +368,7 @@  discard block
 block discarded – undo
377 368
 					$module = $path[0];
378 369
 					$class = ucfirst($path[1]);
379 370
 				}
380
-			}
381
-			else{
371
+			} else{
382 372
 				$class = ucfirst($class);
383 373
 			}
384 374
 			if (! $module && !empty($obj->moduleName)){
@@ -499,8 +489,7 @@  discard block
 block discarded – undo
499 489
 				if (isset($path[1])){
500 490
 					$instance = strtolower($path[1]);
501 491
 				}
502
-			}
503
-			else{
492
+			} else{
504 493
 				$instance = strtolower($class);
505 494
 			}
506 495
 			return $instance;
@@ -522,8 +511,7 @@  discard block
 block discarded – undo
522 511
 			if ($moduleLibraryPath){
523 512
 				$logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
524 513
 				$libraryFilePath = $moduleLibraryPath;
525
-			}
526
-			else{
514
+			} else{
527 515
 				$logger->info('Cannot find library [' . $class . '] from modules using the default location');
528 516
 			}
529 517
 			return $libraryFilePath;
@@ -547,12 +535,10 @@  discard block
 block discarded – undo
547 535
 					$obj->{$instance} = $c;
548 536
 					static::$loaded[$instance] = $class;
549 537
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550
-				}
551
-				else{
538
+				} else{
552 539
 					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
553 540
 				}
554
-			}
555
-			else{
541
+			} else{
556 542
 				show_error('Unable to find library class [' . $class . ']');
557 543
 			}
558 544
 		}
@@ -578,8 +564,7 @@  discard block
 block discarded – undo
578 564
 				}
579 565
 				static::$loaded['lang_' . $language] = $languageFilePath;
580 566
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581
-			}
582
-			else{
567
+			} else{
583 568
 				show_error('Unable to find language [' . $language . ']');
584 569
 			}
585 570
 		}
Please login to merge, or discard this patch.
Indentation   +622 added lines, -622 removed lines patch added patch discarded remove patch
@@ -1,657 +1,657 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
26
-	class Loader{
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+    class Loader{
27 27
 		
28
-		/**
29
-		 * List of loaded resources
30
-		 * @var array
31
-		 */
32
-		public static $loaded = array();
28
+        /**
29
+         * List of loaded resources
30
+         * @var array
31
+         */
32
+        public static $loaded = array();
33 33
 		
34
-		/**
35
-		 * The logger instance
36
-		 * @var object
37
-		 */
38
-		private static $logger;
34
+        /**
35
+         * The logger instance
36
+         * @var object
37
+         */
38
+        private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
42
-			//add the resources already loaded during application bootstrap
43
-			//in the list to prevent duplicate or loading the resources again.
44
-			static::$loaded = class_loaded();
41
+        public function __construct(){
42
+            //add the resources already loaded during application bootstrap
43
+            //in the list to prevent duplicate or loading the resources again.
44
+            static::$loaded = class_loaded();
45 45
 			
46
-			//Load resources from autoload configuration
47
-			$this->loadResourcesFromAutoloadConfig();
48
-		}
46
+            //Load resources from autoload configuration
47
+            $this->loadResourcesFromAutoloadConfig();
48
+        }
49 49
 
50
-		/**
51
-		 * The signleton of the logger
52
-		 * @return object the Log instance
53
-		 */
54
-		public static function getLogger(){
55
-			if(self::$logger == null){
56
-				$logger = array();
57
-				$logger[0] =& class_loader('Log', 'classes');
58
-				$logger[0]->setLogger('Library::Loader');
59
-				self::$logger = $logger[0];
60
-			}
61
-			return self::$logger;			
62
-		}
50
+        /**
51
+         * The signleton of the logger
52
+         * @return object the Log instance
53
+         */
54
+        public static function getLogger(){
55
+            if(self::$logger == null){
56
+                $logger = array();
57
+                $logger[0] =& class_loader('Log', 'classes');
58
+                $logger[0]->setLogger('Library::Loader');
59
+                self::$logger = $logger[0];
60
+            }
61
+            return self::$logger;			
62
+        }
63 63
 
64
-		/**
65
-		 * Set the log instance for future use
66
-		 * @param object $logger the log object
67
-		 * @return object the log instance
68
-		 */
69
-		public static function setLogger($logger){
70
-			self::$logger = $logger;
71
-			return self::$logger;
72
-		}
64
+        /**
65
+         * Set the log instance for future use
66
+         * @param object $logger the log object
67
+         * @return object the log instance
68
+         */
69
+        public static function setLogger($logger){
70
+            self::$logger = $logger;
71
+            return self::$logger;
72
+        }
73 73
 
74 74
 		
75
-		/**
76
-		 * Load the model class
77
-		 *
78
-		 * @param  string $class    the class name to be loaded
79
-		 * @param  string $instance the name of the instance to use in super object
80
-		 *
81
-		 * @return void
82
-		 */
83
-		public static function model($class, $instance = null){
84
-			$logger = static::getLogger();
85
-			$class = str_ireplace('.php', '', $class);
86
-			$class = trim($class, '/\\');
87
-			$file = ucfirst($class).'.php';
88
-			$logger->debug('Loading model [' . $class . '] ...');
89
-			//************
90
-			if (! $instance){
91
-				$instance = self::getModelLibraryInstanceName($class);
92
-			}
93
-			//****************
94
-			if (isset(static::$loaded[$instance])){
95
-				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
96
-				return;
97
-			}
98
-			$classFilePath = APPS_MODEL_PATH . $file;
99
-			//first check if this model is in the module
100
-			$logger->debug('Checking model [' . $class . '] from module list ...');
101
-			//check if the request class contains module name
102
-			$moduleInfo = self::getModuleInfoForModelLibrary($class);
103
-			$module = $moduleInfo['module'];
104
-			$class  = $moduleInfo['class'];
75
+        /**
76
+         * Load the model class
77
+         *
78
+         * @param  string $class    the class name to be loaded
79
+         * @param  string $instance the name of the instance to use in super object
80
+         *
81
+         * @return void
82
+         */
83
+        public static function model($class, $instance = null){
84
+            $logger = static::getLogger();
85
+            $class = str_ireplace('.php', '', $class);
86
+            $class = trim($class, '/\\');
87
+            $file = ucfirst($class).'.php';
88
+            $logger->debug('Loading model [' . $class . '] ...');
89
+            //************
90
+            if (! $instance){
91
+                $instance = self::getModelLibraryInstanceName($class);
92
+            }
93
+            //****************
94
+            if (isset(static::$loaded[$instance])){
95
+                $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
96
+                return;
97
+            }
98
+            $classFilePath = APPS_MODEL_PATH . $file;
99
+            //first check if this model is in the module
100
+            $logger->debug('Checking model [' . $class . '] from module list ...');
101
+            //check if the request class contains module name
102
+            $moduleInfo = self::getModuleInfoForModelLibrary($class);
103
+            $module = $moduleInfo['module'];
104
+            $class  = $moduleInfo['class'];
105 105
 			
106
-			$moduleModelFilePath = Module::findModelFullPath($class, $module);
107
-			if ($moduleModelFilePath){
108
-				$logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
109
-				$classFilePath = $moduleModelFilePath;
110
-			}
111
-			else{
112
-				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
113
-			}
114
-			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
115
-			if (file_exists($classFilePath)){
116
-				require_once $classFilePath;
117
-				if (class_exists($class)){
118
-					$c = new $class();
119
-					$obj = & get_instance();
120
-					$obj->{$instance} = $c;
121
-					static::$loaded[$instance] = $class;
122
-					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123
-				}
124
-				else{
125
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
126
-				}
127
-			}
128
-			else{
129
-				show_error('Unable to find the model [' . $class . ']');
130
-			}
131
-		}
106
+            $moduleModelFilePath = Module::findModelFullPath($class, $module);
107
+            if ($moduleModelFilePath){
108
+                $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
109
+                $classFilePath = $moduleModelFilePath;
110
+            }
111
+            else{
112
+                $logger->info('Cannot find model [' . $class . '] from modules using the default location');
113
+            }
114
+            $logger->info('The model file path to be loaded is [' . $classFilePath . ']');
115
+            if (file_exists($classFilePath)){
116
+                require_once $classFilePath;
117
+                if (class_exists($class)){
118
+                    $c = new $class();
119
+                    $obj = & get_instance();
120
+                    $obj->{$instance} = $c;
121
+                    static::$loaded[$instance] = $class;
122
+                    $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123
+                }
124
+                else{
125
+                    show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
126
+                }
127
+            }
128
+            else{
129
+                show_error('Unable to find the model [' . $class . ']');
130
+            }
131
+        }
132 132
 
133 133
 		
134
-		/**
135
-		 * Load the library class
136
-		 *
137
-		 * @param  string $class    the library class name to be loaded
138
-		 * @param  string $instance the instance name to use in super object
139
-		 * @param mixed $params the arguments to pass to the constructor
140
-		 *
141
-		 * @return void
142
-		 */
143
-		public static function library($class, $instance = null, array $params = array()){
144
-			$logger = static::getLogger();
145
-			$class = str_ireplace('.php', '', $class);
146
-			$class = trim($class, '/\\');
147
-			$file = ucfirst($class) .'.php';
148
-			$logger->debug('Loading library [' . $class . '] ...');
149
-			if (! $instance){
150
-				$instance = self::getModelLibraryInstanceName($class);
151
-			}
152
-			if (isset(static::$loaded[$instance])){
153
-				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
154
-				return;
155
-			}
156
-			$obj = & get_instance();
157
-			//Check and load Database library
158
-			if (strtolower($class) == 'database'){
159
-				$logger->info('This is the Database library ...');
160
-				$obj->{$instance} = & class_loader('Database', 'classes/database', $params);
161
-				static::$loaded[$instance] = $class;
162
-				$logger->info('Library Database loaded successfully.');
163
-				return;
164
-			}
165
-			$libraryFilePath = null;
166
-			$logger->debug('Check if this is a system library ...');
167
-			if (file_exists(CORE_LIBRARY_PATH . $file)){
168
-				$libraryFilePath = CORE_LIBRARY_PATH . $file;
169
-				$class = ucfirst($class);
170
-				$logger->info('This library is a system library');
171
-			}
172
-			else{
173
-				$logger->info('This library is not a system library');	
174
-				//first check if this library is in the module
175
-				$libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
176
-				//***************
177
-			}
178
-			if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){
179
-				$libraryFilePath = LIBRARY_PATH . $file;
180
-			}
181
-			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
182
-			//*************************
183
-			self::loadLibrary($libraryFilePath, $class, $instance, $params);
184
-		}
134
+        /**
135
+         * Load the library class
136
+         *
137
+         * @param  string $class    the library class name to be loaded
138
+         * @param  string $instance the instance name to use in super object
139
+         * @param mixed $params the arguments to pass to the constructor
140
+         *
141
+         * @return void
142
+         */
143
+        public static function library($class, $instance = null, array $params = array()){
144
+            $logger = static::getLogger();
145
+            $class = str_ireplace('.php', '', $class);
146
+            $class = trim($class, '/\\');
147
+            $file = ucfirst($class) .'.php';
148
+            $logger->debug('Loading library [' . $class . '] ...');
149
+            if (! $instance){
150
+                $instance = self::getModelLibraryInstanceName($class);
151
+            }
152
+            if (isset(static::$loaded[$instance])){
153
+                $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
154
+                return;
155
+            }
156
+            $obj = & get_instance();
157
+            //Check and load Database library
158
+            if (strtolower($class) == 'database'){
159
+                $logger->info('This is the Database library ...');
160
+                $obj->{$instance} = & class_loader('Database', 'classes/database', $params);
161
+                static::$loaded[$instance] = $class;
162
+                $logger->info('Library Database loaded successfully.');
163
+                return;
164
+            }
165
+            $libraryFilePath = null;
166
+            $logger->debug('Check if this is a system library ...');
167
+            if (file_exists(CORE_LIBRARY_PATH . $file)){
168
+                $libraryFilePath = CORE_LIBRARY_PATH . $file;
169
+                $class = ucfirst($class);
170
+                $logger->info('This library is a system library');
171
+            }
172
+            else{
173
+                $logger->info('This library is not a system library');	
174
+                //first check if this library is in the module
175
+                $libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
176
+                //***************
177
+            }
178
+            if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){
179
+                $libraryFilePath = LIBRARY_PATH . $file;
180
+            }
181
+            $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
182
+            //*************************
183
+            self::loadLibrary($libraryFilePath, $class, $instance, $params);
184
+        }
185 185
 
186
-		/**
187
-		 * Load the helper
188
-		 *
189
-		 * @param  string $function the helper name to be loaded
190
-		 *
191
-		 * @return void
192
-		 */
193
-		public static function functions($function){
194
-			$logger = static::getLogger();
195
-			$function = str_ireplace('.php', '', $function);
196
-			$function = trim($function, '/\\');
197
-			$function = str_ireplace('function_', '', $function);
198
-			$file = 'function_'.$function.'.php';
199
-			$logger->debug('Loading helper [' . $function . '] ...');
200
-			if (isset(static::$loaded['function_' . $function])){
201
-				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
202
-				return;
203
-			}
204
-			$functionFilePath = null;
205
-			//first check if this helper is in the module
206
-			$logger->debug('Checking helper [' . $function . '] from module list ...');
207
-			$moduleInfo = self::getModuleInfoForFunction($function);
208
-			$module    = $moduleInfo['module'];
209
-			$function  = $moduleInfo['function'];
210
-			if(! empty($moduleInfo['file'])){
211
-				$file = $moduleInfo['file'];
212
-			}
213
-			$moduleFunctionPath = Module::findFunctionFullPath($function, $module);
214
-			if ($moduleFunctionPath){
215
-				$logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
216
-				$functionFilePath = $moduleFunctionPath;
217
-			}
218
-			else{
219
-				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220
-			}
221
-			if (! $functionFilePath){
222
-				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
223
-				foreach($searchDir as $dir){
224
-					$filePath = $dir . $file;
225
-					if (file_exists($filePath)){
226
-						$functionFilePath = $filePath;
227
-						//is already found not to continue
228
-						break;
229
-					}
230
-				}
231
-			}
232
-			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
233
-			if ($functionFilePath){
234
-				require_once $functionFilePath;
235
-				static::$loaded['function_' . $function] = $functionFilePath;
236
-				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237
-			}
238
-			else{
239
-				show_error('Unable to find helper file [' . $file . ']');
240
-			}
241
-		}
186
+        /**
187
+         * Load the helper
188
+         *
189
+         * @param  string $function the helper name to be loaded
190
+         *
191
+         * @return void
192
+         */
193
+        public static function functions($function){
194
+            $logger = static::getLogger();
195
+            $function = str_ireplace('.php', '', $function);
196
+            $function = trim($function, '/\\');
197
+            $function = str_ireplace('function_', '', $function);
198
+            $file = 'function_'.$function.'.php';
199
+            $logger->debug('Loading helper [' . $function . '] ...');
200
+            if (isset(static::$loaded['function_' . $function])){
201
+                $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
202
+                return;
203
+            }
204
+            $functionFilePath = null;
205
+            //first check if this helper is in the module
206
+            $logger->debug('Checking helper [' . $function . '] from module list ...');
207
+            $moduleInfo = self::getModuleInfoForFunction($function);
208
+            $module    = $moduleInfo['module'];
209
+            $function  = $moduleInfo['function'];
210
+            if(! empty($moduleInfo['file'])){
211
+                $file = $moduleInfo['file'];
212
+            }
213
+            $moduleFunctionPath = Module::findFunctionFullPath($function, $module);
214
+            if ($moduleFunctionPath){
215
+                $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
216
+                $functionFilePath = $moduleFunctionPath;
217
+            }
218
+            else{
219
+                $logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220
+            }
221
+            if (! $functionFilePath){
222
+                $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
223
+                foreach($searchDir as $dir){
224
+                    $filePath = $dir . $file;
225
+                    if (file_exists($filePath)){
226
+                        $functionFilePath = $filePath;
227
+                        //is already found not to continue
228
+                        break;
229
+                    }
230
+                }
231
+            }
232
+            $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
233
+            if ($functionFilePath){
234
+                require_once $functionFilePath;
235
+                static::$loaded['function_' . $function] = $functionFilePath;
236
+                $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237
+            }
238
+            else{
239
+                show_error('Unable to find helper file [' . $file . ']');
240
+            }
241
+        }
242 242
 
243
-		/**
244
-		 * Load the configuration file
245
-		 *
246
-		 * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
247
-		 *
248
-		 * @return void
249
-		 */
250
-		public static function config($filename){
251
-			$logger = static::getLogger();
252
-			$filename = str_ireplace('.php', '', $filename);
253
-			$filename = trim($filename, '/\\');
254
-			$filename = str_ireplace('config_', '', $filename);
255
-			$file = 'config_'.$filename.'.php';
256
-			$logger->debug('Loading configuration [' . $filename . '] ...');
257
-			if (isset(static::$loaded['config_' . $filename])){
258
-				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
259
-				return;
260
-			}
261
-			$configFilePath = CONFIG_PATH . $file;
262
-			//first check if this config is in the module
263
-			$logger->debug('Checking config [' . $filename . '] from module list ...');
264
-			$moduleInfo = self::getModuleInfoForConfig($filename);
265
-			$module    = $moduleInfo['module'];
266
-			$filename  = $moduleInfo['filename'];
267
-			$moduleConfigPath = Module::findConfigFullPath($filename, $module);
268
-			if ($moduleConfigPath){
269
-				$logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
270
-				$configFilePath = $moduleConfigPath;
271
-			}
272
-			else{
273
-				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274
-			}
275
-			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
276
-			$config = array();
277
-			if (file_exists($configFilePath)){
278
-				require_once $configFilePath;
279
-				if (! empty($config) && is_array($config)){
280
-					Config::setAll($config);
281
-					static::$loaded['config_' . $filename] = $configFilePath;
282
-					$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
283
-					$logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
284
-					unset($config);
285
-				}
286
-			}
287
-			else{
288
-				show_error('Unable to find config file ['. $configFilePath . ']');
289
-			}
290
-		}
243
+        /**
244
+         * Load the configuration file
245
+         *
246
+         * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
247
+         *
248
+         * @return void
249
+         */
250
+        public static function config($filename){
251
+            $logger = static::getLogger();
252
+            $filename = str_ireplace('.php', '', $filename);
253
+            $filename = trim($filename, '/\\');
254
+            $filename = str_ireplace('config_', '', $filename);
255
+            $file = 'config_'.$filename.'.php';
256
+            $logger->debug('Loading configuration [' . $filename . '] ...');
257
+            if (isset(static::$loaded['config_' . $filename])){
258
+                $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
259
+                return;
260
+            }
261
+            $configFilePath = CONFIG_PATH . $file;
262
+            //first check if this config is in the module
263
+            $logger->debug('Checking config [' . $filename . '] from module list ...');
264
+            $moduleInfo = self::getModuleInfoForConfig($filename);
265
+            $module    = $moduleInfo['module'];
266
+            $filename  = $moduleInfo['filename'];
267
+            $moduleConfigPath = Module::findConfigFullPath($filename, $module);
268
+            if ($moduleConfigPath){
269
+                $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
270
+                $configFilePath = $moduleConfigPath;
271
+            }
272
+            else{
273
+                $logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274
+            }
275
+            $logger->info('The config file path to be loaded is [' . $configFilePath . ']');
276
+            $config = array();
277
+            if (file_exists($configFilePath)){
278
+                require_once $configFilePath;
279
+                if (! empty($config) && is_array($config)){
280
+                    Config::setAll($config);
281
+                    static::$loaded['config_' . $filename] = $configFilePath;
282
+                    $logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
283
+                    $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
284
+                    unset($config);
285
+                }
286
+            }
287
+            else{
288
+                show_error('Unable to find config file ['. $configFilePath . ']');
289
+            }
290
+        }
291 291
 
292 292
 
293
-		/**
294
-		 * Load the language
295
-		 *
296
-		 * @param  string $language the language name to be loaded
297
-		 *
298
-		 * @return void
299
-		 */
300
-		public static function lang($language){
301
-			$logger = static::getLogger();
302
-			$language = str_ireplace('.php', '', $language);
303
-			$language = trim($language, '/\\');
304
-			$language = str_ireplace('lang_', '', $language);
305
-			$file = 'lang_'.$language.'.php';
306
-			$logger->debug('Loading language [' . $language . '] ...');
307
-			if (isset(static::$loaded['lang_' . $language])){
308
-				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
309
-				return;
310
-			}
311
-			//get the current language
312
-			$appLang = self::getAppLang();
313
-			$languageFilePath = null;
314
-			//first check if this language is in the module
315
-			$logger->debug('Checking language [' . $language . '] from module list ...');
316
-			$moduleInfo = self::getModuleInfoForLanguage($language);
317
-			$module    = $moduleInfo['module'];
318
-			$language  = $moduleInfo['language'];
319
-			if(! empty($moduleInfo['file'])){
320
-				$file = $moduleInfo['file'];
321
-			}
322
-			$moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang);
323
-			if ($moduleLanguagePath){
324
-				$logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
325
-				$languageFilePath = $moduleLanguagePath;
326
-			}
327
-			else{
328
-				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
329
-			}
330
-			if (! $languageFilePath){
331
-				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
332
-				foreach($searchDir as $dir){
333
-					$filePath = $dir . $appLang . DS . $file;
334
-					if (file_exists($filePath)){
335
-						$languageFilePath = $filePath;
336
-						//already found no need continue
337
-						break;
338
-					}
339
-				}
340
-			}
341
-			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
342
-			self::loadLanguage($languageFilePath, $language);
343
-		}
293
+        /**
294
+         * Load the language
295
+         *
296
+         * @param  string $language the language name to be loaded
297
+         *
298
+         * @return void
299
+         */
300
+        public static function lang($language){
301
+            $logger = static::getLogger();
302
+            $language = str_ireplace('.php', '', $language);
303
+            $language = trim($language, '/\\');
304
+            $language = str_ireplace('lang_', '', $language);
305
+            $file = 'lang_'.$language.'.php';
306
+            $logger->debug('Loading language [' . $language . '] ...');
307
+            if (isset(static::$loaded['lang_' . $language])){
308
+                $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
309
+                return;
310
+            }
311
+            //get the current language
312
+            $appLang = self::getAppLang();
313
+            $languageFilePath = null;
314
+            //first check if this language is in the module
315
+            $logger->debug('Checking language [' . $language . '] from module list ...');
316
+            $moduleInfo = self::getModuleInfoForLanguage($language);
317
+            $module    = $moduleInfo['module'];
318
+            $language  = $moduleInfo['language'];
319
+            if(! empty($moduleInfo['file'])){
320
+                $file = $moduleInfo['file'];
321
+            }
322
+            $moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang);
323
+            if ($moduleLanguagePath){
324
+                $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
325
+                $languageFilePath = $moduleLanguagePath;
326
+            }
327
+            else{
328
+                $logger->info('Cannot find language [' . $language . '] from modules using the default location');
329
+            }
330
+            if (! $languageFilePath){
331
+                $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
332
+                foreach($searchDir as $dir){
333
+                    $filePath = $dir . $appLang . DS . $file;
334
+                    if (file_exists($filePath)){
335
+                        $languageFilePath = $filePath;
336
+                        //already found no need continue
337
+                        break;
338
+                    }
339
+                }
340
+            }
341
+            $logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
342
+            self::loadLanguage($languageFilePath, $language);
343
+        }
344 344
 
345
-		/**
346
-		 * Return the current app language by default will use the value from cookie 
347
-		 * if can not found will use the default value from configuration
348
-		 * @return string the app language like "en", "fr"
349
-		 */
350
-		protected static function getAppLang(){
351
-			//determine the current language
352
-			$appLang = get_config('default_language');
353
-			//if the language exists in the cookie use it
354
-			$cfgKey = get_config('language_cookie_name');
355
-			$objCookie = & class_loader('Cookie');
356
-			$cookieLang = $objCookie->get($cfgKey);
357
-			if ($cookieLang){
358
-				$appLang = $cookieLang;
359
-			}
360
-			return $appLang;
361
-		}
362
-		/**
363
-		 * Get the module information for the model and library to load
364
-		 * @param  string $class the full class name like moduleName/className, className,
365
-		 * @return array        the module information
366
-		 * array(
367
-		 * 	'module'=> 'module_name'
368
-		 * 	'class' => 'class_name'
369
-		 * )
370
-		 */
371
-		protected static function getModuleInfoForModelLibrary($class){
372
-			$module = null;
373
-			$obj = & get_instance();
374
-			if (strpos($class, '/') !== false){
375
-				$path = explode('/', $class);
376
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
377
-					$module = $path[0];
378
-					$class = ucfirst($path[1]);
379
-				}
380
-			}
381
-			else{
382
-				$class = ucfirst($class);
383
-			}
384
-			if (! $module && !empty($obj->moduleName)){
385
-				$module = $obj->moduleName;
386
-			}
387
-			return array(
388
-						'class' => $class,
389
-						'module' => $module
390
-					);
391
-		}
345
+        /**
346
+         * Return the current app language by default will use the value from cookie 
347
+         * if can not found will use the default value from configuration
348
+         * @return string the app language like "en", "fr"
349
+         */
350
+        protected static function getAppLang(){
351
+            //determine the current language
352
+            $appLang = get_config('default_language');
353
+            //if the language exists in the cookie use it
354
+            $cfgKey = get_config('language_cookie_name');
355
+            $objCookie = & class_loader('Cookie');
356
+            $cookieLang = $objCookie->get($cfgKey);
357
+            if ($cookieLang){
358
+                $appLang = $cookieLang;
359
+            }
360
+            return $appLang;
361
+        }
362
+        /**
363
+         * Get the module information for the model and library to load
364
+         * @param  string $class the full class name like moduleName/className, className,
365
+         * @return array        the module information
366
+         * array(
367
+         * 	'module'=> 'module_name'
368
+         * 	'class' => 'class_name'
369
+         * )
370
+         */
371
+        protected static function getModuleInfoForModelLibrary($class){
372
+            $module = null;
373
+            $obj = & get_instance();
374
+            if (strpos($class, '/') !== false){
375
+                $path = explode('/', $class);
376
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
377
+                    $module = $path[0];
378
+                    $class = ucfirst($path[1]);
379
+                }
380
+            }
381
+            else{
382
+                $class = ucfirst($class);
383
+            }
384
+            if (! $module && !empty($obj->moduleName)){
385
+                $module = $obj->moduleName;
386
+            }
387
+            return array(
388
+                        'class' => $class,
389
+                        'module' => $module
390
+                    );
391
+        }
392 392
 
393
-		/**
394
-		 * Get the module information for the function to load
395
-		 * @param  string $function the function name like moduleName/functionName, functionName,
396
-		 * @return array        the module information
397
-		 * array(
398
-		 * 	'module'=> 'module_name'
399
-		 * 	'function' => 'function'
400
-		 * 	'file' => 'file'
401
-		 * )
402
-		 */
403
-		protected static function getModuleInfoForFunction($function){
404
-			$module = null;
405
-			$file = null;
406
-			$obj = & get_instance();
407
-			//check if the request class contains module name
408
-			if (strpos($function, '/') !== false){
409
-				$path = explode('/', $function);
410
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
411
-					$module = $path[0];
412
-					$function = 'function_' . $path[1];
413
-					$file = $path[0] . DS . $function.'.php';
414
-				}
415
-			}
416
-			if (! $module && !empty($obj->moduleName)){
417
-				$module = $obj->moduleName;
418
-			}
419
-			return array(
420
-						'function' => $function,
421
-						'module' => $module,
422
-						'file' => $file
423
-					);
424
-		}
393
+        /**
394
+         * Get the module information for the function to load
395
+         * @param  string $function the function name like moduleName/functionName, functionName,
396
+         * @return array        the module information
397
+         * array(
398
+         * 	'module'=> 'module_name'
399
+         * 	'function' => 'function'
400
+         * 	'file' => 'file'
401
+         * )
402
+         */
403
+        protected static function getModuleInfoForFunction($function){
404
+            $module = null;
405
+            $file = null;
406
+            $obj = & get_instance();
407
+            //check if the request class contains module name
408
+            if (strpos($function, '/') !== false){
409
+                $path = explode('/', $function);
410
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
411
+                    $module = $path[0];
412
+                    $function = 'function_' . $path[1];
413
+                    $file = $path[0] . DS . $function.'.php';
414
+                }
415
+            }
416
+            if (! $module && !empty($obj->moduleName)){
417
+                $module = $obj->moduleName;
418
+            }
419
+            return array(
420
+                        'function' => $function,
421
+                        'module' => $module,
422
+                        'file' => $file
423
+                    );
424
+        }
425 425
 
426
-		/**
427
-		 * Get the module information for the language to load
428
-		 * @param  string $language the language name like moduleName/languageName, languageName,
429
-		 * @return array        the module information
430
-		 * array(
431
-		 * 	'module'=> 'module_name'
432
-		 * 	'language' => 'language'
433
-		 * 	'file' => 'file'
434
-		 * )
435
-		 */
436
-		protected static function getModuleInfoForLanguage($language){
437
-			$module = null;
438
-			$file = null;
439
-			$obj = & get_instance();
440
-			//check if the request class contains module name
441
-			if (strpos($language, '/') !== false){
442
-				$path = explode('/', $language);
443
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
444
-					$module = $path[0];
445
-					$language = 'lang_' . $path[1] . '.php';
446
-					$file = $path[0] . DS .$language;
447
-				}
448
-			}
449
-			if (! $module && !empty($obj->moduleName)){
450
-				$module = $obj->moduleName;
451
-			}
452
-			return array(
453
-						'language' => $language,
454
-						'module' => $module,
455
-						'file' => $file
456
-					);
457
-		}
426
+        /**
427
+         * Get the module information for the language to load
428
+         * @param  string $language the language name like moduleName/languageName, languageName,
429
+         * @return array        the module information
430
+         * array(
431
+         * 	'module'=> 'module_name'
432
+         * 	'language' => 'language'
433
+         * 	'file' => 'file'
434
+         * )
435
+         */
436
+        protected static function getModuleInfoForLanguage($language){
437
+            $module = null;
438
+            $file = null;
439
+            $obj = & get_instance();
440
+            //check if the request class contains module name
441
+            if (strpos($language, '/') !== false){
442
+                $path = explode('/', $language);
443
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
444
+                    $module = $path[0];
445
+                    $language = 'lang_' . $path[1] . '.php';
446
+                    $file = $path[0] . DS .$language;
447
+                }
448
+            }
449
+            if (! $module && !empty($obj->moduleName)){
450
+                $module = $obj->moduleName;
451
+            }
452
+            return array(
453
+                        'language' => $language,
454
+                        'module' => $module,
455
+                        'file' => $file
456
+                    );
457
+        }
458 458
 
459 459
 
460
-		/**
461
-		 * Get the module information for the config to load
462
-		 * @param  string $filename the filename of the configuration file,
463
-		 * @return array        the module information
464
-		 * array(
465
-		 * 	'module'=> 'module_name'
466
-		 * 	'filename' => 'filename'
467
-		 * )
468
-		 */
469
-		protected static function getModuleInfoForConfig($filename){
470
-			$module = null;
471
-			$obj = & get_instance();
472
-			//check if the request class contains module name
473
-			if (strpos($filename, '/') !== false){
474
-				$path = explode('/', $filename);
475
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
476
-					$module = $path[0];
477
-					$filename = $path[1] . '.php';
478
-				}
479
-			}
480
-			if (! $module && !empty($obj->moduleName)){
481
-				$module = $obj->moduleName;
482
-			}
483
-			return array(
484
-						'filename' => $filename,
485
-						'module' => $module
486
-					);
487
-		}
460
+        /**
461
+         * Get the module information for the config to load
462
+         * @param  string $filename the filename of the configuration file,
463
+         * @return array        the module information
464
+         * array(
465
+         * 	'module'=> 'module_name'
466
+         * 	'filename' => 'filename'
467
+         * )
468
+         */
469
+        protected static function getModuleInfoForConfig($filename){
470
+            $module = null;
471
+            $obj = & get_instance();
472
+            //check if the request class contains module name
473
+            if (strpos($filename, '/') !== false){
474
+                $path = explode('/', $filename);
475
+                if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
476
+                    $module = $path[0];
477
+                    $filename = $path[1] . '.php';
478
+                }
479
+            }
480
+            if (! $module && !empty($obj->moduleName)){
481
+                $module = $obj->moduleName;
482
+            }
483
+            return array(
484
+                        'filename' => $filename,
485
+                        'module' => $module
486
+                    );
487
+        }
488 488
 
489
-		/**
490
-		 * Get the name of model or library instance if is null
491
-		 * @param  string $class the class name to determine the instance
492
-		 * @return string        the instance name
493
-		 */
494
-		protected static function getModelLibraryInstanceName($class){
495
-			//for module
496
-			$instance = null;
497
-			if (strpos($class, '/') !== false){
498
-				$path = explode('/', $class);
499
-				if (isset($path[1])){
500
-					$instance = strtolower($path[1]);
501
-				}
502
-			}
503
-			else{
504
-				$instance = strtolower($class);
505
-			}
506
-			return $instance;
507
-		}
489
+        /**
490
+         * Get the name of model or library instance if is null
491
+         * @param  string $class the class name to determine the instance
492
+         * @return string        the instance name
493
+         */
494
+        protected static function getModelLibraryInstanceName($class){
495
+            //for module
496
+            $instance = null;
497
+            if (strpos($class, '/') !== false){
498
+                $path = explode('/', $class);
499
+                if (isset($path[1])){
500
+                    $instance = strtolower($path[1]);
501
+                }
502
+            }
503
+            else{
504
+                $instance = strtolower($class);
505
+            }
506
+            return $instance;
507
+        }
508 508
 
509
-		/**
510
-		 * Get the library file path using the module information
511
-		 * @param  string $class the class name
512
-		 * @return string|null        the library file path otherwise null will be returned
513
-		 */
514
-		protected static function getLibraryPathUsingModuleInfo($class){
515
-			$logger = static::getLogger();
516
-			$libraryFilePath = null;
517
-			$logger->debug('Checking library [' . $class . '] from module list ...');
518
-			$moduleInfo = self::getModuleInfoForModelLibrary($class);
519
-			$module = $moduleInfo['module'];
520
-			$class  = $moduleInfo['class'];
521
-			$moduleLibraryPath = Module::findLibraryFullPath($class, $module);
522
-			if ($moduleLibraryPath){
523
-				$logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
524
-				$libraryFilePath = $moduleLibraryPath;
525
-			}
526
-			else{
527
-				$logger->info('Cannot find library [' . $class . '] from modules using the default location');
528
-			}
529
-			return $libraryFilePath;
530
-		}
509
+        /**
510
+         * Get the library file path using the module information
511
+         * @param  string $class the class name
512
+         * @return string|null        the library file path otherwise null will be returned
513
+         */
514
+        protected static function getLibraryPathUsingModuleInfo($class){
515
+            $logger = static::getLogger();
516
+            $libraryFilePath = null;
517
+            $logger->debug('Checking library [' . $class . '] from module list ...');
518
+            $moduleInfo = self::getModuleInfoForModelLibrary($class);
519
+            $module = $moduleInfo['module'];
520
+            $class  = $moduleInfo['class'];
521
+            $moduleLibraryPath = Module::findLibraryFullPath($class, $module);
522
+            if ($moduleLibraryPath){
523
+                $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
524
+                $libraryFilePath = $moduleLibraryPath;
525
+            }
526
+            else{
527
+                $logger->info('Cannot find library [' . $class . '] from modules using the default location');
528
+            }
529
+            return $libraryFilePath;
530
+        }
531 531
 
532
-		/**
533
-		 * Load the library 
534
-		 * @param  string $libraryFilePath the file path of the library to load
535
-		 * @param  string $class           the class name
536
-		 * @param  string $instance        the instance
537
-		 * @param  array  $params          the parameter to use
538
-		 * @return void
539
-		 */
540
-		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){
541
-			if ($libraryFilePath){
542
-				$logger = static::getLogger();
543
-				require_once $libraryFilePath;
544
-				if (class_exists($class)){
545
-					$c = $params ? new $class($params) : new $class();
546
-					$obj = & get_instance();
547
-					$obj->{$instance} = $c;
548
-					static::$loaded[$instance] = $class;
549
-					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550
-				}
551
-				else{
552
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
553
-				}
554
-			}
555
-			else{
556
-				show_error('Unable to find library class [' . $class . ']');
557
-			}
558
-		}
532
+        /**
533
+         * Load the library 
534
+         * @param  string $libraryFilePath the file path of the library to load
535
+         * @param  string $class           the class name
536
+         * @param  string $instance        the instance
537
+         * @param  array  $params          the parameter to use
538
+         * @return void
539
+         */
540
+        protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){
541
+            if ($libraryFilePath){
542
+                $logger = static::getLogger();
543
+                require_once $libraryFilePath;
544
+                if (class_exists($class)){
545
+                    $c = $params ? new $class($params) : new $class();
546
+                    $obj = & get_instance();
547
+                    $obj->{$instance} = $c;
548
+                    static::$loaded[$instance] = $class;
549
+                    $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550
+                }
551
+                else{
552
+                    show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
553
+                }
554
+            }
555
+            else{
556
+                show_error('Unable to find library class [' . $class . ']');
557
+            }
558
+        }
559 559
 
560
-		/**
561
-		 * Load the language 
562
-		 * @param  string $languageFilePath the file path of the language to load
563
-		 * @param  string $language           the language name
564
-		 * @return void
565
-		 */
566
-		protected static function loadLanguage($languageFilePath, $language){
567
-			if ($languageFilePath){
568
-				$logger = static::getLogger();
569
-				$lang = array();
570
-				require_once $languageFilePath;
571
-				if (! empty($lang) && is_array($lang)){
572
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
573
-					//Note: may be here the class 'Lang' not yet loaded
574
-					$langObj =& class_loader('Lang', 'classes');
575
-					$langObj->addLangMessages($lang);
576
-					//free the memory
577
-					unset($lang);
578
-				}
579
-				static::$loaded['lang_' . $language] = $languageFilePath;
580
-				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581
-			}
582
-			else{
583
-				show_error('Unable to find language [' . $language . ']');
584
-			}
585
-		}
560
+        /**
561
+         * Load the language 
562
+         * @param  string $languageFilePath the file path of the language to load
563
+         * @param  string $language           the language name
564
+         * @return void
565
+         */
566
+        protected static function loadLanguage($languageFilePath, $language){
567
+            if ($languageFilePath){
568
+                $logger = static::getLogger();
569
+                $lang = array();
570
+                require_once $languageFilePath;
571
+                if (! empty($lang) && is_array($lang)){
572
+                    $logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
573
+                    //Note: may be here the class 'Lang' not yet loaded
574
+                    $langObj =& class_loader('Lang', 'classes');
575
+                    $langObj->addLangMessages($lang);
576
+                    //free the memory
577
+                    unset($lang);
578
+                }
579
+                static::$loaded['lang_' . $language] = $languageFilePath;
580
+                $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581
+            }
582
+            else{
583
+                show_error('Unable to find language [' . $language . ']');
584
+            }
585
+        }
586 586
 
587
-		/**
588
-		 * Get all the autoload using the configuration file
589
-		 * @return array
590
-		 */
591
-		private function getResourcesFromAutoloadConfig(){
592
-			$autoloads = array();
593
-			$autoloads['config']    = array();
594
-			$autoloads['languages'] = array();
595
-			$autoloads['libraries'] = array();
596
-			$autoloads['models']    = array();
597
-			$autoloads['functions'] = array();
598
-			//loading of the resources from autoload configuration file
599
-			if (file_exists(CONFIG_PATH . 'autoload.php')){
600
-				$autoload = array();
601
-				require_once CONFIG_PATH . 'autoload.php';
602
-				if (! empty($autoload) && is_array($autoload)){
603
-					$autoloads = array_merge($autoloads, $autoload);
604
-					unset($autoload);
605
-				}
606
-			}
607
-			//loading autoload configuration for modules
608
-			$modulesAutoloads = Module::getModulesAutoloadConfig();
609
-			if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){
610
-				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
611
-			}
612
-			return $autoloads;
613
-		}
587
+        /**
588
+         * Get all the autoload using the configuration file
589
+         * @return array
590
+         */
591
+        private function getResourcesFromAutoloadConfig(){
592
+            $autoloads = array();
593
+            $autoloads['config']    = array();
594
+            $autoloads['languages'] = array();
595
+            $autoloads['libraries'] = array();
596
+            $autoloads['models']    = array();
597
+            $autoloads['functions'] = array();
598
+            //loading of the resources from autoload configuration file
599
+            if (file_exists(CONFIG_PATH . 'autoload.php')){
600
+                $autoload = array();
601
+                require_once CONFIG_PATH . 'autoload.php';
602
+                if (! empty($autoload) && is_array($autoload)){
603
+                    $autoloads = array_merge($autoloads, $autoload);
604
+                    unset($autoload);
605
+                }
606
+            }
607
+            //loading autoload configuration for modules
608
+            $modulesAutoloads = Module::getModulesAutoloadConfig();
609
+            if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){
610
+                $autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
611
+            }
612
+            return $autoloads;
613
+        }
614 614
 
615
-		/**
616
-		 * Load the autoload configuration
617
-		 * @return void
618
-		 */
619
-		private function loadResourcesFromAutoloadConfig(){
620
-			$autoloads = array();
621
-			$autoloads['config']    = array();
622
-			$autoloads['languages'] = array();
623
-			$autoloads['libraries'] = array();
624
-			$autoloads['models']    = array();
625
-			$autoloads['functions'] = array();
615
+        /**
616
+         * Load the autoload configuration
617
+         * @return void
618
+         */
619
+        private function loadResourcesFromAutoloadConfig(){
620
+            $autoloads = array();
621
+            $autoloads['config']    = array();
622
+            $autoloads['languages'] = array();
623
+            $autoloads['libraries'] = array();
624
+            $autoloads['models']    = array();
625
+            $autoloads['functions'] = array();
626 626
 
627
-			$list = $this->getResourcesFromAutoloadConfig();
628
-			$autoloads = array_merge($autoloads, $list);
627
+            $list = $this->getResourcesFromAutoloadConfig();
628
+            $autoloads = array_merge($autoloads, $list);
629 629
 			
630
-			//config autoload
631
-			$this->loadAutoloadResourcesArray('config', $autoloads['config']);
630
+            //config autoload
631
+            $this->loadAutoloadResourcesArray('config', $autoloads['config']);
632 632
 			
633
-			//languages autoload
634
-			$this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
633
+            //languages autoload
634
+            $this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
635 635
 			
636
-			//libraries autoload
637
-			$this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
636
+            //libraries autoload
637
+            $this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
638 638
 
639
-			//models autoload
640
-			$this->loadAutoloadResourcesArray('model', $autoloads['models']);
639
+            //models autoload
640
+            $this->loadAutoloadResourcesArray('model', $autoloads['models']);
641 641
 			
642
-			//functions autoload
643
-			$this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
644
-		}
642
+            //functions autoload
643
+            $this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
644
+        }
645 645
 
646
-		/**
647
-		 * Load the resources autoload array
648
-		 * @param  string $method    this object method name to call
649
-		 * @param  array  $resources the resource to load
650
-		 * @return void            
651
-		 */
652
-		private function loadAutoloadResourcesArray($method, array $resources){
653
-			foreach ($resources as $name) {
654
-				$this->{$method}($name);
655
-			}
656
-		}
657
-	}
646
+        /**
647
+         * Load the resources autoload array
648
+         * @param  string $method    this object method name to call
649
+         * @param  array  $resources the resource to load
650
+         * @return void            
651
+         */
652
+        private function loadAutoloadResourcesArray($method, array $resources){
653
+            foreach ($resources as $name) {
654
+                $this->{$method}($name);
655
+            }
656
+        }
657
+    }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 		 * The signleton of the logger
52 52
 		 * @return object the Log instance
53 53
 		 */
54
-		public static function getLogger(){
55
-			if(self::$logger == null){
54
+		public static function getLogger() {
55
+			if (self::$logger == null) {
56 56
 				$logger = array();
57
-				$logger[0] =& class_loader('Log', 'classes');
57
+				$logger[0] = & class_loader('Log', 'classes');
58 58
 				$logger[0]->setLogger('Library::Loader');
59 59
 				self::$logger = $logger[0];
60 60
 			}
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		 * @param object $logger the log object
67 67
 		 * @return object the log instance
68 68
 		 */
69
-		public static function setLogger($logger){
69
+		public static function setLogger($logger) {
70 70
 			self::$logger = $logger;
71 71
 			return self::$logger;
72 72
 		}
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
 		 *
81 81
 		 * @return void
82 82
 		 */
83
-		public static function model($class, $instance = null){
83
+		public static function model($class, $instance = null) {
84 84
 			$logger = static::getLogger();
85 85
 			$class = str_ireplace('.php', '', $class);
86 86
 			$class = trim($class, '/\\');
87
-			$file = ucfirst($class).'.php';
87
+			$file = ucfirst($class) . '.php';
88 88
 			$logger->debug('Loading model [' . $class . '] ...');
89 89
 			//************
90
-			if (! $instance){
90
+			if (!$instance) {
91 91
 				$instance = self::getModelLibraryInstanceName($class);
92 92
 			}
93 93
 			//****************
94
-			if (isset(static::$loaded[$instance])){
94
+			if (isset(static::$loaded[$instance])) {
95 95
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
96 96
 				return;
97 97
 			}
@@ -104,28 +104,28 @@  discard block
 block discarded – undo
104 104
 			$class  = $moduleInfo['class'];
105 105
 			
106 106
 			$moduleModelFilePath = Module::findModelFullPath($class, $module);
107
-			if ($moduleModelFilePath){
108
-				$logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
107
+			if ($moduleModelFilePath) {
108
+				$logger->info('Found model [' . $class . '] from module [' . $module . '], the file path is [' . $moduleModelFilePath . '] we will used it');
109 109
 				$classFilePath = $moduleModelFilePath;
110 110
 			}
111
-			else{
111
+			else {
112 112
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
113 113
 			}
114 114
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
115
-			if (file_exists($classFilePath)){
115
+			if (file_exists($classFilePath)) {
116 116
 				require_once $classFilePath;
117
-				if (class_exists($class)){
117
+				if (class_exists($class)) {
118 118
 					$c = new $class();
119 119
 					$obj = & get_instance();
120 120
 					$obj->{$instance} = $c;
121 121
 					static::$loaded[$instance] = $class;
122 122
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123 123
 				}
124
-				else{
125
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
124
+				else {
125
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
126 126
 				}
127 127
 			}
128
-			else{
128
+			else {
129 129
 				show_error('Unable to find the model [' . $class . ']');
130 130
 			}
131 131
 		}
@@ -140,22 +140,22 @@  discard block
 block discarded – undo
140 140
 		 *
141 141
 		 * @return void
142 142
 		 */
143
-		public static function library($class, $instance = null, array $params = array()){
143
+		public static function library($class, $instance = null, array $params = array()) {
144 144
 			$logger = static::getLogger();
145 145
 			$class = str_ireplace('.php', '', $class);
146 146
 			$class = trim($class, '/\\');
147
-			$file = ucfirst($class) .'.php';
147
+			$file = ucfirst($class) . '.php';
148 148
 			$logger->debug('Loading library [' . $class . '] ...');
149
-			if (! $instance){
149
+			if (!$instance) {
150 150
 				$instance = self::getModelLibraryInstanceName($class);
151 151
 			}
152
-			if (isset(static::$loaded[$instance])){
152
+			if (isset(static::$loaded[$instance])) {
153 153
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
154 154
 				return;
155 155
 			}
156 156
 			$obj = & get_instance();
157 157
 			//Check and load Database library
158
-			if (strtolower($class) == 'database'){
158
+			if (strtolower($class) == 'database') {
159 159
 				$logger->info('This is the Database library ...');
160 160
 				$obj->{$instance} = & class_loader('Database', 'classes/database', $params);
161 161
 				static::$loaded[$instance] = $class;
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 			}
165 165
 			$libraryFilePath = null;
166 166
 			$logger->debug('Check if this is a system library ...');
167
-			if (file_exists(CORE_LIBRARY_PATH . $file)){
167
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
168 168
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
169 169
 				$class = ucfirst($class);
170 170
 				$logger->info('This library is a system library');
171 171
 			}
172
-			else{
172
+			else {
173 173
 				$logger->info('This library is not a system library');	
174 174
 				//first check if this library is in the module
175 175
 				$libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
176 176
 				//***************
177 177
 			}
178
-			if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){
178
+			if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) {
179 179
 				$libraryFilePath = LIBRARY_PATH . $file;
180 180
 			}
181 181
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 		 *
191 191
 		 * @return void
192 192
 		 */
193
-		public static function functions($function){
193
+		public static function functions($function) {
194 194
 			$logger = static::getLogger();
195 195
 			$function = str_ireplace('.php', '', $function);
196 196
 			$function = trim($function, '/\\');
197 197
 			$function = str_ireplace('function_', '', $function);
198
-			$file = 'function_'.$function.'.php';
198
+			$file = 'function_' . $function . '.php';
199 199
 			$logger->debug('Loading helper [' . $function . '] ...');
200
-			if (isset(static::$loaded['function_' . $function])){
200
+			if (isset(static::$loaded['function_' . $function])) {
201 201
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
202 202
 				return;
203 203
 			}
@@ -207,22 +207,22 @@  discard block
 block discarded – undo
207 207
 			$moduleInfo = self::getModuleInfoForFunction($function);
208 208
 			$module    = $moduleInfo['module'];
209 209
 			$function  = $moduleInfo['function'];
210
-			if(! empty($moduleInfo['file'])){
210
+			if (!empty($moduleInfo['file'])) {
211 211
 				$file = $moduleInfo['file'];
212 212
 			}
213 213
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $module);
214
-			if ($moduleFunctionPath){
215
-				$logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
214
+			if ($moduleFunctionPath) {
215
+				$logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it');
216 216
 				$functionFilePath = $moduleFunctionPath;
217 217
 			}
218
-			else{
218
+			else {
219 219
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220 220
 			}
221
-			if (! $functionFilePath){
221
+			if (!$functionFilePath) {
222 222
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
223
-				foreach($searchDir as $dir){
223
+				foreach ($searchDir as $dir) {
224 224
 					$filePath = $dir . $file;
225
-					if (file_exists($filePath)){
225
+					if (file_exists($filePath)) {
226 226
 						$functionFilePath = $filePath;
227 227
 						//is already found not to continue
228 228
 						break;
@@ -230,12 +230,12 @@  discard block
 block discarded – undo
230 230
 				}
231 231
 			}
232 232
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
233
-			if ($functionFilePath){
233
+			if ($functionFilePath) {
234 234
 				require_once $functionFilePath;
235 235
 				static::$loaded['function_' . $function] = $functionFilePath;
236 236
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237 237
 			}
238
-			else{
238
+			else {
239 239
 				show_error('Unable to find helper file [' . $file . ']');
240 240
 			}
241 241
 		}
@@ -247,14 +247,14 @@  discard block
 block discarded – undo
247 247
 		 *
248 248
 		 * @return void
249 249
 		 */
250
-		public static function config($filename){
250
+		public static function config($filename) {
251 251
 			$logger = static::getLogger();
252 252
 			$filename = str_ireplace('.php', '', $filename);
253 253
 			$filename = trim($filename, '/\\');
254 254
 			$filename = str_ireplace('config_', '', $filename);
255
-			$file = 'config_'.$filename.'.php';
255
+			$file = 'config_' . $filename . '.php';
256 256
 			$logger->debug('Loading configuration [' . $filename . '] ...');
257
-			if (isset(static::$loaded['config_' . $filename])){
257
+			if (isset(static::$loaded['config_' . $filename])) {
258 258
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
259 259
 				return;
260 260
 			}
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 			$module    = $moduleInfo['module'];
266 266
 			$filename  = $moduleInfo['filename'];
267 267
 			$moduleConfigPath = Module::findConfigFullPath($filename, $module);
268
-			if ($moduleConfigPath){
269
-				$logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
268
+			if ($moduleConfigPath) {
269
+				$logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it');
270 270
 				$configFilePath = $moduleConfigPath;
271 271
 			}
272
-			else{
272
+			else {
273 273
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274 274
 			}
275 275
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
276 276
 			$config = array();
277
-			if (file_exists($configFilePath)){
277
+			if (file_exists($configFilePath)) {
278 278
 				require_once $configFilePath;
279
-				if (! empty($config) && is_array($config)){
279
+				if (!empty($config) && is_array($config)) {
280 280
 					Config::setAll($config);
281 281
 					static::$loaded['config_' . $filename] = $configFilePath;
282 282
 					$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 					unset($config);
285 285
 				}
286 286
 			}
287
-			else{
288
-				show_error('Unable to find config file ['. $configFilePath . ']');
287
+			else {
288
+				show_error('Unable to find config file [' . $configFilePath . ']');
289 289
 			}
290 290
 		}
291 291
 
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
 		 *
298 298
 		 * @return void
299 299
 		 */
300
-		public static function lang($language){
300
+		public static function lang($language) {
301 301
 			$logger = static::getLogger();
302 302
 			$language = str_ireplace('.php', '', $language);
303 303
 			$language = trim($language, '/\\');
304 304
 			$language = str_ireplace('lang_', '', $language);
305
-			$file = 'lang_'.$language.'.php';
305
+			$file = 'lang_' . $language . '.php';
306 306
 			$logger->debug('Loading language [' . $language . '] ...');
307
-			if (isset(static::$loaded['lang_' . $language])){
307
+			if (isset(static::$loaded['lang_' . $language])) {
308 308
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
309 309
 				return;
310 310
 			}
@@ -316,22 +316,22 @@  discard block
 block discarded – undo
316 316
 			$moduleInfo = self::getModuleInfoForLanguage($language);
317 317
 			$module    = $moduleInfo['module'];
318 318
 			$language  = $moduleInfo['language'];
319
-			if(! empty($moduleInfo['file'])){
319
+			if (!empty($moduleInfo['file'])) {
320 320
 				$file = $moduleInfo['file'];
321 321
 			}
322 322
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang);
323
-			if ($moduleLanguagePath){
324
-				$logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
323
+			if ($moduleLanguagePath) {
324
+				$logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it');
325 325
 				$languageFilePath = $moduleLanguagePath;
326 326
 			}
327
-			else{
327
+			else {
328 328
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
329 329
 			}
330
-			if (! $languageFilePath){
330
+			if (!$languageFilePath) {
331 331
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
332
-				foreach($searchDir as $dir){
332
+				foreach ($searchDir as $dir) {
333 333
 					$filePath = $dir . $appLang . DS . $file;
334
-					if (file_exists($filePath)){
334
+					if (file_exists($filePath)) {
335 335
 						$languageFilePath = $filePath;
336 336
 						//already found no need continue
337 337
 						break;
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
 		 * if can not found will use the default value from configuration
348 348
 		 * @return string the app language like "en", "fr"
349 349
 		 */
350
-		protected static function getAppLang(){
350
+		protected static function getAppLang() {
351 351
 			//determine the current language
352 352
 			$appLang = get_config('default_language');
353 353
 			//if the language exists in the cookie use it
354 354
 			$cfgKey = get_config('language_cookie_name');
355 355
 			$objCookie = & class_loader('Cookie');
356 356
 			$cookieLang = $objCookie->get($cfgKey);
357
-			if ($cookieLang){
357
+			if ($cookieLang) {
358 358
 				$appLang = $cookieLang;
359 359
 			}
360 360
 			return $appLang;
@@ -368,20 +368,20 @@  discard block
 block discarded – undo
368 368
 		 * 	'class' => 'class_name'
369 369
 		 * )
370 370
 		 */
371
-		protected static function getModuleInfoForModelLibrary($class){
371
+		protected static function getModuleInfoForModelLibrary($class) {
372 372
 			$module = null;
373 373
 			$obj = & get_instance();
374
-			if (strpos($class, '/') !== false){
374
+			if (strpos($class, '/') !== false) {
375 375
 				$path = explode('/', $class);
376
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
376
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
377 377
 					$module = $path[0];
378 378
 					$class = ucfirst($path[1]);
379 379
 				}
380 380
 			}
381
-			else{
381
+			else {
382 382
 				$class = ucfirst($class);
383 383
 			}
384
-			if (! $module && !empty($obj->moduleName)){
384
+			if (!$module && !empty($obj->moduleName)) {
385 385
 				$module = $obj->moduleName;
386 386
 			}
387 387
 			return array(
@@ -400,20 +400,20 @@  discard block
 block discarded – undo
400 400
 		 * 	'file' => 'file'
401 401
 		 * )
402 402
 		 */
403
-		protected static function getModuleInfoForFunction($function){
403
+		protected static function getModuleInfoForFunction($function) {
404 404
 			$module = null;
405 405
 			$file = null;
406 406
 			$obj = & get_instance();
407 407
 			//check if the request class contains module name
408
-			if (strpos($function, '/') !== false){
408
+			if (strpos($function, '/') !== false) {
409 409
 				$path = explode('/', $function);
410
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
410
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
411 411
 					$module = $path[0];
412 412
 					$function = 'function_' . $path[1];
413
-					$file = $path[0] . DS . $function.'.php';
413
+					$file = $path[0] . DS . $function . '.php';
414 414
 				}
415 415
 			}
416
-			if (! $module && !empty($obj->moduleName)){
416
+			if (!$module && !empty($obj->moduleName)) {
417 417
 				$module = $obj->moduleName;
418 418
 			}
419 419
 			return array(
@@ -433,20 +433,20 @@  discard block
 block discarded – undo
433 433
 		 * 	'file' => 'file'
434 434
 		 * )
435 435
 		 */
436
-		protected static function getModuleInfoForLanguage($language){
436
+		protected static function getModuleInfoForLanguage($language) {
437 437
 			$module = null;
438 438
 			$file = null;
439 439
 			$obj = & get_instance();
440 440
 			//check if the request class contains module name
441
-			if (strpos($language, '/') !== false){
441
+			if (strpos($language, '/') !== false) {
442 442
 				$path = explode('/', $language);
443
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
443
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
444 444
 					$module = $path[0];
445 445
 					$language = 'lang_' . $path[1] . '.php';
446
-					$file = $path[0] . DS .$language;
446
+					$file = $path[0] . DS . $language;
447 447
 				}
448 448
 			}
449
-			if (! $module && !empty($obj->moduleName)){
449
+			if (!$module && !empty($obj->moduleName)) {
450 450
 				$module = $obj->moduleName;
451 451
 			}
452 452
 			return array(
@@ -466,18 +466,18 @@  discard block
 block discarded – undo
466 466
 		 * 	'filename' => 'filename'
467 467
 		 * )
468 468
 		 */
469
-		protected static function getModuleInfoForConfig($filename){
469
+		protected static function getModuleInfoForConfig($filename) {
470 470
 			$module = null;
471 471
 			$obj = & get_instance();
472 472
 			//check if the request class contains module name
473
-			if (strpos($filename, '/') !== false){
473
+			if (strpos($filename, '/') !== false) {
474 474
 				$path = explode('/', $filename);
475
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
475
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
476 476
 					$module = $path[0];
477 477
 					$filename = $path[1] . '.php';
478 478
 				}
479 479
 			}
480
-			if (! $module && !empty($obj->moduleName)){
480
+			if (!$module && !empty($obj->moduleName)) {
481 481
 				$module = $obj->moduleName;
482 482
 			}
483 483
 			return array(
@@ -491,16 +491,16 @@  discard block
 block discarded – undo
491 491
 		 * @param  string $class the class name to determine the instance
492 492
 		 * @return string        the instance name
493 493
 		 */
494
-		protected static function getModelLibraryInstanceName($class){
494
+		protected static function getModelLibraryInstanceName($class) {
495 495
 			//for module
496 496
 			$instance = null;
497
-			if (strpos($class, '/') !== false){
497
+			if (strpos($class, '/') !== false) {
498 498
 				$path = explode('/', $class);
499
-				if (isset($path[1])){
499
+				if (isset($path[1])) {
500 500
 					$instance = strtolower($path[1]);
501 501
 				}
502 502
 			}
503
-			else{
503
+			else {
504 504
 				$instance = strtolower($class);
505 505
 			}
506 506
 			return $instance;
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		 * @param  string $class the class name
512 512
 		 * @return string|null        the library file path otherwise null will be returned
513 513
 		 */
514
-		protected static function getLibraryPathUsingModuleInfo($class){
514
+		protected static function getLibraryPathUsingModuleInfo($class) {
515 515
 			$logger = static::getLogger();
516 516
 			$libraryFilePath = null;
517 517
 			$logger->debug('Checking library [' . $class . '] from module list ...');
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
 			$module = $moduleInfo['module'];
520 520
 			$class  = $moduleInfo['class'];
521 521
 			$moduleLibraryPath = Module::findLibraryFullPath($class, $module);
522
-			if ($moduleLibraryPath){
523
-				$logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
522
+			if ($moduleLibraryPath) {
523
+				$logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it');
524 524
 				$libraryFilePath = $moduleLibraryPath;
525 525
 			}
526
-			else{
526
+			else {
527 527
 				$logger->info('Cannot find library [' . $class . '] from modules using the default location');
528 528
 			}
529 529
 			return $libraryFilePath;
@@ -537,22 +537,22 @@  discard block
 block discarded – undo
537 537
 		 * @param  array  $params          the parameter to use
538 538
 		 * @return void
539 539
 		 */
540
-		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){
541
-			if ($libraryFilePath){
540
+		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) {
541
+			if ($libraryFilePath) {
542 542
 				$logger = static::getLogger();
543 543
 				require_once $libraryFilePath;
544
-				if (class_exists($class)){
544
+				if (class_exists($class)) {
545 545
 					$c = $params ? new $class($params) : new $class();
546 546
 					$obj = & get_instance();
547 547
 					$obj->{$instance} = $c;
548 548
 					static::$loaded[$instance] = $class;
549 549
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550 550
 				}
551
-				else{
552
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
551
+				else {
552
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
553 553
 				}
554 554
 			}
555
-			else{
555
+			else {
556 556
 				show_error('Unable to find library class [' . $class . ']');
557 557
 			}
558 558
 		}
@@ -563,15 +563,15 @@  discard block
 block discarded – undo
563 563
 		 * @param  string $language           the language name
564 564
 		 * @return void
565 565
 		 */
566
-		protected static function loadLanguage($languageFilePath, $language){
567
-			if ($languageFilePath){
566
+		protected static function loadLanguage($languageFilePath, $language) {
567
+			if ($languageFilePath) {
568 568
 				$logger = static::getLogger();
569 569
 				$lang = array();
570 570
 				require_once $languageFilePath;
571
-				if (! empty($lang) && is_array($lang)){
572
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
571
+				if (!empty($lang) && is_array($lang)) {
572
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
573 573
 					//Note: may be here the class 'Lang' not yet loaded
574
-					$langObj =& class_loader('Lang', 'classes');
574
+					$langObj = & class_loader('Lang', 'classes');
575 575
 					$langObj->addLangMessages($lang);
576 576
 					//free the memory
577 577
 					unset($lang);
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 				static::$loaded['lang_' . $language] = $languageFilePath;
580 580
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581 581
 			}
582
-			else{
582
+			else {
583 583
 				show_error('Unable to find language [' . $language . ']');
584 584
 			}
585 585
 		}
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 		 * Get all the autoload using the configuration file
589 589
 		 * @return array
590 590
 		 */
591
-		private function getResourcesFromAutoloadConfig(){
591
+		private function getResourcesFromAutoloadConfig() {
592 592
 			$autoloads = array();
593 593
 			$autoloads['config']    = array();
594 594
 			$autoloads['languages'] = array();
@@ -596,17 +596,17 @@  discard block
 block discarded – undo
596 596
 			$autoloads['models']    = array();
597 597
 			$autoloads['functions'] = array();
598 598
 			//loading of the resources from autoload configuration file
599
-			if (file_exists(CONFIG_PATH . 'autoload.php')){
599
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
600 600
 				$autoload = array();
601 601
 				require_once CONFIG_PATH . 'autoload.php';
602
-				if (! empty($autoload) && is_array($autoload)){
602
+				if (!empty($autoload) && is_array($autoload)) {
603 603
 					$autoloads = array_merge($autoloads, $autoload);
604 604
 					unset($autoload);
605 605
 				}
606 606
 			}
607 607
 			//loading autoload configuration for modules
608 608
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
609
-			if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){
609
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
610 610
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
611 611
 			}
612 612
 			return $autoloads;
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 		 * Load the autoload configuration
617 617
 		 * @return void
618 618
 		 */
619
-		private function loadResourcesFromAutoloadConfig(){
619
+		private function loadResourcesFromAutoloadConfig() {
620 620
 			$autoloads = array();
621 621
 			$autoloads['config']    = array();
622 622
 			$autoloads['languages'] = array();
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 		 * @param  array  $resources the resource to load
650 650
 		 * @return void            
651 651
 		 */
652
-		private function loadAutoloadResourcesArray($method, array $resources){
652
+		private function loadAutoloadResourcesArray($method, array $resources) {
653 653
 			foreach ($resources as $name) {
654 654
 				$this->{$method}($name);
655 655
 			}
Please login to merge, or discard this patch.