Passed
Push — 1.0.0-dev ( 9c9ab7...066288 )
by nguereza
02:38
created
index.php 1 patch
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -1,267 +1,267 @@
 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
-	/**
27
-	* the directory separator, under windows it is \ and unix, linux /
28
-	*/
29
-	define('DS', DIRECTORY_SEPARATOR);
26
+    /**
27
+     * the directory separator, under windows it is \ and unix, linux /
28
+     */
29
+    define('DS', DIRECTORY_SEPARATOR);
30 30
 
31
-	/**
32
-	* The root directory of the application.
33
-	*
34
-	* you can place this directory outside of your web directory, for example "/home/your_app", etc.
35
-	*/
36
-	define('ROOT_PATH', dirname(realpath(__FILE__)) . DS);
31
+    /**
32
+     * The root directory of the application.
33
+     *
34
+     * you can place this directory outside of your web directory, for example "/home/your_app", etc.
35
+     */
36
+    define('ROOT_PATH', dirname(realpath(__FILE__)) . DS);
37 37
 
38
-	/**
39
-	* The path to the directory.
40
-	*
41
-	* That contains your static files (javascript, css, images, etc.)
42
-	* Note: the path must be relative to the file index.php (the front-end controller).
43
-	*/
44
-	define('ASSETS_PATH', 'assets/');
38
+    /**
39
+     * The path to the directory.
40
+     *
41
+     * That contains your static files (javascript, css, images, etc.)
42
+     * Note: the path must be relative to the file index.php (the front-end controller).
43
+     */
44
+    define('ASSETS_PATH', 'assets/');
45 45
 
46
-	/**
47
-	* The path to the directory of your cache files.
48
-	*
49
-	* This feature is available currently for database and views.
50
-	*/
51
-	define('CACHE_PATH', ROOT_PATH . 'cache' . DS);
46
+    /**
47
+     * The path to the directory of your cache files.
48
+     *
49
+     * This feature is available currently for database and views.
50
+     */
51
+    define('CACHE_PATH', ROOT_PATH . 'cache' . DS);
52 52
 
53
-	/**
54
-	* The path to the application directory. 
55
-	*
56
-	* It contains your most often used files that is to say which contains your files of the application, 
57
-	* in MVC architecture (controllers, models, views).
58
-	*/
59
-	define('APPS_PATH', ROOT_PATH . 'classes' . DS);
53
+    /**
54
+     * The path to the application directory. 
55
+     *
56
+     * It contains your most often used files that is to say which contains your files of the application, 
57
+     * in MVC architecture (controllers, models, views).
58
+     */
59
+    define('APPS_PATH', ROOT_PATH . 'classes' . DS);
60 60
 
61
-	/**
62
-	* The path to the controller directory of your application.
63
-	*
64
-	* If you already know the MVC architecture you know what a controller means; 
65
-	* it is he who makes the business logic of your application in general.
66
-	*/
67
-	define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS);
61
+    /**
62
+     * The path to the controller directory of your application.
63
+     *
64
+     * If you already know the MVC architecture you know what a controller means; 
65
+     * it is he who makes the business logic of your application in general.
66
+     */
67
+    define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS);
68 68
 
69
-	/**
70
-	* The path to the directory of your model classes of your application. 
71
-	*
72
-	* If you already know the MVC architecture you know what a model means; 
73
-	* it's the one who interacts with the database, in one word persistent data from your application.
74
-	*/
75
-	define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS);
69
+    /**
70
+     * The path to the directory of your model classes of your application. 
71
+     *
72
+     * If you already know the MVC architecture you know what a model means; 
73
+     * it's the one who interacts with the database, in one word persistent data from your application.
74
+     */
75
+    define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS);
76 76
 
77
-	/**
78
-	* The path to the directory of your views.
79
-	*
80
-	* If you already know the MVC architecture you know what a view means, 
81
-	* a view is just a user interface (html page, form, etc.) that is to say 
82
-	* everything displayed in the browser interface, etc.
83
-	*/
84
-	define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS);
77
+    /**
78
+     * The path to the directory of your views.
79
+     *
80
+     * If you already know the MVC architecture you know what a view means, 
81
+     * a view is just a user interface (html page, form, etc.) that is to say 
82
+     * everything displayed in the browser interface, etc.
83
+     */
84
+    define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS);
85 85
 
86
-	/**
87
-	* The path to the configuration directory.
88
-	*
89
-	* That contains most of the configuration files for your 
90
-	* application (database, class loading file, functions, etc.)
91
-	*/
92
-	define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
86
+    /**
87
+     * The path to the configuration directory.
88
+     *
89
+     * That contains most of the configuration files for your 
90
+     * application (database, class loading file, functions, etc.)
91
+     */
92
+    define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
93 93
 
94
-	/** 
95
-	* The core directory
96
-	*
97
-	* It is recommended to put this folder out of the web directory of your server and 
98
-	* you should not change its content because in case of update you could lose the modified files.
99
-	*/
100
-	define('CORE_PATH', ROOT_PATH . 'core' . DS);
94
+    /** 
95
+     * The core directory
96
+     *
97
+     * It is recommended to put this folder out of the web directory of your server and 
98
+     * you should not change its content because in case of update you could lose the modified files.
99
+     */
100
+    define('CORE_PATH', ROOT_PATH . 'core' . DS);
101 101
 	
102
-	/**
103
-	* The path to the directory of core classes that used by the system.
104
-	*
105
-	* It contains PHP classes that are used by the framework internally.
106
-	*/
107
-	define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS);
102
+    /**
103
+     * The path to the directory of core classes that used by the system.
104
+     *
105
+     * It contains PHP classes that are used by the framework internally.
106
+     */
107
+    define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS);
108 108
 	
109
-	/**
110
-	* The path to the directory of core classes for the cache used by the system.
111
-	*
112
-	* It contains PHP classes for the cache drivers.
113
-	*/
114
-	define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS);
109
+    /**
110
+     * The path to the directory of core classes for the cache used by the system.
111
+     *
112
+     * It contains PHP classes for the cache drivers.
113
+     */
114
+    define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS);
115 115
 	
116 116
     /**
117
-	* The path to the directory of core classes for the database used by the system.
118
-	*
119
-	* It contains PHP classes for the database library, drivers, etc.
120
-	*/
121
-	define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS);
117
+     * The path to the directory of core classes for the database used by the system.
118
+     *
119
+     * It contains PHP classes for the database library, drivers, etc.
120
+     */
121
+    define('CORE_CLASSES_DATABASE_PATH', CORE_CLASSES_PATH . 'database' . DS);
122 122
     
123
-	/**
124
-	* The path to the directory of core classes for the model used by the system.
125
-	*
126
-	* It contains PHP classes for the models.
127
-	*/
128
-	define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS);
123
+    /**
124
+     * The path to the directory of core classes for the model used by the system.
125
+     *
126
+     * It contains PHP classes for the models.
127
+     */
128
+    define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS);
129 129
 
130
-	/**
131
-	* The path to the directory of functions or helper systems.
132
-	*
133
-	* It contains PHP functions that perform a particular task: character string processing, URL, etc.
134
-	*/
135
-	define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS);
130
+    /**
131
+     * The path to the directory of functions or helper systems.
132
+     *
133
+     * It contains PHP functions that perform a particular task: character string processing, URL, etc.
134
+     */
135
+    define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS);
136 136
 
137
-	/**
138
-	* The path to the core directory of languages files. 
139
-	*
140
-	*/
141
-	define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS);
137
+    /**
138
+     * The path to the core directory of languages files. 
139
+     *
140
+     */
141
+    define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS);
142 142
 
143
-	/**
144
-	* The path to the system library directory.
145
-	*
146
-	* Which contains the libraries most often used in your web application, as for the 
147
-	* core directory it is advisable to put it out of the root directory of your application.
148
-	*/
149
-	define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS);
143
+    /**
144
+     * The path to the system library directory.
145
+     *
146
+     * Which contains the libraries most often used in your web application, as for the 
147
+     * core directory it is advisable to put it out of the root directory of your application.
148
+     */
149
+    define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS);
150 150
 
151
-	/**
152
-	* The path to the system view directory.
153
-	*
154
-	* That contains the views used for the system, such as error messages, and so on.
155
-	*/
156
-	define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS);
151
+    /**
152
+     * The path to the system view directory.
153
+     *
154
+     * That contains the views used for the system, such as error messages, and so on.
155
+     */
156
+    define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS);
157 157
 	
158
-	/**
159
-	* The path to the directory of your PHP personal functions or helper.
160
-	*
161
-	* It contains your PHP functions that perform a particular task: utilities, etc.
162
-	* Note: Do not put your personal functions or helpers in the system functions directory, 
163
-	* because if you update the system you may lose them.
164
-	*/
165
-	define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS);
158
+    /**
159
+     * The path to the directory of your PHP personal functions or helper.
160
+     *
161
+     * It contains your PHP functions that perform a particular task: utilities, etc.
162
+     * Note: Do not put your personal functions or helpers in the system functions directory, 
163
+     * because if you update the system you may lose them.
164
+     */
165
+    define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS);
166 166
 
167
-	/**
168
-	* The path to the app directory of personal language. 
169
-	*
170
-	* This feature is not yet available. 
171
-	* You can help us do this if you are nice or wish to see the developed framework.
172
-	*/
173
-	define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS);
167
+    /**
168
+     * The path to the app directory of personal language. 
169
+     *
170
+     * This feature is not yet available. 
171
+     * You can help us do this if you are nice or wish to see the developed framework.
172
+     */
173
+    define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS);
174 174
 
175
-	/**
176
-	* The path to the directory of your personal libraries
177
-	*
178
-	* It contains your PHP classes, package, etc.
179
-	* Note: you should not put your personal libraries in the system library directory, 
180
-	* because it is recalled in case of updating the system you might have surprises.
181
-	*/
182
-	define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS);
175
+    /**
176
+     * The path to the directory of your personal libraries
177
+     *
178
+     * It contains your PHP classes, package, etc.
179
+     * Note: you should not put your personal libraries in the system library directory, 
180
+     * because it is recalled in case of updating the system you might have surprises.
181
+     */
182
+    define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS);
183 183
 
184
-	/**
185
-	* The path to the directory that contains the log files.
186
-	*
187
-	* Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
188
-	* under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
189
-	* details see the documentation of your web server.
190
-	* Example for Unix or linux with apache web server:
191
-	* # chmod -R 700 /path/to/your/logs/directory/
192
-	* # chown -R www-data:www-data /path/to/your/logs/directory/
193
-	*/
194
-	define('LOGS_PATH', ROOT_PATH . 'logs' . DS);
184
+    /**
185
+     * The path to the directory that contains the log files.
186
+     *
187
+     * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, 
188
+     * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more
189
+     * details see the documentation of your web server.
190
+     * Example for Unix or linux with apache web server:
191
+     * # chmod -R 700 /path/to/your/logs/directory/
192
+     * # chown -R www-data:www-data /path/to/your/logs/directory/
193
+     */
194
+    define('LOGS_PATH', ROOT_PATH . 'logs' . DS);
195 195
 
196
-	/**
197
-	* The path to the modules directory. 
198
-	*
199
-	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
200
-	* in HMVC architecture (hierichical, controllers, models, views).
201
-	*/
202
-	define('MODULE_PATH', ROOT_PATH . 'modules' . DS);
196
+    /**
197
+     * The path to the modules directory. 
198
+     *
199
+     * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
200
+     * in HMVC architecture (hierichical, controllers, models, views).
201
+     */
202
+    define('MODULE_PATH', ROOT_PATH . 'modules' . DS);
203 203
 
204
-	/**
205
-	* The path to the directory of sources external to your application.
206
-	*
207
-	* If you have already used "composer" you know what that means.
208
-	*/
209
-	define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
204
+    /**
205
+     * The path to the directory of sources external to your application.
206
+     *
207
+     * If you have already used "composer" you know what that means.
208
+     */
209
+    define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
210 210
 
211
-	/**
212
-	* The front controller of your application.
213
-	*
214
-	* "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
215
-	* your application by using the rewrite module URL of your web server .
216
-	* For example, under apache web server, there is a configuration example file that is located at the root 
217
-	* of your framework folder : "htaccess.txt" rename it to ".htaccess".
218
-	*/
219
-	define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
211
+    /**
212
+     * The front controller of your application.
213
+     *
214
+     * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of 
215
+     * your application by using the rewrite module URL of your web server .
216
+     * For example, under apache web server, there is a configuration example file that is located at the root 
217
+     * of your framework folder : "htaccess.txt" rename it to ".htaccess".
218
+     */
219
+    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
220 220
 	
221
-	/**
222
-	 * Check if user run the application under CLI
223
-	 */
224
-	define('IS_CLI', stripos('cli', php_sapi_name()) !== false);
221
+    /**
222
+     * Check if user run the application under CLI
223
+     */
224
+    define('IS_CLI', stripos('cli', php_sapi_name()) !== false);
225 225
 
226
-	/**
227
-	* The environment of your application (production, test, development). 
228
-	*
229
-	* if your application is still in development you use the value "development" 
230
-	* so you will have the display of the error messages, etc. 
231
-	* Once you finish the development of your application that is to put it online 
232
-	* you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
233
-	* the loading of the system, will be fast.
234
-	*/
235
-	define('ENVIRONMENT', 'development');
226
+    /**
227
+     * The environment of your application (production, test, development). 
228
+     *
229
+     * if your application is still in development you use the value "development" 
230
+     * so you will have the display of the error messages, etc. 
231
+     * Once you finish the development of your application that is to put it online 
232
+     * you change this value to "production" or "testing", in this case there will be deactivation of error messages, 
233
+     * the loading of the system, will be fast.
234
+     */
235
+    define('ENVIRONMENT', 'development');
236 236
 
237
-	/* ---------------------------------------------------------------------------------- */
238
-	///////////////////////////////////////////////////////////////////////////////////////
239
-	/******************** DO NOT CHANGE THE LINES BELOW *********************************/
240
-	/////////////////////////////////////////////////////////////////////////////////////
237
+    /* ---------------------------------------------------------------------------------- */
238
+    ///////////////////////////////////////////////////////////////////////////////////////
239
+    /******************** DO NOT CHANGE THE LINES BELOW *********************************/
240
+    /////////////////////////////////////////////////////////////////////////////////////
241 241
 
242
-	switch (ENVIRONMENT) {
243
-		case 'development':
244
-			error_reporting(-1);
245
-			ini_set('display_errors', 1);
246
-		break;
247
-		case 'testing':
248
-		case 'production':
249
-			ini_set('display_errors', 0);
250
-			if (version_compare(PHP_VERSION, '5.3', '>=')) {
251
-				error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
252
-			}
253
-			else{
254
-				error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
255
-			}
256
-		break;
257
-		default:
258
-			header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
259
-			echo 'The application environment is not set correctly.';
260
-			exit(1);
261
-	}
242
+    switch (ENVIRONMENT) {
243
+        case 'development':
244
+            error_reporting(-1);
245
+            ini_set('display_errors', 1);
246
+        break;
247
+        case 'testing':
248
+        case 'production':
249
+            ini_set('display_errors', 0);
250
+            if (version_compare(PHP_VERSION, '5.3', '>=')) {
251
+                error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
252
+            }
253
+            else{
254
+                error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
255
+            }
256
+        break;
257
+        default:
258
+            header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
259
+            echo 'The application environment is not set correctly.';
260
+            exit(1);
261
+    }
262 262
 	
263
-	/**
264
-	* let's go.
265
-	* Everything is OK now we launch our application.
266
-	*/
267
-	require_once CORE_PATH . 'bootstrap.php';
268 263
\ No newline at end of file
264
+    /**
265
+     * let's go.
266
+     * Everything is OK now we launch our application.
267
+     */
268
+    require_once CORE_PATH . 'bootstrap.php';
269 269
\ No newline at end of file
Please login to merge, or discard this patch.
core/classes/database/Database.php 1 patch
Indentation   +356 added lines, -356 removed lines patch added patch discarded remove patch
@@ -1,119 +1,119 @@  discard block
 block discarded – undo
1 1
 <?php
2 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 Database{
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 Database{
27 27
 	
28
-  	/**
29
-  	 * The PDO instance
30
-  	 * @var object
31
-  	*/
28
+        /**
29
+         * The PDO instance
30
+         * @var object
31
+         */
32 32
     private $pdo                 = null;
33 33
     
34
-  	/**
35
-  	 * The database name used for the application
36
-  	 * @var string
37
-  	*/
38
-	  private $databaseName        = null;
34
+        /**
35
+         * The database name used for the application
36
+         * @var string
37
+         */
38
+        private $databaseName        = null;
39 39
 	
40
-  	/**
41
-  	 * The number of rows returned by the last query
42
-  	 * @var int
43
-  	*/
40
+        /**
41
+         * The number of rows returned by the last query
42
+         * @var int
43
+         */
44 44
     private $numRows             = 0;
45 45
 	
46
-  	/**
47
-  	 * The last insert id for the primary key column that have auto increment or sequence
48
-  	 * @var mixed
49
-  	*/
46
+        /**
47
+         * The last insert id for the primary key column that have auto increment or sequence
48
+         * @var mixed
49
+         */
50 50
     private $insertId            = null;
51 51
 	
52
-  	/**
53
-  	 * The full SQL query statment after build for each command
54
-  	 * @var string
55
-  	*/
52
+        /**
53
+         * The full SQL query statment after build for each command
54
+         * @var string
55
+         */
56 56
     private $query               = null;
57 57
 	
58
-  	/**
59
-  	 * The result returned for the last query
60
-  	 * @var mixed
61
-  	*/
58
+        /**
59
+         * The result returned for the last query
60
+         * @var mixed
61
+         */
62 62
     private $result              = array();
63 63
 	
64
-  	/**
65
-  	 * The cache default time to live in second. 0 means no need to use the cache feature
66
-  	 * @var int
67
-  	*/
68
-  	private $cacheTtl             = 0;
64
+        /**
65
+         * The cache default time to live in second. 0 means no need to use the cache feature
66
+         * @var int
67
+         */
68
+        private $cacheTtl             = 0;
69 69
 	
70
-  	/**
71
-  	 * The cache current time to live. 0 means no need to use the cache feature
72
-  	 * @var int
73
-  	*/
70
+        /**
71
+         * The cache current time to live. 0 means no need to use the cache feature
72
+         * @var int
73
+         */
74 74
     private $temporaryCacheTtl   = 0;
75 75
 	
76
-  	/**
77
-  	 * The number of executed query for the current request
78
-  	 * @var int
79
-  	*/
76
+        /**
77
+         * The number of executed query for the current request
78
+         * @var int
79
+         */
80 80
     private $queryCount          = 0;
81 81
 	
82
-  	/**
83
-  	 * The default data to be used in the statments query INSERT, UPDATE
84
-  	 * @var array
85
-  	*/
82
+        /**
83
+         * The default data to be used in the statments query INSERT, UPDATE
84
+         * @var array
85
+         */
86 86
     private $data                = array();
87 87
 	
88
-  	/**
89
-  	 * The database configuration
90
-  	 * @var array
91
-  	*/
88
+        /**
89
+         * The database configuration
90
+         * @var array
91
+         */
92 92
     private $config              = array();
93 93
 	
94
-  	/**
95
-  	 * The logger instance
96
-  	 * @var object
97
-  	 */
94
+        /**
95
+         * The logger instance
96
+         * @var object
97
+         */
98 98
     private $logger              = null;
99 99
 
100 100
     /**
101
-    * The cache instance
102
-    * @var object
103
-    */
101
+     * The cache instance
102
+     * @var object
103
+     */
104 104
     private $cacheInstance       = null;
105 105
 
106 106
     
107
-  	/**
108
-    * The DatabaseQueryBuilder instance
109
-    * @var object
110
-    */
107
+        /**
108
+         * The DatabaseQueryBuilder instance
109
+         * @var object
110
+         */
111 111
     private $queryBuilder        = null;
112 112
     
113 113
     /**
114
-    * The DatabaseQueryRunner instance
115
-    * @var object
116
-    */
114
+     * The DatabaseQueryRunner instance
115
+     * @var object
116
+     */
117 117
     private $queryRunner         = null;
118 118
 
119 119
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         //Set Log instance to use
127 127
         $this->setLoggerFromParamOrCreate(null);
128 128
 		
129
-    		//Set DatabaseQueryBuilder instance to use
129
+            //Set DatabaseQueryBuilder instance to use
130 130
         $this->setDependencyInstanceFromParamOrCreate('queryBuilder', null, 'DatabaseQueryBuilder', 'classes/database');
131 131
        
132 132
         //Set DatabaseQueryRunner instance to use
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
      * @return bool 
145 145
      */
146 146
     public function connect(){
147
-      $config = $this->getDatabaseConfiguration();
148
-      if (! empty($config)){
147
+        $config = $this->getDatabaseConfiguration();
148
+        if (! empty($config)){
149 149
         try{
150 150
             $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']);
151 151
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
@@ -156,14 +156,14 @@  discard block
 block discarded – undo
156 156
             $this->updateQueryBuilderAndRunnerProperties();
157 157
 
158 158
             return is_object($this->pdo);
159
-          }
160
-          catch (PDOException $e){
159
+            }
160
+            catch (PDOException $e){
161 161
             $this->logger->fatal($e->getMessage());
162 162
             show_error('Cannot connect to Database.');
163 163
             return false;
164
-          }
165
-      }
166
-      return false;
164
+            }
165
+        }
166
+        return false;
167 167
     }
168 168
 
169 169
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @return int
173 173
      */
174 174
     public function numRows(){
175
-      return $this->numRows;
175
+        return $this->numRows;
176 176
     }
177 177
 
178 178
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      * @return mixed
181 181
      */
182 182
     public function insertId(){
183
-      return $this->insertId;
183
+        return $this->insertId;
184 184
     }
185 185
 
186 186
 
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
      * @return mixed       the query SQL string or the record result
192 192
      */
193 193
     public function get($returnSQLQueryOrResultType = false){
194
-      $this->queryBuilder->limit(1);
195
-      $query = $this->getAll(true);
196
-      if ($returnSQLQueryOrResultType === true){
194
+        $this->queryBuilder->limit(1);
195
+        $query = $this->getAll(true);
196
+        if ($returnSQLQueryOrResultType === true){
197 197
         return $query;
198
-      } else {
198
+        } else {
199 199
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
200
-      }
200
+        }
201 201
     }
202 202
 
203 203
     /**
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
      * @return mixed       the query SQL string or the record result
208 208
      */
209 209
     public function getAll($returnSQLQueryOrResultType = false){
210
-	   $query = $this->queryBuilder->getQuery();
211
-	   if ($returnSQLQueryOrResultType === true){
212
-      	return $query;
213
-      }
214
-      return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
210
+        $query = $this->queryBuilder->getQuery();
211
+        if ($returnSQLQueryOrResultType === true){
212
+            return $query;
213
+        }
214
+        return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
215 215
     }
216 216
 
217 217
     /**
@@ -221,19 +221,19 @@  discard block
 block discarded – undo
221 221
      * @return mixed          the insert id of the new record or null
222 222
      */
223 223
     public function insert($data = array(), $escape = true){
224
-      if (empty($data) && ! empty($this->data)){
224
+        if (empty($data) && ! empty($this->data)){
225 225
         //as when using $this->setData() may be the data already escaped
226 226
         $escape = false;
227 227
         $data = $this->data;
228
-      }
229
-      $query = $this->queryBuilder->insert($data, $escape)->getQuery();
230
-      $result = $this->query($query);
231
-      if ($result){
228
+        }
229
+        $query = $this->queryBuilder->insert($data, $escape)->getQuery();
230
+        $result = $this->query($query);
231
+        if ($result){
232 232
         $this->insertId = $this->pdo->lastInsertId();
233
-		    //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
233
+            //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
234 234
         return ! ($this->insertId) ? true : $this->insertId;
235
-      }
236
-      return false;
235
+        }
236
+        return false;
237 237
     }
238 238
 
239 239
     /**
@@ -243,13 +243,13 @@  discard block
 block discarded – undo
243 243
      * @return mixed          the update status
244 244
      */
245 245
     public function update($data = array(), $escape = true){
246
-      if (empty($data) && ! empty($this->data)){
246
+        if (empty($data) && ! empty($this->data)){
247 247
         //as when using $this->setData() may be the data already escaped
248 248
         $escape = false;
249 249
         $data = $this->data;
250
-      }
251
-      $query = $this->queryBuilder->update($data, $escape)->getQuery();
252
-      return $this->query($query);
250
+        }
251
+        $query = $this->queryBuilder->update($data, $escape)->getQuery();
252
+        return $this->query($query);
253 253
     }
254 254
 
255 255
     /**
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
      * @return mixed the delete status
258 258
      */
259 259
     public function delete(){
260
-		  $query = $this->queryBuilder->delete()->getQuery();
261
-    	return $this->query($query);
260
+            $query = $this->queryBuilder->delete()->getQuery();
261
+        return $this->query($query);
262 262
     }
263 263
 
264 264
     /**
@@ -267,17 +267,17 @@  discard block
 block discarded – undo
267 267
      * @return object        the current Database instance
268 268
      */
269 269
     public function setCache($ttl = 0){
270
-      $this->cacheTtl = $ttl;
271
-      $this->temporaryCacheTtl = $ttl;
272
-      return $this;
270
+        $this->cacheTtl = $ttl;
271
+        $this->temporaryCacheTtl = $ttl;
272
+        return $this;
273 273
     }
274 274
 	
275
-	/**
276
-	 * Enabled cache temporary for the current query not globally	
277
-	 * @param  integer $ttl the cache time to live in second
278
-	 * @return object        the current Database instance
279
-	 */
280
-  	public function cached($ttl = 0){
275
+    /**
276
+     * Enabled cache temporary for the current query not globally	
277
+     * @param  integer $ttl the cache time to live in second
278
+     * @return object        the current Database instance
279
+     */
280
+        public function cached($ttl = 0){
281 281
         $this->temporaryCacheTtl = $ttl;
282 282
         return $this;
283 283
     }
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
      * need escaped
291 291
      */
292 292
     public function escape($data, $escaped = true){
293
-      $data = trim($data);
294
-      if($escaped){
293
+        $data = trim($data);
294
+        if($escaped){
295 295
         return $this->pdo->quote($data);
296
-      }
297
-      return $data; 
296
+        }
297
+        return $data; 
298 298
     }
299 299
 
300 300
     /**
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      * @return int
303 303
      */
304 304
     public function queryCount(){
305
-      return $this->queryCount;
305
+        return $this->queryCount;
306 306
     }
307 307
 
308 308
     /**
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      * @return string
311 311
      */
312 312
     public function getQuery(){
313
-      return $this->query;
313
+        return $this->query;
314 314
     }
315 315
 
316 316
     /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      * @return string
319 319
      */
320 320
     public function getDatabaseName(){
321
-      return $this->databaseName;
321
+        return $this->databaseName;
322 322
     }
323 323
 
324 324
     /**
@@ -326,17 +326,17 @@  discard block
 block discarded – undo
326 326
      * @return object
327 327
      */
328 328
     public function getPdo(){
329
-      return $this->pdo;
329
+        return $this->pdo;
330 330
     }
331 331
 
332 332
     /**
333 333
      * Set the PDO instance
334 334
      * @param object $pdo the pdo object
335
-	 * @return object Database
335
+     * @return object Database
336 336
      */
337 337
     public function setPdo(PDO $pdo){
338
-      $this->pdo = $pdo;
339
-      return $this;
338
+        $this->pdo = $pdo;
339
+        return $this;
340 340
     }
341 341
 
342 342
 
@@ -345,44 +345,44 @@  discard block
 block discarded – undo
345 345
      * @return Log
346 346
      */
347 347
     public function getLogger(){
348
-      return $this->logger;
348
+        return $this->logger;
349 349
     }
350 350
 
351 351
     /**
352 352
      * Set the log instance
353 353
      * @param Log $logger the log object
354
-	 * @return object Database
354
+     * @return object Database
355 355
      */
356 356
     public function setLogger($logger){
357
-      $this->logger = $logger;
358
-      return $this;
357
+        $this->logger = $logger;
358
+        return $this;
359 359
     }
360 360
 
361
-     /**
362
-     * Return the cache instance
363
-     * @return CacheInterface
364
-     */
361
+        /**
362
+         * Return the cache instance
363
+         * @return CacheInterface
364
+         */
365 365
     public function getCacheInstance(){
366
-      return $this->cacheInstance;
366
+        return $this->cacheInstance;
367 367
     }
368 368
 
369 369
     /**
370 370
      * Set the cache instance
371 371
      * @param CacheInterface $cache the cache object
372
-	 * @return object Database
372
+     * @return object Database
373 373
      */
374 374
     public function setCacheInstance($cache){
375
-      $this->cacheInstance = $cache;
376
-      return $this;
375
+        $this->cacheInstance = $cache;
376
+        return $this;
377 377
     }
378 378
 	
379 379
 	
380
-	   /**
381
-     * Return the DatabaseQueryBuilder instance
382
-     * @return object DatabaseQueryBuilder
383
-     */
380
+        /**
381
+         * Return the DatabaseQueryBuilder instance
382
+         * @return object DatabaseQueryBuilder
383
+         */
384 384
     public function getQueryBuilder(){
385
-      return $this->queryBuilder;
385
+        return $this->queryBuilder;
386 386
     }
387 387
 
388 388
     /**
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
391 391
      */
392 392
     public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
393
-      $this->queryBuilder = $queryBuilder;
394
-      return $this;
393
+        $this->queryBuilder = $queryBuilder;
394
+        return $this;
395 395
     }
396 396
     
397 397
     /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      * @return object DatabaseQueryRunner
400 400
      */
401 401
     public function getQueryRunner(){
402
-      return $this->queryRunner;
402
+        return $this->queryRunner;
403 403
     }
404 404
 
405 405
     /**
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
      * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object
408 408
      */
409 409
     public function setQueryRunner(DatabaseQueryRunner $queryRunner){
410
-      $this->queryRunner = $queryRunner;
411
-      return $this;
410
+        $this->queryRunner = $queryRunner;
411
+        return $this;
412 412
     }
413 413
 
414 414
     /**
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
      * @return array
417 417
      */
418 418
     public function getData(){
419
-      return $this->data;
419
+        return $this->data;
420 420
     }
421 421
 
422 422
     /**
@@ -427,62 +427,62 @@  discard block
 block discarded – undo
427 427
      * @return object        the current Database instance
428 428
      */
429 429
     public function setData($key, $value = null, $escape = true){
430
-  	  if (is_array($key)){
431
-    		foreach($key as $k => $v){
432
-    			$this->setData($k, $v, $escape);
433
-    		}	
434
-  	  } else {
430
+        if (is_array($key)){
431
+            foreach($key as $k => $v){
432
+                $this->setData($k, $v, $escape);
433
+            }	
434
+        } else {
435 435
         $this->data[$key] = $this->escape($value, $escape);
436
-  	  }
437
-      return $this;
436
+        }
437
+        return $this;
438 438
     }
439 439
 
440
-     /**
441
-     * Execute an SQL query
442
-     * @param  string  $query the query SQL string
443
-     * @param  boolean $returnAsList  indicate whether to return all record or just one row 
444
-     * @param  boolean $returnAsArray return the result as array or not
445
-     * @return mixed         the query result
446
-     */
440
+        /**
441
+         * Execute an SQL query
442
+         * @param  string  $query the query SQL string
443
+         * @param  boolean $returnAsList  indicate whether to return all record or just one row 
444
+         * @param  boolean $returnAsArray return the result as array or not
445
+         * @return mixed         the query result
446
+         */
447 447
     public function query($query, $returnAsList = true, $returnAsArray = false){
448
-      $this->reset();
449
-      $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
450
-      //If is the SELECT query
451
-      $isSqlSELECTQuery = stristr($this->query, 'SELECT');
448
+        $this->reset();
449
+        $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
450
+        //If is the SELECT query
451
+        $isSqlSELECTQuery = stristr($this->query, 'SELECT');
452 452
 
453
-      //cache expire time
454
-      $cacheExpire = $this->temporaryCacheTtl;
453
+        //cache expire time
454
+        $cacheExpire = $this->temporaryCacheTtl;
455 455
       
456
-      //return to the initial cache time
457
-      $this->temporaryCacheTtl = $this->cacheTtl;
456
+        //return to the initial cache time
457
+        $this->temporaryCacheTtl = $this->cacheTtl;
458 458
       
459
-      //config for cache
460
-      $cacheEnable = get_config('cache_enable');
459
+        //config for cache
460
+        $cacheEnable = get_config('cache_enable');
461 461
       
462
-      //the database cache content
463
-      $cacheContent = null;
462
+        //the database cache content
463
+        $cacheContent = null;
464 464
 
465
-      //if can use cache feature for this query
466
-      $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
465
+        //if can use cache feature for this query
466
+        $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
467 467
     
468
-      if ($dbCacheStatus && $isSqlSELECTQuery){
469
-          $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
470
-          $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
471
-      }
468
+        if ($dbCacheStatus && $isSqlSELECTQuery){
469
+            $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
470
+            $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
471
+        }
472 472
       
473
-      if (!$cacheContent){
474
-  	   	//count the number of query execution to server
473
+        if (!$cacheContent){
474
+                //count the number of query execution to server
475 475
         $this->queryCount++;
476 476
         
477 477
         $queryResult = $this->queryRunner->setQuery($query)
478
-                                          ->setReturnType($returnAsList)
479
-                                          ->setReturnAsArray($returnAsArray)
480
-                                          ->execute();
478
+                                            ->setReturnType($returnAsList)
479
+                                            ->setReturnAsArray($returnAsArray)
480
+                                            ->execute();
481 481
 
482 482
         if (!is_object($queryResult)){
483
-          $this->result = false;
484
-          $this->numRows = 0;
485
-          return $this->result;
483
+            $this->result = false;
484
+            $this->numRows = 0;
485
+            return $this->result;
486 486
         }
487 487
         $this->result  = $queryResult->getResult();
488 488
         $this->numRows = $queryResult->getNumRows();
@@ -490,72 +490,72 @@  discard block
 block discarded – undo
490 490
             $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray);
491 491
             $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire);
492 492
         }
493
-      } else if ($isSqlSELECTQuery){
494
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
495
-          $this->result = $cacheContent;
496
-          $this->numRows = count($this->result);
497
-      }
498
-      return $this->result;
499
-    }
500
-
501
-   /**
502
-    * Setting the database configuration using the configuration file and additional configuration from param
503
-    * @param array $overwriteConfig the additional configuration to overwrite with the existing one
504
-    * @param boolean $useConfigFile whether to use database configuration file
505
-    * @param boolean $autoConnect whether to connect to database after set the configuration
506
-	  * @return object Database
507
-    */
493
+        } else if ($isSqlSELECTQuery){
494
+            $this->logger->info('The result for query [' .$this->query. '] already cached use it');
495
+            $this->result = $cacheContent;
496
+            $this->numRows = count($this->result);
497
+        }
498
+        return $this->result;
499
+    }
500
+
501
+    /**
502
+     * Setting the database configuration using the configuration file and additional configuration from param
503
+     * @param array $overwriteConfig the additional configuration to overwrite with the existing one
504
+     * @param boolean $useConfigFile whether to use database configuration file
505
+     * @param boolean $autoConnect whether to connect to database after set the configuration
506
+     * @return object Database
507
+     */
508 508
     public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){
509
-      $db = array();
510
-      if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
511
-          //here don't use require_once because somewhere user can create database instance directly
512
-          require CONFIG_PATH . 'database.php';
513
-      }
509
+        $db = array();
510
+        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
511
+            //here don't use require_once because somewhere user can create database instance directly
512
+            require CONFIG_PATH . 'database.php';
513
+        }
514 514
       
515
-      //merge with the parameter  
516
-      $db = array_merge($db, $overwriteConfig);
515
+        //merge with the parameter  
516
+        $db = array_merge($db, $overwriteConfig);
517 517
       
518
-      //get the default configuration
519
-      $config = $this->getDatabaseDefaultConfiguration();
518
+        //get the default configuration
519
+        $config = $this->getDatabaseDefaultConfiguration();
520 520
 		  
521
-    	$config = array_merge($config, $db);
522
-    	//determine the port using the hostname like localhost:3307
523
-      //hostname will be "localhost", and port "3307"
524
-      $p = explode(':', $config['hostname']);
525
-  	  if (count($p) >= 2){
526
-  		  $config['hostname'] = $p[0];
527
-  		  $config['port'] = $p[1];
528
-  		}
521
+        $config = array_merge($config, $db);
522
+        //determine the port using the hostname like localhost:3307
523
+        //hostname will be "localhost", and port "3307"
524
+        $p = explode(':', $config['hostname']);
525
+        if (count($p) >= 2){
526
+            $config['hostname'] = $p[0];
527
+            $config['port'] = $p[1];
528
+            }
529 529
 		
530
-		 $this->databaseName = $config['database'];
531
-		 $this->config = $config;
532
-		 $this->logger->info(
533
-								'The database configuration are listed below: ' 
534
-								. stringfy_vars(array_merge(
535
-															$this->config, 
536
-															array('password' => string_hidden($this->config['password']))
537
-												))
538
-							);
539
-  	  if($autoConnect){
540
-    		 //Now connect to the database
541
-    		 $this->connect();
542
-  		}
543
-		 return $this;
544
-    }
545
-
546
-    /**
547
-   * Return the database configuration
548
-   * @return array
549
-   */
530
+            $this->databaseName = $config['database'];
531
+            $this->config = $config;
532
+            $this->logger->info(
533
+                                'The database configuration are listed below: ' 
534
+                                . stringfy_vars(array_merge(
535
+                                                            $this->config, 
536
+                                                            array('password' => string_hidden($this->config['password']))
537
+                                                ))
538
+                            );
539
+        if($autoConnect){
540
+                //Now connect to the database
541
+                $this->connect();
542
+            }
543
+            return $this;
544
+    }
545
+
546
+    /**
547
+     * Return the database configuration
548
+     * @return array
549
+     */
550 550
     public  function getDatabaseConfiguration(){
551
-      return $this->config;
551
+        return $this->config;
552 552
     }
553 553
 
554 554
     /**
555 555
      * Close the connexion
556 556
      */
557 557
     public function close(){
558
-      $this->pdo = null;
558
+        $this->pdo = null;
559 559
     }
560 560
 
561 561
     /**
@@ -563,16 +563,16 @@  discard block
 block discarded – undo
563 563
      * @return array
564 564
      */
565 565
     protected function getDatabaseDefaultConfiguration(){
566
-      return array(
567
-              'driver' => '',
568
-              'username' => '',
569
-              'password' => '',
570
-              'database' => '',
571
-              'hostname' => 'localhost',
572
-              'charset' => 'utf8',
573
-              'collation' => 'utf8_general_ci',
574
-              'prefix' => '',
575
-              'port' => ''
566
+        return array(
567
+                'driver' => '',
568
+                'username' => '',
569
+                'password' => '',
570
+                'database' => '',
571
+                'hostname' => 'localhost',
572
+                'charset' => 'utf8',
573
+                'collation' => 'utf8_general_ci',
574
+                'prefix' => '',
575
+                'port' => ''
576 576
             );
577 577
     }
578 578
 
@@ -581,18 +581,18 @@  discard block
 block discarded – undo
581 581
      * @return void
582 582
      */
583 583
     protected function updateQueryBuilderAndRunnerProperties(){
584
-       //update queryBuilder with some properties needed
585
-     if (is_object($this->queryBuilder)){
584
+        //update queryBuilder with some properties needed
585
+        if (is_object($this->queryBuilder)){
586 586
         $this->queryBuilder->setDriver($this->config['driver'])
587
-                           ->setPrefix($this->config['prefix'])
588
-                           ->setPdo($this->pdo);
589
-     }
587
+                            ->setPrefix($this->config['prefix'])
588
+                            ->setPdo($this->pdo);
589
+        }
590 590
 
591
-      //update queryRunner with some properties needed
592
-     if (is_object($this->queryRunner)){
591
+        //update queryRunner with some properties needed
592
+        if (is_object($this->queryRunner)){
593 593
         $this->queryRunner->setDriver($this->config['driver'])
594
-                          ->setPdo($this->pdo);
595
-     }
594
+                            ->setPdo($this->pdo);
595
+        }
596 596
     }
597 597
 	
598 598
 
@@ -601,21 +601,21 @@  discard block
 block discarded – undo
601 601
      * @return string|null the DSN string or null if can not find it
602 602
      */
603 603
     protected function getDsnValueFromConfig(){
604
-      $dsn = null;
605
-      $config = $this->getDatabaseConfiguration();
606
-      if (! empty($config)){
604
+        $dsn = null;
605
+        $config = $this->getDatabaseConfiguration();
606
+        if (! empty($config)){
607 607
         $driver = $config['driver'];
608 608
         $driverDsnMap = array(
609
-                              'mysql'  => $this->getDsnValueForDriver('mysql'),
610
-                              'pgsql'  => $this->getDsnValueForDriver('pgsql'),
611
-                              'sqlite' => $this->getDsnValueForDriver('sqlite'),
612
-                              'oracle' => $this->getDsnValueForDriver('oracle')
613
-                              );
609
+                                'mysql'  => $this->getDsnValueForDriver('mysql'),
610
+                                'pgsql'  => $this->getDsnValueForDriver('pgsql'),
611
+                                'sqlite' => $this->getDsnValueForDriver('sqlite'),
612
+                                'oracle' => $this->getDsnValueForDriver('oracle')
613
+                                );
614 614
         if (isset($driverDsnMap[$driver])){
615
-          $dsn = $driverDsnMap[$driver];
615
+            $dsn = $driverDsnMap[$driver];
616 616
         }
617
-      }    
618
-      return $dsn;
617
+        }    
618
+        return $dsn;
619 619
     }
620 620
 
621 621
     /**
@@ -624,32 +624,32 @@  discard block
 block discarded – undo
624 624
      * @return string|null         the dsn name
625 625
      */
626 626
     protected function getDsnValueForDriver($driver){
627
-      $dsn = '';
628
-      $config = $this->getDatabaseConfiguration();
629
-      if (empty($config)){
627
+        $dsn = '';
628
+        $config = $this->getDatabaseConfiguration();
629
+        if (empty($config)){
630 630
         return null;
631
-      }
632
-      switch ($driver) {
631
+        }
632
+        switch ($driver) {
633 633
         case 'mysql':
634 634
         case 'pgsql':
635 635
           $port = '';
636
-          if (! empty($config['port'])) {
636
+            if (! empty($config['port'])) {
637 637
             $port = 'port=' . $config['port'] . ';';
638
-          }
639
-          $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
640
-          break;
638
+            }
639
+            $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
640
+            break;
641 641
         case 'sqlite':
642 642
           $dsn = 'sqlite:' . $config['database'];
643
-          break;
644
-          case 'oracle':
643
+            break;
644
+            case 'oracle':
645 645
           $port = '';
646
-          if (! empty($config['port'])) {
646
+            if (! empty($config['port'])) {
647 647
             $port = ':' . $config['port'];
648
-          }
649
-          $dsn =  'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
650
-          break;
651
-      }
652
-      return $dsn;
648
+            }
649
+            $dsn =  'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
650
+            break;
651
+        }
652
+        return $dsn;
653 653
     }
654 654
 
655 655
     /**
@@ -661,11 +661,11 @@  discard block
 block discarded – undo
661 661
     protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){
662 662
         $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray);
663 663
         if (! is_object($this->cacheInstance)){
664
-    			//can not call method with reference in argument
665
-    			//like $this->setCacheInstance(& get_instance()->cache);
666
-    			//use temporary variable
667
-    			$instance = & get_instance()->cache;
668
-    			$this->cacheInstance = $instance;
664
+                //can not call method with reference in argument
665
+                //like $this->setCacheInstance(& get_instance()->cache);
666
+                //use temporary variable
667
+                $instance = & get_instance()->cache;
668
+                $this->cacheInstance = $instance;
669 669
         }
670 670
         return $this->cacheInstance->get($cacheKey);
671 671
     }
@@ -677,80 +677,80 @@  discard block
 block discarded – undo
677 677
      * @param mixed $result the query result to save
678 678
      * @param int $expire the cache TTL
679 679
      */
680
-     protected function setCacheContentForQuery($query, $key, $result, $expire){
680
+        protected function setCacheContentForQuery($query, $key, $result, $expire){
681 681
         $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
682 682
         if (! is_object($this->cacheInstance)){
683
-  				//can not call method with reference in argument
684
-  				//like $this->setCacheInstance(& get_instance()->cache);
685
-  				//use temporary variable
686
-  				$instance = & get_instance()->cache;
687
-  				$this->cacheInstance = $instance;
688
-  			}
683
+                    //can not call method with reference in argument
684
+                    //like $this->setCacheInstance(& get_instance()->cache);
685
+                    //use temporary variable
686
+                    $instance = & get_instance()->cache;
687
+                    $this->cacheInstance = $instance;
688
+                }
689 689
         $this->cacheInstance->set($key, $result, $expire);
690
-     }
690
+        }
691 691
 
692 692
     
693
-	 /**
694
-     * Return the cache key for the given query
695
-     * @see Database::query
696
-     * 
697
-     *  @return string
698
-     */
693
+        /**
694
+         * Return the cache key for the given query
695
+         * @see Database::query
696
+         * 
697
+         *  @return string
698
+         */
699 699
     protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){
700
-      return md5($query . $returnAsList . $returnAsArray);
701
-    }
702
-
703
-     /**
704
-     * Set the dependencies instance using argument or create new instance if is null
705
-     * @param string $name this class property name.
706
-     * @param object $instance the instance. If is not null will use it
707
-     * otherwise will create new instance.
708
-     * @param string $loadClassName the name of class to load using class_loader function.
709
-     * @param string $loadClassPath the path of class to load using class_loader function.
710
-     *
711
-     * @return object this current instance
712
-     */
700
+        return md5($query . $returnAsList . $returnAsArray);
701
+    }
702
+
703
+        /**
704
+         * Set the dependencies instance using argument or create new instance if is null
705
+         * @param string $name this class property name.
706
+         * @param object $instance the instance. If is not null will use it
707
+         * otherwise will create new instance.
708
+         * @param string $loadClassName the name of class to load using class_loader function.
709
+         * @param string $loadClassPath the path of class to load using class_loader function.
710
+         *
711
+         * @return object this current instance
712
+         */
713 713
     protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
714
-      if ($instance !== null){
714
+        if ($instance !== null){
715 715
         $this->{$name} = $instance;
716 716
         return $this;
717
-      }
718
-      $this->{$name} =& class_loader($loadClassName, $loadClassePath);
719
-      return $this;
717
+        }
718
+        $this->{$name} =& class_loader($loadClassName, $loadClassePath);
719
+        return $this;
720 720
     }
721 721
     
722
-	   /**
723
-     * Set the Log instance using argument or create new instance
724
-     * @param object $logger the Log instance if not null
725
-     *
726
-     * @return object this current instance
727
-     */
722
+        /**
723
+         * Set the Log instance using argument or create new instance
724
+         * @param object $logger the Log instance if not null
725
+         *
726
+         * @return object this current instance
727
+         */
728 728
     protected function setLoggerFromParamOrCreate(Log $logger = null){
729
-      $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
730
-      if ($logger === null){
729
+        $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
730
+        if ($logger === null){
731 731
         $this->logger->setLogger('Library::Database');
732
-      }
733
-      return $this;
732
+        }
733
+        return $this;
734 734
     }
735 735
 	
736 736
     /**
737 737
      * Reset the database class attributs to the initail values before each query.
738 738
      */
739 739
     private function reset(){
740
-	   //query builder reset
741
-      $this->queryBuilder->reset();
742
-      $this->numRows  = 0;
743
-      $this->insertId = null;
744
-      $this->query    = null;
745
-      $this->result   = array();
746
-      $this->data     = array();
740
+        //query builder reset
741
+        $this->queryBuilder->reset();
742
+        $this->numRows  = 0;
743
+        $this->insertId = null;
744
+        $this->query    = null;
745
+        $this->result   = array();
746
+        $this->data     = array();
747 747
     }
748 748
 
749 749
     /**
750 750
      * The class destructor
751 751
      */
752 752
     public function __destruct(){
753
-      $this->pdo = null;
753
+        $this->pdo = null;
754 754
     }
755 755
 
756 756
 }
Please login to merge, or discard this patch.
core/libraries/Pagination.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@  discard block
 block discarded – undo
1 1
 <?php
2 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
-	*/
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 27
     class Pagination{
28 28
         
29
-		/**
29
+        /**
30 30
          * The list of loaded config
31 31
          * @var array
32 32
          */
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
                 if (empty($config) || ! is_array($config)){
50 50
                     show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
51 51
                 }
52
-				else{
53
-					$config = array_merge($config, $overwriteConfig);
54
-					$this->config = $config;
52
+                else{
53
+                    $config = array_merge($config, $overwriteConfig);
54
+                    $this->config = $config;
55 55
                     //put it gobally
56
-					Config::setAll($config);
57
-					unset($config);
58
-				}
56
+                    Config::setAll($config);
57
+                    unset($config);
58
+                }
59 59
             }
60 60
             else{
61 61
                 show_error('Unable to find the pagination configuration file');
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
             return $this->paginationQueryString;
93 93
         }
94 94
 
95
-         /**
96
-         * Set the value of the pagination query string
97
-         * @param string $paginationQueryString the new value
98
-         * @return object
99
-         */
95
+            /**
96
+             * Set the value of the pagination query string
97
+             * @param string $paginationQueryString the new value
98
+             * @return object
99
+             */
100 100
         public function setPaginationQueryString($paginationQueryString){
101 101
             $this->paginationQueryString = $paginationQueryString;
102 102
             return $this;
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
             $queryString = Url::queryString();
114 114
             $currentUrl = Url::current();
115 115
             $query = '';
116
-             if ($queryString == ''){
116
+                if ($queryString == ''){
117 117
                 $query = '?' . $pageQueryName . '=';
118 118
             }
119 119
             else{
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
          */
147 147
         public function getLink($totalRows, $currentPageNumber){
148 148
             $numberOfLink = $this->config['nb_link'];
149
-			$numberOfRowPerPage = $this->config['pagination_per_page'];
149
+            $numberOfRowPerPage = $this->config['pagination_per_page'];
150 150
             if (empty($this->paginationQueryString)){
151 151
                 //determine the pagination query string value
152 152
                 $this->determinePaginationQueryStringValue();
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
             $numberOfRowPerPage = (int) $numberOfRowPerPage;
160 160
 			
161 161
             if ($currentPageNumber <= 0){
162
-				$currentPageNumber = 1;
163
-			}
162
+                $currentPageNumber = 1;
163
+            }
164 164
             if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) {
165 165
                 return $navbar;
166 166
             }
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                 $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber);
186 186
             }
187 187
             else if ($currentPageNumber == $numberOfPage){
188
-               $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber);
188
+                $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber);
189 189
             }
190 190
             $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
191 191
             return $navbar;
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
                 }
254 254
             }
255 255
             $navbar .= $this->config['next_open']
256
-                         . '<a href="' . $query . ($currentPageNumber + 1) . '">' 
257
-                         . $this->config['next_text'] . '</a>' . $this->config['next_close'];
256
+                            . '<a href="' . $query . ($currentPageNumber + 1) . '">' 
257
+                            . $this->config['next_text'] . '</a>' . $this->config['next_close'];
258 258
             return $navbar;
259 259
         }
260 260
 
Please login to merge, or discard this patch.
core/classes/Module.php 1 patch
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4 4
      * TNH Framework
5 5
      *
6 6
      * A simple PHP framework using HMVC architecture
@@ -22,308 +22,308 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
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 26
    
27
-	class Module{
27
+    class Module{
28 28
 		
29
-		/**
30
-		 * list of loaded module
31
-		 * @var array
32
-		 */
33
-		private static $list = array();
29
+        /**
30
+         * list of loaded module
31
+         * @var array
32
+         */
33
+        private static $list = array();
34 34
 
35
-		/**
36
-		 * logger instance
37
-		 * @var Log
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * logger instance
37
+         * @var Log
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * The signleton of the logger
43
-		 * @return Object the Log instance
44
-		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
47
-				self::$logger[0] =& class_loader('Log', 'classes');
48
-				self::$logger[0]->setLogger('Library::Module');
49
-			}
50
-			return self::$logger[0];
51
-		}
41
+        /**
42
+         * The signleton of the logger
43
+         * @return Object the Log instance
44
+         */
45
+        private static function getLogger(){
46
+            if(self::$logger == null){
47
+                self::$logger[0] =& class_loader('Log', 'classes');
48
+                self::$logger[0]->setLogger('Library::Module');
49
+            }
50
+            return self::$logger[0];
51
+        }
52 52
 
53
-		/**
54
-		 * Initialise the module list by scanning the directory MODULE_PATH
55
-		 */
56
-		public function init(){
57
-			$logger = self::getLogger();
58
-			$logger->debug('Check if the application contains the modules ...');
59
-			$moduleDir = opendir(MODULE_PATH);
60
-			if(is_resource($moduleDir)){
61
-				while(($module = readdir($moduleDir)) !== false){
62
-					if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
63
-						self::$list[] = $module;
64
-					}
65
-					else{
66
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
67
-					}
68
-				}
69
-				closedir($moduleDir);
70
-			}
71
-			ksort(self::$list);
53
+        /**
54
+         * Initialise the module list by scanning the directory MODULE_PATH
55
+         */
56
+        public function init(){
57
+            $logger = self::getLogger();
58
+            $logger->debug('Check if the application contains the modules ...');
59
+            $moduleDir = opendir(MODULE_PATH);
60
+            if(is_resource($moduleDir)){
61
+                while(($module = readdir($moduleDir)) !== false){
62
+                    if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
63
+                        self::$list[] = $module;
64
+                    }
65
+                    else{
66
+                        $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
67
+                    }
68
+                }
69
+                closedir($moduleDir);
70
+            }
71
+            ksort(self::$list);
72 72
 			
73
-			if(self::hasModule()){
74
-				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
75
-			}
76
-		}
73
+            if(self::hasModule()){
74
+                $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
75
+            }
76
+        }
77 77
 		
78
-		/**
79
-		 * Get the list of the custom autoload configuration from module if exists
80
-		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
81
-		 */
82
-		public static function getModulesAutoloadConfig(){
83
-			$logger = self::getLogger();
84
-			if(! self::hasModule()){
85
-				$logger->info('No module was loaded skipping.');
86
-				return false;
87
-			}
88
-			$autoloads = array();
89
-			$autoloads['libraries'] = array();
90
-			$autoloads['config']    = array();
91
-			$autoloads['models']    = array();
92
-			$autoloads['functions'] = array();
93
-			$autoloads['languages'] = array();
78
+        /**
79
+         * Get the list of the custom autoload configuration from module if exists
80
+         * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
81
+         */
82
+        public static function getModulesAutoloadConfig(){
83
+            $logger = self::getLogger();
84
+            if(! self::hasModule()){
85
+                $logger->info('No module was loaded skipping.');
86
+                return false;
87
+            }
88
+            $autoloads = array();
89
+            $autoloads['libraries'] = array();
90
+            $autoloads['config']    = array();
91
+            $autoloads['models']    = array();
92
+            $autoloads['functions'] = array();
93
+            $autoloads['languages'] = array();
94 94
 			
95
-			foreach (self::$list as $module) {
96
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
97
-				if(file_exists($file)){
98
-					$autoload = array();
99
-					require_once $file;
100
-					if(! empty($autoload) && is_array($autoload)){
101
-						$autoloads = array_merge_recursive($autoloads, $autoload);
102
-						unset($autoload);
103
-					}
104
-				}
105
-			}
106
-			return $autoloads;
107
-		}
95
+            foreach (self::$list as $module) {
96
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
97
+                if(file_exists($file)){
98
+                    $autoload = array();
99
+                    require_once $file;
100
+                    if(! empty($autoload) && is_array($autoload)){
101
+                        $autoloads = array_merge_recursive($autoloads, $autoload);
102
+                        unset($autoload);
103
+                    }
104
+                }
105
+            }
106
+            return $autoloads;
107
+        }
108 108
 
109
-		/**
110
-		 * Get the list of the custom routes configuration from module if exists
111
-		 * @return array|boolean the routes list or false if no module contains the routes configuration
112
-		 */
113
-		public static function getModulesRoutes(){
114
-			$logger = self::getLogger();
115
-			if(! self::hasModule()){
116
-				$logger->info('No module was loaded skipping.');
117
-				return false;
118
-			}
119
-			$routes = array();
120
-			foreach (self::$list as $module) {
121
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
122
-				if(file_exists($file)){
123
-					$route = array();
124
-					require_once $file;
125
-					if(! empty($route) && is_array($route)){
126
-						$routes = array_merge($routes, $route);
127
-						unset($route);
128
-					}
129
-				}
130
-			}
131
-			return $routes;
132
-		}
109
+        /**
110
+         * Get the list of the custom routes configuration from module if exists
111
+         * @return array|boolean the routes list or false if no module contains the routes configuration
112
+         */
113
+        public static function getModulesRoutes(){
114
+            $logger = self::getLogger();
115
+            if(! self::hasModule()){
116
+                $logger->info('No module was loaded skipping.');
117
+                return false;
118
+            }
119
+            $routes = array();
120
+            foreach (self::$list as $module) {
121
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
122
+                if(file_exists($file)){
123
+                    $route = array();
124
+                    require_once $file;
125
+                    if(! empty($route) && is_array($route)){
126
+                        $routes = array_merge($routes, $route);
127
+                        unset($route);
128
+                    }
129
+                }
130
+            }
131
+            return $routes;
132
+        }
133 133
 
134 134
 
135
-		/**
136
-		 * Check if in module list can have this controller
137
-		 * @param  string $class the controller class
138
-		 * @param  string $module  the module name
139
-		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
140
-		 */
141
-		public static function findControllerFullPath($class, $module = null){
142
-			$logger = self::getLogger();
143
-			if(! self::hasModule()){
144
-				$logger->info('No module was loaded skiping.');
145
-				return false;
146
-			}
147
-			$class = str_ireplace('.php', '', $class);
148
-			$class = ucfirst($class);
149
-			$classFile = $class.'.php';
150
-			$logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...');
151
-			$filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile;
152
-			if(file_exists($filePath)){
153
-				$logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
154
-				return $filePath;
155
-			}
156
-			$logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
157
-			return false;
158
-		}
135
+        /**
136
+         * Check if in module list can have this controller
137
+         * @param  string $class the controller class
138
+         * @param  string $module  the module name
139
+         * @return boolean|string  false or null if no module have this controller, path the full path of the controller
140
+         */
141
+        public static function findControllerFullPath($class, $module = null){
142
+            $logger = self::getLogger();
143
+            if(! self::hasModule()){
144
+                $logger->info('No module was loaded skiping.');
145
+                return false;
146
+            }
147
+            $class = str_ireplace('.php', '', $class);
148
+            $class = ucfirst($class);
149
+            $classFile = $class.'.php';
150
+            $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...');
151
+            $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile;
152
+            if(file_exists($filePath)){
153
+                $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
154
+                return $filePath;
155
+            }
156
+            $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
157
+            return false;
158
+        }
159 159
 
160
-		/**
161
-		 * Check if in module list can have this model
162
-		 * @param  string $class the model class
163
-		 * @param string $module the module name
164
-		 * @return boolean|string  false or null if no module have this model, return the full path of this model
165
-		 */
166
-		public static function findModelFullPath($class, $module = null){
167
-			$logger = self::getLogger();
168
-			if(! self::hasModule()){
169
-				$logger->info('No module was loaded skiping.');
170
-				return false;
171
-			}
172
-			$class = str_ireplace('.php', '', $class);
173
-			$class = ucfirst($class);
174
-			$classFile = $class.'.php';
175
-			$logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...');
176
-			$filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile;
177
-			if(file_exists($filePath)){
178
-				$logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
179
-				return $filePath;
180
-			}
181
-			$logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
182
-			return false;
183
-		}
160
+        /**
161
+         * Check if in module list can have this model
162
+         * @param  string $class the model class
163
+         * @param string $module the module name
164
+         * @return boolean|string  false or null if no module have this model, return the full path of this model
165
+         */
166
+        public static function findModelFullPath($class, $module = null){
167
+            $logger = self::getLogger();
168
+            if(! self::hasModule()){
169
+                $logger->info('No module was loaded skiping.');
170
+                return false;
171
+            }
172
+            $class = str_ireplace('.php', '', $class);
173
+            $class = ucfirst($class);
174
+            $classFile = $class.'.php';
175
+            $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...');
176
+            $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile;
177
+            if(file_exists($filePath)){
178
+                $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
179
+                return $filePath;
180
+            }
181
+            $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
182
+            return false;
183
+        }
184 184
 		
185
-		/**
186
-		 * Check if in module list can have this config
187
-		 * @param  string $configuration the config name
188
-		 * @param string $module the module name
189
-		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
190
-		 */
191
-		public static function findConfigFullPath($configuration, $module = null){
192
-			$logger = self::getLogger();
193
-			if(! self::hasModule()){
194
-				$logger->info('No module was loaded skiping.');
195
-				return false;
196
-			}
197
-			$configuration = str_ireplace('.php', '', $configuration);
198
-			$file = $configuration.'.php';
199
-			$logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...');
200
-			$filePath = MODULE_PATH . $module . DS . 'config' . DS . $file;
201
-			if(file_exists($filePath)){
202
-				$logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
203
-				return $filePath;
204
-			}
205
-			$logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
206
-			return false;
207
-		}
185
+        /**
186
+         * Check if in module list can have this config
187
+         * @param  string $configuration the config name
188
+         * @param string $module the module name
189
+         * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
190
+         */
191
+        public static function findConfigFullPath($configuration, $module = null){
192
+            $logger = self::getLogger();
193
+            if(! self::hasModule()){
194
+                $logger->info('No module was loaded skiping.');
195
+                return false;
196
+            }
197
+            $configuration = str_ireplace('.php', '', $configuration);
198
+            $file = $configuration.'.php';
199
+            $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...');
200
+            $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file;
201
+            if(file_exists($filePath)){
202
+                $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
203
+                return $filePath;
204
+            }
205
+            $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
206
+            return false;
207
+        }
208 208
 
209
-		/**
210
-		 * Check if in module list can have this helper
211
-		 * @param  string $helper the helper name
212
-		 * @param string $module the module name
213
-		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
214
-		 */
215
-		public static function findFunctionFullPath($helper, $module = null){
216
-			$logger = self::getLogger();
217
-			if(! self::hasModule()){
218
-				$logger->info('No module was loaded skiping.');
219
-				return false;
220
-			}
221
-			$helper = str_ireplace('.php', '', $helper);
222
-			$helper = str_ireplace('function_', '', $helper);
223
-			$file = 'function_'.$helper.'.php';
224
-			$logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...');
225
-			$filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file;
226
-			if(file_exists($filePath)){
227
-				$logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
228
-				return $filePath;
229
-			}
230
-			$logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
231
-			return false;
209
+        /**
210
+         * Check if in module list can have this helper
211
+         * @param  string $helper the helper name
212
+         * @param string $module the module name
213
+         * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
214
+         */
215
+        public static function findFunctionFullPath($helper, $module = null){
216
+            $logger = self::getLogger();
217
+            if(! self::hasModule()){
218
+                $logger->info('No module was loaded skiping.');
219
+                return false;
220
+            }
221
+            $helper = str_ireplace('.php', '', $helper);
222
+            $helper = str_ireplace('function_', '', $helper);
223
+            $file = 'function_'.$helper.'.php';
224
+            $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...');
225
+            $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file;
226
+            if(file_exists($filePath)){
227
+                $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
228
+                return $filePath;
229
+            }
230
+            $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
231
+            return false;
232 232
 			
233
-		}
233
+        }
234 234
 
235 235
 
236
-		/**
237
-		 * Check if in module list can have this library
238
-		 * @param  string $class the library name
239
-		 * @param string $module the module name
240
-		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
241
-		 */
242
-		public static function findLibraryFullPath($class, $module = null){
243
-			$logger = self::getLogger();
244
-			if(! self::hasModule()){
245
-				$logger->info('No module was loaded skiping.');
246
-				return false;
247
-			}
248
-			$class = str_ireplace('.php', '', $class);
249
-			$file = $class.'.php';
250
-			$logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...');
251
-			$filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file;
252
-			if(file_exists($filePath)){
253
-				$logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
254
-				return $filePath;
255
-			}
256
-			$logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
257
-			return false;
258
-		}
236
+        /**
237
+         * Check if in module list can have this library
238
+         * @param  string $class the library name
239
+         * @param string $module the module name
240
+         * @return boolean|string  false or null if no module have this library,  return the full path of this library
241
+         */
242
+        public static function findLibraryFullPath($class, $module = null){
243
+            $logger = self::getLogger();
244
+            if(! self::hasModule()){
245
+                $logger->info('No module was loaded skiping.');
246
+                return false;
247
+            }
248
+            $class = str_ireplace('.php', '', $class);
249
+            $file = $class.'.php';
250
+            $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...');
251
+            $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file;
252
+            if(file_exists($filePath)){
253
+                $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
254
+                return $filePath;
255
+            }
256
+            $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
257
+            return false;
258
+        }
259 259
 
260 260
 
261
-		/**
262
-		 * Check if in module list can have this view
263
-		 * @param  string $view the view path
264
-		 * @param string $module the module name to check
265
-		 * @return boolean|string  false or null if no module have this view, path the full path of the view
266
-		 */
267
-		public static function findViewFullPath($view, $module = null){
268
-			$logger = self::getLogger();
269
-			if(! self::hasModule()){
270
-				$logger->info('No module was loaded skiping.');
271
-				return false;
272
-			}
273
-			$view = str_ireplace('.php', '', $view);
274
-			$view = trim($view, '/\\');
275
-			$view = str_ireplace('/', DS, $view);
276
-			$viewFile = $view . '.php';
277
-			$logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...');
278
-			$filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile;
279
-			if(file_exists($filePath)){
280
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
281
-				return $filePath;
282
-			}
283
-			$logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
284
-			return false;
285
-		}
261
+        /**
262
+         * Check if in module list can have this view
263
+         * @param  string $view the view path
264
+         * @param string $module the module name to check
265
+         * @return boolean|string  false or null if no module have this view, path the full path of the view
266
+         */
267
+        public static function findViewFullPath($view, $module = null){
268
+            $logger = self::getLogger();
269
+            if(! self::hasModule()){
270
+                $logger->info('No module was loaded skiping.');
271
+                return false;
272
+            }
273
+            $view = str_ireplace('.php', '', $view);
274
+            $view = trim($view, '/\\');
275
+            $view = str_ireplace('/', DS, $view);
276
+            $viewFile = $view . '.php';
277
+            $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...');
278
+            $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile;
279
+            if(file_exists($filePath)){
280
+                $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
281
+                return $filePath;
282
+            }
283
+            $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
284
+            return false;
285
+        }
286 286
 
287
-		/**
288
-		 * Check if in module list can have this language
289
-		 * @param  string $language the language name
290
-		 * @param string $module the module name
291
-		 * @param string $appLang the application language like 'en', 'fr'
292
-		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
293
-		 */
294
-		public static function findLanguageFullPath($language, $module = null, $appLang){
295
-			$logger = self::getLogger();
296
-			if(! self::hasModule()){
297
-				$logger->info('No module was loaded skiping.');
298
-				return false;
299
-			}
300
-			$language = str_ireplace('.php', '', $language);
301
-			$language = str_ireplace('lang_', '', $language);
302
-			$file = 'lang_'.$language.'.php';
303
-			$logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...');
304
-			$filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file;
305
-			if(file_exists($filePath)){
306
-				$logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
307
-				return $filePath;
308
-			}
309
-			$logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
310
-			return false;
311
-		}
287
+        /**
288
+         * Check if in module list can have this language
289
+         * @param  string $language the language name
290
+         * @param string $module the module name
291
+         * @param string $appLang the application language like 'en', 'fr'
292
+         * @return boolean|string  false or null if no module have this language,  return the full path of this language
293
+         */
294
+        public static function findLanguageFullPath($language, $module = null, $appLang){
295
+            $logger = self::getLogger();
296
+            if(! self::hasModule()){
297
+                $logger->info('No module was loaded skiping.');
298
+                return false;
299
+            }
300
+            $language = str_ireplace('.php', '', $language);
301
+            $language = str_ireplace('lang_', '', $language);
302
+            $file = 'lang_'.$language.'.php';
303
+            $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...');
304
+            $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file;
305
+            if(file_exists($filePath)){
306
+                $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
307
+                return $filePath;
308
+            }
309
+            $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
310
+            return false;
311
+        }
312 312
 
313
-		/**
314
-		 * Get the list of module loaded
315
-		 * @return array the module list
316
-		 */
317
-		public static function getModuleList(){
318
-			return self::$list;
319
-		}
313
+        /**
314
+         * Get the list of module loaded
315
+         * @return array the module list
316
+         */
317
+        public static function getModuleList(){
318
+            return self::$list;
319
+        }
320 320
 
321
-		/**
322
-		 * Check if the application has an module
323
-		 * @return boolean
324
-		 */
325
-		public static function hasModule(){
326
-			return !empty(self::$list);
327
-		}
321
+        /**
322
+         * Check if the application has an module
323
+         * @return boolean
324
+         */
325
+        public static function hasModule(){
326
+            return !empty(self::$list);
327
+        }
328 328
 
329
-	}
329
+    }
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -1,190 +1,190 @@
 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
-	class Config{
27
+    class Config{
28 28
 		
29
-		/**
30
-		 * The list of loaded configuration
31
-		 * @var array
32
-		 */
33
-		private static $config = array();
29
+        /**
30
+         * The list of loaded configuration
31
+         * @var array
32
+         */
33
+        private static $config = array();
34 34
 
35
-		/**
36
-		 * The logger instance
37
-		 * @var object
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var object
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * The signleton of the logger
43
-		 * @return Object the Log instance
44
-		 */
45
-		public static function getLogger(){
46
-			if(self::$logger == null){
47
-				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
49
-				$logger[0]->setLogger('Library::Config');
50
-				self::$logger = $logger[0];
51
-			}
52
-			return self::$logger;			
53
-		}
41
+        /**
42
+         * The signleton of the logger
43
+         * @return Object the Log instance
44
+         */
45
+        public static function getLogger(){
46
+            if(self::$logger == null){
47
+                $logger = array();
48
+                $logger[0] =& class_loader('Log', 'classes');
49
+                $logger[0]->setLogger('Library::Config');
50
+                self::$logger = $logger[0];
51
+            }
52
+            return self::$logger;			
53
+        }
54 54
 
55
-		/**
56
-		 * Set the log instance for future use
57
-		 * @param object $logger the log object
58
-		 * @return object the log instance
59
-		 */
60
-		public static function setLogger($logger){
61
-			self::$logger = $logger;
62
-			return self::$logger;
63
-		}
55
+        /**
56
+         * Set the log instance for future use
57
+         * @param object $logger the log object
58
+         * @return object the log instance
59
+         */
60
+        public static function setLogger($logger){
61
+            self::$logger = $logger;
62
+            return self::$logger;
63
+        }
64 64
 
65
-		/**
66
-		 * Initialize the configuration by loading all the configuration from config file
67
-		 */
68
-		public static function init(){
69
-			$logger = static::getLogger();
70
-			$logger->debug('Initialization of the configuration');
71
-			self::$config = & load_configurations();
72
-			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
-				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
-			}
76
-			$logger->info('Configuration initialized successfully');
77
-			$logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
-		}
65
+        /**
66
+         * Initialize the configuration by loading all the configuration from config file
67
+         */
68
+        public static function init(){
69
+            $logger = static::getLogger();
70
+            $logger->debug('Initialization of the configuration');
71
+            self::$config = & load_configurations();
72
+            self::setBaseUrlUsingServerVar();
73
+            if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
+                $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
+            }
76
+            $logger->info('Configuration initialized successfully');
77
+            $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
+        }
79 79
 
80
-		/**
81
-		 * Get the configuration item value
82
-		 * @param  string $item    the configuration item name to get
83
-		 * @param  mixed $default the default value to use if can not find the config item in the list
84
-		 * @return mixed          the config value if exist or the default value
85
-		 */
86
-		public static function get($item, $default = null){
87
-			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
89
-				return self::$config[$item];
90
-			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
-			return $default;
93
-		}
80
+        /**
81
+         * Get the configuration item value
82
+         * @param  string $item    the configuration item name to get
83
+         * @param  mixed $default the default value to use if can not find the config item in the list
84
+         * @return mixed          the config value if exist or the default value
85
+         */
86
+        public static function get($item, $default = null){
87
+            $logger = static::getLogger();
88
+            if(array_key_exists($item, self::$config)){
89
+                return self::$config[$item];
90
+            }
91
+            $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
+            return $default;
93
+        }
94 94
 
95
-		/**
96
-		 * Set the configuration item value
97
-		 * @param string $item  the config item name to set
98
-		 * @param mixed $value the config item value
99
-		 */
100
-		public static function set($item, $value){
101
-			self::$config[$item] = $value;
102
-		}
95
+        /**
96
+         * Set the configuration item value
97
+         * @param string $item  the config item name to set
98
+         * @param mixed $value the config item value
99
+         */
100
+        public static function set($item, $value){
101
+            self::$config[$item] = $value;
102
+        }
103 103
 
104
-		/**
105
-		 * Get all the configuration values
106
-		 * @return array the config values
107
-		 */
108
-		public static function getAll(){
109
-			return self::$config;
110
-		}
104
+        /**
105
+         * Get all the configuration values
106
+         * @return array the config values
107
+         */
108
+        public static function getAll(){
109
+            return self::$config;
110
+        }
111 111
 
112
-		/**
113
-		 * Set the configuration values bu merged with the existing configuration
114
-		 * @param array $config the config values to add in the configuration list
115
-		 */
116
-		public static function setAll(array $config = array()){
117
-			self::$config = array_merge(self::$config, $config);
118
-		}
112
+        /**
113
+         * Set the configuration values bu merged with the existing configuration
114
+         * @param array $config the config values to add in the configuration list
115
+         */
116
+        public static function setAll(array $config = array()){
117
+            self::$config = array_merge(self::$config, $config);
118
+        }
119 119
 
120
-		/**
121
-		 * Delete the configuration item in the list
122
-		 * @param  string $item the config item name to be deleted
123
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
-		 */
125
-		public static function delete($item){
126
-			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
129
-				unset(self::$config[$item]);
130
-				return true;
131
-			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
-				return false;
135
-			}
136
-		}
120
+        /**
121
+         * Delete the configuration item in the list
122
+         * @param  string $item the config item name to be deleted
123
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
+         */
125
+        public static function delete($item){
126
+            $logger = static::getLogger();
127
+            if(array_key_exists($item, self::$config)){
128
+                $logger->info('Delete config item ['.$item.']');
129
+                unset(self::$config[$item]);
130
+                return true;
131
+            }
132
+            else{
133
+                $logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
+                return false;
135
+            }
136
+        }
137 137
 
138
-		/**
139
-		 * Load the configuration file. This an alias to Loader::config()
140
-		 * @param  string $config the config name to be loaded
141
-		 */
142
-		public static function load($config){
143
-			Loader::config($config);
144
-		}
138
+        /**
139
+         * Load the configuration file. This an alias to Loader::config()
140
+         * @param  string $config the config name to be loaded
141
+         */
142
+        public static function load($config){
143
+            Loader::config($config);
144
+        }
145 145
 
146
-		/**
147
-		 * Set the configuration for "base_url" if is not set in the configuration
148
-		 */
149
-		private static function setBaseUrlUsingServerVar(){
150
-			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
153
-					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
-				}
155
-				$baseUrl = null;
156
-				$protocol = 'http';
157
-				if(is_https()){
158
-					$protocol = 'https';
159
-				}
160
-				$protocol .='://';
146
+        /**
147
+         * Set the configuration for "base_url" if is not set in the configuration
148
+         */
149
+        private static function setBaseUrlUsingServerVar(){
150
+            $logger = static::getLogger();
151
+            if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
+                if(ENVIRONMENT == 'production'){
153
+                    $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
+                }
155
+                $baseUrl = null;
156
+                $protocol = 'http';
157
+                if(is_https()){
158
+                    $protocol = 'https';
159
+                }
160
+                $protocol .='://';
161 161
 
162
-				if (isset($_SERVER['SERVER_ADDR'])){
163
-					$baseUrl = $_SERVER['SERVER_ADDR'];
164
-					//check if the server is running under IPv6
165
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
166
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
167
-					}
168
-					$serverPort = 80;
169
-					if (isset($_SERVER['SERVER_PORT'])) {
170
-						$serverPort = $_SERVER['SERVER_PORT'];
171
-					}
172
-					$port = '';
173
-					if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
174
-						$port = ':'.$serverPort;
175
-					}
176
-					$baseUrl = $protocol . $baseUrl . $port . substr(
177
-																		$_SERVER['SCRIPT_NAME'], 
178
-																		0, 
179
-																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
180
-																	);
181
-				}
182
-				else{
183
-					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
184
-					$baseUrl = 'http://localhost/';
185
-				}
186
-				self::set('base_url', $baseUrl);
187
-			}
188
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
189
-		}
190
-	}
162
+                if (isset($_SERVER['SERVER_ADDR'])){
163
+                    $baseUrl = $_SERVER['SERVER_ADDR'];
164
+                    //check if the server is running under IPv6
165
+                    if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
166
+                        $baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
167
+                    }
168
+                    $serverPort = 80;
169
+                    if (isset($_SERVER['SERVER_PORT'])) {
170
+                        $serverPort = $_SERVER['SERVER_PORT'];
171
+                    }
172
+                    $port = '';
173
+                    if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
174
+                        $port = ':'.$serverPort;
175
+                    }
176
+                    $baseUrl = $protocol . $baseUrl . $port . substr(
177
+                                                                        $_SERVER['SCRIPT_NAME'], 
178
+                                                                        0, 
179
+                                                                        strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
180
+                                                                    );
181
+                }
182
+                else{
183
+                    $logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
184
+                    $baseUrl = 'http://localhost/';
185
+                }
186
+                self::set('base_url', $baseUrl);
187
+            }
188
+            self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
189
+        }
190
+    }
Please login to merge, or discard this patch.
core/classes/Loader.php 1 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.
core/libraries/Html.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -1,343 +1,343 @@
 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
-	class Html{
27
+    class Html{
28 28
 
29
-		/**
30
-		 * Generate the html anchor link
31
-		 * @param  string $link       the href attribute value
32
-		 * @param  string $anchor     the displayed anchor
33
-		 * @param  array  $attributes the additional attributes to be added
34
-		 * @param boolean $return whether need return the generated html or just display it directly
35
-		 *
36
-		 * @return string|void             the anchor link generated html if $return is true or display it if not
37
-		 */
38
-		public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){
39
-			$link = Url::site_url($link);
40
-			if(! $anchor){
41
-				$anchor = $link;
42
-			}
43
-			$str = null;
44
-			$str .= '<a href = "'.$link.'"';
45
-			$str .= attributes_to_string($attributes);
46
-			$str .= '>';
47
-			$str .= $anchor;
48
-			$str .= '</a>';
29
+        /**
30
+         * Generate the html anchor link
31
+         * @param  string $link       the href attribute value
32
+         * @param  string $anchor     the displayed anchor
33
+         * @param  array  $attributes the additional attributes to be added
34
+         * @param boolean $return whether need return the generated html or just display it directly
35
+         *
36
+         * @return string|void             the anchor link generated html if $return is true or display it if not
37
+         */
38
+        public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){
39
+            $link = Url::site_url($link);
40
+            if(! $anchor){
41
+                $anchor = $link;
42
+            }
43
+            $str = null;
44
+            $str .= '<a href = "'.$link.'"';
45
+            $str .= attributes_to_string($attributes);
46
+            $str .= '>';
47
+            $str .= $anchor;
48
+            $str .= '</a>';
49 49
 
50
-			if($return){
51
-				return $str;
52
-			}
53
-			echo $str;
54
-		}
50
+            if($return){
51
+                return $str;
52
+            }
53
+            echo $str;
54
+        }
55 55
 		
56
-		/**
57
-		 * Generate an mailto anchor link
58
-		 * @param  string $link       the email address 
59
-		 * @param  string $anchor     the displayed value of the link
60
-		 * @param  array  $attributes the additional attributes to be added
61
-		 * @param boolean $return whether need return the generated html or just display it directly
62
-		 *
63
-		 * @return string|void             the generated html for mailto link if $return is true or display it if not
64
-		 */
65
-		public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){
66
-			if(! $anchor){
67
-				$anchor = $link;
68
-			}
69
-			$str = null;
70
-			$str .= '<a href = "mailto:'.$link.'"';
71
-			$str .= attributes_to_string($attributes);
72
-			$str .= '>';
73
-			$str .= $anchor;
74
-			$str .= '</a>';
56
+        /**
57
+         * Generate an mailto anchor link
58
+         * @param  string $link       the email address 
59
+         * @param  string $anchor     the displayed value of the link
60
+         * @param  array  $attributes the additional attributes to be added
61
+         * @param boolean $return whether need return the generated html or just display it directly
62
+         *
63
+         * @return string|void             the generated html for mailto link if $return is true or display it if not
64
+         */
65
+        public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){
66
+            if(! $anchor){
67
+                $anchor = $link;
68
+            }
69
+            $str = null;
70
+            $str .= '<a href = "mailto:'.$link.'"';
71
+            $str .= attributes_to_string($attributes);
72
+            $str .= '>';
73
+            $str .= $anchor;
74
+            $str .= '</a>';
75 75
 
76
-			if($return){
77
-				return $str;
78
-			}
79
-			echo $str;
80
-		}
76
+            if($return){
77
+                return $str;
78
+            }
79
+            echo $str;
80
+        }
81 81
 
82
-		/**
83
-		 * Generate the html "br" tag  
84
-		 * @param  integer $nb the number of generated "<br />" tag
85
-		 * @param boolean $return whether need return the generated html or just display it directly
86
-		 *
87
-		 * @return string|void      the generated "br" html if $return is true or display it if not
88
-		 */
89
-		public static function br($nb = 1, $return = true){
90
-			$nb = (int) $nb;
91
-			$str = null;
92
-			for ($i = 1; $i <= $nb; $i++) {
93
-				$str .= '<br />';
94
-			}
82
+        /**
83
+         * Generate the html "br" tag  
84
+         * @param  integer $nb the number of generated "<br />" tag
85
+         * @param boolean $return whether need return the generated html or just display it directly
86
+         *
87
+         * @return string|void      the generated "br" html if $return is true or display it if not
88
+         */
89
+        public static function br($nb = 1, $return = true){
90
+            $nb = (int) $nb;
91
+            $str = null;
92
+            for ($i = 1; $i <= $nb; $i++) {
93
+                $str .= '<br />';
94
+            }
95 95
 
96
-			if($return){
97
-				return $str;
98
-			}
99
-			echo $str;
100
-		}
96
+            if($return){
97
+                return $str;
98
+            }
99
+            echo $str;
100
+        }
101 101
 
102
-		/**
103
-		 * Generate the html content for tag "hr"
104
-		 * @param integer $nb the number of generated "<hr />" tag
105
-		 * @param  array   $attributes the tag attributes
106
-		 * @param  boolean $return    whether need return the generated html or just display it directly
107
-		 *
108
-		 * @return string|void the generated "hr" html if $return is true or display it if not.
109
-		 */
110
-		public static function hr($nb = 1, array $attributes = array(), $return = true){
111
-			$nb = (int) $nb;
112
-			$str = null;
113
-			for ($i = 1; $i <= $nb; $i++) {
114
-				$str .= '<hr' .attributes_to_string($attributes). ' />';
115
-			}
116
-			if($return){
117
-				return $str;
118
-			}
119
-			echo $str;
120
-		}
102
+        /**
103
+         * Generate the html content for tag "hr"
104
+         * @param integer $nb the number of generated "<hr />" tag
105
+         * @param  array   $attributes the tag attributes
106
+         * @param  boolean $return    whether need return the generated html or just display it directly
107
+         *
108
+         * @return string|void the generated "hr" html if $return is true or display it if not.
109
+         */
110
+        public static function hr($nb = 1, array $attributes = array(), $return = true){
111
+            $nb = (int) $nb;
112
+            $str = null;
113
+            for ($i = 1; $i <= $nb; $i++) {
114
+                $str .= '<hr' .attributes_to_string($attributes). ' />';
115
+            }
116
+            if($return){
117
+                return $str;
118
+            }
119
+            echo $str;
120
+        }
121 121
 
122
-		/**
123
-		 * Generate the html content for tag like h1, h2, h3, h4, h5 and h6
124
-		 * @param  integer $type       the tag type 1 mean h1, 2 h2, etc,
125
-		 * @param  string  $text       the display text
126
-		 * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>"
127
-		 * @param  array   $attributes the tag attributes
128
-		 * @param  boolean $return    whether need return the generated html or just display it directly
129
-		 *
130
-		 * @return string|void the generated header html if $return is true or display it if not.
131
-		 */
132
-		public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){
133
-			$nb = (int) $nb;
134
-			$type = (int) $type;
135
-			$str = null;
136
-			for ($i = 1; $i <= $nb; $i++) {
137
-				$str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>';
138
-			}
139
-			if($return){
140
-				return $str;
141
-			}
142
-			echo $str;
143
-		}
122
+        /**
123
+         * Generate the html content for tag like h1, h2, h3, h4, h5 and h6
124
+         * @param  integer $type       the tag type 1 mean h1, 2 h2, etc,
125
+         * @param  string  $text       the display text
126
+         * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>"
127
+         * @param  array   $attributes the tag attributes
128
+         * @param  boolean $return    whether need return the generated html or just display it directly
129
+         *
130
+         * @return string|void the generated header html if $return is true or display it if not.
131
+         */
132
+        public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){
133
+            $nb = (int) $nb;
134
+            $type = (int) $type;
135
+            $str = null;
136
+            for ($i = 1; $i <= $nb; $i++) {
137
+                $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>';
138
+            }
139
+            if($return){
140
+                return $str;
141
+            }
142
+            echo $str;
143
+        }
144 144
 
145
-		/**
146
-		 * Generate the html "ul" tag
147
-		 * @param  array   $data the data to use for each "li" tag
148
-		 * @param  array   $attributes   the "ul" properties attribute use the array index below for each tag:
149
-		 *  for ul "ul", for li "li".
150
-		 * @param  boolean $return whether need return the generated html or just display it directly
151
-		 *
152
-		 * @return string|void the generated "ul" html  if $return is true or display it if not.
153
-		 */
154
-		public static function ul($data = array(), $attributes = array(), $return = true){
155
-			if($return){
156
-				return self::buildUlOl($data, $attributes, true, 'ul');
157
-			}
158
-			self::buildUlOl($data, $attributes, false, 'ul');
159
-		}
145
+        /**
146
+         * Generate the html "ul" tag
147
+         * @param  array   $data the data to use for each "li" tag
148
+         * @param  array   $attributes   the "ul" properties attribute use the array index below for each tag:
149
+         *  for ul "ul", for li "li".
150
+         * @param  boolean $return whether need return the generated html or just display it directly
151
+         *
152
+         * @return string|void the generated "ul" html  if $return is true or display it if not.
153
+         */
154
+        public static function ul($data = array(), $attributes = array(), $return = true){
155
+            if($return){
156
+                return self::buildUlOl($data, $attributes, true, 'ul');
157
+            }
158
+            self::buildUlOl($data, $attributes, false, 'ul');
159
+        }
160 160
 
161
-		/**
162
-		 * Generate the html "ol" tag
163
-		 * @param  array   $data the data to use for each "li" tag
164
-		 * @param  array   $attributes   the "ol" properties attribute use the array index below for each tag:
165
-		 *  for ol "ol", for li "li".
166
-		 * @param  boolean $return whether need return the generated html or just display it directly
167
-		 * @return string|void the generated "ol" html  if $return is true or display it if not.
168
-		 */
169
-		public static function ol($data = array(), $attributes = array(), $return = true){
170
-			if($return){
171
-				return self::buildUlOl($data, $attributes, true, 'ol');
172
-			}
173
-			self::buildUlOl($data, $attributes, false, 'ol');
174
-		}
161
+        /**
162
+         * Generate the html "ol" tag
163
+         * @param  array   $data the data to use for each "li" tag
164
+         * @param  array   $attributes   the "ol" properties attribute use the array index below for each tag:
165
+         *  for ol "ol", for li "li".
166
+         * @param  boolean $return whether need return the generated html or just display it directly
167
+         * @return string|void the generated "ol" html  if $return is true or display it if not.
168
+         */
169
+        public static function ol($data = array(), $attributes = array(), $return = true){
170
+            if($return){
171
+                return self::buildUlOl($data, $attributes, true, 'ol');
172
+            }
173
+            self::buildUlOl($data, $attributes, false, 'ol');
174
+        }
175 175
 
176 176
 
177
-		/**
178
-		 * Generate the html "table" tag
179
-		 * @param  array   $headers            the table headers to use between (<thead>)
180
-		 * @param  array   $body the table body values between (<tbody>)
181
-		 * @param  array   $attributes   the table properties attribute use the array index below for each tag:
182
-		 *  for table "table", for thead "thead", for thead tr "thead_tr",
183
-		 *  for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot",
184
-		 *  for tfoot tr "tfoot_tr", for tfoot th "tfoot_th".
185
-		 * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values
186
-		 * @param  boolean $return whether need return the generated html or just display it directly
187
-		 * @return string|void the generated "table" html  if $return is true or display it if not.
188
-		 */
189
-		public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){
190
-			$headers = (array) $headers;
191
-			$body = (array) $body;
192
-			$str = null;
193
-			$tableAttributes = '';
194
-			if(! empty($attributes['table'])){
195
-				$tableAttributes = ' ' . attributes_to_string($attributes['table']);
196
-			}
197
-			$str .= '<table' . $tableAttributes . '>';
198
-			$str .= self::buildTableHeader($headers, $attributes);
199
-			$str .= self::buildTableBody($body, $attributes);
177
+        /**
178
+         * Generate the html "table" tag
179
+         * @param  array   $headers            the table headers to use between (<thead>)
180
+         * @param  array   $body the table body values between (<tbody>)
181
+         * @param  array   $attributes   the table properties attribute use the array index below for each tag:
182
+         *  for table "table", for thead "thead", for thead tr "thead_tr",
183
+         *  for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot",
184
+         *  for tfoot tr "tfoot_tr", for tfoot th "tfoot_th".
185
+         * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values
186
+         * @param  boolean $return whether need return the generated html or just display it directly
187
+         * @return string|void the generated "table" html  if $return is true or display it if not.
188
+         */
189
+        public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){
190
+            $headers = (array) $headers;
191
+            $body = (array) $body;
192
+            $str = null;
193
+            $tableAttributes = '';
194
+            if(! empty($attributes['table'])){
195
+                $tableAttributes = ' ' . attributes_to_string($attributes['table']);
196
+            }
197
+            $str .= '<table' . $tableAttributes . '>';
198
+            $str .= self::buildTableHeader($headers, $attributes);
199
+            $str .= self::buildTableBody($body, $attributes);
200 200
 
201
-			if($use_footer){
202
-				$str .= self::buildTableFooter($headers, $attributes);
203
-			}
204
-			$str .= '</table>';
205
-			if($return){
206
-				return $str;
207
-			}
208
-			echo $str;
209
-		}
201
+            if($use_footer){
202
+                $str .= self::buildTableFooter($headers, $attributes);
203
+            }
204
+            $str .= '</table>';
205
+            if($return){
206
+                return $str;
207
+            }
208
+            echo $str;
209
+        }
210 210
 
211
-		/**
212
-		 * This method is used to build the header of the html table
213
-		 * @see  Html::table 
214
-		 * @return string|null
215
-		 */
216
-		protected static function buildTableHeader(array $headers, $attributes = array()){
217
-			$str = null;
218
-			$theadAttributes = '';
219
-			if(! empty($attributes['thead'])){
220
-				$theadAttributes = ' ' . attributes_to_string($attributes['thead']);
221
-			}
222
-			$theadtrAttributes = '';
223
-			if(! empty($attributes['thead_tr'])){
224
-				$theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']);
225
-			}
226
-			$thAttributes = '';
227
-			if(! empty($attributes['thead_th'])){
228
-				$thAttributes = ' ' . attributes_to_string($attributes['thead_th']);
229
-			}
230
-			$str .= '<thead' . $theadAttributes .'>';
231
-			$str .= '<tr' . $theadtrAttributes .'>';
232
-			foreach ($headers as $value) {
233
-				$str .= '<th' . $thAttributes .'>' .$value. '</th>';
234
-			}
235
-			$str .= '</tr>';
236
-			$str .= '</thead>';
237
-			return $str;
238
-		}
211
+        /**
212
+         * This method is used to build the header of the html table
213
+         * @see  Html::table 
214
+         * @return string|null
215
+         */
216
+        protected static function buildTableHeader(array $headers, $attributes = array()){
217
+            $str = null;
218
+            $theadAttributes = '';
219
+            if(! empty($attributes['thead'])){
220
+                $theadAttributes = ' ' . attributes_to_string($attributes['thead']);
221
+            }
222
+            $theadtrAttributes = '';
223
+            if(! empty($attributes['thead_tr'])){
224
+                $theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']);
225
+            }
226
+            $thAttributes = '';
227
+            if(! empty($attributes['thead_th'])){
228
+                $thAttributes = ' ' . attributes_to_string($attributes['thead_th']);
229
+            }
230
+            $str .= '<thead' . $theadAttributes .'>';
231
+            $str .= '<tr' . $theadtrAttributes .'>';
232
+            foreach ($headers as $value) {
233
+                $str .= '<th' . $thAttributes .'>' .$value. '</th>';
234
+            }
235
+            $str .= '</tr>';
236
+            $str .= '</thead>';
237
+            return $str;
238
+        }
239 239
 
240
-		/**
241
-		 * This method is used to build the body of the html table
242
-		 * @see  Html::table 
243
-		 * @return string|null
244
-		 */
245
-		protected static function buildTableBody(array $body, $attributes = array()){
246
-			$str = null;
247
-			$tbodyAttributes = '';
248
-			if(! empty($attributes['tbody'])){
249
-				$tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']);
250
-			}
251
-			$tbodytrAttributes = '';
252
-			if(! empty($attributes['tbody_tr'])){
253
-				$tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']);
254
-			}
255
-			$tbodytdAttributes = '';
256
-			if(! empty($attributes['tbody_td'])){
257
-				$tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']);
258
-			}
259
-			$str .= '<tbody' . $tbodyAttributes .'>';
260
-			$str .= self::buildTableBodyContent($body, $tbodytrAttributes, $tbodytdAttributes);
261
-			$str .= '</tbody>';
262
-			return $str;
263
-		}
240
+        /**
241
+         * This method is used to build the body of the html table
242
+         * @see  Html::table 
243
+         * @return string|null
244
+         */
245
+        protected static function buildTableBody(array $body, $attributes = array()){
246
+            $str = null;
247
+            $tbodyAttributes = '';
248
+            if(! empty($attributes['tbody'])){
249
+                $tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']);
250
+            }
251
+            $tbodytrAttributes = '';
252
+            if(! empty($attributes['tbody_tr'])){
253
+                $tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']);
254
+            }
255
+            $tbodytdAttributes = '';
256
+            if(! empty($attributes['tbody_td'])){
257
+                $tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']);
258
+            }
259
+            $str .= '<tbody' . $tbodyAttributes .'>';
260
+            $str .= self::buildTableBodyContent($body, $tbodytrAttributes, $tbodytdAttributes);
261
+            $str .= '</tbody>';
262
+            return $str;
263
+        }
264 264
 
265
-		/**
266
-		 * This method is used to build the body content of the html table
267
-		 * @param  array  $body              the table body data
268
-		 * @param  string $tbodytrAttributes the html attributes for each tr in tbody
269
-		 * @param  string $tbodytdAttributes the html attributes for each td in tbody
270
-		 * @return string                    
271
-		 */
272
-		protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes){
273
-			$str = null;
274
-			foreach ($body as $row) {
275
-				if(is_array($row)){
276
-					$str .= '<tr' . $tbodytrAttributes .'>';
277
-					foreach ($row as $value) {
278
-						$str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>';	
279
-					}
280
-					$str .= '</tr>';
281
-				}
282
-			}
283
-			return $str;
284
-		}
265
+        /**
266
+         * This method is used to build the body content of the html table
267
+         * @param  array  $body              the table body data
268
+         * @param  string $tbodytrAttributes the html attributes for each tr in tbody
269
+         * @param  string $tbodytdAttributes the html attributes for each td in tbody
270
+         * @return string                    
271
+         */
272
+        protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes){
273
+            $str = null;
274
+            foreach ($body as $row) {
275
+                if(is_array($row)){
276
+                    $str .= '<tr' . $tbodytrAttributes .'>';
277
+                    foreach ($row as $value) {
278
+                        $str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>';	
279
+                    }
280
+                    $str .= '</tr>';
281
+                }
282
+            }
283
+            return $str;
284
+        }
285 285
 
286
-		/**
287
-		 * This method is used to build the footer of the html table
288
-		 * @see  Html::table 
289
-		 * @return string|null
290
-		 */
291
-		protected static function buildTableFooter(array $footers, $attributes = array()){
292
-			$str = null;
293
-			$tfootAttributes = '';
294
-			if(! empty($attributes['tfoot'])){
295
-				$tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']);
296
-			}
297
-			$tfoottrAttributes = '';
298
-			if(! empty($attributes['tfoot_tr'])){
299
-				$tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']);
300
-			}
301
-			$thAttributes = '';
302
-			if(! empty($attributes['tfoot_th'])){
303
-				$thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']);
304
-			}
305
-			$str .= '<tfoot' . $tfootAttributes .'>';
306
-				$str .= '<tr' . $tfoottrAttributes .'>';
307
-				foreach ($footers as $value) {
308
-					$str .= '<th' . $thAttributes .'>' .$value. '</th>';
309
-				}
310
-				$str .= '</tr>';
311
-				$str .= '</tfoot>';
312
-			return $str;
313
-		}
286
+        /**
287
+         * This method is used to build the footer of the html table
288
+         * @see  Html::table 
289
+         * @return string|null
290
+         */
291
+        protected static function buildTableFooter(array $footers, $attributes = array()){
292
+            $str = null;
293
+            $tfootAttributes = '';
294
+            if(! empty($attributes['tfoot'])){
295
+                $tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']);
296
+            }
297
+            $tfoottrAttributes = '';
298
+            if(! empty($attributes['tfoot_tr'])){
299
+                $tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']);
300
+            }
301
+            $thAttributes = '';
302
+            if(! empty($attributes['tfoot_th'])){
303
+                $thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']);
304
+            }
305
+            $str .= '<tfoot' . $tfootAttributes .'>';
306
+                $str .= '<tr' . $tfoottrAttributes .'>';
307
+                foreach ($footers as $value) {
308
+                    $str .= '<th' . $thAttributes .'>' .$value. '</th>';
309
+                }
310
+                $str .= '</tr>';
311
+                $str .= '</tfoot>';
312
+            return $str;
313
+        }
314 314
 
315
-		/**
316
-		 * Return the HTML content for ol or ul tags
317
-		 * @see  Html::ol
318
-		 * @see  Html::ul
319
-		 * @param  string  $olul   the type 'ol' or 'ul'
320
-		 * @return void|string
321
-		 */
322
-		protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul'){
323
-			$data = (array) $data;
324
-			$str = null;
325
-			$olulAttributes = '';
326
-			if(! empty($attributes[$olul])){
327
-				$olulAttributes = ' ' . attributes_to_string($attributes[$olul]);
328
-			}
329
-			$liAttributes = '';
330
-			if(! empty($attributes['li'])){
331
-				$liAttributes = ' ' . attributes_to_string($attributes['li']);
332
-			}
333
-			$str .= '<' . $olul . $olulAttributes . '>';
334
-			foreach ($data as $row) {
335
-				$str .= '<li' . $liAttributes .'>' .$row. '</li>';
336
-			}
337
-			$str .= '</' . $olul . '>';
338
-			if($return){
339
-				return $str;
340
-			}
341
-			echo $str;
342
-		}
343
-	}
315
+        /**
316
+         * Return the HTML content for ol or ul tags
317
+         * @see  Html::ol
318
+         * @see  Html::ul
319
+         * @param  string  $olul   the type 'ol' or 'ul'
320
+         * @return void|string
321
+         */
322
+        protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul'){
323
+            $data = (array) $data;
324
+            $str = null;
325
+            $olulAttributes = '';
326
+            if(! empty($attributes[$olul])){
327
+                $olulAttributes = ' ' . attributes_to_string($attributes[$olul]);
328
+            }
329
+            $liAttributes = '';
330
+            if(! empty($attributes['li'])){
331
+                $liAttributes = ' ' . attributes_to_string($attributes['li']);
332
+            }
333
+            $str .= '<' . $olul . $olulAttributes . '>';
334
+            foreach ($data as $row) {
335
+                $str .= '<li' . $liAttributes .'>' .$row. '</li>';
336
+            }
337
+            $str .= '</' . $olul . '>';
338
+            if($return){
339
+                return $str;
340
+            }
341
+            echo $str;
342
+        }
343
+    }
Please login to merge, or discard this patch.
core/classes/model/Model.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
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 26
 
27 27
 
28 28
     /**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
         protected $_temporary_return_type = NULL;
121 121
     	
122 122
     	
123
-    	/**
123
+        /**
124 124
     		The database cache time 
125
-    	*/
126
-    	protected $dbCacheTime = 0;
125
+         */
126
+        protected $dbCacheTime = 0;
127 127
 
128 128
         /**
129 129
          * Instance of the Loader class
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
             }
152 152
             else{
153 153
                 $obj = & get_instance();
154
-        		if (isset($obj->database) && is_object($obj->database)){
154
+                if (isset($obj->database) && is_object($obj->database)){
155 155
                     /**
156
-                    * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
-                    * to prevent duplication
158
-                    */
159
-        			$this->setDatabaseInstance(clone $obj->database);
156
+                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
+                     * to prevent duplication
158
+                     */
159
+                    $this->setDatabaseInstance(clone $obj->database);
160 160
                 }
161 161
             }
162 162
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
          */
175 175
         public function get($primary_value)
176 176
         {
177
-    		return $this->get_by($this->primary_key, $primary_value);
177
+            return $this->get_by($this->primary_key, $primary_value);
178 178
         }
179 179
 
180 180
         /**
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
             {
190 190
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
191 191
             }
192
-    		$this->_set_where($where);
192
+            $this->_set_where($where);
193 193
 
194 194
             $this->trigger('before_get');
195
-			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
195
+            $type = $this->_temporary_return_type == 'array' ? 'array' : false;
196 196
             $this->getQueryBuilder()->from($this->_table);
197
-			$row = $this->_database->get($type);
197
+            $row = $this->_database->get($type);
198 198
             $this->_temporary_return_type = $this->return_type;
199 199
             $row = $this->trigger('after_get', $row);
200 200
             $this->_with = array();
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
             {
232 232
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
233 233
             }
234
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
234
+            $type = $this->_temporary_return_type == 'array' ? 'array':false;
235 235
             $this->getQueryBuilder()->from($this->_table);
236
-			$result = $this->_database->getAll($type);
236
+            $result = $this->_database->getAll($type);
237 237
             $this->_temporary_return_type = $this->return_type;
238 238
 
239 239
             foreach ($result as $key => &$row)
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         /**
248 248
          * Insert a new row into the table. $data should be an associative array
249 249
          * of data to be inserted. Returns newly created ID.
250
-		 * @see Database::insert
250
+         * @see Database::insert
251 251
          */
252 252
         public function insert($data = array(), $skip_validation = FALSE, $escape = true)
253 253
         {
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
             {
261 261
                 $data = $this->trigger('before_create', $data);
262 262
                 $this->getQueryBuilder()->from($this->_table);
263
-				$this->_database->insert($data, $escape);
263
+                $this->_database->insert($data, $escape);
264 264
                 $insert_id = $this->_database->insertId();
265 265
                 $this->trigger('after_create', $insert_id);
266
-				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
-				return ! $insert_id ? true : $insert_id;
266
+                //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
+                return ! $insert_id ? true : $insert_id;
268 268
             }
269 269
             else
270 270
             {
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
             {
325 325
                 $this->getQueryBuilder()->in($this->primary_key, $primary_values)
326 326
                                         ->from($this->_table);
327
-				$result = $this->_database->update($data, $escape);
327
+                $result = $this->_database->update($data, $escape);
328 328
                 $this->trigger('after_update', array($data, $result));
329 329
                 return $result;
330 330
             }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
             {
357 357
                 $this->_set_where($args);
358 358
                 $this->getQueryBuilder()->from($this->_table);
359
-				$result = $this->_database->update($data);
359
+                $result = $this->_database->update($data);
360 360
                 $this->trigger('after_update', array($data, $result));
361 361
                 return $result;
362 362
             }
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
         {
371 371
             $data = $this->trigger('before_update', $data);
372 372
             $this->getQueryBuilder()->from($this->_table);
373
-			$result = $this->_database->update($data, $escape);
373
+            $result = $this->_database->update($data, $escape);
374 374
             $this->trigger('after_update', array($data, $result));
375 375
             return $result;
376 376
         }
@@ -382,16 +382,16 @@  discard block
 block discarded – undo
382 382
         {
383 383
             $this->trigger('before_delete', $id);
384 384
             $this->getQueryBuilder()->where($this->primary_key, $id);
385
-			$result = false;
385
+            $result = false;
386 386
             if ($this->soft_delete)
387 387
             {
388 388
                 $this->getQueryBuilder()->from($this->_table);	
389
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
389
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
390 390
             }
391 391
             else
392 392
             {
393 393
                 $this->getQueryBuilder()->from($this->_table); 
394
-				$result = $this->_database->delete();
394
+                $result = $this->_database->delete();
395 395
             }
396 396
 
397 397
             $this->trigger('after_delete', $result);
@@ -404,18 +404,18 @@  discard block
 block discarded – undo
404 404
         public function delete_by()
405 405
         {
406 406
             $where = func_get_args();
407
-    	    $where = $this->trigger('before_delete', $where);
407
+            $where = $this->trigger('before_delete', $where);
408 408
             $this->_set_where($where);
409
-			$result = false;
409
+            $result = false;
410 410
             if ($this->soft_delete)
411 411
             {
412 412
                 $this->getQueryBuilder()->from($this->_table);	
413
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
413
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
414 414
             }
415 415
             else
416 416
             {
417 417
                 $this->getQueryBuilder()->from($this->_table); 
418
-				$result = $this->_database->delete();
418
+                $result = $this->_database->delete();
419 419
             }
420 420
             $this->trigger('after_delete', $result);
421 421
             return $result;
@@ -428,16 +428,16 @@  discard block
 block discarded – undo
428 428
         {
429 429
             $primary_values = $this->trigger('before_delete', $primary_values);
430 430
             $this->getQueryBuilder()->in($this->primary_key, $primary_values);
431
-			$result = false;
431
+            $result = false;
432 432
             if ($this->soft_delete)
433 433
             {
434 434
                 $this->getQueryBuilder()->from($this->_table);	
435
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
435
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
436 436
             }
437 437
             else
438 438
             {
439 439
                 $this->getQueryBuilder()->from($this->_table); 
440
-				$result = $this->_database->delete();
440
+                $result = $this->_database->delete();
441 441
             }
442 442
             $this->trigger('after_delete', $result);
443 443
             return $result;
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
          */
450 450
         public function truncate()
451 451
         {
452
-			$this->getQueryBuilder()->from($this->_table); 
453
-			$result = $this->_database->delete();
452
+            $this->getQueryBuilder()->from($this->_table); 
453
+            $result = $this->_database->delete();
454 454
             return $result;
455 455
         }
456 456
 
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
             return $this;
469 469
         }
470 470
 		
471
-		/**
472
-		* Relationship
473
-		*/
471
+        /**
472
+         * Relationship
473
+         */
474 474
         public function relate($row)
475 475
         {
476
-    		if (empty($row))
476
+            if (empty($row))
477 477
             {
478
-    		    return $row;
478
+                return $row;
479 479
             }
480 480
 
481 481
             $row = $this->relateBelongsTo($row);
@@ -508,9 +508,9 @@  discard block
 block discarded – undo
508 508
                 $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
509 509
             }
510 510
             $this->getQueryBuilder()
511
-									 ->select(array($key, $value))
512
-									 ->from($this->_table);
513
-			$result = $this->_database->getAll();
511
+                                        ->select(array($key, $value))
512
+                                        ->from($this->_table);
513
+            $result = $this->_database->getAll();
514 514
             $options = array();
515 515
             foreach ($result as $row)
516 516
             {
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
             $where = func_get_args();
533 533
             $this->_set_where($where);
534 534
             $this->getQueryBuilder()->from($this->_table);
535
-			$this->_database->getAll();
535
+            $this->_database->getAll();
536 536
             return $this->_database->numRows();
537 537
         }
538 538
 
@@ -545,20 +545,20 @@  discard block
 block discarded – undo
545 545
             {
546 546
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
547 547
             }
548
-			$this->getQueryBuilder()->from($this->_table);
549
-			$this->_database->getAll();
548
+            $this->getQueryBuilder()->from($this->_table);
549
+            $this->_database->getAll();
550 550
             return $this->_database->numRows();
551 551
         }
552 552
 		
553
-		/**
554
-		* Enabled cache temporary
555
-		*/
556
-		public function cached($ttl = 0){
557
-		  if ($ttl > 0){
558
-			$this->_database = $this->_database->cached($ttl);
559
-		  }
560
-		  return $this;
561
-		}
553
+        /**
554
+         * Enabled cache temporary
555
+         */
556
+        public function cached($ttl = 0){
557
+            if ($ttl > 0){
558
+            $this->_database = $this->_database->cached($ttl);
559
+            }
560
+            return $this;
561
+        }
562 562
 
563 563
         /**
564 564
          * Tell the class to skip the insert validation
@@ -582,10 +582,10 @@  discard block
 block discarded – undo
582 582
          */
583 583
         public function get_next_id()
584 584
         {
585
-			$this->getQueryBuilder()->select('AUTO_INCREMENT')
586
-									->from('information_schema.TABLES')
587
-									->where('TABLE_NAME', $this->_table)
588
-									->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
585
+            $this->getQueryBuilder()->select('AUTO_INCREMENT')
586
+                                    ->from('information_schema.TABLES')
587
+                                    ->where('TABLE_NAME', $this->_table)
588
+                                    ->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
589 589
             return (int) $this->_database->get()->AUTO_INCREMENT;
590 590
         }
591 591
 
@@ -708,24 +708,24 @@  discard block
 block discarded – undo
708 708
             {
709 709
                 if (is_object($row))
710 710
                 {
711
-					if (isset($row->$attr)){
712
-						unset($row->$attr);
713
-					}
711
+                    if (isset($row->$attr)){
712
+                        unset($row->$attr);
713
+                    }
714 714
                 }
715 715
                 else
716 716
                 {
717
-					if (isset($row[$attr])){
718
-						unset($row[$attr]);
719
-					}
717
+                    if (isset($row[$attr])){
718
+                        unset($row[$attr]);
719
+                    }
720 720
                 }
721 721
             }
722 722
             return $row;
723 723
         }
724 724
 		
725
-		 /**
726
-         * Return the database instance
727
-         * @return Database the database instance
728
-         */
725
+            /**
726
+             * Return the database instance
727
+             * @return Database the database instance
728
+             */
729 729
         public function getDatabaseInstance(){
730 730
             return $this->_database;
731 731
         }
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
          * set the Database instance for future use
735 735
          * @param Database $db the database object
736 736
          */
737
-         public function setDatabaseInstance($db){
737
+            public function setDatabaseInstance($db){
738 738
             $this->_database = $db;
739 739
             if ($this->dbCacheTime > 0){
740 740
                 $this->_database->setCache($this->dbCacheTime);
@@ -753,14 +753,14 @@  discard block
 block discarded – undo
753 753
         /**
754 754
          * Set the loader instance for future use
755 755
          * @param Loader $loader the loader object
756
-		 * @return object
756
+         * @return object
757 757
          */
758
-         public function setLoader($loader){
758
+            public function setLoader($loader){
759 759
             $this->loaderInstance = $loader;
760 760
             return $this;
761 761
         }
762 762
 
763
-		/**
763
+        /**
764 764
          * Return the queryBuilder instance this is the shortcut to database queryBuilder
765 765
          * @return object the DatabaseQueryBuilder instance
766 766
          */
@@ -771,9 +771,9 @@  discard block
 block discarded – undo
771 771
         /**
772 772
          * Set the DatabaseQueryBuilder instance for future use
773 773
          * @param object $queryBuilder the DatabaseQueryBuilder object
774
-		 * @return object
774
+         * @return object
775 775
          */
776
-         public function setQueryBuilder($queryBuilder){
776
+            public function setQueryBuilder($queryBuilder){
777 777
             $this->_database->setQueryBuilder($queryBuilder);
778 778
             return $this;
779 779
         }
@@ -790,9 +790,9 @@  discard block
 block discarded – undo
790 790
         /**
791 791
          * Set the form validation instance for future use
792 792
          * @param FormValidation $fv the form validation object
793
-		 * @return object
793
+         * @return object
794 794
          */
795
-         public function setFormValidation($fv){
795
+            public function setFormValidation($fv){
796 796
             $this->formValidationInstance = $fv;
797 797
             return $this;
798 798
         }
@@ -833,12 +833,12 @@  discard block
 block discarded – undo
833 833
          * INTERNAL METHODS
834 834
          * ------------------------------------------------------------ */
835 835
 
836
-		/**
837
-		* relate for the relation "belongs_to"
838
-		* @return mixed
839
-		*/
840
-		protected function relateBelongsTo($row){
841
-			foreach ($this->belongs_to as $key => $value)
836
+        /**
837
+         * relate for the relation "belongs_to"
838
+         * @return mixed
839
+         */
840
+        protected function relateBelongsTo($row){
841
+            foreach ($this->belongs_to as $key => $value)
842 842
             {
843 843
                 if (is_string($value))
844 844
                 {
@@ -869,15 +869,15 @@  discard block
 block discarded – undo
869 869
                     }
870 870
                 }
871 871
             }
872
-			return $row;
873
-		}
874
-
875
-		/**
876
-		* relate for the relation "has_many"
877
-		* @return mixed
878
-		*/
879
-		protected function relateHasMany($row){
880
-			foreach ($this->has_many as $key => $value)
872
+            return $row;
873
+        }
874
+
875
+        /**
876
+         * relate for the relation "has_many"
877
+         * @return mixed
878
+         */
879
+        protected function relateHasMany($row){
880
+            foreach ($this->has_many as $key => $value)
881 881
             {
882 882
                 if (is_string($value))
883 883
                 {
@@ -908,8 +908,8 @@  discard block
 block discarded – undo
908 908
                     }
909 909
                 }
910 910
             }
911
-			return $row;
912
-		}
911
+            return $row;
912
+        }
913 913
 		
914 914
         /**
915 915
          * Trigger an event and call its observers. Pass through the event name
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
             }
946 946
             $fv = $this->formValidationInstance;
947 947
             if (! is_object($fv)){
948
-                 Loader::library('FormValidation');
948
+                    Loader::library('FormValidation');
949 949
                 $fv = $this->formvalidation;
950 950
                 $this->setFormValidation($fv);  
951 951
             }
@@ -960,30 +960,30 @@  discard block
 block discarded – undo
960 960
         }
961 961
 		
962 962
 		
963
-		/**
964
-		* Set WHERE parameters, when is array
965
-		* @param array $params
966
-		*/
967
-		protected function _set_where_array(array $params){
968
-			foreach ($params as $field => $filter)
969
-			{
970
-				if (is_array($filter))
971
-				{
972
-					$this->getQueryBuilder()->in($field, $filter);
973
-				}
974
-				else
975
-				{
976
-					if (is_int($field))
977
-					{
978
-						$this->getQueryBuilder()->where($filter);
979
-					}
980
-					else
981
-					{
982
-						$this->getQueryBuilder()->where($field, $filter);
983
-					}
984
-				}
985
-			}
986
-		}
963
+        /**
964
+         * Set WHERE parameters, when is array
965
+         * @param array $params
966
+         */
967
+        protected function _set_where_array(array $params){
968
+            foreach ($params as $field => $filter)
969
+            {
970
+                if (is_array($filter))
971
+                {
972
+                    $this->getQueryBuilder()->in($field, $filter);
973
+                }
974
+                else
975
+                {
976
+                    if (is_int($field))
977
+                    {
978
+                        $this->getQueryBuilder()->where($filter);
979
+                    }
980
+                    else
981
+                    {
982
+                        $this->getQueryBuilder()->where($field, $filter);
983
+                    }
984
+                }
985
+            }
986
+        }
987 987
 
988 988
 
989 989
         /**
@@ -999,8 +999,8 @@  discard block
 block discarded – undo
999 999
             {
1000 1000
                 $this->getQueryBuilder()->where($params[0]);
1001 1001
             }
1002
-        	else if (count($params) == 2)
1003
-    		{
1002
+            else if (count($params) == 2)
1003
+            {
1004 1004
                 if (is_array($params[1]))
1005 1005
                 {
1006 1006
                     $this->getQueryBuilder()->in($params[0], $params[1]);
@@ -1009,11 +1009,11 @@  discard block
 block discarded – undo
1009 1009
                 {
1010 1010
                     $this->getQueryBuilder()->where($params[0], $params[1]);
1011 1011
                 }
1012
-    		}
1013
-    		else if (count($params) == 3)
1014
-    		{
1015
-    			$this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1016
-    		}
1012
+            }
1013
+            else if (count($params) == 3)
1014
+            {
1015
+                $this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1016
+            }
1017 1017
             else
1018 1018
             {
1019 1019
                 if (is_array($params[1]))
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 
1030 1030
         /**
1031 1031
             Shortcut to controller
1032
-        */
1032
+         */
1033 1033
         public function __get($key){
1034 1034
             return get_instance()->{$key};
1035 1035
         }
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Indentation   +489 added lines, -489 removed lines patch added patch discarded remove patch
@@ -1,541 +1,541 @@
 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 Response{
27
+    class Response{
28 28
 
29
-		/**
30
-		 * The list of request header to send with response
31
-		 * @var array
32
-		 */
33
-		private static $headers = array();
29
+        /**
30
+         * The list of request header to send with response
31
+         * @var array
32
+         */
33
+        private static $headers = array();
34 34
 
35
-		/**
36
-		 * The logger instance
37
-		 * @var object
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var object
38
+         */
39
+        private static $logger;
40 40
 		
41
-		/**
42
-		 * The final page content to display to user
43
-		 * @var string
44
-		 */
45
-		private $_pageRender = null;
41
+        /**
42
+         * The final page content to display to user
43
+         * @var string
44
+         */
45
+        private $_pageRender = null;
46 46
 		
47
-		/**
48
-		 * The current request URL
49
-		 * @var string
50
-		 */
51
-		private $_currentUrl = null;
47
+        /**
48
+         * The current request URL
49
+         * @var string
50
+         */
51
+        private $_currentUrl = null;
52 52
 		
53
-		/**
54
-		 * The current request URL cache key
55
-		 * @var string
56
-		 */
57
-		private $_currentUrlCacheKey = null;
53
+        /**
54
+         * The current request URL cache key
55
+         * @var string
56
+         */
57
+        private $_currentUrlCacheKey = null;
58 58
 		
59
-		/**
60
-		* Whether we can compress the output using Gzip
61
-		* @var boolean
62
-		*/
63
-		private static $_canCompressOutput = false;
59
+        /**
60
+         * Whether we can compress the output using Gzip
61
+         * @var boolean
62
+         */
63
+        private static $_canCompressOutput = false;
64 64
 		
65
-		/**
66
-		 * Construct new response instance
67
-		 */
68
-		public function __construct(){
69
-			$currentUrl = '';
70
-			if (! empty($_SERVER['REQUEST_URI'])){
71
-				$currentUrl = $_SERVER['REQUEST_URI'];
72
-			}
73
-			if (! empty($_SERVER['QUERY_STRING'])){
74
-				$currentUrl .= '?' . $_SERVER['QUERY_STRING'];
75
-			}
76
-			$this->_currentUrl =  $currentUrl;
65
+        /**
66
+         * Construct new response instance
67
+         */
68
+        public function __construct(){
69
+            $currentUrl = '';
70
+            if (! empty($_SERVER['REQUEST_URI'])){
71
+                $currentUrl = $_SERVER['REQUEST_URI'];
72
+            }
73
+            if (! empty($_SERVER['QUERY_STRING'])){
74
+                $currentUrl .= '?' . $_SERVER['QUERY_STRING'];
75
+            }
76
+            $this->_currentUrl =  $currentUrl;
77 77
 					
78
-			$this->_currentUrlCacheKey = md5($this->_currentUrl);
78
+            $this->_currentUrlCacheKey = md5($this->_currentUrl);
79 79
 			
80
-			self::$_canCompressOutput = get_config('compress_output')
81
-										  && isset($_SERVER['HTTP_ACCEPT_ENCODING']) 
82
-										  && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false 
83
-										  && extension_loaded('zlib')
84
-										  && (bool) ini_get('zlib.output_compression') === false;
85
-		}
80
+            self::$_canCompressOutput = get_config('compress_output')
81
+                                          && isset($_SERVER['HTTP_ACCEPT_ENCODING']) 
82
+                                          && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false 
83
+                                          && extension_loaded('zlib')
84
+                                          && (bool) ini_get('zlib.output_compression') === false;
85
+        }
86 86
 
87 87
 		
88
-		/**
89
-		 * The signleton of the logger
90
-		 * @return Object the Log instance
91
-		 */
92
-		public static function getLogger(){
93
-			if(self::$logger == null){
94
-				$logger = array();
95
-				$logger[0] =& class_loader('Log', 'classes');
96
-				$logger[0]->setLogger('Library::Response');
97
-				self::$logger = $logger[0];
98
-			}
99
-			return self::$logger;			
100
-		}
88
+        /**
89
+         * The signleton of the logger
90
+         * @return Object the Log instance
91
+         */
92
+        public static function getLogger(){
93
+            if(self::$logger == null){
94
+                $logger = array();
95
+                $logger[0] =& class_loader('Log', 'classes');
96
+                $logger[0]->setLogger('Library::Response');
97
+                self::$logger = $logger[0];
98
+            }
99
+            return self::$logger;			
100
+        }
101 101
 
102
-		/**
103
-		 * Set the log instance for future use
104
-		 * @param object $logger the log object
105
-		 * @return object the log instance
106
-		 */
107
-		public static function setLogger($logger){
108
-			self::$logger = $logger;
109
-			return self::$logger;
110
-		}
102
+        /**
103
+         * Set the log instance for future use
104
+         * @param object $logger the log object
105
+         * @return object the log instance
106
+         */
107
+        public static function setLogger($logger){
108
+            self::$logger = $logger;
109
+            return self::$logger;
110
+        }
111 111
 
112 112
 
113
-		/**
114
-		 * Send the HTTP Response headers
115
-		 * @param  integer $httpCode the HTTP status code
116
-		 * @param  array   $headers   the additional headers to add to the existing headers list
117
-		 */
118
-		public static function sendHeaders($httpCode = 200, array $headers = array()){
119
-			set_http_status_header($httpCode);
120
-			self::setHeaders($headers);
121
-			if(! headers_sent()){
122
-				foreach(self::getHeaders() as $key => $value){
123
-					header($key .': '.$value);
124
-				}
125
-			}
126
-		}
113
+        /**
114
+         * Send the HTTP Response headers
115
+         * @param  integer $httpCode the HTTP status code
116
+         * @param  array   $headers   the additional headers to add to the existing headers list
117
+         */
118
+        public static function sendHeaders($httpCode = 200, array $headers = array()){
119
+            set_http_status_header($httpCode);
120
+            self::setHeaders($headers);
121
+            if(! headers_sent()){
122
+                foreach(self::getHeaders() as $key => $value){
123
+                    header($key .': '.$value);
124
+                }
125
+            }
126
+        }
127 127
 
128
-		/**
129
-		 * Get the list of the headers
130
-		 * @return array the headers list
131
-		 */
132
-		public static function getHeaders(){
133
-			return self::$headers;
134
-		}
128
+        /**
129
+         * Get the list of the headers
130
+         * @return array the headers list
131
+         */
132
+        public static function getHeaders(){
133
+            return self::$headers;
134
+        }
135 135
 
136
-		/**
137
-		 * Get the header value for the given name
138
-		 * @param  string $name the header name
139
-		 * @return string|null       the header value
140
-		 */
141
-		public static function getHeader($name){
142
-			if(array_key_exists($name, self::$headers)){
143
-				return self::$headers[$name];
144
-			}
145
-			return null;
146
-		}
136
+        /**
137
+         * Get the header value for the given name
138
+         * @param  string $name the header name
139
+         * @return string|null       the header value
140
+         */
141
+        public static function getHeader($name){
142
+            if(array_key_exists($name, self::$headers)){
143
+                return self::$headers[$name];
144
+            }
145
+            return null;
146
+        }
147 147
 
148 148
 
149
-		/**
150
-		 * Set the header value for the specified name
151
-		 * @param string $name  the header name
152
-		 * @param string $value the header value to be set
153
-		 */
154
-		public static function setHeader($name, $value){
155
-			self::$headers[$name] = $value;
156
-		}
149
+        /**
150
+         * Set the header value for the specified name
151
+         * @param string $name  the header name
152
+         * @param string $value the header value to be set
153
+         */
154
+        public static function setHeader($name, $value){
155
+            self::$headers[$name] = $value;
156
+        }
157 157
 
158
-		/**
159
-		 * Set the headers using array
160
-		 * @param array $headers the list of the headers to set. 
161
-		 * Note: this will merge with the existing headers
162
-		 */
163
-		public static function setHeaders(array $headers){
164
-			self::$headers = array_merge(self::getHeaders(), $headers);
165
-		}
158
+        /**
159
+         * Set the headers using array
160
+         * @param array $headers the list of the headers to set. 
161
+         * Note: this will merge with the existing headers
162
+         */
163
+        public static function setHeaders(array $headers){
164
+            self::$headers = array_merge(self::getHeaders(), $headers);
165
+        }
166 166
 		
167
-		/**
168
-		 * Redirect user to the specified page
169
-		 * @param  string $path the URL or URI to be redirect to
170
-		 */
171
-		public static function redirect($path = ''){
172
-			$logger = self::getLogger();
173
-			$url = Url::site_url($path);
174
-			$logger->info('Redirect to URL [' .$url. ']');
175
-			if(! headers_sent()){
176
-				header('Location: '.$url);
177
-				exit;
178
-			}
179
-			echo '<script>
167
+        /**
168
+         * Redirect user to the specified page
169
+         * @param  string $path the URL or URI to be redirect to
170
+         */
171
+        public static function redirect($path = ''){
172
+            $logger = self::getLogger();
173
+            $url = Url::site_url($path);
174
+            $logger->info('Redirect to URL [' .$url. ']');
175
+            if(! headers_sent()){
176
+                header('Location: '.$url);
177
+                exit;
178
+            }
179
+            echo '<script>
180 180
 					location.href = "'.$url.'";
181 181
 				</script>';
182
-		}
182
+        }
183 183
 
184
-		/**
185
-		 * Render the view to display later or return the content
186
-		 * @param  string  $view   the view name or path
187
-		 * @param  array|object   $data   the variable data to use in the view
188
-		 * @param  boolean $return whether to return the view generated content or display it directly
189
-		 * @return void|string          if $return is true will return the view content otherwise
190
-		 * will display the view content.
191
-		 */
192
-		public function render($view, $data = null, $return = false){
193
-			$logger = self::getLogger();
194
-			//convert data to an array
195
-			$data = (array) $data;
196
-			$view = str_ireplace('.php', '', $view);
197
-			$view = trim($view, '/\\');
198
-			$viewFile = $view . '.php';
199
-			$path = APPS_VIEWS_PATH . $viewFile;
184
+        /**
185
+         * Render the view to display later or return the content
186
+         * @param  string  $view   the view name or path
187
+         * @param  array|object   $data   the variable data to use in the view
188
+         * @param  boolean $return whether to return the view generated content or display it directly
189
+         * @return void|string          if $return is true will return the view content otherwise
190
+         * will display the view content.
191
+         */
192
+        public function render($view, $data = null, $return = false){
193
+            $logger = self::getLogger();
194
+            //convert data to an array
195
+            $data = (array) $data;
196
+            $view = str_ireplace('.php', '', $view);
197
+            $view = trim($view, '/\\');
198
+            $viewFile = $view . '.php';
199
+            $path = APPS_VIEWS_PATH . $viewFile;
200 200
 			
201
-			//check in module first
202
-			$logger->debug('Checking the view [' . $view . '] from module list ...');
203
-			$moduleInfo = $this->getModuleInfoForView($view);
204
-			$module    = $moduleInfo['module'];
205
-			$view  = $moduleInfo['view'];
201
+            //check in module first
202
+            $logger->debug('Checking the view [' . $view . '] from module list ...');
203
+            $moduleInfo = $this->getModuleInfoForView($view);
204
+            $module    = $moduleInfo['module'];
205
+            $view  = $moduleInfo['view'];
206 206
 			
207
-			$moduleViewPath = Module::findViewFullPath($view, $module);
208
-			if($moduleViewPath){
209
-				$path = $moduleViewPath;
210
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it');
211
-			}
212
-			else{
213
-				$logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location');
214
-			}
207
+            $moduleViewPath = Module::findViewFullPath($view, $module);
208
+            if($moduleViewPath){
209
+                $path = $moduleViewPath;
210
+                $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it');
211
+            }
212
+            else{
213
+                $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location');
214
+            }
215 215
 			
216
-			$logger->info('The view file path to be loaded is [' . $path . ']');
216
+            $logger->info('The view file path to be loaded is [' . $path . ']');
217 217
 			
218
-			/////////
219
-			if($return){
220
-				return $this->loadView($path, $data, true);
221
-			}
222
-			$this->loadView($path, $data, false);
223
-		}
218
+            /////////
219
+            if($return){
220
+                return $this->loadView($path, $data, true);
221
+            }
222
+            $this->loadView($path, $data, false);
223
+        }
224 224
 
225 225
 		
226
-		/**
227
-		* Send the final page output to user
228
-		*/
229
-		public function renderFinalPage(){
230
-			$logger = self::getLogger();
231
-			$obj = & get_instance();
232
-			$cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
233
-			$dispatcher = $obj->eventdispatcher;
234
-			$content = $this->_pageRender;
235
-			if(! $content){
236
-				$logger->warning('The final view content is empty.');
237
-				return;
238
-			}
239
-			//dispatch
240
-			$event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
241
-			$content = null;
242
-			if(! empty($event->payload)){
243
-				$content = $event->payload;
244
-			}
245
-			if(empty($content)){
246
-				$logger->warning('The view content is empty after dispatch to event listeners.');
247
-			}
248
-			//remove unsed space in the content
249
-			$content = preg_replace('~>\s*\n\s*<~', '><', $content);
250
-			//check whether need save the page into cache.
251
-			if($cachePageStatus){
252
-				$this->savePageContentIntoCache($content);
253
-			}
254
-			$content = $this->replaceElapseTimeAndMemoryUsage($content);
226
+        /**
227
+         * Send the final page output to user
228
+         */
229
+        public function renderFinalPage(){
230
+            $logger = self::getLogger();
231
+            $obj = & get_instance();
232
+            $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
233
+            $dispatcher = $obj->eventdispatcher;
234
+            $content = $this->_pageRender;
235
+            if(! $content){
236
+                $logger->warning('The final view content is empty.');
237
+                return;
238
+            }
239
+            //dispatch
240
+            $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
241
+            $content = null;
242
+            if(! empty($event->payload)){
243
+                $content = $event->payload;
244
+            }
245
+            if(empty($content)){
246
+                $logger->warning('The view content is empty after dispatch to event listeners.');
247
+            }
248
+            //remove unsed space in the content
249
+            $content = preg_replace('~>\s*\n\s*<~', '><', $content);
250
+            //check whether need save the page into cache.
251
+            if($cachePageStatus){
252
+                $this->savePageContentIntoCache($content);
253
+            }
254
+            $content = $this->replaceElapseTimeAndMemoryUsage($content);
255 255
 
256
-			//compress the output if is available
257
-			$type = null;
258
-			if (self::$_canCompressOutput){
259
-				$type = 'ob_gzhandler';
260
-			}
261
-			ob_start($type);
262
-			self::sendHeaders(200);
263
-			echo $content;
264
-			ob_end_flush();
265
-		}
256
+            //compress the output if is available
257
+            $type = null;
258
+            if (self::$_canCompressOutput){
259
+                $type = 'ob_gzhandler';
260
+            }
261
+            ob_start($type);
262
+            self::sendHeaders(200);
263
+            echo $content;
264
+            ob_end_flush();
265
+        }
266 266
 
267 267
 		
268
-		/**
269
-		* Send the final page output to user if is cached
270
-		* @param object $cache the cache instance
271
-		*
272
-		* @return boolean whether the page content if available or not
273
-		*/
274
-		public function renderFinalPageFromCache(&$cache){
275
-			$logger = self::getLogger();
276
-			//the current page cache key for identification
277
-			$pageCacheKey = $this->_currentUrlCacheKey;
268
+        /**
269
+         * Send the final page output to user if is cached
270
+         * @param object $cache the cache instance
271
+         *
272
+         * @return boolean whether the page content if available or not
273
+         */
274
+        public function renderFinalPageFromCache(&$cache){
275
+            $logger = self::getLogger();
276
+            //the current page cache key for identification
277
+            $pageCacheKey = $this->_currentUrlCacheKey;
278 278
 			
279
-			$logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...');
280
-			//get the cache information to prepare header to send to browser
281
-			$cacheInfo = $cache->getInfo($pageCacheKey);
282
-			if($cacheInfo){
283
-				$status = $this->sendCacheNotYetExpireInfo($cacheInfo);
284
-				if($status === false){
285
-					return $this->sendCachePageContentToBrowser($cache);
286
-				}
287
-				return true;
288
-			}
289
-			return false;
290
-		}
279
+            $logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...');
280
+            //get the cache information to prepare header to send to browser
281
+            $cacheInfo = $cache->getInfo($pageCacheKey);
282
+            if($cacheInfo){
283
+                $status = $this->sendCacheNotYetExpireInfo($cacheInfo);
284
+                if($status === false){
285
+                    return $this->sendCachePageContentToBrowser($cache);
286
+                }
287
+                return true;
288
+            }
289
+            return false;
290
+        }
291 291
 	
292 292
 		
293
-		/**
294
-		* Get the final page to be rendered
295
-		* @return string
296
-		*/
297
-		public function getFinalPageRendered(){
298
-			return $this->_pageRender;
299
-		}
293
+        /**
294
+         * Get the final page to be rendered
295
+         * @return string
296
+         */
297
+        public function getFinalPageRendered(){
298
+            return $this->_pageRender;
299
+        }
300 300
 
301
-		/**
302
-		 * Send the HTTP 404 error if can not found the 
303
-		 * routing information for the current request
304
-		 */
305
-		public static function send404(){
306
-			/********* for logs **************/
307
-			//can't use $obj = & get_instance()  here because the global super object will be available until
308
-			//the main controller is loaded even for Loader::library('xxxx');
309
-			$logger = self::getLogger();
310
-			$request =& class_loader('Request', 'classes');
311
-			$userAgent =& class_loader('Browser');
312
-			$browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion();
301
+        /**
302
+         * Send the HTTP 404 error if can not found the 
303
+         * routing information for the current request
304
+         */
305
+        public static function send404(){
306
+            /********* for logs **************/
307
+            //can't use $obj = & get_instance()  here because the global super object will be available until
308
+            //the main controller is loaded even for Loader::library('xxxx');
309
+            $logger = self::getLogger();
310
+            $request =& class_loader('Request', 'classes');
311
+            $userAgent =& class_loader('Browser');
312
+            $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion();
313 313
 			
314
-			//here can't use Loader::functions just include the helper manually
315
-			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
314
+            //here can't use Loader::functions just include the helper manually
315
+            require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
316 316
 
317
-			$str = '[404 page not found] : ';
318
-			$str .= ' Unable to find the request page [' . $request->requestUri() . ']. The visitor IP address [' . get_ip() . '], browser [' . $browser . ']';
319
-			$logger->error($str);
320
-			/***********************************/
321
-			$path = CORE_VIEWS_PATH . '404.php';
322
-			if(file_exists($path)){
323
-				//compress the output if is available
324
-				$type = null;
325
-				if (self::$_canCompressOutput){
326
-					$type = 'ob_gzhandler';
327
-				}
328
-				ob_start($type);
329
-				require_once $path;
330
-				$output = ob_get_clean();
331
-				self::sendHeaders(404);
332
-				echo $output;
333
-			}
334
-			else{
335
-				show_error('The 404 view [' .$path. '] does not exist');
336
-			}
337
-		}
317
+            $str = '[404 page not found] : ';
318
+            $str .= ' Unable to find the request page [' . $request->requestUri() . ']. The visitor IP address [' . get_ip() . '], browser [' . $browser . ']';
319
+            $logger->error($str);
320
+            /***********************************/
321
+            $path = CORE_VIEWS_PATH . '404.php';
322
+            if(file_exists($path)){
323
+                //compress the output if is available
324
+                $type = null;
325
+                if (self::$_canCompressOutput){
326
+                    $type = 'ob_gzhandler';
327
+                }
328
+                ob_start($type);
329
+                require_once $path;
330
+                $output = ob_get_clean();
331
+                self::sendHeaders(404);
332
+                echo $output;
333
+            }
334
+            else{
335
+                show_error('The 404 view [' .$path. '] does not exist');
336
+            }
337
+        }
338 338
 
339
-		/**
340
-		 * Display the error to user
341
-		 * @param  array  $data the error information
342
-		 */
343
-		public static function sendError(array $data = array()){
344
-			$path = CORE_VIEWS_PATH . 'errors.php';
345
-			if(file_exists($path)){
346
-				//compress the output if is available
347
-				$type = null;
348
-				if (self::$_canCompressOutput){
349
-					$type = 'ob_gzhandler';
350
-				}
351
-				ob_start($type);
352
-				extract($data);
353
-				require_once $path;
354
-				$output = ob_get_clean();
355
-				self::sendHeaders(503);
356
-				echo $output;
357
-			}
358
-			else{
359
-				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
360
-				set_http_status_header(503);
361
-				echo 'The error view [' . $path . '] does not exist';
362
-			}
363
-		}
339
+        /**
340
+         * Display the error to user
341
+         * @param  array  $data the error information
342
+         */
343
+        public static function sendError(array $data = array()){
344
+            $path = CORE_VIEWS_PATH . 'errors.php';
345
+            if(file_exists($path)){
346
+                //compress the output if is available
347
+                $type = null;
348
+                if (self::$_canCompressOutput){
349
+                    $type = 'ob_gzhandler';
350
+                }
351
+                ob_start($type);
352
+                extract($data);
353
+                require_once $path;
354
+                $output = ob_get_clean();
355
+                self::sendHeaders(503);
356
+                echo $output;
357
+            }
358
+            else{
359
+                //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
360
+                set_http_status_header(503);
361
+                echo 'The error view [' . $path . '] does not exist';
362
+            }
363
+        }
364 364
 
365
-		/**
366
-		 * Send the cache not yet expire to browser
367
-		 * @param  array $cacheInfo the cache information
368
-		 * @return boolean            true if the information is sent otherwise false
369
-		 */
370
-		protected function sendCacheNotYetExpireInfo($cacheInfo){
371
-			if(! empty($cacheInfo)){
372
-				$logger = self::getLogger();
373
-				$lastModified = $cacheInfo['mtime'];
374
-				$expire = $cacheInfo['expire'];
375
-				$maxAge = $expire - $_SERVER['REQUEST_TIME'];
376
-				self::setHeader('Pragma', 'public');
377
-				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
378
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
379
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');
380
-				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
381
-					$logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser');
382
-					self::sendHeaders(304);
383
-					return true;
384
-				}
385
-			}
386
-			return false;
387
-		}
365
+        /**
366
+         * Send the cache not yet expire to browser
367
+         * @param  array $cacheInfo the cache information
368
+         * @return boolean            true if the information is sent otherwise false
369
+         */
370
+        protected function sendCacheNotYetExpireInfo($cacheInfo){
371
+            if(! empty($cacheInfo)){
372
+                $logger = self::getLogger();
373
+                $lastModified = $cacheInfo['mtime'];
374
+                $expire = $cacheInfo['expire'];
375
+                $maxAge = $expire - $_SERVER['REQUEST_TIME'];
376
+                self::setHeader('Pragma', 'public');
377
+                self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
378
+                self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
379
+                self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');
380
+                if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
381
+                    $logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser');
382
+                    self::sendHeaders(304);
383
+                    return true;
384
+                }
385
+            }
386
+            return false;
387
+        }
388 388
 
389
-		/**
390
-		 * Set the value of '{elapsed_time}' and '{memory_usage}'
391
-		 * @param  string $content the page content
392
-		 * @return string          the page content after replace 
393
-		 * '{elapsed_time}', '{memory_usage}'
394
-		 */
395
-		protected function replaceElapseTimeAndMemoryUsage($content){
396
-			//load benchmark class
397
-			$benchmark = & class_loader('Benchmark');
389
+        /**
390
+         * Set the value of '{elapsed_time}' and '{memory_usage}'
391
+         * @param  string $content the page content
392
+         * @return string          the page content after replace 
393
+         * '{elapsed_time}', '{memory_usage}'
394
+         */
395
+        protected function replaceElapseTimeAndMemoryUsage($content){
396
+            //load benchmark class
397
+            $benchmark = & class_loader('Benchmark');
398 398
 			
399
-			// Parse out the elapsed time and memory usage,
400
-			// then swap the pseudo-variables with the data
401
-			$elapsedTime = $benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END');
402
-			$memoryUsage	= round($benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB';
403
-			return str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content);	
404
-		}
399
+            // Parse out the elapsed time and memory usage,
400
+            // then swap the pseudo-variables with the data
401
+            $elapsedTime = $benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END');
402
+            $memoryUsage	= round($benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB';
403
+            return str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content);	
404
+        }
405 405
 
406
-		/**
407
-		 * Send the page content from cache to browser
408
-		 * @param object $cache the cache instance
409
-		 * @return boolean     the status of the operation
410
-		 */
411
-		protected function sendCachePageContentToBrowser(&$cache){
412
-			$logger = self::getLogger();
413
-			$logger->info('The cache page content is expired or the browser doesn\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser');
414
-			self::sendHeaders(200);
415
-			//current page cache key
416
-			$pageCacheKey = $this->_currentUrlCacheKey;
417
-			//get the cache content
418
-			$content = $cache->get($pageCacheKey);
419
-			if($content){
420
-				$logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it');
421
-				$content = $this->replaceElapseTimeAndMemoryUsage($content);
422
-				///display the final output
423
-				//compress the output if is available
424
-				$type = null;
425
-				if (self::$_canCompressOutput){
426
-					$type = 'ob_gzhandler';
427
-				}
428
-				ob_start($type);
429
-				echo $content;
430
-				ob_end_flush();
431
-				return true;
432
-			}
433
-			$logger->info('The page cache content for the URL [' . $this->_currentUrl . '] is not valid may be already expired');
434
-			$cache->delete($pageCacheKey);
435
-			return false;
436
-		}
406
+        /**
407
+         * Send the page content from cache to browser
408
+         * @param object $cache the cache instance
409
+         * @return boolean     the status of the operation
410
+         */
411
+        protected function sendCachePageContentToBrowser(&$cache){
412
+            $logger = self::getLogger();
413
+            $logger->info('The cache page content is expired or the browser doesn\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser');
414
+            self::sendHeaders(200);
415
+            //current page cache key
416
+            $pageCacheKey = $this->_currentUrlCacheKey;
417
+            //get the cache content
418
+            $content = $cache->get($pageCacheKey);
419
+            if($content){
420
+                $logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it');
421
+                $content = $this->replaceElapseTimeAndMemoryUsage($content);
422
+                ///display the final output
423
+                //compress the output if is available
424
+                $type = null;
425
+                if (self::$_canCompressOutput){
426
+                    $type = 'ob_gzhandler';
427
+                }
428
+                ob_start($type);
429
+                echo $content;
430
+                ob_end_flush();
431
+                return true;
432
+            }
433
+            $logger->info('The page cache content for the URL [' . $this->_currentUrl . '] is not valid may be already expired');
434
+            $cache->delete($pageCacheKey);
435
+            return false;
436
+        }
437 437
 
438
-		/**
439
-		 * Save the content of page into cache
440
-		 * @param  string $content the page content to be saved
441
-		 * @return void
442
-		 */
443
-		protected function savePageContentIntoCache($content){
444
-			$obj = & get_instance();
445
-			$logger = self::getLogger();
438
+        /**
439
+         * Save the content of page into cache
440
+         * @param  string $content the page content to be saved
441
+         * @return void
442
+         */
443
+        protected function savePageContentIntoCache($content){
444
+            $obj = & get_instance();
445
+            $logger = self::getLogger();
446 446
 
447
-			//current page URL
448
-			$url = $this->_currentUrl;
449
-			//Cache view Time to live in second
450
-			$viewCacheTtl = get_config('cache_ttl');
451
-			if (!empty($obj->view_cache_ttl)){
452
-				$viewCacheTtl = $obj->view_cache_ttl;
453
-			}
454
-			//the cache handler instance
455
-			$cacheInstance = $obj->cache;
456
-			//the current page cache key for identification
457
-			$cacheKey = $this->_currentUrlCacheKey;
458
-			$logger->debug('Save the page content for URL [' . $url . '] into the cache ...');
459
-			$cacheInstance->set($cacheKey, $content, $viewCacheTtl);
447
+            //current page URL
448
+            $url = $this->_currentUrl;
449
+            //Cache view Time to live in second
450
+            $viewCacheTtl = get_config('cache_ttl');
451
+            if (!empty($obj->view_cache_ttl)){
452
+                $viewCacheTtl = $obj->view_cache_ttl;
453
+            }
454
+            //the cache handler instance
455
+            $cacheInstance = $obj->cache;
456
+            //the current page cache key for identification
457
+            $cacheKey = $this->_currentUrlCacheKey;
458
+            $logger->debug('Save the page content for URL [' . $url . '] into the cache ...');
459
+            $cacheInstance->set($cacheKey, $content, $viewCacheTtl);
460 460
 			
461
-			//get the cache information to prepare header to send to browser
462
-			$cacheInfo = $cacheInstance->getInfo($cacheKey);
463
-			if($cacheInfo){
464
-				$lastModified = $cacheInfo['mtime'];
465
-				$expire = $cacheInfo['expire'];
466
-				$maxAge = $expire - time();
467
-				self::setHeader('Pragma', 'public');
468
-				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
469
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
470
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');	
471
-			}
472
-		}
461
+            //get the cache information to prepare header to send to browser
462
+            $cacheInfo = $cacheInstance->getInfo($cacheKey);
463
+            if($cacheInfo){
464
+                $lastModified = $cacheInfo['mtime'];
465
+                $expire = $cacheInfo['expire'];
466
+                $maxAge = $expire - time();
467
+                self::setHeader('Pragma', 'public');
468
+                self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
469
+                self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
470
+                self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');	
471
+            }
472
+        }
473 473
 		
474 474
 
475
-		/**
476
-		 * Get the module information for the view to load
477
-		 * @param  string $view the view name like moduleName/viewName, viewName
478
-		 * 
479
-		 * @return array        the module information
480
-		 * array(
481
-		 * 	'module'=> 'module_name'
482
-		 * 	'view' => 'view_name'
483
-		 * 	'viewFile' => 'view_file'
484
-		 * )
485
-		 */
486
-		protected  function getModuleInfoForView($view){
487
-			$module = null;
488
-			$viewFile = null;
489
-			$obj = & get_instance();
490
-			//check if the request class contains module name
491
-			if(strpos($view, '/') !== false){
492
-				$viewPath = explode('/', $view);
493
-				if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){
494
-					$module = $viewPath[0];
495
-					array_shift($viewPath);
496
-					$view = implode('/', $viewPath);
497
-					$viewFile = $view . '.php';
498
-				}
499
-			}
500
-			if(! $module && !empty($obj->moduleName)){
501
-				$module = $obj->moduleName;
502
-			}
503
-			return array(
504
-						'view' => $view,
505
-						'module' => $module,
506
-						'viewFile' => $viewFile
507
-					);
508
-		}
475
+        /**
476
+         * Get the module information for the view to load
477
+         * @param  string $view the view name like moduleName/viewName, viewName
478
+         * 
479
+         * @return array        the module information
480
+         * array(
481
+         * 	'module'=> 'module_name'
482
+         * 	'view' => 'view_name'
483
+         * 	'viewFile' => 'view_file'
484
+         * )
485
+         */
486
+        protected  function getModuleInfoForView($view){
487
+            $module = null;
488
+            $viewFile = null;
489
+            $obj = & get_instance();
490
+            //check if the request class contains module name
491
+            if(strpos($view, '/') !== false){
492
+                $viewPath = explode('/', $view);
493
+                if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){
494
+                    $module = $viewPath[0];
495
+                    array_shift($viewPath);
496
+                    $view = implode('/', $viewPath);
497
+                    $viewFile = $view . '.php';
498
+                }
499
+            }
500
+            if(! $module && !empty($obj->moduleName)){
501
+                $module = $obj->moduleName;
502
+            }
503
+            return array(
504
+                        'view' => $view,
505
+                        'module' => $module,
506
+                        'viewFile' => $viewFile
507
+                    );
508
+        }
509 509
 
510
-		/**
511
-		 * Render the view page
512
-		 * @see  Response::render
513
-		 * @return void|string
514
-		 */
515
-		protected  function loadView($path, array $data = array(), $return = false){
516
-			$found = false;
517
-			if(file_exists($path)){
518
-				//super instance
519
-				$obj = & get_instance();
520
-				foreach(get_object_vars($obj) as $key => $value){
521
-					if(! isset($this->{$key})){
522
-						$this->{$key} = & $obj->{$key};
523
-					}
524
-				}
525
-				ob_start();
526
-				extract($data);
527
-				//need use require() instead of require_once because can load this view many time
528
-				require $path;
529
-				$content = ob_get_clean();
530
-				if($return){
531
-					return $content;
532
-				}
533
-				$this->_pageRender .= $content;
534
-				$found = true;
535
-			}
536
-			if(! $found){
537
-				show_error('Unable to find view [' .$view . ']');
538
-			}
539
-		}
510
+        /**
511
+         * Render the view page
512
+         * @see  Response::render
513
+         * @return void|string
514
+         */
515
+        protected  function loadView($path, array $data = array(), $return = false){
516
+            $found = false;
517
+            if(file_exists($path)){
518
+                //super instance
519
+                $obj = & get_instance();
520
+                foreach(get_object_vars($obj) as $key => $value){
521
+                    if(! isset($this->{$key})){
522
+                        $this->{$key} = & $obj->{$key};
523
+                    }
524
+                }
525
+                ob_start();
526
+                extract($data);
527
+                //need use require() instead of require_once because can load this view many time
528
+                require $path;
529
+                $content = ob_get_clean();
530
+                if($return){
531
+                    return $content;
532
+                }
533
+                $this->_pageRender .= $content;
534
+                $found = true;
535
+            }
536
+            if(! $found){
537
+                show_error('Unable to find view [' .$view . ']');
538
+            }
539
+        }
540 540
 
541
-	}
541
+    }
Please login to merge, or discard this patch.