Passed
Pull Request — 1.0.0-dev (#1)
by
unknown
02:46
created
index.php 2 patches
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.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -249,8 +249,7 @@
 block discarded – undo
249 249
 			ini_set('display_errors', 0);
250 250
 			if (version_compare(PHP_VERSION, '5.3', '>=')) {
251 251
 				error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
252
-			}
253
-			else {
252
+			} else {
254 253
 				error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
255 254
 			}
256 255
 		break;
Please login to merge, or discard this patch.
core/classes/Module.php 2 patches
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -22,251 +22,251 @@
 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 extends BaseStaticClass {
27
+    class Module extends BaseStaticClass {
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
-		 * Initialise the module list by scanning the directory MODULE_PATH
37
-		 */
38
-		public function init(){
39
-			$logger = self::getLogger();
40
-			$logger->debug('Check if the application contains the modules ...');
41
-			$moduleDir = opendir(MODULE_PATH);
42
-			if (is_resource($moduleDir)){
43
-				while(($module = readdir($moduleDir)) !== false){
44
-					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
45
-						self::$list[] = $module;
46
-					} else{
47
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
48
-					}
49
-				}
50
-				closedir($moduleDir);
51
-			}
52
-			ksort(self::$list);
35
+        /**
36
+         * Initialise the module list by scanning the directory MODULE_PATH
37
+         */
38
+        public function init(){
39
+            $logger = self::getLogger();
40
+            $logger->debug('Check if the application contains the modules ...');
41
+            $moduleDir = opendir(MODULE_PATH);
42
+            if (is_resource($moduleDir)){
43
+                while(($module = readdir($moduleDir)) !== false){
44
+                    if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
45
+                        self::$list[] = $module;
46
+                    } else{
47
+                        $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
48
+                    }
49
+                }
50
+                closedir($moduleDir);
51
+            }
52
+            ksort(self::$list);
53 53
 			
54
-			if (! empty(self::$list)){
55
-				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
56
-			}
57
-		}
54
+            if (! empty(self::$list)){
55
+                $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
56
+            }
57
+        }
58 58
 		
59 59
 
60
-		/**
61
-		 * Add new module in the list
62
-		 * @param string $name the name of the module
63
-		 *
64
-		 * @return object the current instance
65
-		 */
66
-		public function add($name) {
67
-			self::$list[] = $name;
68
-			return $this;
69
-		}
60
+        /**
61
+         * Add new module in the list
62
+         * @param string $name the name of the module
63
+         *
64
+         * @return object the current instance
65
+         */
66
+        public function add($name) {
67
+            self::$list[] = $name;
68
+            return $this;
69
+        }
70 70
 		
71
-		/**
72
-		 * Get the list of the custom autoload configuration from module if exists
73
-		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
74
-		 */
75
-		public static function getModulesAutoloadConfig() {
76
-			$logger = self::getLogger();
77
-			if (empty(self::$list)) {
78
-				$logger->info('No module was loaded skipping.');
79
-				return false;
80
-			}
81
-			$autoloads = array();
82
-			$autoloads['libraries'] = array();
83
-			$autoloads['config']    = array();
84
-			$autoloads['models']    = array();
85
-			$autoloads['functions'] = array();
86
-			$autoloads['languages'] = array();
71
+        /**
72
+         * Get the list of the custom autoload configuration from module if exists
73
+         * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
74
+         */
75
+        public static function getModulesAutoloadConfig() {
76
+            $logger = self::getLogger();
77
+            if (empty(self::$list)) {
78
+                $logger->info('No module was loaded skipping.');
79
+                return false;
80
+            }
81
+            $autoloads = array();
82
+            $autoloads['libraries'] = array();
83
+            $autoloads['config']    = array();
84
+            $autoloads['models']    = array();
85
+            $autoloads['functions'] = array();
86
+            $autoloads['languages'] = array();
87 87
 			
88
-			foreach (self::$list as $module) {
89
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
90
-				if (file_exists($file)) {
91
-					$autoload = array();
92
-					require_once $file;
93
-					if (!empty($autoload) && is_array($autoload)) {
94
-						$autoloads = array_merge_recursive($autoloads, $autoload);
95
-						unset($autoload);
96
-					}
97
-				}
98
-			}
99
-			return $autoloads;
100
-		}
88
+            foreach (self::$list as $module) {
89
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
90
+                if (file_exists($file)) {
91
+                    $autoload = array();
92
+                    require_once $file;
93
+                    if (!empty($autoload) && is_array($autoload)) {
94
+                        $autoloads = array_merge_recursive($autoloads, $autoload);
95
+                        unset($autoload);
96
+                    }
97
+                }
98
+            }
99
+            return $autoloads;
100
+        }
101 101
 
102
-		/**
103
-		 * Get the list of the custom routes configuration from module if exists
104
-		 * @return array|boolean the routes list or false if no module contains the routes configuration
105
-		 */
106
-		public static function getModulesRoutesConfig() {
107
-			$logger = self::getLogger();
108
-			if (empty(self::$list)) {
109
-				$logger->info('No module was loaded skipping.');
110
-				return false;
111
-			}
112
-			$routes = array();
113
-			foreach (self::$list as $module) {
114
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
115
-				if (file_exists($file)) {
116
-					$route = array();
117
-					require_once $file;
118
-					if (!empty($route) && is_array($route)) {
119
-						$routes = array_merge($routes, $route);
120
-						unset($route);
121
-					}
122
-				}
123
-			}
124
-			return $routes;
125
-		}
102
+        /**
103
+         * Get the list of the custom routes configuration from module if exists
104
+         * @return array|boolean the routes list or false if no module contains the routes configuration
105
+         */
106
+        public static function getModulesRoutesConfig() {
107
+            $logger = self::getLogger();
108
+            if (empty(self::$list)) {
109
+                $logger->info('No module was loaded skipping.');
110
+                return false;
111
+            }
112
+            $routes = array();
113
+            foreach (self::$list as $module) {
114
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
115
+                if (file_exists($file)) {
116
+                    $route = array();
117
+                    require_once $file;
118
+                    if (!empty($route) && is_array($route)) {
119
+                        $routes = array_merge($routes, $route);
120
+                        unset($route);
121
+                    }
122
+                }
123
+            }
124
+            return $routes;
125
+        }
126 126
 
127 127
 
128
-		/**
129
-		 * Check if in module list can have this controller
130
-		 * @see Module::findClassInModuleFullFilePath
131
-		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
132
-		 */
133
-		public static function findControllerFullPath($class, $module = null) {
134
-			return self::findClassInModuleFullFilePath($class, $module, 'controllers');
135
-		}
128
+        /**
129
+         * Check if in module list can have this controller
130
+         * @see Module::findClassInModuleFullFilePath
131
+         * @return boolean|string  false or null if no module have this controller, path the full path of the controller
132
+         */
133
+        public static function findControllerFullPath($class, $module = null) {
134
+            return self::findClassInModuleFullFilePath($class, $module, 'controllers');
135
+        }
136 136
 
137
-		/**
138
-		 * Check if in module list can have this model
139
-		 * @see Module::findClassInModuleFullFilePath
140
-		 * @return boolean|string  false or null if no module have this model, return the full path of this model
141
-		 */
142
-		public static function findModelFullPath($class, $module = null) {
143
-			return self::findClassInModuleFullFilePath($class, $module, 'models');
144
-		}
137
+        /**
138
+         * Check if in module list can have this model
139
+         * @see Module::findClassInModuleFullFilePath
140
+         * @return boolean|string  false or null if no module have this model, return the full path of this model
141
+         */
142
+        public static function findModelFullPath($class, $module = null) {
143
+            return self::findClassInModuleFullFilePath($class, $module, 'models');
144
+        }
145 145
 
146
-		/**
147
-		 * Check if in module list can have this library
148
-		 * @see Module::findClassInModuleFullFilePath
149
-		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
150
-		 */
151
-		public static function findLibraryFullPath($class, $module = null) {
152
-			return self::findClassInModuleFullFilePath($class, $module, 'libraries');
153
-		}
146
+        /**
147
+         * Check if in module list can have this library
148
+         * @see Module::findClassInModuleFullFilePath
149
+         * @return boolean|string  false or null if no module have this library,  return the full path of this library
150
+         */
151
+        public static function findLibraryFullPath($class, $module = null) {
152
+            return self::findClassInModuleFullFilePath($class, $module, 'libraries');
153
+        }
154 154
 
155 155
 		
156
-		/**
157
-		 * Check if in module list can have this config
158
-		 * @see  Module::findNonClassInModuleFullFilePath
159
-		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
160
-		 */
161
-		public static function findConfigFullPath($configuration, $module = null) {
162
-			return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
163
-		}
156
+        /**
157
+         * Check if in module list can have this config
158
+         * @see  Module::findNonClassInModuleFullFilePath
159
+         * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
160
+         */
161
+        public static function findConfigFullPath($configuration, $module = null) {
162
+            return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
163
+        }
164 164
 
165
-		/**
166
-		 * Check if in module list can have this helper
167
-		 * @see  Module::findNonClassInModuleFullFilePath
168
-		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
169
-		 */
170
-		public static function findFunctionFullPath($helper, $module = null) {
171
-			return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
172
-		}
165
+        /**
166
+         * Check if in module list can have this helper
167
+         * @see  Module::findNonClassInModuleFullFilePath
168
+         * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
169
+         */
170
+        public static function findFunctionFullPath($helper, $module = null) {
171
+            return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
172
+        }
173 173
 
174
-		/**
175
-		 * Check if in module list can have this view
176
-		 * @see  Module::findNonClassInModuleFullFilePath
177
-		 * @return boolean|string  false or null if no module have this view, path the full path of the view
178
-		 */
179
-		public static function findViewFullPath($view, $module = null) {
180
-			return self::findNonClassInModuleFullFilePath($view, $module, 'views');
181
-		}
174
+        /**
175
+         * Check if in module list can have this view
176
+         * @see  Module::findNonClassInModuleFullFilePath
177
+         * @return boolean|string  false or null if no module have this view, path the full path of the view
178
+         */
179
+        public static function findViewFullPath($view, $module = null) {
180
+            return self::findNonClassInModuleFullFilePath($view, $module, 'views');
181
+        }
182 182
 
183
-		/**
184
-		 * Check if in module list can have this language
185
-		 * @see  Module::findNonClassInModuleFullFilePath
186
-		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
187
-		 */
188
-		public static function findLanguageFullPath($language, $appLang, $module = null) {
189
-			return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
190
-		}
183
+        /**
184
+         * Check if in module list can have this language
185
+         * @see  Module::findNonClassInModuleFullFilePath
186
+         * @return boolean|string  false or null if no module have this language,  return the full path of this language
187
+         */
188
+        public static function findLanguageFullPath($language, $appLang, $module = null) {
189
+            return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
190
+        }
191 191
 
192
-		/**
193
-		 * Get the list of module loaded
194
-		 * @return array the module list
195
-		 */
196
-		public static function getModuleList() {
197
-			return self::$list;
198
-		}
192
+        /**
193
+         * Get the list of module loaded
194
+         * @return array the module list
195
+         */
196
+        public static function getModuleList() {
197
+            return self::$list;
198
+        }
199 199
 
200
-		/**
201
-		 * Check if the application has an module
202
-		 * @return boolean
203
-		 */
204
-		public static function hasModule() {
205
-			return !empty(self::$list);
206
-		}
200
+        /**
201
+         * Check if the application has an module
202
+         * @return boolean
203
+         */
204
+        public static function hasModule() {
205
+            return !empty(self::$list);
206
+        }
207 207
 
208
-		/**
209
-		 * Check if in module list can have the model, controller, library
210
-		 * @param  string $class the class name of library, model, controller
211
-		 * @param string $module the module name
212
-		 * @param string $type the name of the type "controllers", "libraries", "models"
213
-		 * @return boolean|string  false or null if no module 
214
-		 * have this class, return the full path of the class
215
-		 */
216
-		protected static function findClassInModuleFullFilePath($class, $module, $type) {
217
-			$logger = self::getLogger();
218
-		    $class = str_ireplace('.php', '', $class);
219
-		    $class = ucfirst($class);
220
-		    $classFile = $class . '.php';
221
-		    $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
222
-		    $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
223
-		    if (file_exists($filePath)) {
224
-		        $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
225
-		        return $filePath;
226
-		    }
227
-		    $logger->info('Class [' . $class . '] does not exist in the module [' . $module . '] for [' . $type . ']');
228
-		    return false;
229
-		}
208
+        /**
209
+         * Check if in module list can have the model, controller, library
210
+         * @param  string $class the class name of library, model, controller
211
+         * @param string $module the module name
212
+         * @param string $type the name of the type "controllers", "libraries", "models"
213
+         * @return boolean|string  false or null if no module 
214
+         * have this class, return the full path of the class
215
+         */
216
+        protected static function findClassInModuleFullFilePath($class, $module, $type) {
217
+            $logger = self::getLogger();
218
+            $class = str_ireplace('.php', '', $class);
219
+            $class = ucfirst($class);
220
+            $classFile = $class . '.php';
221
+            $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
222
+            $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
223
+            if (file_exists($filePath)) {
224
+                $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
225
+                return $filePath;
226
+            }
227
+            $logger->info('Class [' . $class . '] does not exist in the module [' . $module . '] for [' . $type . ']');
228
+            return false;
229
+        }
230 230
 
231
-		/**
232
-		 * Check if in module list can have the config, view, helper, language
233
-		 * @param string $name the name of config, view, helper, language
234
-		 * @param string $module the module name
235
-		 * @param string $type the name of the type "config", "functions", "views", "lang"
236
-		 * @param string|null $appLang the application language. This is use only when $type = "lang"
237
-		 * @return boolean|string  false or null if no module 
238
-		 * have this resource, return the full path of the resource
239
-		 */
240
-		protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null) {
241
-		    $logger = self::getLogger();
242
-		    $name = str_ireplace('.php', '', $name);
243
-		    $file = $name . '.php';
244
-		    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
245
-		    switch ($type) {
246
-		        case 'functions':
247
-		            $name = str_ireplace('function_', '', $name);
248
-		            $file = 'function_' . $name . '.php';
249
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
250
-		        break;
251
-		        case 'views':
252
-		            $name = trim($name, '/\\');
253
-		            $name = str_ireplace('/', DS, $name);
254
-		            $file = $name . '.php';
255
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
256
-		        break;
257
-		        case 'lang':
258
-		            $name = str_ireplace('lang_', '', $name);
259
-		            $file = 'lang_' . $name . '.php';
260
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
261
-		        break;
262
-		    }
263
-		    $logger->debug('Checking resource [' . $name . '] in module [' . $module . '] for [' . $type . '] ...');
264
-		    if (file_exists($filePath)) {
265
-		        $logger->info('Found resource [' . $name . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
266
-		        return $filePath;
267
-		    }
268
-		    $logger->info('Resource [' . $name . '] does not exist in the module [' . $module . '] for [' . $type . ']');
269
-		    return false;
270
-		}
231
+        /**
232
+         * Check if in module list can have the config, view, helper, language
233
+         * @param string $name the name of config, view, helper, language
234
+         * @param string $module the module name
235
+         * @param string $type the name of the type "config", "functions", "views", "lang"
236
+         * @param string|null $appLang the application language. This is use only when $type = "lang"
237
+         * @return boolean|string  false or null if no module 
238
+         * have this resource, return the full path of the resource
239
+         */
240
+        protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null) {
241
+            $logger = self::getLogger();
242
+            $name = str_ireplace('.php', '', $name);
243
+            $file = $name . '.php';
244
+            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
245
+            switch ($type) {
246
+                case 'functions':
247
+                    $name = str_ireplace('function_', '', $name);
248
+                    $file = 'function_' . $name . '.php';
249
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
250
+                break;
251
+                case 'views':
252
+                    $name = trim($name, '/\\');
253
+                    $name = str_ireplace('/', DS, $name);
254
+                    $file = $name . '.php';
255
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
256
+                break;
257
+                case 'lang':
258
+                    $name = str_ireplace('lang_', '', $name);
259
+                    $file = 'lang_' . $name . '.php';
260
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
261
+                break;
262
+            }
263
+            $logger->debug('Checking resource [' . $name . '] in module [' . $module . '] for [' . $type . '] ...');
264
+            if (file_exists($filePath)) {
265
+                $logger->info('Found resource [' . $name . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
266
+                return $filePath;
267
+            }
268
+            $logger->info('Resource [' . $name . '] does not exist in the module [' . $module . '] for [' . $type . ']');
269
+            return false;
270
+        }
271 271
 
272
-	}
272
+    }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -35,23 +35,23 @@
 block discarded – undo
35 35
 		/**
36 36
 		 * Initialise the module list by scanning the directory MODULE_PATH
37 37
 		 */
38
-		public function init(){
38
+		public function init() {
39 39
 			$logger = self::getLogger();
40 40
 			$logger->debug('Check if the application contains the modules ...');
41 41
 			$moduleDir = opendir(MODULE_PATH);
42
-			if (is_resource($moduleDir)){
43
-				while(($module = readdir($moduleDir)) !== false){
44
-					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
42
+			if (is_resource($moduleDir)) {
43
+				while (($module = readdir($moduleDir)) !== false) {
44
+					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) {
45 45
 						self::$list[] = $module;
46
-					} else{
47
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
46
+					} else {
47
+						$logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name');
48 48
 					}
49 49
 				}
50 50
 				closedir($moduleDir);
51 51
 			}
52 52
 			ksort(self::$list);
53 53
 			
54
-			if (! empty(self::$list)){
54
+			if (!empty(self::$list)) {
55 55
 				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
56 56
 			}
57 57
 		}
Please login to merge, or discard this patch.
core/classes/EventInfo.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -1,63 +1,63 @@
 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
-	/**
28
-	 * This class represent the event detail to dispatch to correspond listener
29
-	 */
30
-	class EventInfo {
27
+    /**
28
+     * This class represent the event detail to dispatch to correspond listener
29
+     */
30
+    class EventInfo {
31 31
 		
32
-		/**
33
-		 * The event name
34
-		 * @var string
35
-		 */
36
-		public $name;
32
+        /**
33
+         * The event name
34
+         * @var string
35
+         */
36
+        public $name;
37 37
 
38
-		/**
39
-		 * The event data to send to the listeners
40
-		 * @var mixed
41
-		 */
42
-		public $payload;
38
+        /**
39
+         * The event data to send to the listeners
40
+         * @var mixed
41
+         */
42
+        public $payload;
43 43
 
44
-		/**
45
-		 * If the listeners need return the event after treatment or not, false means no need
46
-		 * return true need return the event. 
47
-		 * @var boolean
48
-		 */
49
-		public $returnBack;
44
+        /**
45
+         * If the listeners need return the event after treatment or not, false means no need
46
+         * return true need return the event. 
47
+         * @var boolean
48
+         */
49
+        public $returnBack;
50 50
 
51
-		/**
52
-		 * This variable indicates if need stop the event propagation
53
-		 * @var boolean
54
-		 */
55
-		public $stop;
51
+        /**
52
+         * This variable indicates if need stop the event propagation
53
+         * @var boolean
54
+         */
55
+        public $stop;
56 56
 		
57
-		public function __construct($name, $payload = array(), $returnBack = false, $stop = false) {
58
-			$this->name = $name;
59
-			$this->payload = $payload;
60
-			$this->returnBack = $returnBack;
61
-			$this->stop = $stop;
62
-		}
63
-	}
57
+        public function __construct($name, $payload = array(), $returnBack = false, $stop = false) {
58
+            $this->name = $name;
59
+            $this->payload = $payload;
60
+            $this->returnBack = $returnBack;
61
+            $this->stop = $stop;
62
+        }
63
+    }
Please login to merge, or discard this patch.
core/classes/Security.php 2 patches
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -1,135 +1,135 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Security extends BaseStaticClass {
27
+    class Security extends BaseStaticClass {
28 28
 
29
-		/**
30
-		 * This method is used to generate the CSRF token
31
-		 * @return string the generated CSRF token
32
-		 */
33
-		public static function generateCSRF() {
34
-			$logger = self::getLogger();
35
-			$logger->debug('Generation of CSRF ...');
29
+        /**
30
+         * This method is used to generate the CSRF token
31
+         * @return string the generated CSRF token
32
+         */
33
+        public static function generateCSRF() {
34
+            $logger = self::getLogger();
35
+            $logger->debug('Generation of CSRF ...');
36 36
 			
37
-			$key = get_config('csrf_key', 'csrf_key');
38
-			$expire = get_config('csrf_expire', 60);
39
-			$keyExpire = 'csrf_expire';
40
-			$currentTime = time();
41
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
42
-				$logger->info('The CSRF token not yet expire just return it');
43
-				return Session::get($key);
44
-			} else{
45
-				$newTime = $currentTime + $expire;
46
-				$token = sha1(uniqid()) . sha1(uniqid());
47
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
48
-				Session::set($keyExpire, $newTime);
49
-				Session::set($key, $token);
50
-				return Session::get($key);
51
-			}
52
-		}
37
+            $key = get_config('csrf_key', 'csrf_key');
38
+            $expire = get_config('csrf_expire', 60);
39
+            $keyExpire = 'csrf_expire';
40
+            $currentTime = time();
41
+            if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
42
+                $logger->info('The CSRF token not yet expire just return it');
43
+                return Session::get($key);
44
+            } else{
45
+                $newTime = $currentTime + $expire;
46
+                $token = sha1(uniqid()) . sha1(uniqid());
47
+                $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
48
+                Session::set($keyExpire, $newTime);
49
+                Session::set($key, $token);
50
+                return Session::get($key);
51
+            }
52
+        }
53 53
 
54
-		/**
55
-		 * This method is used to check the CSRF if is valid, not yet expire, etc.
56
-		 * @return boolean true if valid, false if not valid
57
-		 */
58
-		public static function validateCSRF() {
59
-			$logger = self::getLogger();
60
-			$logger->debug('Validation of CSRF ...');
54
+        /**
55
+         * This method is used to check the CSRF if is valid, not yet expire, etc.
56
+         * @return boolean true if valid, false if not valid
57
+         */
58
+        public static function validateCSRF() {
59
+            $logger = self::getLogger();
60
+            $logger->debug('Validation of CSRF ...');
61 61
 				
62
-			$key = get_config('csrf_key', 'csrf_key');
63
-			$expire = get_config('csrf_expire', 60);
64
-			$keyExpire = 'csrf_expire';
65
-			$currentTime = time();
66
-			$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
67
-			if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
68
-				$logger->warning('The CSRF session data is not valide');
69
-				return false;
70
-			}
71
-			//perform form data
72
-			//need use request->query() for best retrieve
73
-			//super instance
74
-			$obj = & get_instance();
75
-			$token = $obj->request->query($key);
76
-			if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
77
-				$logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
78
-				return false;
79
-			}
80
-			$logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
81
-			//remove the token from session
82
-			Session::clear($key);
83
-			Session::clear($keyExpire);
84
-			return true;
85
-		}
62
+            $key = get_config('csrf_key', 'csrf_key');
63
+            $expire = get_config('csrf_expire', 60);
64
+            $keyExpire = 'csrf_expire';
65
+            $currentTime = time();
66
+            $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
67
+            if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
68
+                $logger->warning('The CSRF session data is not valide');
69
+                return false;
70
+            }
71
+            //perform form data
72
+            //need use request->query() for best retrieve
73
+            //super instance
74
+            $obj = & get_instance();
75
+            $token = $obj->request->query($key);
76
+            if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
77
+                $logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
78
+                return false;
79
+            }
80
+            $logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
81
+            //remove the token from session
82
+            Session::clear($key);
83
+            Session::clear($keyExpire);
84
+            return true;
85
+        }
86 86
 		
87
-		/**
88
-		 * This method is used to check the whitelist IP address access
89
-		 */
90
-		 public static function checkWhiteListIpAccess(){
91
-			$logger = self::getLogger();
92
-			$logger->debug('Validation of the IP address access ...');
93
-			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
94
-			$isEnable = get_config('white_list_ip_enable', false);
95
-			if($isEnable){
96
-				$logger->info('Whitelist IP access is enabled in the configuration');
97
-				$list = get_config('white_list_ip_addresses', array());
98
-				if(! empty($list)){
99
-					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
100
-					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
101
-					$ip = get_ip();
102
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
103
-						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
104
-						//wildcard to access all ip address
105
-						return;
106
-					} else{
107
-						// go through all whitelisted ips
108
-						foreach ($list as $ipaddr) {
109
-							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
110
-							$wildcardPosition = strpos($ipaddr, '*');
111
-							if ($wildcardPosition === false) {
112
-								// no wild card in whitelisted ip --continue searching
113
-								continue;
114
-							}
115
-							// cut ip at the position where we got the wild card on the whitelisted ip
116
-							// and add the wold card to get the same pattern
117
-							if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) {
118
-								// f.e. we got
119
-								//  ip "127.0.0.1"
120
-								//  whitelisted ip "127.0.*"
121
-								// then we compared "127.0.*" with "127.0.*"
122
-								// return success
123
-								$logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"');
124
-								return;
125
-							}
126
-						}
127
-						$logger->warning('IP address ' . $ip . ' is not allowed to access to this application');
128
-						show_error('Access to this application is not allowed');
129
-					}
130
-				}
131
-			} else{
132
-				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
133
-			}
134
-		 }
135
-	}
87
+        /**
88
+         * This method is used to check the whitelist IP address access
89
+         */
90
+            public static function checkWhiteListIpAccess(){
91
+            $logger = self::getLogger();
92
+            $logger->debug('Validation of the IP address access ...');
93
+            $logger->debug('Check if whitelist IP access is enabled in the configuration ...');
94
+            $isEnable = get_config('white_list_ip_enable', false);
95
+            if($isEnable){
96
+                $logger->info('Whitelist IP access is enabled in the configuration');
97
+                $list = get_config('white_list_ip_addresses', array());
98
+                if(! empty($list)){
99
+                    //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
100
+                    require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
101
+                    $ip = get_ip();
102
+                    if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
103
+                        $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
104
+                        //wildcard to access all ip address
105
+                        return;
106
+                    } else{
107
+                        // go through all whitelisted ips
108
+                        foreach ($list as $ipaddr) {
109
+                            // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
110
+                            $wildcardPosition = strpos($ipaddr, '*');
111
+                            if ($wildcardPosition === false) {
112
+                                // no wild card in whitelisted ip --continue searching
113
+                                continue;
114
+                            }
115
+                            // cut ip at the position where we got the wild card on the whitelisted ip
116
+                            // and add the wold card to get the same pattern
117
+                            if (substr($ip, 0, $wildcardPosition) . '*' === $ipaddr) {
118
+                                // f.e. we got
119
+                                //  ip "127.0.0.1"
120
+                                //  whitelisted ip "127.0.*"
121
+                                // then we compared "127.0.*" with "127.0.*"
122
+                                // return success
123
+                                $logger->info('IP address ' . $ip . ' allowed using the wildcard like "x.x.x.*"');
124
+                                return;
125
+                            }
126
+                        }
127
+                        $logger->warning('IP address ' . $ip . ' is not allowed to access to this application');
128
+                        show_error('Access to this application is not allowed');
129
+                    }
130
+                }
131
+            } else{
132
+                $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
133
+            }
134
+            }
135
+    }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
 			$expire = get_config('csrf_expire', 60);
39 39
 			$keyExpire = 'csrf_expire';
40 40
 			$currentTime = time();
41
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
41
+			if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
42 42
 				$logger->info('The CSRF token not yet expire just return it');
43 43
 				return Session::get($key);
44
-			} else{
44
+			} else {
45 45
 				$newTime = $currentTime + $expire;
46 46
 				$token = sha1(uniqid()) . sha1(uniqid());
47
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
47
+				$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
48 48
 				Session::set($keyExpire, $newTime);
49 49
 				Session::set($key, $token);
50 50
 				return Session::get($key);
@@ -87,23 +87,23 @@  discard block
 block discarded – undo
87 87
 		/**
88 88
 		 * This method is used to check the whitelist IP address access
89 89
 		 */
90
-		 public static function checkWhiteListIpAccess(){
90
+		 public static function checkWhiteListIpAccess() {
91 91
 			$logger = self::getLogger();
92 92
 			$logger->debug('Validation of the IP address access ...');
93 93
 			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
94 94
 			$isEnable = get_config('white_list_ip_enable', false);
95
-			if($isEnable){
95
+			if ($isEnable) {
96 96
 				$logger->info('Whitelist IP access is enabled in the configuration');
97 97
 				$list = get_config('white_list_ip_addresses', array());
98
-				if(! empty($list)){
98
+				if (!empty($list)) {
99 99
 					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
100 100
 					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
101 101
 					$ip = get_ip();
102
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
102
+					if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) {
103 103
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
104 104
 						//wildcard to access all ip address
105 105
 						return;
106
-					} else{
106
+					} else {
107 107
 						// go through all whitelisted ips
108 108
 						foreach ($list as $ipaddr) {
109 109
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 						show_error('Access to this application is not allowed');
129 129
 					}
130 130
 				}
131
-			} else{
131
+			} else {
132 132
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
133 133
 			}
134 134
 		 }
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryResult.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
      */
26 26
   
27
-    class DatabaseQueryResult{
27
+    class DatabaseQueryResult {
28 28
   	
29 29
         /**
30 30
          * The database query result
31 31
          * @var mixed
32 32
          */
33
-        private $result  = null;
33
+        private $result = null;
34 34
   	
35 35
     
36 36
         /**
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
          *
57 57
          * @return mixed
58 58
          */
59
-    public function getResult(){
59
+    public function getResult() {
60 60
         return $this->result;
61 61
     }
62 62
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      *
67 67
      * @return object DatabaseQueryResult
68 68
      */
69
-    public function setResult($result){
69
+    public function setResult($result) {
70 70
         $this->result = $result;
71 71
         return $this;
72 72
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @return int
78 78
      */
79
-    public function getNumRows(){
79
+    public function getNumRows() {
80 80
         return $this->numRows;
81 81
     }
82 82
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      *
87 87
      * @return object DatabaseQueryResult
88 88
      */
89
-    public function setNumRows($numRows){
89
+    public function setNumRows($numRows) {
90 90
         $this->numRows = $numRows;
91 91
         return $this;
92 92
     }
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryBuilder.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218 218
     public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
219
-      $on = $field1;
220
-      $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
219
+        $on = $field1;
220
+        $table = $this->getPrefix() . $table;
221
+        if (! is_null($op)){
222 222
         $on = (! in_array($op, $this->operatorList) 
223
-													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224
-													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225
-      }
226
-      if (empty($this->join)){
223
+                                                    ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224
+                                                    : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225
+        }
226
+        if (empty($this->join)){
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-      } else{
228
+        } else{
229 229
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
230
-      }
231
-      return $this;
230
+        }
231
+        return $this;
232 232
     }
233 233
 
234 234
     /**
@@ -330,18 +330,18 @@  discard block
 block discarded – undo
330 330
      * @return object        the current DatabaseQueryBuilder instance
331 331
      */
332 332
     public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
333
-      $whereStr = '';
334
-      if (is_array($where)){
333
+        $whereStr = '';
334
+        if (is_array($where)){
335 335
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
336
-      } else{
336
+        } else{
337 337
         if (is_array($op)){
338
-          $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
338
+            $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
339 339
         } else {
340
-          $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
340
+            $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
341 341
         }
342
-      }
343
-      $this->setWhereStr($whereStr, $andOr);
344
-      return $this;
342
+        }
343
+        $this->setWhereStr($whereStr, $andOr);
344
+        return $this;
345 345
     }
346 346
 
347 347
     /**
@@ -578,15 +578,15 @@  discard block
 block discarded – undo
578 578
      * @return object        the current DatabaseQueryBuilder instance
579 579
      */
580 580
     public function limit($limit, $limitEnd = null){
581
-      if (empty($limit)){
581
+        if (empty($limit)){
582 582
         $limit = 0;
583
-      }
584
-      if (! is_null($limitEnd)){
583
+        }
584
+        if (! is_null($limitEnd)){
585 585
         $this->limit = $limit . ', ' . $limitEnd;
586
-      } else{
586
+        } else{
587 587
         $this->limit = $limit;
588
-      }
589
-      return $this;
588
+        }
589
+        return $this;
590 590
     }
591 591
 
592 592
     /**
@@ -596,14 +596,14 @@  discard block
 block discarded – undo
596 596
      * @return object        the current DatabaseQueryBuilder instance
597 597
      */
598 598
     public function orderBy($orderBy, $orderDir = ' ASC'){
599
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
599
+        if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
600 600
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
601
-      } else{
601
+        } else{
602 602
         $this->orderBy = empty($this->orderBy) 
603
-						? ($orderBy . ' ' . strtoupper($orderDir)) 
604
-						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
605
-      }
606
-      return $this;
603
+                        ? ($orderBy . ' ' . strtoupper($orderDir)) 
604
+                        : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
605
+        }
606
+        return $this;
607 607
     }
608 608
 
609 609
     /**
@@ -612,12 +612,12 @@  discard block
 block discarded – undo
612 612
      * @return object        the current DatabaseQueryBuilder instance
613 613
      */
614 614
     public function groupBy($field){
615
-      if (is_array($field)){
615
+        if (is_array($field)){
616 616
         $this->groupBy = implode(', ', $field);
617
-      } else{
617
+        } else{
618 618
         $this->groupBy = $field;
619
-      }
620
-      return $this;
619
+        }
620
+        return $this;
621 621
     }
622 622
 
623 623
     /**
@@ -629,20 +629,20 @@  discard block
 block discarded – undo
629 629
      * @return object        the current DatabaseQueryBuilder instance
630 630
      */
631 631
     public function having($field, $op = null, $val = null, $escape = true){
632
-      if (is_array($op)){
632
+        if (is_array($op)){
633 633
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
634
-      } else if (! in_array($op, $this->operatorList)){
634
+        } else if (! in_array($op, $this->operatorList)){
635 635
         if (is_null($op)){
636
-          $op = '';
636
+            $op = '';
637 637
         }
638 638
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
639
-      } else{
639
+        } else{
640 640
         if (is_null($val)){
641
-          $val = '';
641
+            $val = '';
642 642
         }
643 643
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
644
-      }
645
-      return $this;
644
+        }
645
+        return $this;
646 646
     }
647 647
 
648 648
     /**
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -23,94 +23,94 @@  discard block
 block discarded – undo
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
      */
26
-    class DatabaseQueryBuilder{
26
+    class DatabaseQueryBuilder {
27 27
         /**
28 28
          * The SQL SELECT statment
29 29
          * @var string
30 30
          */
31
-        private $select              = '*';
31
+        private $select = '*';
32 32
   	
33 33
         /**
34 34
          * The SQL FROM statment
35 35
          * @var string
36 36
          */
37
-        private $from              = null;
37
+        private $from = null;
38 38
   	
39 39
         /**
40 40
          * The SQL WHERE statment
41 41
          * @var string
42 42
          */
43
-        private $where               = null;
43
+        private $where = null;
44 44
   	
45 45
         /**
46 46
          * The SQL LIMIT statment
47 47
          * @var string
48 48
          */
49
-        private $limit               = null;
49
+        private $limit = null;
50 50
   	
51 51
         /**
52 52
          * The SQL JOIN statment
53 53
          * @var string
54 54
          */
55
-        private $join                = null;
55
+        private $join = null;
56 56
   	
57 57
         /**
58 58
          * The SQL ORDER BY statment
59 59
          * @var string
60 60
          */
61
-        private $orderBy             = null;
61
+        private $orderBy = null;
62 62
   	
63 63
         /**
64 64
          * The SQL GROUP BY statment
65 65
          * @var string
66 66
          */
67
-        private $groupBy             = null;
67
+        private $groupBy = null;
68 68
   	
69 69
         /**
70 70
          * The SQL HAVING statment
71 71
          * @var string
72 72
          */
73
-        private $having              = null;
73
+        private $having = null;
74 74
   	
75 75
         /**
76 76
          * The full SQL query statment after build for each command
77 77
          * @var string
78 78
          */
79
-        private $query               = null;
79
+        private $query = null;
80 80
   	
81 81
         /**
82 82
          * The list of SQL valid operators
83 83
          * @var array
84 84
          */
85
-    private $operatorList        = array('=','!=','<','>','<=','>=','<>');
85
+    private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>');
86 86
   	
87 87
 	
88 88
     /**
89 89
      * The prefix used in each database table
90 90
      * @var string
91 91
      */
92
-    private $prefix              = null;
92
+    private $prefix = null;
93 93
     
94 94
 
95 95
     /**
96 96
      * The PDO instance
97 97
      * @var object
98 98
      */
99
-    private $pdo                 = null;
99
+    private $pdo = null;
100 100
 	
101 101
         /**
102 102
          * The database driver name used
103 103
          * @var string
104 104
          */
105
-        private $driver              = null;
105
+        private $driver = null;
106 106
   	
107 107
 	
108 108
     /**
109 109
      * Construct new DatabaseQueryBuilder
110 110
      * @param object $pdo the PDO object
111 111
      */
112
-    public function __construct(PDO $pdo = null){
113
-        if (is_object($pdo)){
112
+    public function __construct(PDO $pdo = null) {
113
+        if (is_object($pdo)) {
114 114
             $this->setPdo($pdo);
115 115
         }
116 116
     }
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
      * @param  string|array $table the table name or array of table list
121 121
      * @return object        the current DatabaseQueryBuilder instance
122 122
      */
123
-    public function from($table){
124
-        if (is_array($table)){
123
+    public function from($table) {
124
+        if (is_array($table)) {
125 125
         $froms = '';
126
-        foreach($table as $key){
126
+        foreach ($table as $key) {
127 127
             $froms .= $this->getPrefix() . $key . ', ';
128 128
         }
129 129
         $this->from = rtrim($froms, ', ');
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @param  string|array $fields the field name or array of field list
139 139
      * @return object        the current DatabaseQueryBuilder instance
140 140
      */
141
-    public function select($fields){
141
+    public function select($fields) {
142 142
         $select = (is_array($fields) ? implode(', ', $fields) : $fields);
143 143
         $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select);
144 144
         return $this;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      * @param  string $field the field name to distinct
150 150
      * @return object        the current DatabaseQueryBuilder instance
151 151
      */
152
-    public function distinct($field){
152
+    public function distinct($field) {
153 153
         $distinct = ' DISTINCT ' . $field;
154 154
         $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct);
155 155
         return $this;
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
          * @param  string $name  if is not null represent the alias used for this field in the result
162 162
          * @return object        the current DatabaseQueryBuilder instance
163 163
          */
164
-    public function count($field = '*', $name = null){
164
+    public function count($field = '*', $name = null) {
165 165
         return $this->select_min_max_sum_count_avg('COUNT', $field, $name);
166 166
     }
167 167
     
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param  string $name  if is not null represent the alias used for this field in the result
172 172
      * @return object        the current DatabaseQueryBuilder instance
173 173
      */
174
-    public function min($field, $name = null){
174
+    public function min($field, $name = null) {
175 175
         return $this->select_min_max_sum_count_avg('MIN', $field, $name);
176 176
     }
177 177
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      * @param  string $name  if is not null represent the alias used for this field in the result
182 182
      * @return object        the current DatabaseQueryBuilder instance
183 183
      */
184
-    public function max($field, $name = null){
184
+    public function max($field, $name = null) {
185 185
         return $this->select_min_max_sum_count_avg('MAX', $field, $name);
186 186
     }
187 187
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param  string $name  if is not null represent the alias used for this field in the result
192 192
      * @return object        the current DatabaseQueryBuilder instance
193 193
      */
194
-    public function sum($field, $name = null){
194
+    public function sum($field, $name = null) {
195 195
         return $this->select_min_max_sum_count_avg('SUM', $field, $name);
196 196
     }
197 197
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      * @param  string $name  if is not null represent the alias used for this field in the result
202 202
      * @return object        the current DatabaseQueryBuilder instance
203 203
      */
204
-    public function avg($field, $name = null){
204
+    public function avg($field, $name = null) {
205 205
         return $this->select_min_max_sum_count_avg('AVG', $field, $name);
206 206
     }
207 207
 
@@ -215,17 +215,17 @@  discard block
 block discarded – undo
215 215
      * @param  string $type   the type of join (INNER, LEFT, RIGHT)
216 216
      * @return object        the current DatabaseQueryBuilder instance
217 217
      */
218
-    public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){
218
+    public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') {
219 219
       $on = $field1;
220 220
       $table = $this->getPrefix() . $table;
221
-      if (! is_null($op)){
222
-        $on = (! in_array($op, $this->operatorList) 
221
+      if (!is_null($op)) {
222
+        $on = (!in_array($op, $this->operatorList) 
223 223
 													? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) 
224 224
 													: ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2));
225 225
       }
226
-      if (empty($this->join)){
226
+      if (empty($this->join)) {
227 227
         $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
228
-      } else{
228
+      } else {
229 229
         $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on;
230 230
       }
231 231
       return $this;
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      * @see  DatabaseQueryBuilder::join()
237 237
      * @return object        the current DatabaseQueryBuilder instance
238 238
      */
239
-    public function innerJoin($table, $field1, $op = null, $field2 = ''){
239
+    public function innerJoin($table, $field1, $op = null, $field2 = '') {
240 240
         return $this->join($table, $field1, $op, $field2, 'INNER ');
241 241
     }
242 242
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      * @see  DatabaseQueryBuilder::join()
246 246
      * @return object        the current DatabaseQueryBuilder instance
247 247
      */
248
-    public function leftJoin($table, $field1, $op = null, $field2 = ''){
248
+    public function leftJoin($table, $field1, $op = null, $field2 = '') {
249 249
         return $this->join($table, $field1, $op, $field2, 'LEFT ');
250 250
     }
251 251
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      * @see  DatabaseQueryBuilder::join()
255 255
      * @return object        the current DatabaseQueryBuilder instance
256 256
      */
257
-    public function rightJoin($table, $field1, $op = null, $field2 = ''){
257
+    public function rightJoin($table, $field1, $op = null, $field2 = '') {
258 258
         return $this->join($table, $field1, $op, $field2, 'RIGHT ');
259 259
     }
260 260
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      * @see  DatabaseQueryBuilder::join()
264 264
      * @return object        the current DatabaseQueryBuilder instance
265 265
      */
266
-    public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){
266
+    public function fullOuterJoin($table, $field1, $op = null, $field2 = '') {
267 267
         return $this->join($table, $field1, $op, $field2, 'FULL OUTER ');
268 268
     }
269 269
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
      * @see  DatabaseQueryBuilder::join()
273 273
      * @return object        the current DatabaseQueryBuilder instance
274 274
      */
275
-    public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){
275
+    public function leftOuterJoin($table, $field1, $op = null, $field2 = '') {
276 276
         return $this->join($table, $field1, $op, $field2, 'LEFT OUTER ');
277 277
     }
278 278
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
      * @see  DatabaseQueryBuilder::join()
282 282
      * @return object        the current DatabaseQueryBuilder instance
283 283
      */
284
-    public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){
284
+    public function rightOuterJoin($table, $field1, $op = null, $field2 = '') {
285 285
         return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER ');
286 286
     }
287 287
 
@@ -291,13 +291,13 @@  discard block
 block discarded – undo
291 291
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
292 292
      * @return object        the current DatabaseQueryBuilder instance
293 293
      */
294
-    public function whereIsNull($field, $andOr = 'AND'){
295
-        if (is_array($field)){
296
-        foreach($field as $f){
294
+    public function whereIsNull($field, $andOr = 'AND') {
295
+        if (is_array($field)) {
296
+        foreach ($field as $f) {
297 297
             $this->whereIsNull($f, $andOr);
298 298
         }
299 299
         } else {
300
-            $this->setWhereStr($field.' IS NULL ', $andOr);
300
+            $this->setWhereStr($field . ' IS NULL ', $andOr);
301 301
         }
302 302
         return $this;
303 303
     }
@@ -308,13 +308,13 @@  discard block
 block discarded – undo
308 308
      * @param  string $andOr the separator type used 'AND', 'OR', etc.
309 309
      * @return object        the current DatabaseQueryBuilder instance
310 310
      */
311
-    public function whereIsNotNull($field, $andOr = 'AND'){
312
-        if (is_array($field)){
313
-        foreach($field as $f){
311
+    public function whereIsNotNull($field, $andOr = 'AND') {
312
+        if (is_array($field)) {
313
+        foreach ($field as $f) {
314 314
             $this->whereIsNotNull($f, $andOr);
315 315
         }
316 316
         } else {
317
-            $this->setWhereStr($field.' IS NOT NULL ', $andOr);
317
+            $this->setWhereStr($field . ' IS NOT NULL ', $andOr);
318 318
         }
319 319
         return $this;
320 320
     }
@@ -329,12 +329,12 @@  discard block
 block discarded – undo
329 329
      * @param  boolean $escape whether to escape or not the $val
330 330
      * @return object        the current DatabaseQueryBuilder instance
331 331
      */
332
-    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){
332
+    public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) {
333 333
       $whereStr = '';
334
-      if (is_array($where)){
334
+      if (is_array($where)) {
335 335
         $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape);
336
-      } else{
337
-        if (is_array($op)){
336
+      } else {
337
+        if (is_array($op)) {
338 338
           $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape);
339 339
         } else {
340 340
           $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape);
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
      * @see  DatabaseQueryBuilder::where()
350 350
      * @return object        the current DatabaseQueryBuilder instance
351 351
      */
352
-    public function orWhere($where, $op = null, $val = null, $escape = true){
352
+    public function orWhere($where, $op = null, $val = null, $escape = true) {
353 353
         return $this->where($where, $op, $val, '', 'OR', $escape);
354 354
     }
355 355
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
      * @see  DatabaseQueryBuilder::where()
360 360
      * @return object        the current DatabaseQueryBuilder instance
361 361
      */
362
-    public function notWhere($where, $op = null, $val = null, $escape = true){
362
+    public function notWhere($where, $op = null, $val = null, $escape = true) {
363 363
         return $this->where($where, $op, $val, 'NOT ', 'AND', $escape);
364 364
     }
365 365
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      * @see  DatabaseQueryBuilder::where()
369 369
      * @return object        the current DatabaseQueryBuilder instance
370 370
      */
371
-    public function orNotWhere($where, $op = null, $val = null, $escape = true){
371
+    public function orNotWhere($where, $op = null, $val = null, $escape = true) {
372 372
         return $this->where($where, $op, $val, 'NOT ', 'OR', $escape);
373 373
     }
374 374
 
@@ -378,11 +378,11 @@  discard block
 block discarded – undo
378 378
      * @param  string $andOr the multiple conditions separator (AND, OR, etc.)
379 379
      * @return object        the current DatabaseQueryBuilder instance
380 380
      */
381
-    public function groupStart($type = '', $andOr = ' AND'){
382
-        if (empty($this->where)){
381
+    public function groupStart($type = '', $andOr = ' AND') {
382
+        if (empty($this->where)) {
383 383
         $this->where = $type . ' (';
384 384
         } else {
385
-            if (substr(trim($this->where), -1) == '('){
385
+            if (substr(trim($this->where), -1) == '(') {
386 386
             $this->where .= $type . ' (';
387 387
             } else {
388 388
                 $this->where .= $andOr . ' ' . $type . ' (';
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
      * @see  DatabaseQueryBuilder::groupStart()
397 397
      * @return object        the current DatabaseQueryBuilder instance
398 398
      */
399
-    public function notGroupStart(){
399
+    public function notGroupStart() {
400 400
         return $this->groupStart('NOT');
401 401
     }
402 402
 
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
      * @see  DatabaseQueryBuilder::groupStart()
406 406
      * @return object        the current DatabaseQueryBuilder instance
407 407
      */
408
-    public function orGroupStart(){
408
+    public function orGroupStart() {
409 409
         return $this->groupStart('', ' OR');
410 410
     }
411 411
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
          * @see  DatabaseQueryBuilder::groupStart()
415 415
          * @return object        the current DatabaseQueryBuilder instance
416 416
          */
417
-    public function orNotGroupStart(){
417
+    public function orNotGroupStart() {
418 418
         return $this->groupStart('NOT', ' OR');
419 419
     }
420 420
 
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
      * Close the parenthesis for the grouped SQL
423 423
      * @return object        the current DatabaseQueryBuilder instance
424 424
      */
425
-    public function groupEnd(){
425
+    public function groupEnd() {
426 426
         $this->where .= ')';
427 427
         return $this;
428 428
     }
@@ -436,10 +436,10 @@  discard block
 block discarded – undo
436 436
      * @param  boolean $escape whether to escape or not the values
437 437
      * @return object        the current DatabaseQueryBuilder instance
438 438
      */
439
-    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){
439
+    public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) {
440 440
         $_keys = array();
441
-        foreach ($keys as $k => $v){
442
-        if (is_null($v)){
441
+        foreach ($keys as $k => $v) {
442
+        if (is_null($v)) {
443 443
             $v = '';
444 444
         }
445 445
         $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape));
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
      * @see  DatabaseQueryBuilder::in()
456 456
      * @return object        the current DatabaseQueryBuilder instance
457 457
      */
458
-    public function notIn($field, array $keys, $escape = true){
458
+    public function notIn($field, array $keys, $escape = true) {
459 459
         return $this->in($field, $keys, 'NOT ', 'AND', $escape);
460 460
     }
461 461
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
      * @see  DatabaseQueryBuilder::in()
465 465
      * @return object        the current DatabaseQueryBuilder instance
466 466
      */
467
-    public function orIn($field, array $keys, $escape = true){
467
+    public function orIn($field, array $keys, $escape = true) {
468 468
         return $this->in($field, $keys, '', 'OR', $escape);
469 469
     }
470 470
 
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
      * @see  DatabaseQueryBuilder::in()
474 474
      * @return object        the current DatabaseQueryBuilder instance
475 475
      */
476
-    public function orNotIn($field, array $keys, $escape = true){
476
+    public function orNotIn($field, array $keys, $escape = true) {
477 477
         return $this->in($field, $keys, 'NOT ', 'OR', $escape);
478 478
     }
479 479
 
@@ -487,11 +487,11 @@  discard block
 block discarded – undo
487 487
      * @param  boolean $escape whether to escape or not the values
488 488
      * @return object        the current DatabaseQueryBuilder instance
489 489
      */
490
-    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){
491
-        if (is_null($value1)){
490
+    public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) {
491
+        if (is_null($value1)) {
492 492
         $value1 = '';
493 493
         }
494
-        if (is_null($value2)){
494
+        if (is_null($value2)) {
495 495
         $value2 = '';
496 496
         }
497 497
         $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape);
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
      * @see  DatabaseQueryBuilder::between()
505 505
      * @return object        the current DatabaseQueryBuilder instance
506 506
      */
507
-    public function notBetween($field, $value1, $value2, $escape = true){
507
+    public function notBetween($field, $value1, $value2, $escape = true) {
508 508
         return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape);
509 509
     }
510 510
 
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
      * @see  DatabaseQueryBuilder::between()
514 514
      * @return object        the current DatabaseQueryBuilder instance
515 515
      */
516
-    public function orBetween($field, $value1, $value2, $escape = true){
516
+    public function orBetween($field, $value1, $value2, $escape = true) {
517 517
         return $this->between($field, $value1, $value2, '', 'OR', $escape);
518 518
     }
519 519
 
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
      * @see  DatabaseQueryBuilder::between()
523 523
      * @return object        the current DatabaseQueryBuilder instance
524 524
      */
525
-    public function orNotBetween($field, $value1, $value2, $escape = true){
525
+    public function orNotBetween($field, $value1, $value2, $escape = true) {
526 526
         return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape);
527 527
     }
528 528
 
@@ -535,8 +535,8 @@  discard block
 block discarded – undo
535 535
      * @param  boolean $escape whether to escape or not the values
536 536
      * @return object        the current DatabaseQueryBuilder instance
537 537
      */
538
-    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){
539
-        if (empty($data)){
538
+    public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) {
539
+        if (empty($data)) {
540 540
         $data = '';
541 541
         }
542 542
         $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr);
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
      * @see  DatabaseQueryBuilder::like()
549 549
      * @return object        the current DatabaseQueryBuilder instance
550 550
      */
551
-    public function orLike($field, $data, $escape = true){
551
+    public function orLike($field, $data, $escape = true) {
552 552
         return $this->like($field, $data, '', 'OR', $escape);
553 553
     }
554 554
 
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
      * @see  DatabaseQueryBuilder::like()
558 558
      * @return object        the current DatabaseQueryBuilder instance
559 559
      */
560
-    public function notLike($field, $data, $escape = true){
560
+    public function notLike($field, $data, $escape = true) {
561 561
         return $this->like($field, $data, 'NOT ', 'AND', $escape);
562 562
     }
563 563
 
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
      * @see  DatabaseQueryBuilder::like()
567 567
      * @return object        the current DatabaseQueryBuilder instance
568 568
      */
569
-    public function orNotLike($field, $data, $escape = true){
569
+    public function orNotLike($field, $data, $escape = true) {
570 570
         return $this->like($field, $data, 'NOT ', 'OR', $escape);
571 571
     }
572 572
 
@@ -577,13 +577,13 @@  discard block
 block discarded – undo
577 577
      * @param  int $limitEnd the limit count
578 578
      * @return object        the current DatabaseQueryBuilder instance
579 579
      */
580
-    public function limit($limit, $limitEnd = null){
581
-      if (empty($limit)){
580
+    public function limit($limit, $limitEnd = null) {
581
+      if (empty($limit)) {
582 582
         $limit = 0;
583 583
       }
584
-      if (! is_null($limitEnd)){
584
+      if (!is_null($limitEnd)) {
585 585
         $this->limit = $limit . ', ' . $limitEnd;
586
-      } else{
586
+      } else {
587 587
         $this->limit = $limit;
588 588
       }
589 589
       return $this;
@@ -595,10 +595,10 @@  discard block
 block discarded – undo
595 595
      * @param  string $orderDir the order direction (ASC or DESC)
596 596
      * @return object        the current DatabaseQueryBuilder instance
597 597
      */
598
-    public function orderBy($orderBy, $orderDir = ' ASC'){
599
-      if (stristr($orderBy, ' ') || $orderBy == 'rand()'){
598
+    public function orderBy($orderBy, $orderDir = ' ASC') {
599
+      if (stristr($orderBy, ' ') || $orderBy == 'rand()') {
600 600
         $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy;
601
-      } else{
601
+      } else {
602 602
         $this->orderBy = empty($this->orderBy) 
603 603
 						? ($orderBy . ' ' . strtoupper($orderDir)) 
604 604
 						: $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir);
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
      * @param  string|array $field the field name used or array of field list
612 612
      * @return object        the current DatabaseQueryBuilder instance
613 613
      */
614
-    public function groupBy($field){
615
-      if (is_array($field)){
614
+    public function groupBy($field) {
615
+      if (is_array($field)) {
616 616
         $this->groupBy = implode(', ', $field);
617
-      } else{
617
+      } else {
618 618
         $this->groupBy = $field;
619 619
       }
620 620
       return $this;
@@ -628,16 +628,16 @@  discard block
 block discarded – undo
628 628
      * @param  boolean $escape whether to escape or not the values
629 629
      * @return object        the current DatabaseQueryBuilder instance
630 630
      */
631
-    public function having($field, $op = null, $val = null, $escape = true){
632
-      if (is_array($op)){
631
+    public function having($field, $op = null, $val = null, $escape = true) {
632
+      if (is_array($op)) {
633 633
         $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape);
634
-      } else if (! in_array($op, $this->operatorList)){
635
-        if (is_null($op)){
634
+      } else if (!in_array($op, $this->operatorList)) {
635
+        if (is_null($op)) {
636 636
           $op = '';
637 637
         }
638 638
         $this->having = $field . ' > ' . ($this->escape($op, $escape));
639
-      } else{
640
-        if (is_null($val)){
639
+      } else {
640
+        if (is_null($val)) {
641 641
           $val = '';
642 642
         }
643 643
         $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape));
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
      * @param  boolean $escape  whether to escape or not the values
652 652
      * @return object  the current DatabaseQueryBuilder instance        
653 653
      */
654
-    public function insert($data = array(), $escape = true){
654
+    public function insert($data = array(), $escape = true) {
655 655
         $columns = array_keys($data);
656 656
         $column = implode(', ', $columns);
657 657
         $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data));
@@ -666,22 +666,22 @@  discard block
 block discarded – undo
666 666
      * @param  boolean $escape  whether to escape or not the values
667 667
      * @return object  the current DatabaseQueryBuilder instance 
668 668
      */
669
-    public function update($data = array(), $escape = true){
669
+    public function update($data = array(), $escape = true) {
670 670
         $query = 'UPDATE ' . $this->from . ' SET ';
671 671
         $values = array();
672
-        foreach ($data as $column => $val){
672
+        foreach ($data as $column => $val) {
673 673
         $values[] = $column . ' = ' . ($this->escape($val, $escape));
674 674
         }
675 675
         $query .= implode(', ', $values);
676
-        if (! empty($this->where)){
676
+        if (!empty($this->where)) {
677 677
         $query .= ' WHERE ' . $this->where;
678 678
         }
679 679
 
680
-        if (! empty($this->orderBy)){
680
+        if (!empty($this->orderBy)) {
681 681
         $query .= ' ORDER BY ' . $this->orderBy;
682 682
         }
683 683
 
684
-        if (! empty($this->limit)){
684
+        if (!empty($this->limit)) {
685 685
         $query .= ' LIMIT ' . $this->limit;
686 686
         }
687 687
         $this->query = $query;
@@ -692,22 +692,22 @@  discard block
 block discarded – undo
692 692
      * Delete the record in database
693 693
      * @return object  the current DatabaseQueryBuilder instance 
694 694
      */
695
-    public function delete(){
695
+    public function delete() {
696 696
         $query = 'DELETE FROM ' . $this->from;
697 697
         $isTruncate = $query;
698
-        if (! empty($this->where)){
698
+        if (!empty($this->where)) {
699 699
             $query .= ' WHERE ' . $this->where;
700 700
         }
701 701
 
702
-        if (! empty($this->orderBy)){
702
+        if (!empty($this->orderBy)) {
703 703
             $query .= ' ORDER BY ' . $this->orderBy;
704 704
         }
705 705
 
706
-        if (! empty($this->limit)){
706
+        if (!empty($this->limit)) {
707 707
             $query .= ' LIMIT ' . $this->limit;
708 708
         }
709 709
 
710
-            if ($isTruncate == $query && $this->driver != 'sqlite'){  
710
+            if ($isTruncate == $query && $this->driver != 'sqlite') {  
711 711
             $query = 'TRUNCATE TABLE ' . $this->from;
712 712
             }
713 713
         $this->query = $query;
@@ -720,9 +720,9 @@  discard block
 block discarded – undo
720 720
      * @param boolean $escaped whether we can do escape of not 
721 721
      * @return mixed       the data after escaped or the same data if not
722 722
      */
723
-    public function escape($data, $escaped = true){
723
+    public function escape($data, $escaped = true) {
724 724
         $data = trim($data);
725
-        if($escaped){
725
+        if ($escaped) {
726 726
         return $this->pdo->quote($data);
727 727
         }
728 728
         return $data;  
@@ -733,31 +733,31 @@  discard block
 block discarded – undo
733 733
      * Return the current SQL query string
734 734
      * @return string
735 735
      */
736
-    public function getQuery(){
736
+    public function getQuery() {
737 737
         //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now
738
-        if(empty($this->query)){
738
+        if (empty($this->query)) {
739 739
             $query = 'SELECT ' . $this->select . ' FROM ' . $this->from;
740
-            if (! empty($this->join)){
740
+            if (!empty($this->join)) {
741 741
             $query .= $this->join;
742 742
             }
743 743
   		  
744
-            if (! empty($this->where)){
744
+            if (!empty($this->where)) {
745 745
             $query .= ' WHERE ' . $this->where;
746 746
             }
747 747
 
748
-            if (! empty($this->groupBy)){
748
+            if (!empty($this->groupBy)) {
749 749
             $query .= ' GROUP BY ' . $this->groupBy;
750 750
             }
751 751
 
752
-            if (! empty($this->having)){
752
+            if (!empty($this->having)) {
753 753
             $query .= ' HAVING ' . $this->having;
754 754
             }
755 755
 
756
-            if (! empty($this->orderBy)){
756
+            if (!empty($this->orderBy)) {
757 757
                 $query .= ' ORDER BY ' . $this->orderBy;
758 758
             }
759 759
 
760
-            if (! empty($this->limit)){
760
+            if (!empty($this->limit)) {
761 761
             $query .= ' LIMIT ' . $this->limit;
762 762
             }
763 763
             $this->query = $query;
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
          * Return the PDO instance
771 771
          * @return object
772 772
          */
773
-    public function getPdo(){
773
+    public function getPdo() {
774 774
         return $this->pdo;
775 775
     }
776 776
 
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
      * @param PDO $pdo the pdo object
780 780
      * @return object DatabaseQueryBuilder
781 781
      */
782
-    public function setPdo(PDO $pdo = null){
782
+    public function setPdo(PDO $pdo = null) {
783 783
         $this->pdo = $pdo;
784 784
         return $this;
785 785
     }
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
      * Return the database table prefix
789 789
      * @return string
790 790
      */
791
-    public function getPrefix(){
791
+    public function getPrefix() {
792 792
         return $this->prefix;
793 793
     }
794 794
 
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
      * @param string $prefix the new prefix
798 798
      * @return object DatabaseQueryBuilder
799 799
      */
800
-    public function setPrefix($prefix){
800
+    public function setPrefix($prefix) {
801 801
         $this->prefix = $prefix;
802 802
         return $this;
803 803
     }
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
          * Return the database driver
807 807
          * @return string
808 808
          */
809
-    public function getDriver(){
809
+    public function getDriver() {
810 810
         return $this->driver;
811 811
     }
812 812
 
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
      * @param string $driver the new driver
816 816
      * @return object DatabaseQueryBuilder
817 817
      */
818
-    public function setDriver($driver){
818
+    public function setDriver($driver) {
819 819
         $this->driver = $driver;
820 820
         return $this;
821 821
     }
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
          * Reset the DatabaseQueryBuilder class attributs to the initial values before each query.
825 825
          * @return object  the current DatabaseQueryBuilder instance 
826 826
          */
827
-    public function reset(){
827
+    public function reset() {
828 828
         $this->select   = '*';
829 829
         $this->from     = null;
830 830
         $this->where    = null;
@@ -843,12 +843,12 @@  discard block
 block discarded – undo
843 843
          *
844 844
          * @return string
845 845
          */
846
-    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){
846
+    protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) {
847 847
         $x = explode('?', $field);
848 848
         $w = '';
849
-        foreach($x as $k => $v){
850
-            if (!empty($v)){
851
-            if (! isset($op[$k])){
849
+        foreach ($x as $k => $v) {
850
+            if (!empty($v)) {
851
+            if (!isset($op[$k])) {
852 852
                 $op[$k] = '';
853 853
             }
854 854
                 $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : '');
@@ -864,15 +864,15 @@  discard block
 block discarded – undo
864 864
      *
865 865
      * @return string
866 866
      */
867
-    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){
867
+    protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) {
868 868
         $_where = array();
869
-        foreach ($where as $column => $data){
870
-        if (is_null($data)){
869
+        foreach ($where as $column => $data) {
870
+        if (is_null($data)) {
871 871
             $data = '';
872 872
         }
873 873
         $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape));
874 874
         }
875
-        $where = implode(' '.$andOr.' ', $_where);
875
+        $where = implode(' ' . $andOr . ' ', $_where);
876 876
         return $where;
877 877
     }
878 878
 
@@ -882,12 +882,12 @@  discard block
 block discarded – undo
882 882
          *
883 883
          * @return string
884 884
          */
885
-    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){
885
+    protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) {
886 886
         $x = explode('?', $where);
887 887
         $w = '';
888
-        foreach($x as $k => $v){
889
-        if (! empty($v)){
890
-            if (isset($op[$k]) && is_null($op[$k])){
888
+        foreach ($x as $k => $v) {
889
+        if (!empty($v)) {
890
+            if (isset($op[$k]) && is_null($op[$k])) {
891 891
                 $op[$k] = '';
892 892
             }
893 893
             $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : '');
@@ -902,15 +902,15 @@  discard block
 block discarded – undo
902 902
      *
903 903
      * @return string
904 904
      */
905
-    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){
905
+    protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) {
906 906
         $w = '';
907
-        if (! in_array((string)$op, $this->operatorList)){
908
-            if (is_null($op)){
907
+        if (!in_array((string) $op, $this->operatorList)) {
908
+            if (is_null($op)) {
909 909
             $op = '';
910 910
             }
911 911
             $w = $type . $where . ' = ' . ($this->escape($op, $escape));
912 912
         } else {
913
-            if (is_null($val)){
913
+            if (is_null($val)) {
914 914
             $val = '';
915 915
             }
916 916
             $w = $type . $where . $op . ($this->escape($val, $escape));
@@ -923,14 +923,14 @@  discard block
 block discarded – undo
923 923
          * @param string $whereStr the WHERE clause string
924 924
          * @param  string  $andOr the separator type used 'AND', 'OR', etc.
925 925
          */
926
-        protected function setWhereStr($whereStr, $andOr = 'AND'){
927
-        if (empty($this->where)){
926
+        protected function setWhereStr($whereStr, $andOr = 'AND') {
927
+        if (empty($this->where)) {
928 928
             $this->where = $whereStr;
929 929
         } else {
930
-            if (substr(trim($this->where), -1) == '('){
930
+            if (substr(trim($this->where), -1) == '(') {
931 931
             $this->where = $this->where . ' ' . $whereStr;
932 932
             } else {
933
-            $this->where = $this->where . ' '.$andOr.' ' . $whereStr;
933
+            $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr;
934 934
             }
935 935
         }
936 936
         }
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
          * @see  DatabaseQueryBuilder::avg
947 947
          * @return object
948 948
          */
949
-    protected function select_min_max_sum_count_avg($clause, $field, $name = null){
949
+    protected function select_min_max_sum_count_avg($clause, $field, $name = null) {
950 950
         $clause = strtoupper($clause);
951 951
         $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : '');
952 952
         $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func);
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryRunner.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -128,97 +128,97 @@  discard block
 block discarded – undo
128 128
         $responseTime = $this->benchmarkInstance->elapsedTime(
129 129
                                                                 'DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 
130 130
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
131
-                                                              );
132
-		    //TODO use the configuration value for the high response time currently is 1 second
131
+                                                                );
132
+            //TODO use the configuration value for the high response time currently is 1 second
133 133
         if ($responseTime >= 1 ){
134 134
             $this->logger->warning(
135 135
                                     'High response time while processing database query [' . $this->query . ']. 
136 136
                                      The response time is [' .$responseTime. '] sec.'
137
-                                  );
137
+                                    );
138 138
         }
139 139
 		
140 140
         if ($this->pdoStatment !== false){
141
-          $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
-          if($isSqlSELECTQuery){
143
-              $this->setResultForSelect();              
144
-          } else{
145
-              $this->setResultForNonSelect();
146
-          }
147
-          return $this->queryResult;
141
+            $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
+            if($isSqlSELECTQuery){
143
+                $this->setResultForSelect();              
144
+            } else{
145
+                $this->setResultForNonSelect();
146
+            }
147
+            return $this->queryResult;
148 148
         }
149 149
         $this->setQueryRunnerError();
150 150
     }
151 151
 	
152
-   /**
153
-   * Return the result for SELECT query
154
-   * @see DatabaseQueryRunner::execute
155
-   */
152
+    /**
153
+     * Return the result for SELECT query
154
+     * @see DatabaseQueryRunner::execute
155
+     */
156 156
     protected function setResultForSelect(){
157
-      //if need return all result like list of record
158
-      $result = null;
159
-      $numRows = 0;
160
-      $fetchMode = PDO::FETCH_OBJ;
161
-      if($this->returnAsArray){
157
+        //if need return all result like list of record
158
+        $result = null;
159
+        $numRows = 0;
160
+        $fetchMode = PDO::FETCH_OBJ;
161
+        if($this->returnAsArray){
162 162
         $fetchMode = PDO::FETCH_ASSOC;
163
-      }
164
-      if ($this->returnAsList){
165
-          $result = $this->pdoStatment->fetchAll($fetchMode);
166
-      } else{
167
-          $result = $this->pdoStatment->fetch($fetchMode);
168
-      }
169
-      //Sqlite and pgsql always return 0 when using rowCount()
170
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
163
+        }
164
+        if ($this->returnAsList){
165
+            $result = $this->pdoStatment->fetchAll($fetchMode);
166
+        } else{
167
+            $result = $this->pdoStatment->fetch($fetchMode);
168
+        }
169
+        //Sqlite and pgsql always return 0 when using rowCount()
170
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
171 171
         $numRows = count($result);  
172
-      } else{
172
+        } else{
173 173
         $numRows = $this->pdoStatment->rowCount(); 
174
-      }
175
-      if(! is_object($this->queryResult)){
176
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
177
-      }
178
-      $this->queryResult->setResult($result);
179
-      $this->queryResult->setNumRows($numRows);
174
+        }
175
+        if(! is_object($this->queryResult)){
176
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
177
+        }
178
+        $this->queryResult->setResult($result);
179
+        $this->queryResult->setNumRows($numRows);
180 180
     }
181 181
 
182 182
     /**
183
-   * Return the result for non SELECT query
184
-   * @see DatabaseQueryRunner::execute
185
-   */
183
+     * Return the result for non SELECT query
184
+     * @see DatabaseQueryRunner::execute
185
+     */
186 186
     protected function setResultForNonSelect(){
187
-      //Sqlite and pgsql always return 0 when using rowCount()
188
-      $result = false;
189
-      $numRows = 0;
190
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
187
+        //Sqlite and pgsql always return 0 when using rowCount()
188
+        $result = false;
189
+        $numRows = 0;
190
+        if (in_array($this->driver, array('sqlite', 'pgsql'))){
191 191
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
192 192
         $numRows = 1; //TODO use the correct method to get the exact affected row
193
-      } else{
194
-          //to test the result for the query like UPDATE, INSERT, DELETE
195
-          $result  = $this->pdoStatment->rowCount() >= 0; 
196
-          $numRows = $this->pdoStatment->rowCount(); 
197
-      }
198
-      if(! is_object($this->queryResult)){
199
-          $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
200
-      }
201
-      $this->queryResult->setResult($result);
202
-      $this->queryResult->setNumRows($numRows);
193
+        } else{
194
+            //to test the result for the query like UPDATE, INSERT, DELETE
195
+            $result  = $this->pdoStatment->rowCount() >= 0; 
196
+            $numRows = $this->pdoStatment->rowCount(); 
197
+        }
198
+        if(! is_object($this->queryResult)){
199
+            $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
200
+        }
201
+        $this->queryResult->setResult($result);
202
+        $this->queryResult->setNumRows($numRows);
203 203
     }
204 204
 
205 205
 
206
-	/**
206
+    /**
207 207
      * Return the benchmark instance
208 208
      * @return Benchmark
209 209
      */
210 210
     public function getBenchmark() {
211
-      return $this->benchmarkInstance;
211
+        return $this->benchmarkInstance;
212 212
     }
213 213
 
214 214
     /**
215 215
      * Set the benchmark instance
216 216
      * @param Benchmark $benchmark the benchmark object
217
-	 * @return object DatabaseQueryRunner
217
+     * @return object DatabaseQueryRunner
218 218
      */
219 219
     public function setBenchmark($benchmark) {
220
-      $this->benchmarkInstance = $benchmark;
221
-      return $this;
220
+        $this->benchmarkInstance = $benchmark;
221
+        return $this;
222 222
     }
223 223
     
224 224
     /**
@@ -348,18 +348,18 @@  discard block
 block discarded – undo
348 348
      * @param object $logger the Log instance if not null
349 349
      */
350 350
     protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
351
-      if ($logger !== null){
351
+        if ($logger !== null){
352 352
         $this->logger = $logger;
353
-      } else{
354
-          $this->logger =& class_loader('Log', 'classes');
355
-          $this->logger->setLogger('Library::DatabaseQueryRunner');
356
-      }
353
+        } else{
354
+            $this->logger =& class_loader('Log', 'classes');
355
+            $this->logger->setLogger('Library::DatabaseQueryRunner');
356
+        }
357 357
     }
358 358
     
359 359
     
360 360
     /**
361
-    * Reset the instance before run each query
362
-    */
361
+     * Reset the instance before run each query
362
+     */
363 363
     private function reset() {
364 364
         $this->error = null;
365 365
         $this->pdoStatment = null;
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
      */
26
-    class DatabaseQueryRunner extends BaseClass{
26
+    class DatabaseQueryRunner extends BaseClass {
27 27
       
28 28
    
29 29
         /**
30 30
          * The last query result
31 31
          * @var object
32 32
          */
33
-        private $queryResult       = null;
33
+        private $queryResult = null;
34 34
   	
35 35
         /**
36 36
          * The benchmark instance
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
      * The SQL query statment to execute
43 43
      * @var string
44 44
      */
45
-    private $query             = null;
45
+    private $query = null;
46 46
     
47 47
     /**
48 48
      * Indicate if we need return result as list (boolean) 
49 49
      * or the data used to replace the placeholder (array)
50 50
      * @var array|boolean
51 51
      */
52
-        private $returnAsList     = true;
52
+        private $returnAsList = true;
53 53
      
54 54
      
55 55
         /**
56 56
          * Indicate if we need return result as array or not
57 57
          * @var boolean
58 58
          */
59
-        private $returnAsArray     = true;
59
+        private $returnAsArray = true;
60 60
      
61 61
         /**
62 62
          * The last PDOStatment instance
63 63
          * @var object
64 64
          */
65
-        private $pdoStatment       = null;
65
+        private $pdoStatment = null;
66 66
      
67 67
         /**
68 68
          * The error returned for the last query
69 69
          * @var string
70 70
          */
71
-        private $error             = null;
71
+        private $error = null;
72 72
 	
73 73
     /**
74 74
      * The PDO instance
75 75
      * @var object
76 76
      */
77
-    private $pdo                = null;
77
+    private $pdo = null;
78 78
   
79 79
     /**
80 80
      * The database driver name used
81 81
      * @var string
82 82
      */
83
-    private $driver             = null;
83
+    private $driver = null;
84 84
 
85 85
 
86 86
 	
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      * @param boolean $returnAsList if need return as list or just one row
92 92
      * @param boolean $returnAsArray whether to return the result as array or not
93 93
      */
94
-    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
94
+    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) {
95 95
         parent::__construct();
96
-        if (is_object($pdo)){
96
+        if (is_object($pdo)) {
97 97
             $this->pdo = $pdo;
98 98
         }
99 99
         $this->query         = $query;
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
      * 
109 109
      * @return object|void
110 110
      */
111
-    public function execute(){
111
+    public function execute() {
112 112
         //reset instance
113 113
         $this->reset();
114 114
        
115 115
         //for database query execution time
116 116
         $benchmarkMarkerKey = $this->getBenchmarkKey();
117
-        if (! is_object($this->benchmarkInstance)){
117
+        if (!is_object($this->benchmarkInstance)) {
118 118
             $this->benchmarkInstance = & class_loader('Benchmark');
119 119
         }
120 120
         
@@ -130,18 +130,18 @@  discard block
 block discarded – undo
130 130
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
131 131
                                                               );
132 132
 		    //TODO use the configuration value for the high response time currently is 1 second
133
-        if ($responseTime >= 1 ){
133
+        if ($responseTime >= 1) {
134 134
             $this->logger->warning(
135 135
                                     'High response time while processing database query [' . $this->query . ']. 
136
-                                     The response time is [' .$responseTime. '] sec.'
136
+                                     The response time is [' .$responseTime . '] sec.'
137 137
                                   );
138 138
         }
139 139
 		
140
-        if ($this->pdoStatment !== false){
140
+        if ($this->pdoStatment !== false) {
141 141
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
-          if($isSqlSELECTQuery){
142
+          if ($isSqlSELECTQuery) {
143 143
               $this->setResultForSelect();              
144
-          } else{
144
+          } else {
145 145
               $this->setResultForNonSelect();
146 146
           }
147 147
           return $this->queryResult;
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
    * Return the result for SELECT query
154 154
    * @see DatabaseQueryRunner::execute
155 155
    */
156
-    protected function setResultForSelect(){
156
+    protected function setResultForSelect() {
157 157
       //if need return all result like list of record
158 158
       $result = null;
159 159
       $numRows = 0;
160 160
       $fetchMode = PDO::FETCH_OBJ;
161
-      if($this->returnAsArray){
161
+      if ($this->returnAsArray) {
162 162
         $fetchMode = PDO::FETCH_ASSOC;
163 163
       }
164
-      if ($this->returnAsList){
164
+      if ($this->returnAsList) {
165 165
           $result = $this->pdoStatment->fetchAll($fetchMode);
166
-      } else{
166
+      } else {
167 167
           $result = $this->pdoStatment->fetch($fetchMode);
168 168
       }
169 169
       //Sqlite and pgsql always return 0 when using rowCount()
170
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
170
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
171 171
         $numRows = count($result);  
172
-      } else{
172
+      } else {
173 173
         $numRows = $this->pdoStatment->rowCount(); 
174 174
       }
175
-      if(! is_object($this->queryResult)){
175
+      if (!is_object($this->queryResult)) {
176 176
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
177 177
       }
178 178
       $this->queryResult->setResult($result);
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
    * Return the result for non SELECT query
184 184
    * @see DatabaseQueryRunner::execute
185 185
    */
186
-    protected function setResultForNonSelect(){
186
+    protected function setResultForNonSelect() {
187 187
       //Sqlite and pgsql always return 0 when using rowCount()
188 188
       $result = false;
189 189
       $numRows = 0;
190
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
190
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
191 191
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
192 192
         $numRows = 1; //TODO use the correct method to get the exact affected row
193
-      } else{
193
+      } else {
194 194
           //to test the result for the query like UPDATE, INSERT, DELETE
195 195
           $result  = $this->pdoStatment->rowCount() >= 0; 
196 196
           $numRows = $this->pdoStatment->rowCount(); 
197 197
       }
198
-      if(! is_object($this->queryResult)){
198
+      if (!is_object($this->queryResult)) {
199 199
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
200 200
       }
201 201
       $this->queryResult->setResult($result);
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      *
227 227
      * @return object DatabaseQueryResult
228 228
      */
229
-    public function getQueryResult(){
229
+    public function getQueryResult() {
230 230
         return $this->queryResult;
231 231
     }
232 232
 
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      *
237 237
      * @return object DatabaseQueryRunner
238 238
      */
239
-    public function setQueryResult(DatabaseQueryResult $queryResult){
239
+    public function setQueryResult(DatabaseQueryResult $queryResult) {
240 240
         $this->queryResult = $queryResult;
241 241
         return $this;
242 242
     }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      * Return the current query SQL string
246 246
      * @return string
247 247
      */
248
-    public function getQuery(){
248
+    public function getQuery() {
249 249
         return $this->query;
250 250
     }
251 251
     
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      * @param string $query the SQL query to set
255 255
      * @return object DatabaseQueryRunner
256 256
      */
257
-    public function setQuery($query){
257
+    public function setQuery($query) {
258 258
         $this->query = $query;
259 259
         return $this;
260 260
     }
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      * @param boolean $returnType
265 265
      * @return object DatabaseQueryRunner
266 266
      */
267
-    public function setReturnType($returnType){
267
+    public function setReturnType($returnType) {
268 268
         $this->returnAsList = $returnType;
269 269
         return $this;
270 270
     }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @param boolean $status the status if true will return as array
275 275
      * @return object DatabaseQueryRunner
276 276
      */
277
-    public function setReturnAsArray($status = true){
277
+    public function setReturnAsArray($status = true) {
278 278
         $this->returnAsArray = $status;
279 279
         return $this;
280 280
     }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      * Return the error for last query execution
284 284
      * @return string
285 285
      */
286
-    public function getQueryError(){
286
+    public function getQueryError() {
287 287
         return $this->error;
288 288
     }
289 289
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * Return the PDO instance
292 292
      * @return object
293 293
      */
294
-    public function getPdo(){
294
+    public function getPdo() {
295 295
         return $this->pdo;
296 296
     }
297 297
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      * @param PDO $pdo the pdo object
301 301
      * @return object DatabaseQueryRunner
302 302
      */
303
-    public function setPdo(PDO $pdo = null){
303
+    public function setPdo(PDO $pdo = null) {
304 304
         $this->pdo = $pdo;
305 305
         return $this;
306 306
     }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
          * Return the database driver
310 310
          * @return string
311 311
          */
312
-    public function getDriver(){
312
+    public function getDriver() {
313 313
         return $this->driver;
314 314
     }
315 315
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      * @param string $driver the new driver
319 319
      * @return object DatabaseQueryRunner
320 320
      */
321
-    public function setDriver($driver){
321
+    public function setDriver($driver) {
322 322
         $this->driver = $driver;
323 323
         return $this;
324 324
     }
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
      * 
329 329
      *  @return string
330 330
      */
331
-    protected function getBenchmarkKey(){
331
+    protected function getBenchmarkKey() {
332 332
         return md5($this->query . $this->returnAsList . $this->returnAsArray);
333 333
     }
334 334
     
335 335
     /**
336 336
      * Set error for database query execution
337 337
      */
338
-    protected function setQueryRunnerError(){
338
+    protected function setQueryRunnerError() {
339 339
         $error = $this->pdo->errorInfo();
340 340
         $this->error = isset($error[2]) ? $error[2] : '';
341 341
         $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
      * Set the Log instance using argument or create new instance
348 348
      * @param object $logger the Log instance if not null
349 349
      */
350
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
351
-      if ($logger !== null){
350
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
351
+      if ($logger !== null) {
352 352
         $this->logger = $logger;
353
-      } else{
354
-          $this->logger =& class_loader('Log', 'classes');
353
+      } else {
354
+          $this->logger = & class_loader('Log', 'classes');
355 355
           $this->logger->setLogger('Library::DatabaseQueryRunner');
356 356
       }
357 357
     }
Please login to merge, or discard this patch.
core/classes/database/Database.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -149,13 +149,13 @@
 block discarded – undo
149 149
             $this->updateQueryBuilderAndRunnerProperties();
150 150
 
151 151
             return is_object($this->pdo);
152
-          } catch (PDOException $e){
152
+            } catch (PDOException $e){
153 153
             $this->logger->fatal($e->getMessage());
154 154
             show_error('Cannot connect to Database.');
155 155
             return false;
156
-          }
157
-      }
158
-      return false;
156
+            }
157
+        }
158
+        return false;
159 159
     }
160 160
 
161 161
 
Please login to merge, or discard this patch.
Switch Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -603,17 +603,17 @@
 block discarded – undo
603 603
         return null;
604 604
         }
605 605
         switch ($driver) {
606
-        case 'mysql':
607
-        case 'pgsql':
608
-          $port = '';
609
-            if (! empty($config['port'])) {
610
-            $port = 'port=' . $config['port'] . ';';
611
-            }
612
-            $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
613
-            break;
614
-        case 'sqlite':
615
-          $dsn = 'sqlite:' . $config['database'];
616
-            break;
606
+            case 'mysql':
607
+            case 'pgsql':
608
+              $port = '';
609
+                if (! empty($config['port'])) {
610
+                $port = 'port=' . $config['port'] . ';';
611
+                }
612
+                $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
613
+                break;
614
+            case 'sqlite':
615
+              $dsn = 'sqlite:' . $config['database'];
616
+                break;
617 617
             case 'oracle':
618 618
           $port = '';
619 619
             if (! empty($config['port'])) {
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -23,92 +23,92 @@  discard block
 block discarded – undo
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
      */
26
-    class Database extends BaseClass{
26
+    class Database extends BaseClass {
27 27
 	
28 28
         /**
29 29
          * The PDO instance
30 30
          * @var object
31 31
          */
32
-    private $pdo                 = null;
32
+    private $pdo = null;
33 33
     
34 34
         /**
35 35
          * The database name used for the application
36 36
          * @var string
37 37
          */
38
-        private $databaseName        = null;
38
+        private $databaseName = null;
39 39
 	
40 40
         /**
41 41
          * The number of rows returned by the last query
42 42
          * @var int
43 43
          */
44
-    private $numRows             = 0;
44
+    private $numRows = 0;
45 45
 	
46 46
         /**
47 47
          * The last insert id for the primary key column that have auto increment or sequence
48 48
          * @var mixed
49 49
          */
50
-    private $insertId            = null;
50
+    private $insertId = null;
51 51
 	
52 52
         /**
53 53
          * The full SQL query statment after build for each command
54 54
          * @var string
55 55
          */
56
-    private $query               = null;
56
+    private $query = null;
57 57
 	
58 58
         /**
59 59
          * The result returned for the last query
60 60
          * @var mixed
61 61
          */
62
-    private $result              = array();
62
+    private $result = array();
63 63
 	
64 64
         /**
65 65
          * The cache default time to live in second. 0 means no need to use the cache feature
66 66
          * @var int
67 67
          */
68
-        private $cacheTtl             = 0;
68
+        private $cacheTtl = 0;
69 69
 	
70 70
         /**
71 71
          * The cache current time to live. 0 means no need to use the cache feature
72 72
          * @var int
73 73
          */
74
-    private $temporaryCacheTtl   = 0;
74
+    private $temporaryCacheTtl = 0;
75 75
 	
76 76
         /**
77 77
          * The number of executed query for the current request
78 78
          * @var int
79 79
          */
80
-    private $queryCount          = 0;
80
+    private $queryCount = 0;
81 81
 	
82 82
         /**
83 83
          * The default data to be used in the statments query INSERT, UPDATE
84 84
          * @var array
85 85
          */
86
-    private $data                = array();
86
+    private $data = array();
87 87
 	
88 88
         /**
89 89
          * The database configuration
90 90
          * @var array
91 91
          */
92
-    private $config              = array();
92
+    private $config = array();
93 93
 	
94 94
     /**
95 95
      * The cache instance
96 96
      * @var object
97 97
      */
98
-    private $cacheInstance       = null;
98
+    private $cacheInstance = null;
99 99
 
100 100
     
101 101
         /**
102 102
          * The DatabaseQueryBuilder instance
103 103
          * @var object
104 104
          */
105
-    protected $queryBuilder        = null;
105
+    protected $queryBuilder = null;
106 106
     
107 107
     /**
108 108
      * The DatabaseQueryRunner instance
109 109
      * @var object
110 110
      */
111
-    protected $queryRunner         = null;
111
+    protected $queryRunner = null;
112 112
 
113 113
 
114 114
     /**
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
      * This is used to connect to database
137 137
      * @return bool 
138 138
      */
139
-    public function connect(){
139
+    public function connect() {
140 140
         $config = $this->getDatabaseConfiguration();
141
-        if (! empty($config)){
142
-        try{
141
+        if (!empty($config)) {
142
+        try {
143 143
             $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']);
144 144
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
145 145
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             $this->updateQueryBuilderAndRunnerProperties();
150 150
 
151 151
             return is_object($this->pdo);
152
-          } catch (PDOException $e){
152
+          } catch (PDOException $e) {
153 153
             $this->logger->fatal($e->getMessage());
154 154
             show_error('Cannot connect to Database.');
155 155
             return false;
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      * Return the number of rows returned by the current query
164 164
      * @return int
165 165
      */
166
-    public function numRows(){
166
+    public function numRows() {
167 167
         return $this->numRows;
168 168
     }
169 169
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * Return the last insert id value
172 172
      * @return mixed
173 173
      */
174
-    public function insertId(){
174
+    public function insertId() {
175 175
         return $this->insertId;
176 176
     }
177 177
 
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
      * If is string will determine the result type "array" or "object"
183 183
      * @return mixed       the query SQL string or the record result
184 184
      */
185
-    public function get($returnSQLQueryOrResultType = false){
185
+    public function get($returnSQLQueryOrResultType = false) {
186 186
         $this->queryBuilder->limit(1);
187 187
         $query = $this->getAll(true);
188
-        if ($returnSQLQueryOrResultType === true){
188
+        if ($returnSQLQueryOrResultType === true) {
189 189
         return $query;
190 190
         } else {
191 191
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
      * If is string will determine the result type "array" or "object"
199 199
      * @return mixed       the query SQL string or the record result
200 200
      */
201
-    public function getAll($returnSQLQueryOrResultType = false){
201
+    public function getAll($returnSQLQueryOrResultType = false) {
202 202
         $query = $this->queryBuilder->getQuery();
203
-        if ($returnSQLQueryOrResultType === true){
203
+        if ($returnSQLQueryOrResultType === true) {
204 204
             return $query;
205 205
         }
206 206
         return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
@@ -212,18 +212,18 @@  discard block
 block discarded – undo
212 212
      * @param  boolean $escape  whether to escape or not the values
213 213
      * @return mixed          the insert id of the new record or null
214 214
      */
215
-    public function insert($data = array(), $escape = true){
216
-        if (empty($data) && ! empty($this->data)){
215
+    public function insert($data = array(), $escape = true) {
216
+        if (empty($data) && !empty($this->data)) {
217 217
         //as when using $this->setData() may be the data already escaped
218 218
         $escape = false;
219 219
         $data = $this->data;
220 220
         }
221 221
         $query = $this->queryBuilder->insert($data, $escape)->getQuery();
222 222
         $result = $this->query($query);
223
-        if ($result){
223
+        if ($result) {
224 224
         $this->insertId = $this->pdo->lastInsertId();
225 225
             //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
226
-        return ! ($this->insertId) ? true : $this->insertId;
226
+        return !($this->insertId) ? true : $this->insertId;
227 227
         }
228 228
         return false;
229 229
     }
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
      * @param  boolean $escape  whether to escape or not the values
235 235
      * @return mixed          the update status
236 236
      */
237
-    public function update($data = array(), $escape = true){
238
-        if (empty($data) && ! empty($this->data)){
237
+    public function update($data = array(), $escape = true) {
238
+        if (empty($data) && !empty($this->data)) {
239 239
         //as when using $this->setData() may be the data already escaped
240 240
         $escape = false;
241 241
         $data = $this->data;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      * Delete the record in database
249 249
      * @return mixed the delete status
250 250
      */
251
-    public function delete(){
251
+    public function delete() {
252 252
             $query = $this->queryBuilder->delete()->getQuery();
253 253
         return $this->query($query);
254 254
     }
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      * @param integer $ttl the cache time to live in second
259 259
      * @return object        the current Database instance
260 260
      */
261
-    public function setCache($ttl = 0){
261
+    public function setCache($ttl = 0) {
262 262
         $this->cacheTtl = $ttl;
263 263
         $this->temporaryCacheTtl = $ttl;
264 264
         return $this;
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      * @param  integer $ttl the cache time to live in second
270 270
      * @return object        the current Database instance
271 271
      */
272
-        public function cached($ttl = 0){
272
+        public function cached($ttl = 0) {
273 273
         $this->temporaryCacheTtl = $ttl;
274 274
         return $this;
275 275
     }
@@ -281,9 +281,9 @@  discard block
 block discarded – undo
281 281
      * @return mixed       the data after escaped or the same data if no
282 282
      * need escaped
283 283
      */
284
-    public function escape($data, $escaped = true){
284
+    public function escape($data, $escaped = true) {
285 285
         $data = trim($data);
286
-        if($escaped){
286
+        if ($escaped) {
287 287
         return $this->pdo->quote($data);
288 288
         }
289 289
         return $data; 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
      * Return the number query executed count for the current request
294 294
      * @return int
295 295
      */
296
-    public function queryCount(){
296
+    public function queryCount() {
297 297
         return $this->queryCount;
298 298
     }
299 299
 
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      * Return the current query SQL string
302 302
      * @return string
303 303
      */
304
-    public function getQuery(){
304
+    public function getQuery() {
305 305
         return $this->query;
306 306
     }
307 307
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      * Return the application database name
310 310
      * @return string
311 311
      */
312
-    public function getDatabaseName(){
312
+    public function getDatabaseName() {
313 313
         return $this->databaseName;
314 314
     }
315 315
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      * Return the PDO instance
318 318
      * @return object
319 319
      */
320
-    public function getPdo(){
320
+    public function getPdo() {
321 321
         return $this->pdo;
322 322
     }
323 323
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      * @param object $pdo the pdo object
327 327
      * @return object Database
328 328
      */
329
-    public function setPdo(PDO $pdo){
329
+    public function setPdo(PDO $pdo) {
330 330
         $this->pdo = $pdo;
331 331
         return $this;
332 332
     }
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
          * Return the cache instance
336 336
          * @return CacheInterface
337 337
          */
338
-    public function getCacheInstance(){
338
+    public function getCacheInstance() {
339 339
         return $this->cacheInstance;
340 340
     }
341 341
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      * @param CacheInterface $cache the cache object
345 345
      * @return object Database
346 346
      */
347
-    public function setCacheInstance($cache){
347
+    public function setCacheInstance($cache) {
348 348
         $this->cacheInstance = $cache;
349 349
         return $this;
350 350
     }
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
          * Return the DatabaseQueryBuilder instance
355 355
          * @return object DatabaseQueryBuilder
356 356
          */
357
-    public function getQueryBuilder(){
357
+    public function getQueryBuilder() {
358 358
         return $this->queryBuilder;
359 359
     }
360 360
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * Set the DatabaseQueryBuilder instance
363 363
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
364 364
      */
365
-    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
365
+    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) {
366 366
         $this->queryBuilder = $queryBuilder;
367 367
         return $this;
368 368
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
      * Return the DatabaseQueryRunner instance
372 372
      * @return object DatabaseQueryRunner
373 373
      */
374
-    public function getQueryRunner(){
374
+    public function getQueryRunner() {
375 375
         return $this->queryRunner;
376 376
     }
377 377
 
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
      * Set the DatabaseQueryRunner instance
380 380
      * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object
381 381
      */
382
-    public function setQueryRunner(DatabaseQueryRunner $queryRunner){
382
+    public function setQueryRunner(DatabaseQueryRunner $queryRunner) {
383 383
         $this->queryRunner = $queryRunner;
384 384
         return $this;
385 385
     }
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
      * Return the data to be used for insert, update, etc.
389 389
      * @return array
390 390
      */
391
-    public function getData(){
391
+    public function getData() {
392 392
         return $this->data;
393 393
     }
394 394
 
@@ -399,9 +399,9 @@  discard block
 block discarded – undo
399 399
      * @param boolean $escape whether to escape or not the $value
400 400
      * @return object        the current Database instance
401 401
      */
402
-    public function setData($key, $value = null, $escape = true){
403
-        if (is_array($key)){
404
-            foreach($key as $k => $v){
402
+    public function setData($key, $value = null, $escape = true) {
403
+        if (is_array($key)) {
404
+            foreach ($key as $k => $v) {
405 405
                 $this->setData($k, $v, $escape);
406 406
             }	
407 407
         } else {
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
          * @param  boolean $returnAsArray return the result as array or not
418 418
          * @return mixed         the query result
419 419
          */
420
-    public function query($query, $returnAsList = true, $returnAsArray = false){
420
+    public function query($query, $returnAsList = true, $returnAsArray = false) {
421 421
         $this->reset();
422 422
         $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
423 423
         //If is the SELECT query
@@ -438,12 +438,12 @@  discard block
 block discarded – undo
438 438
         //if can use cache feature for this query
439 439
         $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
440 440
     
441
-        if ($dbCacheStatus && $isSqlSELECTQuery){
441
+        if ($dbCacheStatus && $isSqlSELECTQuery) {
442 442
             $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
443 443
             $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
444 444
         }
445 445
       
446
-        if (!$cacheContent){
446
+        if (!$cacheContent) {
447 447
                 //count the number of query execution to server
448 448
         $this->queryCount++;
449 449
         
@@ -452,19 +452,19 @@  discard block
 block discarded – undo
452 452
                                             ->setReturnAsArray($returnAsArray)
453 453
                                             ->execute();
454 454
 
455
-        if (!is_object($queryResult)){
455
+        if (!is_object($queryResult)) {
456 456
             $this->result = false;
457 457
             $this->numRows = 0;
458 458
             return $this->result;
459 459
         }
460 460
         $this->result  = $queryResult->getResult();
461 461
         $this->numRows = $queryResult->getNumRows();
462
-        if ($isSqlSELECTQuery && $dbCacheStatus){
462
+        if ($isSqlSELECTQuery && $dbCacheStatus) {
463 463
             $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray);
464 464
             $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire);
465 465
         }
466
-        } else if ($isSqlSELECTQuery){
467
-            $this->logger->info('The result for query [' .$this->query. '] already cached use it');
466
+        } else if ($isSqlSELECTQuery) {
467
+            $this->logger->info('The result for query [' . $this->query . '] already cached use it');
468 468
             $this->result = $cacheContent;
469 469
             $this->numRows = count($this->result);
470 470
         }
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
      * @param boolean $autoConnect whether to connect to database after set the configuration
479 479
      * @return object Database
480 480
      */
481
-    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){
481
+    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false) {
482 482
         $db = array();
483
-        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
483
+        if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) {
484 484
             //here don't use require_once because somewhere user can create database instance directly
485 485
             require CONFIG_PATH . 'database.php';
486 486
         }
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
         //determine the port using the hostname like localhost:3307
496 496
         //hostname will be "localhost", and port "3307"
497 497
         $p = explode(':', $config['hostname']);
498
-        if (count($p) >= 2){
498
+        if (count($p) >= 2) {
499 499
             $config['hostname'] = $p[0];
500 500
             $config['port'] = $p[1];
501 501
             }
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
                                                             array('password' => string_hidden($this->config['password']))
510 510
                                                 ))
511 511
                             );
512
-        if($autoConnect){
512
+        if ($autoConnect) {
513 513
                 //Now connect to the database
514 514
                 $this->connect();
515 515
             }
@@ -520,14 +520,14 @@  discard block
 block discarded – undo
520 520
      * Return the database configuration
521 521
      * @return array
522 522
      */
523
-    public  function getDatabaseConfiguration(){
523
+    public  function getDatabaseConfiguration() {
524 524
         return $this->config;
525 525
     }
526 526
 
527 527
     /**
528 528
      * Close the connexion
529 529
      */
530
-    public function close(){
530
+    public function close() {
531 531
         $this->pdo = null;
532 532
     }
533 533
 
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
      * Return the database default configuration
536 536
      * @return array
537 537
      */
538
-    protected function getDatabaseDefaultConfiguration(){
538
+    protected function getDatabaseDefaultConfiguration() {
539 539
         return array(
540 540
                 'driver' => '',
541 541
                 'username' => '',
@@ -553,16 +553,16 @@  discard block
 block discarded – undo
553 553
      * Update the DatabaseQueryBuilder and DatabaseQueryRunner properties
554 554
      * @return void
555 555
      */
556
-    protected function updateQueryBuilderAndRunnerProperties(){
556
+    protected function updateQueryBuilderAndRunnerProperties() {
557 557
         //update queryBuilder with some properties needed
558
-        if (is_object($this->queryBuilder)){
558
+        if (is_object($this->queryBuilder)) {
559 559
         $this->queryBuilder->setDriver($this->config['driver'])
560 560
                             ->setPrefix($this->config['prefix'])
561 561
                             ->setPdo($this->pdo);
562 562
         }
563 563
 
564 564
         //update queryRunner with some properties needed
565
-        if (is_object($this->queryRunner)){
565
+        if (is_object($this->queryRunner)) {
566 566
         $this->queryRunner->setDriver($this->config['driver'])
567 567
                             ->setPdo($this->pdo);
568 568
         }
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
      * This method is used to get the PDO DSN string using the configured driver
574 574
      * @return string|null the DSN string or null if can not find it
575 575
      */
576
-    protected function getDsnValueFromConfig(){
576
+    protected function getDsnValueFromConfig() {
577 577
         $dsn = null;
578 578
         $config = $this->getDatabaseConfiguration();
579
-        if (! empty($config)){
579
+        if (!empty($config)) {
580 580
         $driver = $config['driver'];
581 581
         $driverDsnMap = array(
582 582
                                 'mysql'  => $this->getDsnValueForDriver('mysql'),
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
                                 'sqlite' => $this->getDsnValueForDriver('sqlite'),
585 585
                                 'oracle' => $this->getDsnValueForDriver('oracle')
586 586
                                 );
587
-        if (isset($driverDsnMap[$driver])){
587
+        if (isset($driverDsnMap[$driver])) {
588 588
             $dsn = $driverDsnMap[$driver];
589 589
         }
590 590
         }    
@@ -596,17 +596,17 @@  discard block
 block discarded – undo
596 596
      * @param  string $driver the driver name
597 597
      * @return string|null         the dsn name
598 598
      */
599
-    protected function getDsnValueForDriver($driver){
599
+    protected function getDsnValueForDriver($driver) {
600 600
         $dsn = '';
601 601
         $config = $this->getDatabaseConfiguration();
602
-        if (empty($config)){
602
+        if (empty($config)) {
603 603
         return null;
604 604
         }
605 605
         switch ($driver) {
606 606
         case 'mysql':
607 607
         case 'pgsql':
608 608
           $port = '';
609
-            if (! empty($config['port'])) {
609
+            if (!empty($config['port'])) {
610 610
             $port = 'port=' . $config['port'] . ';';
611 611
             }
612 612
             $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
@@ -616,10 +616,10 @@  discard block
 block discarded – undo
616 616
             break;
617 617
             case 'oracle':
618 618
           $port = '';
619
-            if (! empty($config['port'])) {
619
+            if (!empty($config['port'])) {
620 620
             $port = ':' . $config['port'];
621 621
             }
622
-            $dsn =  'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
622
+            $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
623 623
             break;
624 624
         }
625 625
         return $dsn;
@@ -631,9 +631,9 @@  discard block
 block discarded – undo
631 631
      *      
632 632
      * @return mixed
633 633
      */
634
-    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){
634
+    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray) {
635 635
         $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray);
636
-        if (! is_object($this->cacheInstance)){
636
+        if (!is_object($this->cacheInstance)) {
637 637
                 //can not call method with reference in argument
638 638
                 //like $this->setCacheInstance(& get_instance()->cache);
639 639
                 //use temporary variable
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
      * @param mixed $result the query result to save
651 651
      * @param int $expire the cache TTL
652 652
      */
653
-        protected function setCacheContentForQuery($query, $key, $result, $expire){
654
-        $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
655
-        if (! is_object($this->cacheInstance)){
653
+        protected function setCacheContentForQuery($query, $key, $result, $expire) {
654
+        $this->logger->info('Save the result for query [' . $query . '] into cache for future use');
655
+        if (!is_object($this->cacheInstance)) {
656 656
                     //can not call method with reference in argument
657 657
                     //like $this->setCacheInstance(& get_instance()->cache);
658 658
                     //use temporary variable
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
          * 
670 670
          *  @return string
671 671
          */
672
-    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){
672
+    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray) {
673 673
         return md5($query . $returnAsList . $returnAsArray);
674 674
     }
675 675
 
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
     /**
678 678
      * Reset the database class attributs to the initail values before each query.
679 679
      */
680
-    private function reset(){
680
+    private function reset() {
681 681
         //query builder reset
682 682
         $this->queryBuilder->reset();
683 683
         $this->numRows  = 0;
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
     /**
691 691
      * The class destructor
692 692
      */
693
-    public function __destruct(){
693
+    public function __destruct() {
694 694
         $this->pdo = null;
695 695
     }
696 696
 
Please login to merge, or discard this patch.
core/classes/Session.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -1,147 +1,147 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
26
-	class Session extends BaseStaticClass {
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
+    class Session extends BaseStaticClass {
27 27
 		
28
-		/**
29
-		 * The session flash key to use
30
-		 * @const
31
-		 */
32
-		const SESSION_FLASH_KEY = 'session_flash';
28
+        /**
29
+         * The session flash key to use
30
+         * @const
31
+         */
32
+        const SESSION_FLASH_KEY = 'session_flash';
33 33
 
34
-		/**
35
-		 * Get the session item value
36
-		 * @param  string $item    the session item name to get
37
-		 * @param  mixed $default the default value to use if can not find the session item in the list
38
-		 * @return mixed          the session value if exist or the default value
39
-		 */
40
-		public static function get($item, $default = null) {
41
-			$logger = self::getLogger();
42
-			$logger->debug('Getting session data for item [' . $item . '] ...');
43
-			if (array_key_exists($item, $_SESSION)) {
44
-				$logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
45
-				return $_SESSION[$item];
46
-			}
47
-			$logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']');
48
-			return $default;
49
-		}
34
+        /**
35
+         * Get the session item value
36
+         * @param  string $item    the session item name to get
37
+         * @param  mixed $default the default value to use if can not find the session item in the list
38
+         * @return mixed          the session value if exist or the default value
39
+         */
40
+        public static function get($item, $default = null) {
41
+            $logger = self::getLogger();
42
+            $logger->debug('Getting session data for item [' . $item . '] ...');
43
+            if (array_key_exists($item, $_SESSION)) {
44
+                $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
45
+                return $_SESSION[$item];
46
+            }
47
+            $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']');
48
+            return $default;
49
+        }
50 50
 
51
-		/**
52
-		 * Set the session item value
53
-		 * @param string $item  the session item name to set
54
-		 * @param mixed $value the session item value
55
-		 */
56
-		public static function set($item, $value) {
57
-			$logger = self::getLogger();
58
-			$logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
59
-			$_SESSION[$item] = $value;
60
-		}
51
+        /**
52
+         * Set the session item value
53
+         * @param string $item  the session item name to set
54
+         * @param mixed $value the session item value
55
+         */
56
+        public static function set($item, $value) {
57
+            $logger = self::getLogger();
58
+            $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
59
+            $_SESSION[$item] = $value;
60
+        }
61 61
 
62
-		/**
63
-		 * Get the session flash item value
64
-		 * @param  string $item    the session flash item name to get
65
-		 * @param  mixed $default the default value to use if can not find the session flash item in the list
66
-		 * @return mixed          the session flash value if exist or the default value
67
-		 */
68
-		public static function getFlash($item, $default = null){
69
-			$logger = self::getLogger();
70
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
71
-			$return = array_key_exists($key, $_SESSION) ?
72
-			($_SESSION[$key]) : $default;
73
-			if(array_key_exists($key, $_SESSION)){
74
-				unset($_SESSION[$key]);
75
-			} else{
76
-				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
77
-			}
78
-			return $return;
79
-		}
62
+        /**
63
+         * Get the session flash item value
64
+         * @param  string $item    the session flash item name to get
65
+         * @param  mixed $default the default value to use if can not find the session flash item in the list
66
+         * @return mixed          the session flash value if exist or the default value
67
+         */
68
+        public static function getFlash($item, $default = null){
69
+            $logger = self::getLogger();
70
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
71
+            $return = array_key_exists($key, $_SESSION) ?
72
+            ($_SESSION[$key]) : $default;
73
+            if(array_key_exists($key, $_SESSION)){
74
+                unset($_SESSION[$key]);
75
+            } else{
76
+                $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
77
+            }
78
+            return $return;
79
+        }
80 80
 
81
-		/**
82
-		 * Check whether the given session flash item exists
83
-		 * @param  string  $item the session flash item name
84
-		 * @return boolean 
85
-		 */
86
-		public static function hasFlash($item) {
87
-			$key = self::SESSION_FLASH_KEY . '_' . $item;
88
-			return array_key_exists($key, $_SESSION);
89
-		}
81
+        /**
82
+         * Check whether the given session flash item exists
83
+         * @param  string  $item the session flash item name
84
+         * @return boolean 
85
+         */
86
+        public static function hasFlash($item) {
87
+            $key = self::SESSION_FLASH_KEY . '_' . $item;
88
+            return array_key_exists($key, $_SESSION);
89
+        }
90 90
 
91
-		/**
92
-		 * Set the session flash item value
93
-		 * @param string $item  the session flash item name to set
94
-		 * @param mixed $value the session flash item value
95
-		 */
96
-		public static function setFlash($item, $value) {
97
-			$key = self::SESSION_FLASH_KEY . '_' . $item;
98
-			$_SESSION[$key] = $value;
99
-		}
91
+        /**
92
+         * Set the session flash item value
93
+         * @param string $item  the session flash item name to set
94
+         * @param mixed $value the session flash item value
95
+         */
96
+        public static function setFlash($item, $value) {
97
+            $key = self::SESSION_FLASH_KEY . '_' . $item;
98
+            $_SESSION[$key] = $value;
99
+        }
100 100
 
101
-		/**
102
-		 * Clear the session item in the list
103
-		 * @param  string $item the session item name to be deleted
104
-		 */
105
-		public static function clear($item){
106
-			$logger = self::getLogger();
107
-			if(array_key_exists($item, $_SESSION)){
108
-				$logger->info('Deleting of session for item ['.$item.' ]');
109
-				unset($_SESSION[$item]);
110
-			} else{
111
-				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
112
-			}
113
-		}
101
+        /**
102
+         * Clear the session item in the list
103
+         * @param  string $item the session item name to be deleted
104
+         */
105
+        public static function clear($item){
106
+            $logger = self::getLogger();
107
+            if(array_key_exists($item, $_SESSION)){
108
+                $logger->info('Deleting of session for item ['.$item.' ]');
109
+                unset($_SESSION[$item]);
110
+            } else{
111
+                $logger->warning('Session item ['.$item.'] to be deleted does not exists');
112
+            }
113
+        }
114 114
 		
115
-		/**
116
-		 * Clear the session flash item in the list
117
-		 * @param  string $item the session flash item name to be deleted
118
-		 */
119
-		public static function clearFlash($item){
120
-			$logger = self::getLogger();
121
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
122
-			if(array_key_exists($key, $_SESSION)){
123
-				$logger->info('Delete session flash for item ['.$item.']');
124
-				unset($_SESSION[$item]);
125
-			} else{
126
-				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
127
-			}
128
-		}
115
+        /**
116
+         * Clear the session flash item in the list
117
+         * @param  string $item the session flash item name to be deleted
118
+         */
119
+        public static function clearFlash($item){
120
+            $logger = self::getLogger();
121
+            $key = self::SESSION_FLASH_KEY.'_'.$item;
122
+            if(array_key_exists($key, $_SESSION)){
123
+                $logger->info('Delete session flash for item ['.$item.']');
124
+                unset($_SESSION[$item]);
125
+            } else{
126
+                $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
127
+            }
128
+        }
129 129
 
130
-		/**
131
-		 * Check whether the given session item exists
132
-		 * @param  string  $item the session item name
133
-		 * @return boolean 
134
-		 */
135
-		public static function exists($item) {
136
-			return array_key_exists($item, $_SESSION);
137
-		}
130
+        /**
131
+         * Check whether the given session item exists
132
+         * @param  string  $item the session item name
133
+         * @return boolean 
134
+         */
135
+        public static function exists($item) {
136
+            return array_key_exists($item, $_SESSION);
137
+        }
138 138
 
139
-		/**
140
-		 * Destroy all session data values
141
-		 */
142
-		public static function clearAll() {
143
-			session_unset();
144
-			session_destroy();
145
-		}
139
+        /**
140
+         * Destroy all session data values
141
+         */
142
+        public static function clearAll() {
143
+            session_unset();
144
+            session_destroy();
145
+        }
146 146
 
147
-	}
147
+    }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -65,15 +65,15 @@  discard block
 block discarded – undo
65 65
 		 * @param  mixed $default the default value to use if can not find the session flash item in the list
66 66
 		 * @return mixed          the session flash value if exist or the default value
67 67
 		 */
68
-		public static function getFlash($item, $default = null){
68
+		public static function getFlash($item, $default = null) {
69 69
 			$logger = self::getLogger();
70
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
70
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
71 71
 			$return = array_key_exists($key, $_SESSION) ?
72 72
 			($_SESSION[$key]) : $default;
73
-			if(array_key_exists($key, $_SESSION)){
73
+			if (array_key_exists($key, $_SESSION)) {
74 74
 				unset($_SESSION[$key]);
75
-			} else{
76
-				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
75
+			} else {
76
+				$logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']');
77 77
 			}
78 78
 			return $return;
79 79
 		}
@@ -102,13 +102,13 @@  discard block
 block discarded – undo
102 102
 		 * Clear the session item in the list
103 103
 		 * @param  string $item the session item name to be deleted
104 104
 		 */
105
-		public static function clear($item){
105
+		public static function clear($item) {
106 106
 			$logger = self::getLogger();
107
-			if(array_key_exists($item, $_SESSION)){
108
-				$logger->info('Deleting of session for item ['.$item.' ]');
107
+			if (array_key_exists($item, $_SESSION)) {
108
+				$logger->info('Deleting of session for item [' . $item . ' ]');
109 109
 				unset($_SESSION[$item]);
110
-			} else{
111
-				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
110
+			} else {
111
+				$logger->warning('Session item [' . $item . '] to be deleted does not exists');
112 112
 			}
113 113
 		}
114 114
 		
@@ -116,14 +116,14 @@  discard block
 block discarded – undo
116 116
 		 * Clear the session flash item in the list
117 117
 		 * @param  string $item the session flash item name to be deleted
118 118
 		 */
119
-		public static function clearFlash($item){
119
+		public static function clearFlash($item) {
120 120
 			$logger = self::getLogger();
121
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
122
-			if(array_key_exists($key, $_SESSION)){
123
-				$logger->info('Delete session flash for item ['.$item.']');
121
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
122
+			if (array_key_exists($key, $_SESSION)) {
123
+				$logger->info('Delete session flash for item [' . $item . ']');
124 124
 				unset($_SESSION[$item]);
125
-			} else{
126
-				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
125
+			} else {
126
+				$logger->warning('Dession flash item [' . $item . '] to be deleted does not exists');
127 127
 			}
128 128
 		}
129 129
 
Please login to merge, or discard this patch.