Passed
Push — 1.0.0-dev ( 4efac2...b68981 )
by nguereza
02:49
created
core/libraries/Benchmark.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * Class for Benchmark
29 29
 	 */
30
-	class Benchmark{
30
+	class Benchmark {
31 31
 		/**
32 32
 		 * The markers for excution time
33 33
 		 * @var array
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		 * This method is used to mark one point for benchmark (execution time and memory usage)
45 45
 		 * @param  string $name the marker name
46 46
 		 */
47
-		public function mark($name){
47
+		public function mark($name) {
48 48
 			//Marker for execution time
49 49
 			$this->markersTime[$name] = microtime(true);
50 50
 			//Marker for memory usage
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
 		 * @param  integer $decimalCount   the number of decimal
59 59
 		 * @return string         the total execution time
60 60
 		 */
61
-		public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
62
-			if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){
61
+		public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
62
+			if (!$startMarkerName || !isset($this->markersTime[$startMarkerName])) {
63 63
 				return 0;
64 64
 			}
65 65
 			
66
-			if(! isset($this->markersTime[$endMarkerName])){
66
+			if (!isset($this->markersTime[$endMarkerName])) {
67 67
 				$this->markersTime[$endMarkerName] = microtime(true);
68 68
 			}
69 69
 			return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount);
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 		 * @param  integer $decimalCount   the number of decimal
77 77
 		 * @return string         the total memory usage
78 78
 		 */
79
-		public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
80
-			if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){
79
+		public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
80
+			if (!$startMarkerName || !isset($this->markersMemory[$startMarkerName])) {
81 81
 				return 0;
82 82
 			}
83 83
 			
84
-			if(! isset($this->markersMemory[$endMarkerName])){
84
+			if (!isset($this->markersMemory[$endMarkerName])) {
85 85
 				$this->markersMemory[$endMarkerName] = microtime(true);
86 86
 			}
87 87
 			return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount);
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -1,89 +1,89 @@
 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
-	 * Class for Benchmark
29
-	 */
30
-	class Benchmark{
31
-		/**
32
-		 * The markers for excution time
33
-		 * @var array
34
-		 */
35
-		private $markersTime = array();
27
+    /**
28
+     * Class for Benchmark
29
+     */
30
+    class Benchmark{
31
+        /**
32
+         * The markers for excution time
33
+         * @var array
34
+         */
35
+        private $markersTime = array();
36 36
 		
37
-		/**
38
-		 * The markers for memory usage
39
-		 * @var array
40
-		 */
41
-		private $markersMemory = array();
37
+        /**
38
+         * The markers for memory usage
39
+         * @var array
40
+         */
41
+        private $markersMemory = array();
42 42
 		
43
-		/**
44
-		 * This method is used to mark one point for benchmark (execution time and memory usage)
45
-		 * @param  string $name the marker name
46
-		 */
47
-		public function mark($name){
48
-			//Marker for execution time
49
-			$this->markersTime[$name] = microtime(true);
50
-			//Marker for memory usage
51
-			$this->markersMemory[$name] = memory_get_usage(true);
52
-		}
43
+        /**
44
+         * This method is used to mark one point for benchmark (execution time and memory usage)
45
+         * @param  string $name the marker name
46
+         */
47
+        public function mark($name){
48
+            //Marker for execution time
49
+            $this->markersTime[$name] = microtime(true);
50
+            //Marker for memory usage
51
+            $this->markersMemory[$name] = memory_get_usage(true);
52
+        }
53 53
 		
54
-		/**
55
-		 * This method is used to get the total excution time in second between two markers
56
-		 * @param  string  $startMarkerName the marker for start point
57
-		 * @param  string  $endMarkerName   the marker for end point
58
-		 * @param  integer $decimalCount   the number of decimal
59
-		 * @return string         the total execution time
60
-		 */
61
-		public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
62
-			if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){
63
-				return 0;
64
-			}
54
+        /**
55
+         * This method is used to get the total excution time in second between two markers
56
+         * @param  string  $startMarkerName the marker for start point
57
+         * @param  string  $endMarkerName   the marker for end point
58
+         * @param  integer $decimalCount   the number of decimal
59
+         * @return string         the total execution time
60
+         */
61
+        public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
62
+            if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){
63
+                return 0;
64
+            }
65 65
 			
66
-			if(! isset($this->markersTime[$endMarkerName])){
67
-				$this->markersTime[$endMarkerName] = microtime(true);
68
-			}
69
-			return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount);
70
-		}
66
+            if(! isset($this->markersTime[$endMarkerName])){
67
+                $this->markersTime[$endMarkerName] = microtime(true);
68
+            }
69
+            return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount);
70
+        }
71 71
 		
72
-		/**
73
-		 * This method is used to get the total memory usage in byte between two markers
74
-		 * @param  string  $startMarkerName the marker for start point
75
-		 * @param  string  $endMarkerName   the marker for end point
76
-		 * @param  integer $decimalCount   the number of decimal
77
-		 * @return string         the total memory usage
78
-		 */
79
-		public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
80
-			if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){
81
-				return 0;
82
-			}
72
+        /**
73
+         * This method is used to get the total memory usage in byte between two markers
74
+         * @param  string  $startMarkerName the marker for start point
75
+         * @param  string  $endMarkerName   the marker for end point
76
+         * @param  integer $decimalCount   the number of decimal
77
+         * @return string         the total memory usage
78
+         */
79
+        public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){
80
+            if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){
81
+                return 0;
82
+            }
83 83
 			
84
-			if(! isset($this->markersMemory[$endMarkerName])){
85
-				$this->markersMemory[$endMarkerName] = microtime(true);
86
-			}
87
-			return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount);
88
-		}
89
-	}
84
+            if(! isset($this->markersMemory[$endMarkerName])){
85
+                $this->markersMemory[$endMarkerName] = microtime(true);
86
+            }
87
+            return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount);
88
+        }
89
+    }
Please login to merge, or discard this patch.
core/classes/Loader.php 3 patches
Braces   +17 added lines, -34 removed lines patch added patch discarded remove patch
@@ -148,8 +148,7 @@  discard block
 block discarded – undo
148 148
 					if(isset($path[1])){
149 149
 						$instance = strtolower($path[1]);
150 150
 					}
151
-				}
152
-				else{
151
+				} else{
153 152
 					$instance = strtolower($class);
154 153
 				}
155 154
 			}
@@ -169,8 +168,7 @@  discard block
 block discarded – undo
169 168
 					$searchModuleName = $path[0];
170 169
 					$class = ucfirst($path[1]);
171 170
 				}
172
-			}
173
-			else{
171
+			} else{
174 172
 				$class = ucfirst($class);
175 173
 			}
176 174
 
@@ -181,8 +179,7 @@  discard block
 block discarded – undo
181 179
 			if($moduleModelFilePath){
182 180
 				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
183 181
 				$classFilePath = $moduleModelFilePath;
184
-			}
185
-			else{
182
+			} else{
186 183
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
187 184
 			}
188 185
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
@@ -194,12 +191,10 @@  discard block
 block discarded – undo
194 191
 					$obj->{$instance} = $c;
195 192
 					static::$loaded[$instance] = $class;
196 193
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
197
-				}
198
-				else{
194
+				} else{
199 195
 					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
200 196
 				}
201
-			}
202
-			else{
197
+			} else{
203 198
 				show_error('Unable to find the model [' . $class . ']');
204 199
 			}
205 200
 		}
@@ -227,8 +222,7 @@  discard block
 block discarded – undo
227 222
 					if(isset($path[1])){
228 223
 						$instance = strtolower($path[1]);
229 224
 					}
230
-				}
231
-				else{
225
+				} else{
232 226
 					$instance = strtolower($class);
233 227
 				}
234 228
 			}
@@ -252,8 +246,7 @@  discard block
 block discarded – undo
252 246
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
253 247
 				$class = ucfirst($class);
254 248
 				$logger->info('This library is a system library');
255
-			}
256
-			else{
249
+			} else{
257 250
 				$logger->info('This library is not a system library');	
258 251
 				//first check if this library is in the module
259 252
 				$logger->debug('Checking library [' . $class . '] from module list ...');
@@ -265,8 +258,7 @@  discard block
 block discarded – undo
265 258
 						$searchModuleName = $path[0];
266 259
 						$class = ucfirst($path[1]);
267 260
 					}
268
-				}
269
-				else{
261
+				} else{
270 262
 					$class = ucfirst($class);
271 263
 				}
272 264
 				if(! $searchModuleName && !empty($obj->moduleName)){
@@ -276,8 +268,7 @@  discard block
 block discarded – undo
276 268
 				if($moduleLibraryPath){
277 269
 					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
278 270
 					$libraryFilePath = $moduleLibraryPath;
279
-				}
280
-				else{
271
+				} else{
281 272
 					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
282 273
 				}
283 274
 			}
@@ -301,12 +292,10 @@  discard block
 block discarded – undo
301 292
 					$obj->{$instance} = $c;
302 293
 					static::$loaded[$instance] = $class;
303 294
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
304
-				}
305
-				else{
295
+				} else{
306 296
 					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
307 297
 				}
308
-			}
309
-			else{
298
+			} else{
310 299
 				show_error('Unable to find library class [' . $class . ']');
311 300
 			}
312 301
 		}
@@ -350,8 +339,7 @@  discard block
 block discarded – undo
350 339
 			if($moduleFunctionPath){
351 340
 				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
352 341
 				$functionFilePath = $moduleFunctionPath;
353
-			}
354
-			else{
342
+			} else{
355 343
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
356 344
 			}
357 345
 			if(! $functionFilePath){
@@ -370,8 +358,7 @@  discard block
 block discarded – undo
370 358
 				require_once $functionFilePath;
371 359
 				static::$loaded['function_' . $function] = $functionFilePath;
372 360
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
373
-			}
374
-			else{
361
+			} else{
375 362
 				show_error('Unable to find helper file [' . $file . ']');
376 363
 			}
377 364
 		}
@@ -414,8 +401,7 @@  discard block
 block discarded – undo
414 401
 			if($moduleConfigPath){
415 402
 				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
416 403
 				$configFilePath = $moduleConfigPath;
417
-			}
418
-			else{
404
+			} else{
419 405
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
420 406
 			}
421 407
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
@@ -424,8 +410,7 @@  discard block
 block discarded – undo
424 410
 				if(! empty($config) && is_array($config)){
425 411
 					Config::setAll($config);
426 412
 				}
427
-			}
428
-			else{
413
+			} else{
429 414
 				show_error('Unable to find config file ['. $configFilePath . ']');
430 415
 			}
431 416
 			static::$loaded['config_' . $filename] = $configFilePath;
@@ -483,8 +468,7 @@  discard block
 block discarded – undo
483 468
 			if($moduleLanguagePath){
484 469
 				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
485 470
 				$languageFilePath = $moduleLanguagePath;
486
-			}
487
-			else{
471
+			} else{
488 472
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
489 473
 			}
490 474
 			if(! $languageFilePath){
@@ -511,8 +495,7 @@  discard block
 block discarded – undo
511 495
 				}
512 496
 				static::$loaded['lang_' . $language] = $languageFilePath;
513 497
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
514
-			}
515
-			else{
498
+			} else{
516 499
 				show_error('Unable to find language file [' . $file . ']');
517 500
 			}
518 501
 		}
Please login to merge, or discard this patch.
Indentation   +496 added lines, -496 removed lines patch added patch discarded remove patch
@@ -1,521 +1,521 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
26
-	class Loader{
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+    class Loader{
27 27
 		
28
-		/**
29
-		 * List of loaded resources
30
-		 * @var array
31
-		 */
32
-		public static $loaded = array();
28
+        /**
29
+         * List of loaded resources
30
+         * @var array
31
+         */
32
+        public static $loaded = array();
33 33
 		
34
-		/**
35
-		 * The logger instance
36
-		 * @var Log
37
-		 */
38
-		private static $logger;
34
+        /**
35
+         * The logger instance
36
+         * @var Log
37
+         */
38
+        private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
42
-			//add the resources already loaded during application bootstrap
43
-			//in the list to prevent duplicate or loading the resources again.
44
-			static::$loaded = class_loaded();
41
+        public function __construct(){
42
+            //add the resources already loaded during application bootstrap
43
+            //in the list to prevent duplicate or loading the resources again.
44
+            static::$loaded = class_loaded();
45 45
 			
46
-			//Load resources from autoload configuration
47
-			$this->loadResourcesFromAutoloadConfig();
48
-		}
46
+            //Load resources from autoload configuration
47
+            $this->loadResourcesFromAutoloadConfig();
48
+        }
49 49
 
50
-		/**
51
-		 * Get the logger singleton instance
52
-		 * @return Log the logger instance
53
-		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
57
-				self::$logger[0]->setLogger('Library::Loader');
58
-			}
59
-			return self::$logger[0];
60
-		}
50
+        /**
51
+         * Get the logger singleton instance
52
+         * @return Log the logger instance
53
+         */
54
+        private static function getLogger(){
55
+            if(self::$logger == null){
56
+                self::$logger[0] =& class_loader('Log', 'classes');
57
+                self::$logger[0]->setLogger('Library::Loader');
58
+            }
59
+            return self::$logger[0];
60
+        }
61 61
 
62
-		/**
63
-		 * Load the model class
64
-		 *
65
-		 * @param  string $class    the class name to be loaded
66
-		 * @param  string $instance the name of the instance to use in super object
67
-		 *
68
-		 * @return void
69
-		 */
70
-		public static function model($class, $instance = null){
71
-			$logger = static::getLogger();
72
-			$class = str_ireplace('.php', '', $class);
73
-			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
75
-			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
77
-				//for module
78
-				if(strpos($class, '/') !== false){
79
-					$path = explode('/', $class);
80
-					if(isset($path[1])){
81
-						$instance = strtolower($path[1]);
82
-					}
83
-				}
84
-				else{
85
-					$instance = strtolower($class);
86
-				}
87
-			}
88
-			if(isset(static::$loaded[$instance])){
89
-				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90
-				return;
91
-			}
92
-			$classFilePath = APPS_MODEL_PATH . $file;
93
-			//first check if this model is in the module
94
-			$logger->debug('Checking model [' . $class . '] from module list ...');
95
-			$searchModuleName = null;
96
-			$obj = & get_instance();
97
-			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
99
-				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
101
-					$searchModuleName = $path[0];
102
-					$class = ucfirst($path[1]);
103
-				}
104
-			}
105
-			else{
106
-				$class = ucfirst($class);
107
-			}
62
+        /**
63
+         * Load the model class
64
+         *
65
+         * @param  string $class    the class name to be loaded
66
+         * @param  string $instance the name of the instance to use in super object
67
+         *
68
+         * @return void
69
+         */
70
+        public static function model($class, $instance = null){
71
+            $logger = static::getLogger();
72
+            $class = str_ireplace('.php', '', $class);
73
+            $class = trim($class, '/\\');
74
+            $file = ucfirst($class).'.php';
75
+            $logger->debug('Loading model [' . $class . '] ...');
76
+            if(! $instance){
77
+                //for module
78
+                if(strpos($class, '/') !== false){
79
+                    $path = explode('/', $class);
80
+                    if(isset($path[1])){
81
+                        $instance = strtolower($path[1]);
82
+                    }
83
+                }
84
+                else{
85
+                    $instance = strtolower($class);
86
+                }
87
+            }
88
+            if(isset(static::$loaded[$instance])){
89
+                $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90
+                return;
91
+            }
92
+            $classFilePath = APPS_MODEL_PATH . $file;
93
+            //first check if this model is in the module
94
+            $logger->debug('Checking model [' . $class . '] from module list ...');
95
+            $searchModuleName = null;
96
+            $obj = & get_instance();
97
+            //check if the request class contains module name
98
+            if(strpos($class, '/') !== false){
99
+                $path = explode('/', $class);
100
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
101
+                    $searchModuleName = $path[0];
102
+                    $class = ucfirst($path[1]);
103
+                }
104
+            }
105
+            else{
106
+                $class = ucfirst($class);
107
+            }
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
110
-				$searchModuleName = $obj->moduleName;
111
-			}
112
-			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
115
-				$classFilePath = $moduleModelFilePath;
116
-			}
117
-			else{
118
-				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119
-			}
120
-			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
122
-				require_once $classFilePath;
123
-				if(class_exists($class)){
124
-					$c = new $class();
125
-					$obj = & get_instance();
126
-					$obj->{$instance} = $c;
127
-					static::$loaded[$instance] = $class;
128
-					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129
-				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
132
-				}
133
-			}
134
-			else{
135
-				show_error('Unable to find the model [' . $class . ']');
136
-			}
137
-		}
109
+            if(! $searchModuleName && !empty($obj->moduleName)){
110
+                $searchModuleName = $obj->moduleName;
111
+            }
112
+            $moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
+            if($moduleModelFilePath){
114
+                $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
115
+                $classFilePath = $moduleModelFilePath;
116
+            }
117
+            else{
118
+                $logger->info('Cannot find model [' . $class . '] from modules using the default location');
119
+            }
120
+            $logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
+            if(file_exists($classFilePath)){
122
+                require_once $classFilePath;
123
+                if(class_exists($class)){
124
+                    $c = new $class();
125
+                    $obj = & get_instance();
126
+                    $obj->{$instance} = $c;
127
+                    static::$loaded[$instance] = $class;
128
+                    $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129
+                }
130
+                else{
131
+                    show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
132
+                }
133
+            }
134
+            else{
135
+                show_error('Unable to find the model [' . $class . ']');
136
+            }
137
+        }
138 138
 
139 139
 
140
-		/**
141
-		 * Load the library class
142
-		 *
143
-		 * @param  string $class    the library class name to be loaded
144
-		 * @param  string $instance the instance name to use in super object
145
-		 * @param mixed $params the arguments to pass to the constructor
146
-		 *
147
-		 * @return void
148
-		 */
149
-		public static function library($class, $instance = null, array $params = array()){
150
-			$logger = static::getLogger();
151
-			$class = str_ireplace('.php', '', $class);
152
-			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
154
-			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
156
-				//for module
157
-				if(strpos($class, '/') !== false){
158
-					$path = explode('/', $class);
159
-					if(isset($path[1])){
160
-						$instance = strtolower($path[1]);
161
-					}
162
-				}
163
-				else{
164
-					$instance = strtolower($class);
165
-				}
166
-			}
167
-			if(isset(static::$loaded[$instance])){
168
-				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169
-				return;
170
-			}
171
-			$obj = & get_instance();
172
-			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
174
-				$logger->info('This is the Database library ...');
175
-				$dbInstance = & class_loader('Database', 'classes/database', $params);
176
-				$obj->{$instance} = $dbInstance;
177
-				static::$loaded[$instance] = $class;
178
-				$logger->info('Library Database loaded successfully.');
179
-				return;
180
-			}
181
-			$libraryFilePath = null;
182
-			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
184
-				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185
-				$class = ucfirst($class);
186
-				$logger->info('This library is a system library');
187
-			}
188
-			else{
189
-				$logger->info('This library is not a system library');	
190
-				//first check if this library is in the module
191
-				$logger->debug('Checking library [' . $class . '] from module list ...');
192
-				$searchModuleName = null;
193
-				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
195
-					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
197
-						$searchModuleName = $path[0];
198
-						$class = ucfirst($path[1]);
199
-					}
200
-				}
201
-				else{
202
-					$class = ucfirst($class);
203
-				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
205
-					$searchModuleName = $obj->moduleName;
206
-				}
207
-				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
210
-					$libraryFilePath = $moduleLibraryPath;
211
-				}
212
-				else{
213
-					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214
-				}
215
-			}
216
-			if(! $libraryFilePath){
217
-				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
219
-					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
221
-						$libraryFilePath = $filePath;
222
-						//is already found not to continue
223
-						break;
224
-					}
225
-				}
226
-			}
227
-			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
229
-				require_once $libraryFilePath;
230
-				if(class_exists($class)){
231
-					$c = $params ? new $class($params) : new $class();
232
-					$obj = & get_instance();
233
-					$obj->{$instance} = $c;
234
-					static::$loaded[$instance] = $class;
235
-					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236
-				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
239
-				}
240
-			}
241
-			else{
242
-				show_error('Unable to find library class [' . $class . ']');
243
-			}
244
-		}
140
+        /**
141
+         * Load the library class
142
+         *
143
+         * @param  string $class    the library class name to be loaded
144
+         * @param  string $instance the instance name to use in super object
145
+         * @param mixed $params the arguments to pass to the constructor
146
+         *
147
+         * @return void
148
+         */
149
+        public static function library($class, $instance = null, array $params = array()){
150
+            $logger = static::getLogger();
151
+            $class = str_ireplace('.php', '', $class);
152
+            $class = trim($class, '/\\');
153
+            $file = ucfirst($class) .'.php';
154
+            $logger->debug('Loading library [' . $class . '] ...');
155
+            if(! $instance){
156
+                //for module
157
+                if(strpos($class, '/') !== false){
158
+                    $path = explode('/', $class);
159
+                    if(isset($path[1])){
160
+                        $instance = strtolower($path[1]);
161
+                    }
162
+                }
163
+                else{
164
+                    $instance = strtolower($class);
165
+                }
166
+            }
167
+            if(isset(static::$loaded[$instance])){
168
+                $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169
+                return;
170
+            }
171
+            $obj = & get_instance();
172
+            //TODO for Database library
173
+            if(strtolower($class) == 'database'){
174
+                $logger->info('This is the Database library ...');
175
+                $dbInstance = & class_loader('Database', 'classes/database', $params);
176
+                $obj->{$instance} = $dbInstance;
177
+                static::$loaded[$instance] = $class;
178
+                $logger->info('Library Database loaded successfully.');
179
+                return;
180
+            }
181
+            $libraryFilePath = null;
182
+            $logger->debug('Check if this is a system library ...');
183
+            if(file_exists(CORE_LIBRARY_PATH . $file)){
184
+                $libraryFilePath = CORE_LIBRARY_PATH . $file;
185
+                $class = ucfirst($class);
186
+                $logger->info('This library is a system library');
187
+            }
188
+            else{
189
+                $logger->info('This library is not a system library');	
190
+                //first check if this library is in the module
191
+                $logger->debug('Checking library [' . $class . '] from module list ...');
192
+                $searchModuleName = null;
193
+                //check if the request class contains module name
194
+                if(strpos($class, '/') !== false){
195
+                    $path = explode('/', $class);
196
+                    if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
197
+                        $searchModuleName = $path[0];
198
+                        $class = ucfirst($path[1]);
199
+                    }
200
+                }
201
+                else{
202
+                    $class = ucfirst($class);
203
+                }
204
+                if(! $searchModuleName && !empty($obj->moduleName)){
205
+                    $searchModuleName = $obj->moduleName;
206
+                }
207
+                $moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
+                if($moduleLibraryPath){
209
+                    $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
210
+                    $libraryFilePath = $moduleLibraryPath;
211
+                }
212
+                else{
213
+                    $logger->info('Cannot find library [' . $class . '] from modules using the default location');
214
+                }
215
+            }
216
+            if(! $libraryFilePath){
217
+                $searchDir = array(LIBRARY_PATH);
218
+                foreach($searchDir as $dir){
219
+                    $filePath = $dir . $file;
220
+                    if(file_exists($filePath)){
221
+                        $libraryFilePath = $filePath;
222
+                        //is already found not to continue
223
+                        break;
224
+                    }
225
+                }
226
+            }
227
+            $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
+            if($libraryFilePath){
229
+                require_once $libraryFilePath;
230
+                if(class_exists($class)){
231
+                    $c = $params ? new $class($params) : new $class();
232
+                    $obj = & get_instance();
233
+                    $obj->{$instance} = $c;
234
+                    static::$loaded[$instance] = $class;
235
+                    $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236
+                }
237
+                else{
238
+                    show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
239
+                }
240
+            }
241
+            else{
242
+                show_error('Unable to find library class [' . $class . ']');
243
+            }
244
+        }
245 245
 
246
-		/**
247
-		 * Load the helper
248
-		 *
249
-		 * @param  string $function the helper name to be loaded
250
-		 *
251
-		 * @return void
252
-		 */
253
-		public static function functions($function){
254
-			$logger = static::getLogger();
255
-			$function = str_ireplace('.php', '', $function);
256
-			$function = trim($function, '/\\');
257
-			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
259
-			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
261
-				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262
-				return;
263
-			}
264
-			$functionFilePath = null;
265
-			//first check if this helper is in the module
266
-			$logger->debug('Checking helper [' . $function . '] from module list ...');
267
-			$searchModuleName = null;
268
-			$obj = & get_instance();
269
-			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
271
-				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
273
-					$searchModuleName = $path[0];
274
-					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
276
-				}
277
-			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
279
-				$searchModuleName = $obj->moduleName;
280
-			}
281
-			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
284
-				$functionFilePath = $moduleFunctionPath;
285
-			}
286
-			else{
287
-				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288
-			}
289
-			if(! $functionFilePath){
290
-				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
292
-					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
294
-						$functionFilePath = $filePath;
295
-						//is already found not to continue
296
-						break;
297
-					}
298
-				}
299
-			}
300
-			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
302
-				require_once $functionFilePath;
303
-				static::$loaded['function_' . $function] = $functionFilePath;
304
-				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305
-			}
306
-			else{
307
-				show_error('Unable to find helper file [' . $file . ']');
308
-			}
309
-		}
246
+        /**
247
+         * Load the helper
248
+         *
249
+         * @param  string $function the helper name to be loaded
250
+         *
251
+         * @return void
252
+         */
253
+        public static function functions($function){
254
+            $logger = static::getLogger();
255
+            $function = str_ireplace('.php', '', $function);
256
+            $function = trim($function, '/\\');
257
+            $function = str_ireplace('function_', '', $function);
258
+            $file = 'function_'.$function.'.php';
259
+            $logger->debug('Loading helper [' . $function . '] ...');
260
+            if(isset(static::$loaded['function_' . $function])){
261
+                $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262
+                return;
263
+            }
264
+            $functionFilePath = null;
265
+            //first check if this helper is in the module
266
+            $logger->debug('Checking helper [' . $function . '] from module list ...');
267
+            $searchModuleName = null;
268
+            $obj = & get_instance();
269
+            //check if the request class contains module name
270
+            if(strpos($function, '/') !== false){
271
+                $path = explode('/', $function);
272
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
273
+                    $searchModuleName = $path[0];
274
+                    $function = 'function_' . $path[1] . '.php';
275
+                    $file = $path[0] . DS . 'function_'.$function.'.php';
276
+                }
277
+            }
278
+            if(! $searchModuleName && !empty($obj->moduleName)){
279
+                $searchModuleName = $obj->moduleName;
280
+            }
281
+            $moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
+            if($moduleFunctionPath){
283
+                $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
284
+                $functionFilePath = $moduleFunctionPath;
285
+            }
286
+            else{
287
+                $logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288
+            }
289
+            if(! $functionFilePath){
290
+                $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
+                foreach($searchDir as $dir){
292
+                    $filePath = $dir . $file;
293
+                    if(file_exists($filePath)){
294
+                        $functionFilePath = $filePath;
295
+                        //is already found not to continue
296
+                        break;
297
+                    }
298
+                }
299
+            }
300
+            $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
+            if($functionFilePath){
302
+                require_once $functionFilePath;
303
+                static::$loaded['function_' . $function] = $functionFilePath;
304
+                $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305
+            }
306
+            else{
307
+                show_error('Unable to find helper file [' . $file . ']');
308
+            }
309
+        }
310 310
 
311
-		/**
312
-		 * Load the configuration file
313
-		 *
314
-		 * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
315
-		 *
316
-		 * @return void
317
-		 */
318
-		public static function config($filename){
319
-			$logger = static::getLogger();
320
-			$filename = str_ireplace('.php', '', $filename);
321
-			$filename = trim($filename, '/\\');
322
-			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
324
-			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
326
-				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327
-				return;
328
-			}
329
-			$configFilePath = CONFIG_PATH . $file;
330
-			//first check if this config is in the module
331
-			$logger->debug('Checking config [' . $filename . '] from module list ...');
332
-			$searchModuleName = null;
333
-			$obj = & get_instance();
334
-			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
336
-				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
338
-					$searchModuleName = $path[0];
339
-					$filename = $path[1] . '.php';
340
-				}
341
-			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
343
-				$searchModuleName = $obj->moduleName;
344
-			}
345
-			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
348
-				$configFilePath = $moduleConfigPath;
349
-			}
350
-			else{
351
-				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352
-			}
353
-			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
-			$config = array();
355
-			if(file_exists($configFilePath)){
356
-				require_once $configFilePath;
357
-				if(! empty($config) && is_array($config)){
358
-					Config::setAll($config);
359
-				}
360
-			}
361
-			else{
362
-				show_error('Unable to find config file ['. $configFilePath . ']');
363
-			}
364
-			static::$loaded['config_' . $filename] = $configFilePath;
365
-			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
366
-			$logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
367
-			unset($config);
368
-		}
311
+        /**
312
+         * Load the configuration file
313
+         *
314
+         * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
315
+         *
316
+         * @return void
317
+         */
318
+        public static function config($filename){
319
+            $logger = static::getLogger();
320
+            $filename = str_ireplace('.php', '', $filename);
321
+            $filename = trim($filename, '/\\');
322
+            $filename = str_ireplace('config_', '', $filename);
323
+            $file = 'config_'.$filename.'.php';
324
+            $logger->debug('Loading configuration [' . $filename . '] ...');
325
+            if(isset(static::$loaded['config_' . $filename])){
326
+                $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327
+                return;
328
+            }
329
+            $configFilePath = CONFIG_PATH . $file;
330
+            //first check if this config is in the module
331
+            $logger->debug('Checking config [' . $filename . '] from module list ...');
332
+            $searchModuleName = null;
333
+            $obj = & get_instance();
334
+            //check if the request class contains module name
335
+            if(strpos($filename, '/') !== false){
336
+                $path = explode('/', $filename);
337
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
338
+                    $searchModuleName = $path[0];
339
+                    $filename = $path[1] . '.php';
340
+                }
341
+            }
342
+            if(! $searchModuleName && !empty($obj->moduleName)){
343
+                $searchModuleName = $obj->moduleName;
344
+            }
345
+            $moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
+            if($moduleConfigPath){
347
+                $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
348
+                $configFilePath = $moduleConfigPath;
349
+            }
350
+            else{
351
+                $logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352
+            }
353
+            $logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
+            $config = array();
355
+            if(file_exists($configFilePath)){
356
+                require_once $configFilePath;
357
+                if(! empty($config) && is_array($config)){
358
+                    Config::setAll($config);
359
+                }
360
+            }
361
+            else{
362
+                show_error('Unable to find config file ['. $configFilePath . ']');
363
+            }
364
+            static::$loaded['config_' . $filename] = $configFilePath;
365
+            $logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
366
+            $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
367
+            unset($config);
368
+        }
369 369
 
370 370
 
371
-		/**
372
-		 * Load the language
373
-		 *
374
-		 * @param  string $language the language name to be loaded
375
-		 *
376
-		 * @return void
377
-		 */
378
-		public static function lang($language){
379
-			$logger = static::getLogger();
380
-			$language = str_ireplace('.php', '', $language);
381
-			$language = trim($language, '/\\');
382
-			$language = str_ireplace('lang_', '', $language);
383
-			$file = 'lang_'.$language.'.php';
384
-			$logger->debug('Loading language [' . $language . '] ...');
385
-			if(isset(static::$loaded['lang_' . $language])){
386
-				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387
-				return;
388
-			}
389
-			//determine the current language
390
-			$appLang = get_config('default_language');
391
-			//if the language exists in the cookie use it
392
-			$cfgKey = get_config('language_cookie_name');
393
-			$objCookie = & class_loader('Cookie');
394
-			$cookieLang = $objCookie->get($cfgKey);
395
-			if($cookieLang){
396
-				$appLang = $cookieLang;
397
-			}
398
-			$languageFilePath = null;
399
-			//first check if this language is in the module
400
-			$logger->debug('Checking language [' . $language . '] from module list ...');
401
-			$searchModuleName = null;
402
-			$obj = & get_instance();
403
-			//check if the request class contains module name
404
-			if(strpos($language, '/') !== false){
405
-				$path = explode('/', $language);
406
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
407
-					$searchModuleName = $path[0];
408
-					$language = 'lang_' . $path[1] . '.php';
409
-					$file = $path[0] . DS .$language;
410
-				}
411
-			}
412
-			if(! $searchModuleName && !empty($obj->moduleName)){
413
-				$searchModuleName = $obj->moduleName;
414
-			}
415
-			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
-			if($moduleLanguagePath){
417
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
418
-				$languageFilePath = $moduleLanguagePath;
419
-			}
420
-			else{
421
-				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
422
-			}
423
-			if(! $languageFilePath){
424
-				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
-				foreach($searchDir as $dir){
426
-					$filePath = $dir . $appLang . DS . $file;
427
-					if(file_exists($filePath)){
428
-						$languageFilePath = $filePath;
429
-						//is already found not to continue
430
-						break;
431
-					}
432
-				}
433
-			}
434
-			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
-			if($languageFilePath){
436
-				$lang = array();
437
-				require_once $languageFilePath;
438
-				if(! empty($lang) && is_array($lang)){
439
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
440
-					//Note: may be here the class 'Lang' not yet loaded
441
-					$langObj =& class_loader('Lang', 'classes');
442
-					$langObj->addLangMessages($lang);
443
-					//free the memory
444
-					unset($lang);
445
-				}
446
-				static::$loaded['lang_' . $language] = $languageFilePath;
447
-				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448
-			}
449
-			else{
450
-				show_error('Unable to find language file [' . $file . ']');
451
-			}
452
-		}
371
+        /**
372
+         * Load the language
373
+         *
374
+         * @param  string $language the language name to be loaded
375
+         *
376
+         * @return void
377
+         */
378
+        public static function lang($language){
379
+            $logger = static::getLogger();
380
+            $language = str_ireplace('.php', '', $language);
381
+            $language = trim($language, '/\\');
382
+            $language = str_ireplace('lang_', '', $language);
383
+            $file = 'lang_'.$language.'.php';
384
+            $logger->debug('Loading language [' . $language . '] ...');
385
+            if(isset(static::$loaded['lang_' . $language])){
386
+                $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387
+                return;
388
+            }
389
+            //determine the current language
390
+            $appLang = get_config('default_language');
391
+            //if the language exists in the cookie use it
392
+            $cfgKey = get_config('language_cookie_name');
393
+            $objCookie = & class_loader('Cookie');
394
+            $cookieLang = $objCookie->get($cfgKey);
395
+            if($cookieLang){
396
+                $appLang = $cookieLang;
397
+            }
398
+            $languageFilePath = null;
399
+            //first check if this language is in the module
400
+            $logger->debug('Checking language [' . $language . '] from module list ...');
401
+            $searchModuleName = null;
402
+            $obj = & get_instance();
403
+            //check if the request class contains module name
404
+            if(strpos($language, '/') !== false){
405
+                $path = explode('/', $language);
406
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
407
+                    $searchModuleName = $path[0];
408
+                    $language = 'lang_' . $path[1] . '.php';
409
+                    $file = $path[0] . DS .$language;
410
+                }
411
+            }
412
+            if(! $searchModuleName && !empty($obj->moduleName)){
413
+                $searchModuleName = $obj->moduleName;
414
+            }
415
+            $moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
+            if($moduleLanguagePath){
417
+                $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
418
+                $languageFilePath = $moduleLanguagePath;
419
+            }
420
+            else{
421
+                $logger->info('Cannot find language [' . $language . '] from modules using the default location');
422
+            }
423
+            if(! $languageFilePath){
424
+                $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
+                foreach($searchDir as $dir){
426
+                    $filePath = $dir . $appLang . DS . $file;
427
+                    if(file_exists($filePath)){
428
+                        $languageFilePath = $filePath;
429
+                        //is already found not to continue
430
+                        break;
431
+                    }
432
+                }
433
+            }
434
+            $logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
+            if($languageFilePath){
436
+                $lang = array();
437
+                require_once $languageFilePath;
438
+                if(! empty($lang) && is_array($lang)){
439
+                    $logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
440
+                    //Note: may be here the class 'Lang' not yet loaded
441
+                    $langObj =& class_loader('Lang', 'classes');
442
+                    $langObj->addLangMessages($lang);
443
+                    //free the memory
444
+                    unset($lang);
445
+                }
446
+                static::$loaded['lang_' . $language] = $languageFilePath;
447
+                $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448
+            }
449
+            else{
450
+                show_error('Unable to find language file [' . $file . ']');
451
+            }
452
+        }
453 453
 
454 454
 
455
-		private function getResourcesFromAutoloadConfig(){
456
-			$autoloads = array();
457
-			$autoloads['config']    = array();
458
-			$autoloads['languages'] = array();
459
-			$autoloads['libraries'] = array();
460
-			$autoloads['models']    = array();
461
-			$autoloads['functions'] = array();
462
-			//loading of the resources in autoload.php configuration file
463
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
464
-				$autoload = array();
465
-				require_once CONFIG_PATH . 'autoload.php';
466
-				if(! empty($autoload) && is_array($autoload)){
467
-					$autoloads = array_merge($autoloads, $autoload);
468
-					unset($autoload);
469
-				}
470
-			}
471
-			//loading autoload configuration for modules
472
-			$modulesAutoloads = Module::getModulesAutoloadConfig();
473
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
474
-				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475
-			}
476
-			return $autoloads;
477
-		}
455
+        private function getResourcesFromAutoloadConfig(){
456
+            $autoloads = array();
457
+            $autoloads['config']    = array();
458
+            $autoloads['languages'] = array();
459
+            $autoloads['libraries'] = array();
460
+            $autoloads['models']    = array();
461
+            $autoloads['functions'] = array();
462
+            //loading of the resources in autoload.php configuration file
463
+            if(file_exists(CONFIG_PATH . 'autoload.php')){
464
+                $autoload = array();
465
+                require_once CONFIG_PATH . 'autoload.php';
466
+                if(! empty($autoload) && is_array($autoload)){
467
+                    $autoloads = array_merge($autoloads, $autoload);
468
+                    unset($autoload);
469
+                }
470
+            }
471
+            //loading autoload configuration for modules
472
+            $modulesAutoloads = Module::getModulesAutoloadConfig();
473
+            if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
474
+                $autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475
+            }
476
+            return $autoloads;
477
+        }
478 478
 
479
-		/**
480
-		 * Load the autoload configuration
481
-		 * @return void
482
-		 */
483
-		private function loadResourcesFromAutoloadConfig(){
484
-			$autoloads = array();
485
-			$autoloads['config']    = array();
486
-			$autoloads['languages'] = array();
487
-			$autoloads['libraries'] = array();
488
-			$autoloads['models']    = array();
489
-			$autoloads['functions'] = array();
479
+        /**
480
+         * Load the autoload configuration
481
+         * @return void
482
+         */
483
+        private function loadResourcesFromAutoloadConfig(){
484
+            $autoloads = array();
485
+            $autoloads['config']    = array();
486
+            $autoloads['languages'] = array();
487
+            $autoloads['libraries'] = array();
488
+            $autoloads['models']    = array();
489
+            $autoloads['functions'] = array();
490 490
 
491
-			$list = $this->getResourcesFromAutoloadConfig();
492
-			$autoloads = array_merge($autoloads, $list);
491
+            $list = $this->getResourcesFromAutoloadConfig();
492
+            $autoloads = array_merge($autoloads, $list);
493 493
 			
494
-			//config autoload
495
-			$this->loadAutoloadResourcesArray('config', $autoloads['config']);
494
+            //config autoload
495
+            $this->loadAutoloadResourcesArray('config', $autoloads['config']);
496 496
 			
497
-			//languages autoload
498
-			$this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
497
+            //languages autoload
498
+            $this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
499 499
 			
500
-			//libraries autoload
501
-			$this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
500
+            //libraries autoload
501
+            $this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
502 502
 
503
-			//models autoload
504
-			$this->loadAutoloadResourcesArray('model', $autoloads['models']);
503
+            //models autoload
504
+            $this->loadAutoloadResourcesArray('model', $autoloads['models']);
505 505
 			
506
-			//functions autoload
507
-			$this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
508
-		}
506
+            //functions autoload
507
+            $this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
508
+        }
509 509
 
510
-		/**
511
-		 * Load the resources autoload array
512
-		 * @param  string $method    this object method name to call
513
-		 * @param  array  $resources the resource to load
514
-		 * @return void            
515
-		 */
516
-		private function loadAutoloadResourcesArray($method, array $resources){
517
-			foreach ($resources as $name) {
518
-				$this->{$method}($name);
519
-			}
520
-		}
521
-	}
510
+        /**
511
+         * Load the resources autoload array
512
+         * @param  string $method    this object method name to call
513
+         * @param  array  $resources the resource to load
514
+         * @return void            
515
+         */
516
+        private function loadAutoloadResourcesArray($method, array $resources){
517
+            foreach ($resources as $name) {
518
+                $this->{$method}($name);
519
+            }
520
+        }
521
+    }
Please login to merge, or discard this patch.
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		 * Get the logger singleton instance
52 52
 		 * @return Log the logger instance
53 53
 		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
54
+		private static function getLogger() {
55
+			if (self::$logger == null) {
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Loader');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -67,25 +67,25 @@  discard block
 block discarded – undo
67 67
 		 *
68 68
 		 * @return void
69 69
 		 */
70
-		public static function model($class, $instance = null){
70
+		public static function model($class, $instance = null) {
71 71
 			$logger = static::getLogger();
72 72
 			$class = str_ireplace('.php', '', $class);
73 73
 			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
74
+			$file = ucfirst($class) . '.php';
75 75
 			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
76
+			if (!$instance) {
77 77
 				//for module
78
-				if(strpos($class, '/') !== false){
78
+				if (strpos($class, '/') !== false) {
79 79
 					$path = explode('/', $class);
80
-					if(isset($path[1])){
80
+					if (isset($path[1])) {
81 81
 						$instance = strtolower($path[1]);
82 82
 					}
83 83
 				}
84
-				else{
84
+				else {
85 85
 					$instance = strtolower($class);
86 86
 				}
87 87
 			}
88
-			if(isset(static::$loaded[$instance])){
88
+			if (isset(static::$loaded[$instance])) {
89 89
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90 90
 				return;
91 91
 			}
@@ -95,43 +95,43 @@  discard block
 block discarded – undo
95 95
 			$searchModuleName = null;
96 96
 			$obj = & get_instance();
97 97
 			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
98
+			if (strpos($class, '/') !== false) {
99 99
 				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
100
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
101 101
 					$searchModuleName = $path[0];
102 102
 					$class = ucfirst($path[1]);
103 103
 				}
104 104
 			}
105
-			else{
105
+			else {
106 106
 				$class = ucfirst($class);
107 107
 			}
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
109
+			if (!$searchModuleName && !empty($obj->moduleName)) {
110 110
 				$searchModuleName = $obj->moduleName;
111 111
 			}
112 112
 			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
113
+			if ($moduleModelFilePath) {
114
+				$logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it');
115 115
 				$classFilePath = $moduleModelFilePath;
116 116
 			}
117
-			else{
117
+			else {
118 118
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119 119
 			}
120 120
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
121
+			if (file_exists($classFilePath)) {
122 122
 				require_once $classFilePath;
123
-				if(class_exists($class)){
123
+				if (class_exists($class)) {
124 124
 					$c = new $class();
125 125
 					$obj = & get_instance();
126 126
 					$obj->{$instance} = $c;
127 127
 					static::$loaded[$instance] = $class;
128 128
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129 129
 				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
130
+				else {
131
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
132 132
 				}
133 133
 			}
134
-			else{
134
+			else {
135 135
 				show_error('Unable to find the model [' . $class . ']');
136 136
 			}
137 137
 		}
@@ -146,31 +146,31 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return void
148 148
 		 */
149
-		public static function library($class, $instance = null, array $params = array()){
149
+		public static function library($class, $instance = null, array $params = array()) {
150 150
 			$logger = static::getLogger();
151 151
 			$class = str_ireplace('.php', '', $class);
152 152
 			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
153
+			$file = ucfirst($class) . '.php';
154 154
 			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
155
+			if (!$instance) {
156 156
 				//for module
157
-				if(strpos($class, '/') !== false){
157
+				if (strpos($class, '/') !== false) {
158 158
 					$path = explode('/', $class);
159
-					if(isset($path[1])){
159
+					if (isset($path[1])) {
160 160
 						$instance = strtolower($path[1]);
161 161
 					}
162 162
 				}
163
-				else{
163
+				else {
164 164
 					$instance = strtolower($class);
165 165
 				}
166 166
 			}
167
-			if(isset(static::$loaded[$instance])){
167
+			if (isset(static::$loaded[$instance])) {
168 168
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169 169
 				return;
170 170
 			}
171 171
 			$obj = & get_instance();
172 172
 			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
173
+			if (strtolower($class) == 'database') {
174 174
 				$logger->info('This is the Database library ...');
175 175
 				$dbInstance = & class_loader('Database', 'classes/database', $params);
176 176
 				$obj->{$instance} = $dbInstance;
@@ -180,44 +180,44 @@  discard block
 block discarded – undo
180 180
 			}
181 181
 			$libraryFilePath = null;
182 182
 			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
183
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
184 184
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185 185
 				$class = ucfirst($class);
186 186
 				$logger->info('This library is a system library');
187 187
 			}
188
-			else{
188
+			else {
189 189
 				$logger->info('This library is not a system library');	
190 190
 				//first check if this library is in the module
191 191
 				$logger->debug('Checking library [' . $class . '] from module list ...');
192 192
 				$searchModuleName = null;
193 193
 				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
194
+				if (strpos($class, '/') !== false) {
195 195
 					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
196
+					if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
197 197
 						$searchModuleName = $path[0];
198 198
 						$class = ucfirst($path[1]);
199 199
 					}
200 200
 				}
201
-				else{
201
+				else {
202 202
 					$class = ucfirst($class);
203 203
 				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
204
+				if (!$searchModuleName && !empty($obj->moduleName)) {
205 205
 					$searchModuleName = $obj->moduleName;
206 206
 				}
207 207
 				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
208
+				if ($moduleLibraryPath) {
209
+					$logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it');
210 210
 					$libraryFilePath = $moduleLibraryPath;
211 211
 				}
212
-				else{
212
+				else {
213 213
 					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214 214
 				}
215 215
 			}
216
-			if(! $libraryFilePath){
216
+			if (!$libraryFilePath) {
217 217
 				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
218
+				foreach ($searchDir as $dir) {
219 219
 					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
220
+					if (file_exists($filePath)) {
221 221
 						$libraryFilePath = $filePath;
222 222
 						//is already found not to continue
223 223
 						break;
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
 				}
226 226
 			}
227 227
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
228
+			if ($libraryFilePath) {
229 229
 				require_once $libraryFilePath;
230
-				if(class_exists($class)){
230
+				if (class_exists($class)) {
231 231
 					$c = $params ? new $class($params) : new $class();
232 232
 					$obj = & get_instance();
233 233
 					$obj->{$instance} = $c;
234 234
 					static::$loaded[$instance] = $class;
235 235
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236 236
 				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
237
+				else {
238
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
239 239
 				}
240 240
 			}
241
-			else{
241
+			else {
242 242
 				show_error('Unable to find library class [' . $class . ']');
243 243
 			}
244 244
 		}
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 		 *
251 251
 		 * @return void
252 252
 		 */
253
-		public static function functions($function){
253
+		public static function functions($function) {
254 254
 			$logger = static::getLogger();
255 255
 			$function = str_ireplace('.php', '', $function);
256 256
 			$function = trim($function, '/\\');
257 257
 			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
258
+			$file = 'function_' . $function . '.php';
259 259
 			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
260
+			if (isset(static::$loaded['function_' . $function])) {
261 261
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262 262
 				return;
263 263
 			}
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
 			$searchModuleName = null;
268 268
 			$obj = & get_instance();
269 269
 			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
270
+			if (strpos($function, '/') !== false) {
271 271
 				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
272
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
273 273
 					$searchModuleName = $path[0];
274 274
 					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
275
+					$file = $path[0] . DS . 'function_' . $function . '.php';
276 276
 				}
277 277
 			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
278
+			if (!$searchModuleName && !empty($obj->moduleName)) {
279 279
 				$searchModuleName = $obj->moduleName;
280 280
 			}
281 281
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
282
+			if ($moduleFunctionPath) {
283
+				$logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it');
284 284
 				$functionFilePath = $moduleFunctionPath;
285 285
 			}
286
-			else{
286
+			else {
287 287
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288 288
 			}
289
-			if(! $functionFilePath){
289
+			if (!$functionFilePath) {
290 290
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
291
+				foreach ($searchDir as $dir) {
292 292
 					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
293
+					if (file_exists($filePath)) {
294 294
 						$functionFilePath = $filePath;
295 295
 						//is already found not to continue
296 296
 						break;
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 				}
299 299
 			}
300 300
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
301
+			if ($functionFilePath) {
302 302
 				require_once $functionFilePath;
303 303
 				static::$loaded['function_' . $function] = $functionFilePath;
304 304
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305 305
 			}
306
-			else{
306
+			else {
307 307
 				show_error('Unable to find helper file [' . $file . ']');
308 308
 			}
309 309
 		}
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 		 *
316 316
 		 * @return void
317 317
 		 */
318
-		public static function config($filename){
318
+		public static function config($filename) {
319 319
 			$logger = static::getLogger();
320 320
 			$filename = str_ireplace('.php', '', $filename);
321 321
 			$filename = trim($filename, '/\\');
322 322
 			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
323
+			$file = 'config_' . $filename . '.php';
324 324
 			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
325
+			if (isset(static::$loaded['config_' . $filename])) {
326 326
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327 327
 				return;
328 328
 			}
@@ -332,34 +332,34 @@  discard block
 block discarded – undo
332 332
 			$searchModuleName = null;
333 333
 			$obj = & get_instance();
334 334
 			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
335
+			if (strpos($filename, '/') !== false) {
336 336
 				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
337
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
338 338
 					$searchModuleName = $path[0];
339 339
 					$filename = $path[1] . '.php';
340 340
 				}
341 341
 			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
342
+			if (!$searchModuleName && !empty($obj->moduleName)) {
343 343
 				$searchModuleName = $obj->moduleName;
344 344
 			}
345 345
 			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
346
+			if ($moduleConfigPath) {
347
+				$logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it');
348 348
 				$configFilePath = $moduleConfigPath;
349 349
 			}
350
-			else{
350
+			else {
351 351
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352 352
 			}
353 353
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354 354
 			$config = array();
355
-			if(file_exists($configFilePath)){
355
+			if (file_exists($configFilePath)) {
356 356
 				require_once $configFilePath;
357
-				if(! empty($config) && is_array($config)){
357
+				if (!empty($config) && is_array($config)) {
358 358
 					Config::setAll($config);
359 359
 				}
360 360
 			}
361
-			else{
362
-				show_error('Unable to find config file ['. $configFilePath . ']');
361
+			else {
362
+				show_error('Unable to find config file [' . $configFilePath . ']');
363 363
 			}
364 364
 			static::$loaded['config_' . $filename] = $configFilePath;
365 365
 			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
 		 *
376 376
 		 * @return void
377 377
 		 */
378
-		public static function lang($language){
378
+		public static function lang($language) {
379 379
 			$logger = static::getLogger();
380 380
 			$language = str_ireplace('.php', '', $language);
381 381
 			$language = trim($language, '/\\');
382 382
 			$language = str_ireplace('lang_', '', $language);
383
-			$file = 'lang_'.$language.'.php';
383
+			$file = 'lang_' . $language . '.php';
384 384
 			$logger->debug('Loading language [' . $language . '] ...');
385
-			if(isset(static::$loaded['lang_' . $language])){
385
+			if (isset(static::$loaded['lang_' . $language])) {
386 386
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387 387
 				return;
388 388
 			}
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 			$cfgKey = get_config('language_cookie_name');
393 393
 			$objCookie = & class_loader('Cookie');
394 394
 			$cookieLang = $objCookie->get($cfgKey);
395
-			if($cookieLang){
395
+			if ($cookieLang) {
396 396
 				$appLang = $cookieLang;
397 397
 			}
398 398
 			$languageFilePath = null;
@@ -401,30 +401,30 @@  discard block
 block discarded – undo
401 401
 			$searchModuleName = null;
402 402
 			$obj = & get_instance();
403 403
 			//check if the request class contains module name
404
-			if(strpos($language, '/') !== false){
404
+			if (strpos($language, '/') !== false) {
405 405
 				$path = explode('/', $language);
406
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
406
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
407 407
 					$searchModuleName = $path[0];
408 408
 					$language = 'lang_' . $path[1] . '.php';
409
-					$file = $path[0] . DS .$language;
409
+					$file = $path[0] . DS . $language;
410 410
 				}
411 411
 			}
412
-			if(! $searchModuleName && !empty($obj->moduleName)){
412
+			if (!$searchModuleName && !empty($obj->moduleName)) {
413 413
 				$searchModuleName = $obj->moduleName;
414 414
 			}
415 415
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
-			if($moduleLanguagePath){
417
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
416
+			if ($moduleLanguagePath) {
417
+				$logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it');
418 418
 				$languageFilePath = $moduleLanguagePath;
419 419
 			}
420
-			else{
420
+			else {
421 421
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
422 422
 			}
423
-			if(! $languageFilePath){
423
+			if (!$languageFilePath) {
424 424
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
-				foreach($searchDir as $dir){
425
+				foreach ($searchDir as $dir) {
426 426
 					$filePath = $dir . $appLang . DS . $file;
427
-					if(file_exists($filePath)){
427
+					if (file_exists($filePath)) {
428 428
 						$languageFilePath = $filePath;
429 429
 						//is already found not to continue
430 430
 						break;
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
 				}
433 433
 			}
434 434
 			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
-			if($languageFilePath){
435
+			if ($languageFilePath) {
436 436
 				$lang = array();
437 437
 				require_once $languageFilePath;
438
-				if(! empty($lang) && is_array($lang)){
439
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
438
+				if (!empty($lang) && is_array($lang)) {
439
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
440 440
 					//Note: may be here the class 'Lang' not yet loaded
441
-					$langObj =& class_loader('Lang', 'classes');
441
+					$langObj = & class_loader('Lang', 'classes');
442 442
 					$langObj->addLangMessages($lang);
443 443
 					//free the memory
444 444
 					unset($lang);
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
 				static::$loaded['lang_' . $language] = $languageFilePath;
447 447
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448 448
 			}
449
-			else{
449
+			else {
450 450
 				show_error('Unable to find language file [' . $file . ']');
451 451
 			}
452 452
 		}
453 453
 
454 454
 
455
-		private function getResourcesFromAutoloadConfig(){
455
+		private function getResourcesFromAutoloadConfig() {
456 456
 			$autoloads = array();
457 457
 			$autoloads['config']    = array();
458 458
 			$autoloads['languages'] = array();
@@ -460,17 +460,17 @@  discard block
 block discarded – undo
460 460
 			$autoloads['models']    = array();
461 461
 			$autoloads['functions'] = array();
462 462
 			//loading of the resources in autoload.php configuration file
463
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
463
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
464 464
 				$autoload = array();
465 465
 				require_once CONFIG_PATH . 'autoload.php';
466
-				if(! empty($autoload) && is_array($autoload)){
466
+				if (!empty($autoload) && is_array($autoload)) {
467 467
 					$autoloads = array_merge($autoloads, $autoload);
468 468
 					unset($autoload);
469 469
 				}
470 470
 			}
471 471
 			//loading autoload configuration for modules
472 472
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
473
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
473
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
474 474
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475 475
 			}
476 476
 			return $autoloads;
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		 * Load the autoload configuration
481 481
 		 * @return void
482 482
 		 */
483
-		private function loadResourcesFromAutoloadConfig(){
483
+		private function loadResourcesFromAutoloadConfig() {
484 484
 			$autoloads = array();
485 485
 			$autoloads['config']    = array();
486 486
 			$autoloads['languages'] = array();
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 		 * @param  array  $resources the resource to load
514 514
 		 * @return void            
515 515
 		 */
516
-		private function loadAutoloadResourcesArray($method, array $resources){
516
+		private function loadAutoloadResourcesArray($method, array $resources) {
517 517
 			foreach ($resources as $name) {
518 518
 				$this->{$method}($name);
519 519
 			}
Please login to merge, or discard this patch.
core/classes/Config.php 3 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -128,8 +128,7 @@  discard block
 block discarded – undo
128 128
 				$logger->info('Delete config item ['.$item.']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131
-			}
132
-			else{
131
+			} else{
133 132
 				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134 133
 				return false;
135 134
 			}
@@ -156,15 +155,13 @@  discard block
 block discarded – undo
156 155
 					//check if the server is running under IPv6
157 156
 					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
158 157
 						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
159
-					}
160
-					else{
158
+					} else{
161 159
 						$baseUrl = $_SERVER['SERVER_ADDR'];
162 160
 					}
163 161
 					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
164 162
 					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
165 163
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
166
-				}
167
-				else{
164
+				} else{
168 165
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
169 166
 					$baseUrl = 'http://localhost/';
170 167
 				}
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Config{
27
+	class Config {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47 47
 				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
48
+				$logger[0] = & class_loader('Log', 'classes');
49 49
 				$logger[0]->setLogger('Library::Config');
50 50
 				self::$logger = $logger[0];
51 51
 			}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		 * @param Log $logger the log object
58 58
 		 * @return Log the log instance
59 59
 		 */
60
-		public static function setLogger($logger){
60
+		public static function setLogger($logger) {
61 61
 			self::$logger = $logger;
62 62
 			return self::$logger;
63 63
 		}
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Initialize the configuration by loading all the configuration from config file
67 67
 		 */
68
-		public static function init(){
68
+		public static function init() {
69 69
 			$logger = static::getLogger();
70 70
 			$logger->debug('Initialization of the configuration');
71 71
 			self::$config = & load_configurations();
72 72
 			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
73
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
74 74
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75 75
 			}
76 76
 			$logger->info('Configuration initialized successfully');
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the config item in the list
84 84
 		 * @return mixed          the config value if exist or the default value
85 85
 		 */
86
-		public static function get($item, $default = null){
86
+		public static function get($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
88
+			if (array_key_exists($item, self::$config)) {
89 89
 				return self::$config[$item];
90 90
 			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
91
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
92 92
 			return $default;
93 93
 		}
94 94
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * @param string $item  the config item name to set
98 98
 		 * @param mixed $value the config item value
99 99
 		 */
100
-		public static function set($item, $value){
100
+		public static function set($item, $value) {
101 101
 			self::$config[$item] = $value;
102 102
 		}
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Get all the configuration values
106 106
 		 * @return array the config values
107 107
 		 */
108
-		public static function getAll(){
108
+		public static function getAll() {
109 109
 			return self::$config;
110 110
 		}
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Set the configuration values bu merged with the existing configuration
114 114
 		 * @param array $config the config values to add in the configuration list
115 115
 		 */
116
-		public static function setAll(array $config = array()){
116
+		public static function setAll(array $config = array()) {
117 117
 			self::$config = array_merge(self::$config, $config);
118 118
 		}
119 119
 
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 * @param  string $item the config item name to be deleted
123 123
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124 124
 		 */
125
-		public static function delete($item){
125
+		public static function delete($item) {
126 126
 			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
127
+			if (array_key_exists($item, self::$config)) {
128
+				$logger->info('Delete config item [' . $item . ']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131 131
 			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
132
+			else {
133
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
134 134
 				return false;
135 135
 			}
136 136
 		}
@@ -139,38 +139,38 @@  discard block
 block discarded – undo
139 139
 		 * Load the configuration file. This an alias to Loader::config()
140 140
 		 * @param  string $config the config name to be loaded
141 141
 		 */
142
-		public static function load($config){
142
+		public static function load($config) {
143 143
 			Loader::config($config);
144 144
 		}
145 145
 
146 146
 		/**
147 147
 		 * Set the configuration for "base_url" if is not set in the configuration
148 148
 		 */
149
-		private static function setBaseUrlUsingServerVar(){
149
+		private static function setBaseUrlUsingServerVar() {
150 150
 			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
151
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
152
+				if (ENVIRONMENT == 'production') {
153 153
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154 154
 				}
155 155
 				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
156
+				if (isset($_SERVER['SERVER_ADDR'])) {
157 157
 					//check if the server is running under IPv6
158
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
159
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
158
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
159
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
160 160
 					}
161
-					else{
161
+					else {
162 162
 						$baseUrl = $_SERVER['SERVER_ADDR'];
163 163
 					}
164
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
164
+					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
166 166
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
167 167
 				}
168
-				else{
168
+				else {
169 169
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
170 170
 					$baseUrl = 'http://localhost/';
171 171
 				}
172 172
 				self::set('base_url', $baseUrl);
173 173
 			}
174
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
174
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
175 175
 		}
176 176
 	}
Please login to merge, or discard this patch.
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -1,176 +1,176 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Config{
27
+    class Config{
28 28
 		
29
-		/**
30
-		 * The list of loaded configuration
31
-		 * @var array
32
-		 */
33
-		private static $config = array();
29
+        /**
30
+         * The list of loaded configuration
31
+         * @var array
32
+         */
33
+        private static $config = array();
34 34
 
35
-		/**
36
-		 * The logger instance
37
-		 * @var Log
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * The logger instance
37
+         * @var Log
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * The signleton of the logger
43
-		 * @return Object the Log instance
44
-		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
47
-				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
49
-				$logger[0]->setLogger('Library::Config');
50
-				self::$logger = $logger[0];
51
-			}
52
-			return self::$logger;			
53
-		}
41
+        /**
42
+         * The signleton of the logger
43
+         * @return Object the Log instance
44
+         */
45
+        private static function getLogger(){
46
+            if(self::$logger == null){
47
+                $logger = array();
48
+                $logger[0] =& class_loader('Log', 'classes');
49
+                $logger[0]->setLogger('Library::Config');
50
+                self::$logger = $logger[0];
51
+            }
52
+            return self::$logger;			
53
+        }
54 54
 
55
-		/**
56
-		 * Set the log instance for future use
57
-		 * @param Log $logger the log object
58
-		 * @return Log the log instance
59
-		 */
60
-		public static function setLogger($logger){
61
-			self::$logger = $logger;
62
-			return self::$logger;
63
-		}
55
+        /**
56
+         * Set the log instance for future use
57
+         * @param Log $logger the log object
58
+         * @return Log the log instance
59
+         */
60
+        public static function setLogger($logger){
61
+            self::$logger = $logger;
62
+            return self::$logger;
63
+        }
64 64
 
65
-		/**
66
-		 * Initialize the configuration by loading all the configuration from config file
67
-		 */
68
-		public static function init(){
69
-			$logger = static::getLogger();
70
-			$logger->debug('Initialization of the configuration');
71
-			self::$config = & load_configurations();
72
-			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
-				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
-			}
76
-			$logger->info('Configuration initialized successfully');
77
-			$logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
-		}
65
+        /**
66
+         * Initialize the configuration by loading all the configuration from config file
67
+         */
68
+        public static function init(){
69
+            $logger = static::getLogger();
70
+            $logger->debug('Initialization of the configuration');
71
+            self::$config = & load_configurations();
72
+            self::setBaseUrlUsingServerVar();
73
+            if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
74
+                $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75
+            }
76
+            $logger->info('Configuration initialized successfully');
77
+            $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config));
78
+        }
79 79
 
80
-		/**
81
-		 * Get the configuration item value
82
-		 * @param  string $item    the configuration item name to get
83
-		 * @param  mixed $default the default value to use if can not find the config item in the list
84
-		 * @return mixed          the config value if exist or the default value
85
-		 */
86
-		public static function get($item, $default = null){
87
-			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
89
-				return self::$config[$item];
90
-			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
-			return $default;
93
-		}
80
+        /**
81
+         * Get the configuration item value
82
+         * @param  string $item    the configuration item name to get
83
+         * @param  mixed $default the default value to use if can not find the config item in the list
84
+         * @return mixed          the config value if exist or the default value
85
+         */
86
+        public static function get($item, $default = null){
87
+            $logger = static::getLogger();
88
+            if(array_key_exists($item, self::$config)){
89
+                return self::$config[$item];
90
+            }
91
+            $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
92
+            return $default;
93
+        }
94 94
 
95
-		/**
96
-		 * Set the configuration item value
97
-		 * @param string $item  the config item name to set
98
-		 * @param mixed $value the config item value
99
-		 */
100
-		public static function set($item, $value){
101
-			self::$config[$item] = $value;
102
-		}
95
+        /**
96
+         * Set the configuration item value
97
+         * @param string $item  the config item name to set
98
+         * @param mixed $value the config item value
99
+         */
100
+        public static function set($item, $value){
101
+            self::$config[$item] = $value;
102
+        }
103 103
 
104
-		/**
105
-		 * Get all the configuration values
106
-		 * @return array the config values
107
-		 */
108
-		public static function getAll(){
109
-			return self::$config;
110
-		}
104
+        /**
105
+         * Get all the configuration values
106
+         * @return array the config values
107
+         */
108
+        public static function getAll(){
109
+            return self::$config;
110
+        }
111 111
 
112
-		/**
113
-		 * Set the configuration values bu merged with the existing configuration
114
-		 * @param array $config the config values to add in the configuration list
115
-		 */
116
-		public static function setAll(array $config = array()){
117
-			self::$config = array_merge(self::$config, $config);
118
-		}
112
+        /**
113
+         * Set the configuration values bu merged with the existing configuration
114
+         * @param array $config the config values to add in the configuration list
115
+         */
116
+        public static function setAll(array $config = array()){
117
+            self::$config = array_merge(self::$config, $config);
118
+        }
119 119
 
120
-		/**
121
-		 * Delete the configuration item in the list
122
-		 * @param  string $item the config item name to be deleted
123
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
-		 */
125
-		public static function delete($item){
126
-			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
129
-				unset(self::$config[$item]);
130
-				return true;
131
-			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
-				return false;
135
-			}
136
-		}
120
+        /**
121
+         * Delete the configuration item in the list
122
+         * @param  string $item the config item name to be deleted
123
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124
+         */
125
+        public static function delete($item){
126
+            $logger = static::getLogger();
127
+            if(array_key_exists($item, self::$config)){
128
+                $logger->info('Delete config item ['.$item.']');
129
+                unset(self::$config[$item]);
130
+                return true;
131
+            }
132
+            else{
133
+                $logger->warning('Config item ['.$item.'] to be deleted does not exists');
134
+                return false;
135
+            }
136
+        }
137 137
 
138
-		/**
139
-		 * Load the configuration file. This an alias to Loader::config()
140
-		 * @param  string $config the config name to be loaded
141
-		 */
142
-		public static function load($config){
143
-			Loader::config($config);
144
-		}
138
+        /**
139
+         * Load the configuration file. This an alias to Loader::config()
140
+         * @param  string $config the config name to be loaded
141
+         */
142
+        public static function load($config){
143
+            Loader::config($config);
144
+        }
145 145
 
146
-		/**
147
-		 * Set the configuration for "base_url" if is not set in the configuration
148
-		 */
149
-		private static function setBaseUrlUsingServerVar(){
150
-			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
153
-					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
-				}
155
-				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
157
-					//check if the server is running under IPv6
158
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
159
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
160
-					}
161
-					else{
162
-						$baseUrl = $_SERVER['SERVER_ADDR'];
163
-					}
164
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
166
-						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
167
-				}
168
-				else{
169
-					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
170
-					$baseUrl = 'http://localhost/';
171
-				}
172
-				self::set('base_url', $baseUrl);
173
-			}
174
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
175
-		}
176
-	}
146
+        /**
147
+         * Set the configuration for "base_url" if is not set in the configuration
148
+         */
149
+        private static function setBaseUrlUsingServerVar(){
150
+            $logger = static::getLogger();
151
+            if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
+                if(ENVIRONMENT == 'production'){
153
+                    $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154
+                }
155
+                $baseUrl = null;
156
+                if (isset($_SERVER['SERVER_ADDR'])){
157
+                    //check if the server is running under IPv6
158
+                    if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
159
+                        $baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
160
+                    }
161
+                    else{
162
+                        $baseUrl = $_SERVER['SERVER_ADDR'];
163
+                    }
164
+                    $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
+                    $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
166
+                        . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
167
+                }
168
+                else{
169
+                    $logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
170
+                    $baseUrl = 'http://localhost/';
171
+                }
172
+                self::set('base_url', $baseUrl);
173
+            }
174
+            self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
175
+        }
176
+    }
Please login to merge, or discard this patch.
core/classes/EventInfo.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * This class represent the event detail to dispatch to correspond listener
29 29
 	 */
30
-	class EventInfo{
30
+	class EventInfo {
31 31
 		
32 32
 		/**
33 33
 		 * The event name
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		 */
55 55
 		public $stop;
56 56
 		
57
-		public function __construct($name, $payload = array(), $returnBack = false, $stop = false){
57
+		public function __construct($name, $payload = array(), $returnBack = false, $stop = false) {
58 58
 			$this->name = $name;
59 59
 			$this->payload = $payload;
60 60
 			$this->returnBack = $returnBack;
Please login to merge, or discard this 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/EventDispatcher.php 3 patches
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * also to dispatch the event
30 30
 	 */
31 31
 	
32
-	class EventDispatcher{
32
+	class EventDispatcher {
33 33
 		
34 34
 		/**
35 35
 		 * The list of the registered listeners
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 		 */
45 45
 		private $logger;
46 46
 
47
-		public function __construct(){
48
-			$this->logger =& class_loader('Log', 'classes');
47
+		public function __construct() {
48
+			$this->logger = & class_loader('Log', 'classes');
49 49
 			$this->logger->setLogger('Library::EventDispatcher');
50 50
 		}
51 51
 
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 		 * @param string   $eventName the name of the event to register for
55 55
 		 * @param callable $listener  the function or class method to receive the event information after dispatch
56 56
 		 */
57
-		public function addListener($eventName, callable $listener){
58
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
-			if(! isset($this->listeners[$eventName])){
57
+		public function addListener($eventName, callable $listener) {
58
+			$this->logger->debug('Adding new event listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
59
+			if (!isset($this->listeners[$eventName])) {
60 60
 				$this->logger->info('This event does not have the registered event listener before, adding new one');
61 61
 				$this->listeners[$eventName] = array();
62 62
 			}
63
-			else{
63
+			else {
64 64
 				$this->logger->info('This event already have the registered listener, add this listener to the list');
65 65
 			}
66 66
 			$this->listeners[$eventName][] = $listener;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
 		 * @param  string   $eventName the event name
72 72
 		 * @param  callable $listener  the listener callback
73 73
 		 */
74
-		public function removeListener($eventName, callable $listener){
75
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
-			if(isset($this->listeners[$eventName])){
74
+		public function removeListener($eventName, callable $listener) {
75
+			$this->logger->debug('Removing of the event listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
76
+			if (isset($this->listeners[$eventName])) {
77 77
 				$this->logger->info('This event have the listeners, check if this listener exists');
78
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
78
+				if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) {
79
+					$this->logger->info('Found the listener at index [' . $index . '] remove it');
80 80
 					unset($this->listeners[$eventName][$index]);
81 81
 				}
82
-				else{
82
+				else {
83 83
 					$this->logger->info('Cannot found this listener in the event listener list');
84 84
 				}
85 85
 			}
86
-			else{
86
+			else {
87 87
 				$this->logger->info('This event does not have this listener ignore remove');
88 88
 			}
89 89
 		}
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 		 * remove all listeners for this event
94 94
 		 * @param  string $eventName the event name
95 95
 		 */
96
-		public function removeAllListener($eventName = null){
97
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
-			if($eventName !== null && isset($this->listeners[$eventName])){
96
+		public function removeAllListener($eventName = null) {
97
+			$this->logger->debug('Removing of all event listener, the event name [' . $eventName . ']');
98
+			if ($eventName !== null && isset($this->listeners[$eventName])) {
99 99
 				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100 100
 				unset($this->listeners[$eventName]);
101 101
 			}
102
-			else{
102
+			else {
103 103
 				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104 104
 				$this->listeners = array();
105 105
 			}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		 * @param string $eventName the event name
111 111
 		 * @return array the listeners for this event or empty array if this event does not contain any listener
112 112
 		 */
113
-		public function getListeners($eventName){
113
+		public function getListeners($eventName) {
114 114
 			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115 115
 		}
116 116
 		
@@ -119,21 +119,21 @@  discard block
 block discarded – undo
119 119
 		 * @param  mixed|object $event the event information
120 120
 		 * @return void|object if event need return, will return the final EventInfo object.
121 121
 		 */	
122
-		public function dispatch($event){
123
-			if(! $event || !$event instanceof EventInfo){
122
+		public function dispatch($event) {
123
+			if (!$event || !$event instanceof EventInfo) {
124 124
 				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125 125
 				$event = new EventInfo((string) $event);
126 126
 			}			
127
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
-			if(isset($event->stop) && $event->stop){
127
+			$this->logger->debug('Dispatch to the event listener, the event [' . stringfy_vars($event) . ']');
128
+			if (isset($event->stop) && $event->stop) {
129 129
 				$this->logger->info('This event need stopped, no need call any listener');
130 130
 				return;
131 131
 			}
132
-			if($event->returnBack){
132
+			if ($event->returnBack) {
133 133
 				$this->logger->info('This event need return back, return the result for future use');
134 134
 				return $this->dispatchToListerners($event);
135 135
 			}
136
-			else{
136
+			else {
137 137
 				$this->logger->info('This event no need return back the result, just dispatch it');
138 138
 				$this->dispatchToListerners($event);
139 139
 			}
@@ -144,38 +144,38 @@  discard block
 block discarded – undo
144 144
 		 * @param  object EventInfo $event  the event information
145 145
 		 * @return void|object if event need return, will return the final EventInfo instance.
146 146
 		 */	
147
-		private function dispatchToListerners(EventInfo $event){
147
+		private function dispatchToListerners(EventInfo $event) {
148 148
 			$eBackup = $event;
149 149
 			$list = $this->getListeners($event->name);
150
-			if(empty($list)){
151
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
-				if($event->returnBack){
150
+			if (empty($list)) {
151
+				$this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.');
152
+				if ($event->returnBack) {
153 153
 					return $event;
154 154
 				}
155 155
 				return;
156 156
 			}
157
-			else{
158
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
157
+			else {
158
+				$this->logger->info('Found the registered event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list));
159 159
 			}
160
-			foreach($list as $listener){
161
-				if($eBackup->returnBack){
160
+			foreach ($list as $listener) {
161
+				if ($eBackup->returnBack) {
162 162
 					$returnedEvent = call_user_func_array($listener, array($event));
163
-					if($returnedEvent instanceof EventInfo){
163
+					if ($returnedEvent instanceof EventInfo) {
164 164
 						$event = $returnedEvent;
165 165
 					}
166
-					else{
167
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
166
+					else {
167
+						show_error('This event [' . $event->name . '] need you return the event object after processing');
168 168
 					}
169 169
 				}
170
-				else{
170
+				else {
171 171
 					call_user_func_array($listener, array($event));
172 172
 				}
173
-				if($event->stop){
173
+				if ($event->stop) {
174 174
 					break;
175 175
 				}
176 176
 			}
177 177
 			//only test for original event may be during the flow some listeners change this parameter
178
-			if($eBackup->returnBack){
178
+			if ($eBackup->returnBack) {
179 179
 				return $event;
180 180
 			}
181 181
 		}
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -59,8 +59,7 @@  discard block
 block discarded – undo
59 59
 			if(! isset($this->listeners[$eventName])){
60 60
 				$this->logger->info('This event does not have the registered event listener before, adding new one');
61 61
 				$this->listeners[$eventName] = array();
62
-			}
63
-			else{
62
+			} else{
64 63
 				$this->logger->info('This event already have the registered listener, add this listener to the list');
65 64
 			}
66 65
 			$this->listeners[$eventName][] = $listener;
@@ -78,12 +77,10 @@  discard block
 block discarded – undo
78 77
 				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79 78
 					$this->logger->info('Found the listener at index [' .$index. '] remove it');
80 79
 					unset($this->listeners[$eventName][$index]);
81
-				}
82
-				else{
80
+				} else{
83 81
 					$this->logger->info('Cannot found this listener in the event listener list');
84 82
 				}
85
-			}
86
-			else{
83
+			} else{
87 84
 				$this->logger->info('This event does not have this listener ignore remove');
88 85
 			}
89 86
 		}
@@ -98,8 +95,7 @@  discard block
 block discarded – undo
98 95
 			if($eventName !== null && isset($this->listeners[$eventName])){
99 96
 				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100 97
 				unset($this->listeners[$eventName]);
101
-			}
102
-			else{
98
+			} else{
103 99
 				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104 100
 				$this->listeners = array();
105 101
 			}
@@ -132,8 +128,7 @@  discard block
 block discarded – undo
132 128
 			if($event->returnBack){
133 129
 				$this->logger->info('This event need return back, return the result for future use');
134 130
 				return $this->dispatchToListerners($event);
135
-			}
136
-			else{
131
+			} else{
137 132
 				$this->logger->info('This event no need return back the result, just dispatch it');
138 133
 				$this->dispatchToListerners($event);
139 134
 			}
@@ -153,8 +148,7 @@  discard block
 block discarded – undo
153 148
 					return $event;
154 149
 				}
155 150
 				return;
156
-			}
157
-			else{
151
+			} else{
158 152
 				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
159 153
 			}
160 154
 			foreach($list as $listener){
@@ -162,12 +156,10 @@  discard block
 block discarded – undo
162 156
 					$returnedEvent = call_user_func_array($listener, array($event));
163 157
 					if($returnedEvent instanceof EventInfo){
164 158
 						$event = $returnedEvent;
165
-					}
166
-					else{
159
+					} else{
167 160
 						show_error('This event [' .$event->name. '] need you return the event object after processing');
168 161
 					}
169
-				}
170
-				else{
162
+				} else{
171 163
 					call_user_func_array($listener, array($event));
172 164
 				}
173 165
 				if($event->stop){
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,182 +1,182 @@
 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 dispatcher management, permit to record the listener and 
29
-	 * also to dispatch the event
30
-	 */
27
+    /**
28
+     * This class represent the event dispatcher management, permit to record the listener and 
29
+     * also to dispatch the event
30
+     */
31 31
 	
32
-	class EventDispatcher{
32
+    class EventDispatcher{
33 33
 		
34
-		/**
35
-		 * The list of the registered listeners
36
-		 * @var array
37
-		 */
38
-		private $listeners = array();
34
+        /**
35
+         * The list of the registered listeners
36
+         * @var array
37
+         */
38
+        private $listeners = array();
39 39
 		
40 40
 
41
-		/**
42
-		 * The logger instance
43
-		 * @var Log
44
-		 */
45
-		private $logger;
41
+        /**
42
+         * The logger instance
43
+         * @var Log
44
+         */
45
+        private $logger;
46 46
 
47
-		public function __construct(){
48
-			$this->logger =& class_loader('Log', 'classes');
49
-			$this->logger->setLogger('Library::EventDispatcher');
50
-		}
47
+        public function __construct(){
48
+            $this->logger =& class_loader('Log', 'classes');
49
+            $this->logger->setLogger('Library::EventDispatcher');
50
+        }
51 51
 
52
-		/**
53
-		 * Register new listener
54
-		 * @param string   $eventName the name of the event to register for
55
-		 * @param callable $listener  the function or class method to receive the event information after dispatch
56
-		 */
57
-		public function addListener($eventName, callable $listener){
58
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
-			if(! isset($this->listeners[$eventName])){
60
-				$this->logger->info('This event does not have the registered event listener before, adding new one');
61
-				$this->listeners[$eventName] = array();
62
-			}
63
-			else{
64
-				$this->logger->info('This event already have the registered listener, add this listener to the list');
65
-			}
66
-			$this->listeners[$eventName][] = $listener;
67
-		}
52
+        /**
53
+         * Register new listener
54
+         * @param string   $eventName the name of the event to register for
55
+         * @param callable $listener  the function or class method to receive the event information after dispatch
56
+         */
57
+        public function addListener($eventName, callable $listener){
58
+            $this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
+            if(! isset($this->listeners[$eventName])){
60
+                $this->logger->info('This event does not have the registered event listener before, adding new one');
61
+                $this->listeners[$eventName] = array();
62
+            }
63
+            else{
64
+                $this->logger->info('This event already have the registered listener, add this listener to the list');
65
+            }
66
+            $this->listeners[$eventName][] = $listener;
67
+        }
68 68
 		
69
-		/**
70
-		 * Remove the event listener from list
71
-		 * @param  string   $eventName the event name
72
-		 * @param  callable $listener  the listener callback
73
-		 */
74
-		public function removeListener($eventName, callable $listener){
75
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
-			if(isset($this->listeners[$eventName])){
77
-				$this->logger->info('This event have the listeners, check if this listener exists');
78
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
80
-					unset($this->listeners[$eventName][$index]);
81
-				}
82
-				else{
83
-					$this->logger->info('Cannot found this listener in the event listener list');
84
-				}
85
-			}
86
-			else{
87
-				$this->logger->info('This event does not have this listener ignore remove');
88
-			}
89
-		}
69
+        /**
70
+         * Remove the event listener from list
71
+         * @param  string   $eventName the event name
72
+         * @param  callable $listener  the listener callback
73
+         */
74
+        public function removeListener($eventName, callable $listener){
75
+            $this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
+            if(isset($this->listeners[$eventName])){
77
+                $this->logger->info('This event have the listeners, check if this listener exists');
78
+                if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
+                    $this->logger->info('Found the listener at index [' .$index. '] remove it');
80
+                    unset($this->listeners[$eventName][$index]);
81
+                }
82
+                else{
83
+                    $this->logger->info('Cannot found this listener in the event listener list');
84
+                }
85
+            }
86
+            else{
87
+                $this->logger->info('This event does not have this listener ignore remove');
88
+            }
89
+        }
90 90
 		
91
-		/**
92
-		 * Remove all the event listener. If event name is null will remove all listeners, else will just 
93
-		 * remove all listeners for this event
94
-		 * @param  string $eventName the event name
95
-		 */
96
-		public function removeAllListener($eventName = null){
97
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
-			if($eventName !== null && isset($this->listeners[$eventName])){
99
-				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100
-				unset($this->listeners[$eventName]);
101
-			}
102
-			else{
103
-				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104
-				$this->listeners = array();
105
-			}
106
-		}
91
+        /**
92
+         * Remove all the event listener. If event name is null will remove all listeners, else will just 
93
+         * remove all listeners for this event
94
+         * @param  string $eventName the event name
95
+         */
96
+        public function removeAllListener($eventName = null){
97
+            $this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
+            if($eventName !== null && isset($this->listeners[$eventName])){
99
+                $this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100
+                unset($this->listeners[$eventName]);
101
+            }
102
+            else{
103
+                $this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104
+                $this->listeners = array();
105
+            }
106
+        }
107 107
 		
108
-		/**
109
-		 * Get the list of listener for this event
110
-		 * @param string $eventName the event name
111
-		 * @return array the listeners for this event or empty array if this event does not contain any listener
112
-		 */
113
-		public function getListeners($eventName){
114
-			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115
-		}
108
+        /**
109
+         * Get the list of listener for this event
110
+         * @param string $eventName the event name
111
+         * @return array the listeners for this event or empty array if this event does not contain any listener
112
+         */
113
+        public function getListeners($eventName){
114
+            return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115
+        }
116 116
 		
117
-		/**
118
-		 * Dispatch the event to the registered listeners.
119
-		 * @param  mixed|object $event the event information
120
-		 * @return void|object if event need return, will return the final EventInfo object.
121
-		 */	
122
-		public function dispatch($event){
123
-			if(! $event || !$event instanceof EventInfo){
124
-				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125
-				$event = new EventInfo((string) $event);
126
-			}			
127
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
-			if(isset($event->stop) && $event->stop){
129
-				$this->logger->info('This event need stopped, no need call any listener');
130
-				return;
131
-			}
132
-			if($event->returnBack){
133
-				$this->logger->info('This event need return back, return the result for future use');
134
-				return $this->dispatchToListerners($event);
135
-			}
136
-			else{
137
-				$this->logger->info('This event no need return back the result, just dispatch it');
138
-				$this->dispatchToListerners($event);
139
-			}
140
-		}
117
+        /**
118
+         * Dispatch the event to the registered listeners.
119
+         * @param  mixed|object $event the event information
120
+         * @return void|object if event need return, will return the final EventInfo object.
121
+         */	
122
+        public function dispatch($event){
123
+            if(! $event || !$event instanceof EventInfo){
124
+                $this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125
+                $event = new EventInfo((string) $event);
126
+            }			
127
+            $this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
+            if(isset($event->stop) && $event->stop){
129
+                $this->logger->info('This event need stopped, no need call any listener');
130
+                return;
131
+            }
132
+            if($event->returnBack){
133
+                $this->logger->info('This event need return back, return the result for future use');
134
+                return $this->dispatchToListerners($event);
135
+            }
136
+            else{
137
+                $this->logger->info('This event no need return back the result, just dispatch it');
138
+                $this->dispatchToListerners($event);
139
+            }
140
+        }
141 141
 		
142
-		/**
143
-		 * Dispatch the event to the registered listeners.
144
-		 * @param  object EventInfo $event  the event information
145
-		 * @return void|object if event need return, will return the final EventInfo instance.
146
-		 */	
147
-		private function dispatchToListerners(EventInfo $event){
148
-			$eBackup = $event;
149
-			$list = $this->getListeners($event->name);
150
-			if(empty($list)){
151
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
-				if($event->returnBack){
153
-					return $event;
154
-				}
155
-				return;
156
-			}
157
-			else{
158
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
159
-			}
160
-			foreach($list as $listener){
161
-				if($eBackup->returnBack){
162
-					$returnedEvent = call_user_func_array($listener, array($event));
163
-					if($returnedEvent instanceof EventInfo){
164
-						$event = $returnedEvent;
165
-					}
166
-					else{
167
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
168
-					}
169
-				}
170
-				else{
171
-					call_user_func_array($listener, array($event));
172
-				}
173
-				if($event->stop){
174
-					break;
175
-				}
176
-			}
177
-			//only test for original event may be during the flow some listeners change this parameter
178
-			if($eBackup->returnBack){
179
-				return $event;
180
-			}
181
-		}
182
-	}
142
+        /**
143
+         * Dispatch the event to the registered listeners.
144
+         * @param  object EventInfo $event  the event information
145
+         * @return void|object if event need return, will return the final EventInfo instance.
146
+         */	
147
+        private function dispatchToListerners(EventInfo $event){
148
+            $eBackup = $event;
149
+            $list = $this->getListeners($event->name);
150
+            if(empty($list)){
151
+                $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
+                if($event->returnBack){
153
+                    return $event;
154
+                }
155
+                return;
156
+            }
157
+            else{
158
+                $this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
159
+            }
160
+            foreach($list as $listener){
161
+                if($eBackup->returnBack){
162
+                    $returnedEvent = call_user_func_array($listener, array($event));
163
+                    if($returnedEvent instanceof EventInfo){
164
+                        $event = $returnedEvent;
165
+                    }
166
+                    else{
167
+                        show_error('This event [' .$event->name. '] need you return the event object after processing');
168
+                    }
169
+                }
170
+                else{
171
+                    call_user_func_array($listener, array($event));
172
+                }
173
+                if($event->stop){
174
+                    break;
175
+                }
176
+            }
177
+            //only test for original event may be during the flow some listeners change this parameter
178
+            if($eBackup->returnBack){
179
+                return $event;
180
+            }
181
+        }
182
+    }
Please login to merge, or discard this patch.
core/classes/Controller.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -115,8 +115,7 @@
 block discarded – undo
115 115
 		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116 116
 			if($logger !== null){
117 117
 	          $this->logger = $logger;
118
-	        }
119
-	        else{
118
+	        } else{
120 119
 	            $this->logger =& class_loader('Log', 'classes');
121 120
 				$this->logger->setLogger('MainController');
122 121
 	        }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Controller{
27
+	class Controller {
28 28
 		
29 29
 		/**
30 30
 		 * The name of the module if this controller belong to an module
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		 * Class constructor
49 49
 		 * @param object $logger the Log instance to use if is null will create one
50 50
 		 */
51
-		public function __construct(Log $logger = null){
51
+		public function __construct(Log $logger = null) {
52 52
 			//setting the Log instance
53 53
 			$this->setLoggerFromParamOrCreateNewInstance($logger);
54 54
 			
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 		/**
85 85
 		 * This method is used to set the module name
86 86
 		 */
87
-		protected function setModuleNameFromRouter(){
87
+		protected function setModuleNameFromRouter() {
88 88
 			//determine the current module
89
-			if(isset($this->router) && $this->router->getModule()){
89
+			if (isset($this->router) && $this->router->getModule()) {
90 90
 				$this->moduleName = $this->router->getModule();
91 91
 			}
92 92
 		}
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 		 * Set the cache using the argument otherwise will use the configuration
96 96
 		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
97 97
 		 */
98
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
98
+		protected function setCacheFromParamOrConfig(CacheInterface $cache = null) {
99 99
 			$this->logger->debug('Setting the cache handler instance');
100 100
 			//set cache handler instance
101
-			if(get_config('cache_enable', false)){
102
-				if ($cache !== null){
101
+			if (get_config('cache_enable', false)) {
102
+				if ($cache !== null) {
103 103
 					$this->cache = $cache;
104
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
104
+				} else if (isset($this->{strtolower(get_config('cache_handler'))})) {
105 105
 					$this->cache = $this->{strtolower(get_config('cache_handler'))};
106 106
 					unset($this->{strtolower(get_config('cache_handler'))});
107 107
 				} 
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
 		 * Set the Log instance using argument or create new instance
113 113
 		 * @param object $logger the Log instance if not null
114 114
 		 */
115
-		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116
-			if($logger !== null){
115
+		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
116
+			if ($logger !== null) {
117 117
 	          $this->logger = $logger;
118 118
 	        }
119
-	        else{
120
-	            $this->logger =& class_loader('Log', 'classes');
119
+	        else {
120
+	            $this->logger = & class_loader('Log', 'classes');
121 121
 				$this->logger->setLogger('MainController');
122 122
 	        }
123 123
 		}
@@ -126,20 +126,20 @@  discard block
 block discarded – undo
126 126
 		 * This method is used to load the required resources for framework to work
127 127
 		 * @return void 
128 128
 		 */
129
-		private function loadRequiredResources(){
129
+		private function loadRequiredResources() {
130 130
 			$this->logger->debug('Adding the loaded classes to the super instance');
131
-			foreach (class_loaded() as $var => $class){
132
-				$this->$var =& class_loader($class);
131
+			foreach (class_loaded() as $var => $class) {
132
+				$this->$var = & class_loader($class);
133 133
 			}
134 134
 
135 135
 			$this->logger->debug('Loading the required classes into super instance');
136
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
137
-			$this->loader =& class_loader('Loader', 'classes');
138
-			$this->lang =& class_loader('Lang', 'classes');
139
-			$this->request =& class_loader('Request', 'classes');
136
+			$this->eventdispatcher = & class_loader('EventDispatcher', 'classes');
137
+			$this->loader = & class_loader('Loader', 'classes');
138
+			$this->lang = & class_loader('Lang', 'classes');
139
+			$this->request = & class_loader('Request', 'classes');
140 140
 			//dispatch the request instance created event
141 141
 			$this->eventdispatcher->dispatch('REQUEST_CREATED');
142
-			$this->response =& class_loader('Response', 'classes', 'classes');
142
+			$this->response = & class_loader('Response', 'classes', 'classes');
143 143
 		}
144 144
 
145 145
 	}
Please login to merge, or discard this patch.
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -1,145 +1,145 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Controller{
27
+    class Controller{
28 28
 		
29
-		/**
30
-		 * The name of the module if this controller belong to an module
31
-		 * @var string
32
-		 */
33
-		public $moduleName = null;
29
+        /**
30
+         * The name of the module if this controller belong to an module
31
+         * @var string
32
+         */
33
+        public $moduleName = null;
34 34
 
35
-		/**
36
-		 * The singleton of the super object
37
-		 * @var Controller
38
-		 */
39
-		private static $instance;
35
+        /**
36
+         * The singleton of the super object
37
+         * @var Controller
38
+         */
39
+        private static $instance;
40 40
 
41
-		/**
42
-		 * The logger instance
43
-		 * @var Log
44
-		 */
45
-		protected $logger;
41
+        /**
42
+         * The logger instance
43
+         * @var Log
44
+         */
45
+        protected $logger;
46 46
 
47
-		/**
48
-		 * Class constructor
49
-		 * @param object $logger the Log instance to use if is null will create one
50
-		 */
51
-		public function __construct(Log $logger = null){
52
-			//setting the Log instance
53
-			$this->setLoggerFromParamOrCreateNewInstance($logger);
47
+        /**
48
+         * Class constructor
49
+         * @param object $logger the Log instance to use if is null will create one
50
+         */
51
+        public function __construct(Log $logger = null){
52
+            //setting the Log instance
53
+            $this->setLoggerFromParamOrCreateNewInstance($logger);
54 54
 			
55
-			//instance of the super object
56
-			self::$instance = & $this;
55
+            //instance of the super object
56
+            self::$instance = & $this;
57 57
 			
58
-			//load the required resources
59
-			$this->loadRequiredResources();
58
+            //load the required resources
59
+            $this->loadRequiredResources();
60 60
 			
61
-			//set the cache using the configuration
62
-			$this->setCacheFromParamOrConfig(null);
61
+            //set the cache using the configuration
62
+            $this->setCacheFromParamOrConfig(null);
63 63
 			
64
-			//set application session configuration
65
-			$this->logger->debug('Setting PHP application session handler');
66
-			set_session_config();
64
+            //set application session configuration
65
+            $this->logger->debug('Setting PHP application session handler');
66
+            set_session_config();
67 67
 			
68
-			//set module using the router
69
-			$this->setModuleNameFromRouter();
68
+            //set module using the router
69
+            $this->setModuleNameFromRouter();
70 70
 
71
-			//dispatch the loaded instance of super controller event
72
-			$this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
73
-		}
71
+            //dispatch the loaded instance of super controller event
72
+            $this->eventdispatcher->dispatch('SUPER_CONTROLLER_CREATED');
73
+        }
74 74
 
75 75
 
76
-		/**
77
-		 * This is a very useful method it's used to get the super object instance
78
-		 * @return Controller the super object instance
79
-		 */
80
-		public static function &get_instance(){
81
-			return self::$instance;
82
-		}
76
+        /**
77
+         * This is a very useful method it's used to get the super object instance
78
+         * @return Controller the super object instance
79
+         */
80
+        public static function &get_instance(){
81
+            return self::$instance;
82
+        }
83 83
 
84
-		/**
85
-		 * This method is used to set the module name
86
-		 */
87
-		protected function setModuleNameFromRouter(){
88
-			//determine the current module
89
-			if(isset($this->router) && $this->router->getModule()){
90
-				$this->moduleName = $this->router->getModule();
91
-			}
92
-		}
84
+        /**
85
+         * This method is used to set the module name
86
+         */
87
+        protected function setModuleNameFromRouter(){
88
+            //determine the current module
89
+            if(isset($this->router) && $this->router->getModule()){
90
+                $this->moduleName = $this->router->getModule();
91
+            }
92
+        }
93 93
 
94
-		/**
95
-		 * Set the cache using the argument otherwise will use the configuration
96
-		 * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
97
-		 */
98
-		protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
99
-			$this->logger->debug('Setting the cache handler instance');
100
-			//set cache handler instance
101
-			if(get_config('cache_enable', false)){
102
-				if ($cache !== null){
103
-					$this->cache = $cache;
104
-				} else if (isset($this->{strtolower(get_config('cache_handler'))})){
105
-					$this->cache = $this->{strtolower(get_config('cache_handler'))};
106
-					unset($this->{strtolower(get_config('cache_handler'))});
107
-				} 
108
-			}
109
-		}
94
+        /**
95
+         * Set the cache using the argument otherwise will use the configuration
96
+         * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured
97
+         */
98
+        protected function setCacheFromParamOrConfig(CacheInterface $cache = null){
99
+            $this->logger->debug('Setting the cache handler instance');
100
+            //set cache handler instance
101
+            if(get_config('cache_enable', false)){
102
+                if ($cache !== null){
103
+                    $this->cache = $cache;
104
+                } else if (isset($this->{strtolower(get_config('cache_handler'))})){
105
+                    $this->cache = $this->{strtolower(get_config('cache_handler'))};
106
+                    unset($this->{strtolower(get_config('cache_handler'))});
107
+                } 
108
+            }
109
+        }
110 110
 
111
-		/**
112
-		 * Set the Log instance using argument or create new instance
113
-		 * @param object $logger the Log instance if not null
114
-		 */
115
-		protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116
-			if($logger !== null){
117
-	          $this->logger = $logger;
118
-	        }
119
-	        else{
120
-	            $this->logger =& class_loader('Log', 'classes');
121
-				$this->logger->setLogger('MainController');
122
-	        }
123
-		}
111
+        /**
112
+         * Set the Log instance using argument or create new instance
113
+         * @param object $logger the Log instance if not null
114
+         */
115
+        protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
116
+            if($logger !== null){
117
+                $this->logger = $logger;
118
+            }
119
+            else{
120
+                $this->logger =& class_loader('Log', 'classes');
121
+                $this->logger->setLogger('MainController');
122
+            }
123
+        }
124 124
 
125
-		/**
126
-		 * This method is used to load the required resources for framework to work
127
-		 * @return void 
128
-		 */
129
-		private function loadRequiredResources(){
130
-			$this->logger->debug('Adding the loaded classes to the super instance');
131
-			foreach (class_loaded() as $var => $class){
132
-				$this->$var =& class_loader($class);
133
-			}
125
+        /**
126
+         * This method is used to load the required resources for framework to work
127
+         * @return void 
128
+         */
129
+        private function loadRequiredResources(){
130
+            $this->logger->debug('Adding the loaded classes to the super instance');
131
+            foreach (class_loaded() as $var => $class){
132
+                $this->$var =& class_loader($class);
133
+            }
134 134
 
135
-			$this->logger->debug('Loading the required classes into super instance');
136
-			$this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
137
-			$this->loader =& class_loader('Loader', 'classes');
138
-			$this->lang =& class_loader('Lang', 'classes');
139
-			$this->request =& class_loader('Request', 'classes');
140
-			//dispatch the request instance created event
141
-			$this->eventdispatcher->dispatch('REQUEST_CREATED');
142
-			$this->response =& class_loader('Response', 'classes', 'classes');
143
-		}
135
+            $this->logger->debug('Loading the required classes into super instance');
136
+            $this->eventdispatcher =& class_loader('EventDispatcher', 'classes');
137
+            $this->loader =& class_loader('Loader', 'classes');
138
+            $this->lang =& class_loader('Lang', 'classes');
139
+            $this->request =& class_loader('Request', 'classes');
140
+            //dispatch the request instance created event
141
+            $this->eventdispatcher->dispatch('REQUEST_CREATED');
142
+            $this->response =& class_loader('Response', 'classes', 'classes');
143
+        }
144 144
 
145
-	}
145
+    }
Please login to merge, or discard this patch.
tests/tnhfw/classes/EventInfoTest.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 		
27 27
 		
28
-		public function testDefaultValue(){
28
+		public function testDefaultValue() {
29 29
 			$e = new EventInfo('foo');
30 30
 			$this->assertSame($e->name, 'foo');
31 31
 			$this->assertSame($e->payload, array());
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 			$this->assertFalse($e->stop);
34 34
 		}
35 35
 		
36
-		public function testPayloadValueIsSet(){
36
+		public function testPayloadValueIsSet() {
37 37
 			$e = new EventInfo('foo', array('bar'));
38 38
 			$this->assertSame($e->name, 'foo');
39 39
 			$this->assertSame($e->payload, array('bar'));
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 			$this->assertFalse($e->stop);
42 42
 		}
43 43
 		
44
-		public function testReturnBackValueIsSetToTrue(){
44
+		public function testReturnBackValueIsSetToTrue() {
45 45
 			$e = new EventInfo('foo', array('bar'), true);
46 46
 			$this->assertSame($e->name, 'foo');
47 47
 			$this->assertSame($e->payload, array('bar'));
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 			$this->assertFalse($e->stop);
50 50
 		}
51 51
 		
52
-		public function testStopValueIsSetToTue(){
52
+		public function testStopValueIsSetToTue() {
53 53
 			$e = new EventInfo('foo', array('bar'), true, true);
54 54
 			$this->assertSame($e->name, 'foo');
55 55
 			$this->assertSame($e->payload, array('bar'));
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -1,59 +1,59 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class EventInfoTest extends TestCase
6
-	{	
5
+    class EventInfoTest extends TestCase
6
+    {	
7 7
 	
8
-		public static function setUpBeforeClass()
9
-		{
8
+        public static function setUpBeforeClass()
9
+        {
10 10
 		
11
-		}
11
+        }
12 12
 		
13
-		public static function tearDownAfterClass()
14
-		{
13
+        public static function tearDownAfterClass()
14
+        {
15 15
 			
16
-		}
16
+        }
17 17
 		
18
-		protected function setUp()
19
-		{
20
-		}
18
+        protected function setUp()
19
+        {
20
+        }
21 21
 
22
-		protected function tearDown()
23
-		{
24
-		}
22
+        protected function tearDown()
23
+        {
24
+        }
25 25
 
26 26
 		
27 27
 		
28
-		public function testDefaultValue(){
29
-			$e = new EventInfo('foo');
30
-			$this->assertSame($e->name, 'foo');
31
-			$this->assertSame($e->payload, array());
32
-			$this->assertFalse($e->returnBack);
33
-			$this->assertFalse($e->stop);
34
-		}
35
-		
36
-		public function testPayloadValueIsSet(){
37
-			$e = new EventInfo('foo', array('bar'));
38
-			$this->assertSame($e->name, 'foo');
39
-			$this->assertSame($e->payload, array('bar'));
40
-			$this->assertFalse($e->returnBack);
41
-			$this->assertFalse($e->stop);
42
-		}
43
-		
44
-		public function testReturnBackValueIsSetToTrue(){
45
-			$e = new EventInfo('foo', array('bar'), true);
46
-			$this->assertSame($e->name, 'foo');
47
-			$this->assertSame($e->payload, array('bar'));
48
-			$this->assertTrue($e->returnBack);
49
-			$this->assertFalse($e->stop);
50
-		}
51
-		
52
-		public function testStopValueIsSetToTue(){
53
-			$e = new EventInfo('foo', array('bar'), true, true);
54
-			$this->assertSame($e->name, 'foo');
55
-			$this->assertSame($e->payload, array('bar'));
56
-			$this->assertTrue($e->returnBack);
57
-			$this->assertTrue($e->stop);
58
-		}
59
-	}
60 28
\ No newline at end of file
29
+        public function testDefaultValue(){
30
+            $e = new EventInfo('foo');
31
+            $this->assertSame($e->name, 'foo');
32
+            $this->assertSame($e->payload, array());
33
+            $this->assertFalse($e->returnBack);
34
+            $this->assertFalse($e->stop);
35
+        }
36
+		
37
+        public function testPayloadValueIsSet(){
38
+            $e = new EventInfo('foo', array('bar'));
39
+            $this->assertSame($e->name, 'foo');
40
+            $this->assertSame($e->payload, array('bar'));
41
+            $this->assertFalse($e->returnBack);
42
+            $this->assertFalse($e->stop);
43
+        }
44
+		
45
+        public function testReturnBackValueIsSetToTrue(){
46
+            $e = new EventInfo('foo', array('bar'), true);
47
+            $this->assertSame($e->name, 'foo');
48
+            $this->assertSame($e->payload, array('bar'));
49
+            $this->assertTrue($e->returnBack);
50
+            $this->assertFalse($e->stop);
51
+        }
52
+		
53
+        public function testStopValueIsSetToTue(){
54
+            $e = new EventInfo('foo', array('bar'), true, true);
55
+            $this->assertSame($e->name, 'foo');
56
+            $this->assertSame($e->payload, array('bar'));
57
+            $this->assertTrue($e->returnBack);
58
+            $this->assertTrue($e->stop);
59
+        }
60
+    }
61 61
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 3 patches
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -220,8 +220,7 @@  discard block
 block discarded – undo
220 220
                 //first check for CSRF
221 221
                 if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){
222 222
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
223
-                }
224
-                else{
223
+                } else{
225 224
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
226 225
                 }
227 226
             }
@@ -231,8 +230,7 @@  discard block
 block discarded – undo
231 230
             foreach ($this->getData() as $inputName => $inputVal) {
232 231
     			if(is_array($this->data[$inputName])){
233 232
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
234
-    			}
235
-    			else{
233
+    			} else{
236 234
     				$this->data[$inputName] = trim($this->data[$inputName]);
237 235
     			}
238 236
 
@@ -600,8 +598,7 @@  discard block
 block discarded – undo
600 598
                 if ($inputVal == '' && $callbackReturn == true) {
601 599
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
602 600
                 }
603
-            } 
604
-			else if($inputVal == '') {
601
+            } else if($inputVal == '') {
605 602
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
606 603
             }
607 604
         }
@@ -660,8 +657,7 @@  discard block
 block discarded – undo
660 657
                         $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual))));
661 658
                         continue;
662 659
                     }
663
-                } 
664
-				else{
660
+                } else{
665 661
                     if ($inputVal == $doNotEqual) {
666 662
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
667 663
                         continue;
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
     */
26 26
 
27 27
 
28
-     class FormValidation{
28
+     class FormValidation {
29 29
 		 
30 30
         /**
31 31
          * The form validation status
32 32
          * @var boolean
33 33
          */
34
-        protected $_success  = false;
34
+        protected $_success = false;
35 35
 
36 36
         /**
37 37
          * The list of errors messages
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
         protected $_errorsMessages = array();
41 41
         
42 42
         // Array of rule sets, fieldName => PIPE seperated ruleString
43
-        protected $_rules             = array();
43
+        protected $_rules = array();
44 44
         
45 45
         // Array of errors, niceName => Error Message
46
-        protected $_errors             = array();
46
+        protected $_errors = array();
47 47
         
48 48
         // Array of post Key => Nice name labels
49
-        protected $_labels          = array();
49
+        protected $_labels = array();
50 50
         
51 51
         /**
52 52
          * The errors delimiters
53 53
          * @var array
54 54
          */
55
-        protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
55
+        protected $_allErrorsDelimiter = array('<div class="error">', '</div>');
56 56
 
57 57
         /**
58 58
          * The each error delimiter
59 59
          * @var array
60 60
          */
61
-        protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
61
+        protected $_eachErrorDelimiter = array('<p class="error">', '</p>');
62 62
         
63 63
 		/**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
67
-        protected $_forceFail            = false;
67
+        protected $_forceFail = false;
68 68
 
69 69
         /**
70 70
          * The list of the error messages overrides by the original
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
          * @return void
99 99
          */
100 100
         public function __construct() {
101
-            $this->logger =& class_loader('Log', 'classes');
101
+            $this->logger = & class_loader('Log', 'classes');
102 102
             $this->logger->setLogger('Library::FormValidation');
103 103
            
104 104
 		   //Load form validation language message
105 105
             Loader::lang('form_validation');
106 106
             $obj = & get_instance();
107
-            $this->_errorsMessages  = array(
107
+            $this->_errorsMessages = array(
108 108
                         'required'         => $obj->lang->get('fv_required'),
109 109
                         'min_length'       => $obj->lang->get('fv_min_length'),
110 110
                         'max_length'       => $obj->lang->get('fv_max_length'),
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
             $this->_success              = false;
142 142
             $this->_forceFail            = false;
143 143
             $this->data                  = array();
144
-			$this->enableCsrfCheck       = false;
144
+			$this->enableCsrfCheck = false;
145 145
         }
146 146
 
147 147
         /**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		 *
151 151
          * @return FormValidation Current instance of object.
152 152
          */
153
-        public function setData(array $data){
153
+        public function setData(array $data) {
154 154
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155 155
             $this->data = $data;
156 156
 			return $this;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
          * Get the form validation data
161 161
          * @return array the form validation data to be validated
162 162
          */
163
-        public function getData(){
163
+        public function getData() {
164 164
             return $this->data;
165 165
         }
166 166
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		*
170 170
 		* @return string the function name
171 171
 		*/
172
-        protected function _toCallCase($funcName, $prefix='_validate') {
172
+        protected function _toCallCase($funcName, $prefix = '_validate') {
173 173
             $funcName = strtolower($funcName);
174 174
             $finalFuncName = $prefix;
175 175
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
          * @return boolean Whether or not the form has been submitted or the data is available for validation.
194 194
          */
195 195
         public function canDoValidation() {
196
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
196
+            return get_instance()->request->method() === 'POST' || !empty($this->data);
197 197
         }
198 198
 
199 199
         /**
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
          * Validate the CSRF 
214 214
          * @return void 
215 215
          */
216
-        protected function validateCSRF(){
217
-            if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){
216
+        protected function validateCSRF() {
217
+            if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) {
218 218
                 $this->logger->debug('Check if CSRF is enabled in configuration');
219 219
                 //first check for CSRF
220
-                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){
220
+                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && !Security::validateCSRF()) {
221 221
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
222 222
                 }
223
-                else{
223
+                else {
224 224
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
225 225
                 }
226 226
             }
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
             $this->_forceFail = false;
238 238
 
239 239
             foreach ($this->getData() as $inputName => $inputVal) {
240
-    			if(is_array($this->data[$inputName])){
240
+    			if (is_array($this->data[$inputName])) {
241 241
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
242 242
     			}
243
-    			else{
243
+    			else {
244 244
     				$this->data[$inputName] = trim($this->data[$inputName]);
245 245
     			}
246 246
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         public function setRule($inputField, $inputLabel, $ruleSets) {
268 268
             $this->_rules[$inputField] = $ruleSets;
269 269
             $this->_labels[$inputField] = $inputLabel;
270
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
270
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
271 271
             return $this;
272 272
         }
273 273
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
             }
432 432
             $errorOutput .= $errorsEnd;
433 433
             echo ($echo) ? $errorOutput : '';
434
-            return (! $echo) ? $errorOutput : null;
434
+            return (!$echo) ? $errorOutput : null;
435 435
         }
436 436
 
437 437
         /**
@@ -456,25 +456,25 @@  discard block
 block discarded – undo
456 456
             /*
457 457
             //////////////// hack for regex rule that can contain "|"
458 458
             */
459
-            if(strpos($ruleString, 'regex') !== false){
459
+            if (strpos($ruleString, 'regex') !== false) {
460 460
                 $regexRule = array();
461 461
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
462 462
                 preg_match($rule, $ruleString, $regexRule);
463 463
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
464
-                 if(!empty($regexRule[0])){
464
+                 if (!empty($regexRule[0])) {
465 465
                      $ruleSets[] = $regexRule[0];
466 466
                  }
467 467
                  $ruleStringRegex = explode('|', $ruleStringTemp);
468 468
                 foreach ($ruleStringRegex as $rule) {
469 469
                     $rule = trim($rule);
470
-                    if($rule){
470
+                    if ($rule) {
471 471
                         $ruleSets[] = $rule;
472 472
                     }
473 473
                 }
474 474
                  
475 475
             }
476 476
             /***********************************/
477
-            else{
477
+            else {
478 478
                 if (strpos($ruleString, '|') !== FALSE) {
479 479
                     $ruleSets = explode('|', $ruleString);
480 480
                 } else {
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
          * @return void
507 507
          */
508 508
         protected function _validateRule($inputName, $inputVal, $ruleName) {
509
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
509
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
510 510
             // Array to store args
511 511
             $ruleArgs = array();
512 512
 
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
                 $key = $i - 1;
552 552
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
553 553
             }
554
-            if (! array_key_exists($inputName, $this->_errors)) {
554
+            if (!array_key_exists($inputName, $this->_errors)) {
555 555
                 $this->_errors[$inputName] = $rulePhrase;
556 556
             }
557 557
         }
@@ -603,13 +603,13 @@  discard block
 block discarded – undo
603 603
          */
604 604
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
605 605
             $inputVal = $this->post($inputName);
606
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
606
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
607 607
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
608 608
                 if ($inputVal == '' && $callbackReturn == true) {
609 609
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
610 610
                 }
611 611
             } 
612
-			else if($inputVal == '') {
612
+			else if ($inputVal == '') {
613 613
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
614 614
             }
615 615
         }
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
636 636
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
637 637
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
638
-				if(! $result){
638
+				if (!$result) {
639 639
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
640 640
 				}
641 641
             }
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
                         continue;
670 670
                     }
671 671
                 } 
672
-				else{
672
+				else {
673 673
                     if ($inputVal == $doNotEqual) {
674 674
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
675 675
                         continue;
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
          */
700 700
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
701 701
             $inputVal = $this->post($inputName);
702
-            if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
703
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
702
+            if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
703
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
704 704
                     return;
705 705
                 }
706 706
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
         protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
717 717
             $inputVal = $this->post($inputName);
718 718
             if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
719
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
719
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
720 720
                     return;
721 721
                 }
722 722
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
733 733
             $inputVal = $this->post($inputName);
734 734
             if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
735
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
735
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
736 736
                     return;
737 737
                 }
738 738
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
         protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
749 749
             $inputVal = $this->post($inputName);
750 750
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
751
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
751
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
752 752
                     return;
753 753
                 }
754 754
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
     	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
765 765
             $inputVal = $this->post($inputName);
766 766
             if ($inputVal >= $ruleArgs[1]) { 
767
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
767
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
768 768
                     return;
769 769
                 }
770 770
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
781 781
             $inputVal = $this->post($inputName);
782 782
             if ($inputVal <= $ruleArgs[1]) {
783
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
783
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
784 784
                     return;
785 785
                 }
786 786
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -795,8 +795,8 @@  discard block
 block discarded – undo
795 795
          */
796 796
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
797 797
             $inputVal = $this->post($inputName);
798
-            if (! is_numeric($inputVal)) {
799
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
798
+            if (!is_numeric($inputVal)) {
799
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
800 800
                     return;
801 801
                 }
802 802
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
813 813
             $inputVal = $this->post($inputName);
814 814
     		$obj = & get_instance();
815
-    		if(! isset($obj->database)){
815
+    		if (!isset($obj->database)) {
816 816
     			return;
817 817
     		}
818 818
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
     			          ->get();
822 822
     		$nb = $obj->database->numRows();
823 823
             if ($nb == 0) {
824
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
824
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
825 825
                     return;
826 826
                 }
827 827
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
838 838
             $inputVal = $this->post($inputName);
839 839
     		$obj = & get_instance();
840
-    		if(! isset($obj->database)){
840
+    		if (!isset($obj->database)) {
841 841
     			return;
842 842
     		}
843 843
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
     			          ->get();
847 847
     		$nb = $obj->database->numRows();
848 848
             if ($nb != 0) {
849
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
849
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
850 850
                     return;
851 851
                 }
852 852
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -862,11 +862,11 @@  discard block
 block discarded – undo
862 862
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
863 863
             $inputVal = $this->post($inputName);
864 864
     		$obj = & get_instance();
865
-    		if(! isset($obj->database)){
865
+    		if (!isset($obj->database)) {
866 866
     			return;
867 867
     		}
868 868
     		$data = explode(',', $ruleArgs[1]);
869
-    		if(count($data) < 2){
869
+    		if (count($data) < 2) {
870 870
     			return;
871 871
     		}
872 872
     		list($table, $column) = explode('.', $data[0]);
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
                 		  ->get();
878 878
     		$nb = $obj->database->numRows();
879 879
             if ($nb != 0) {
880
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
880
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
881 881
                     return;
882 882
                 }
883 883
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -894,8 +894,8 @@  discard block
 block discarded – undo
894 894
             $inputVal = $this->post($inputName);
895 895
     		$list = explode(',', $ruleArgs[1]);
896 896
             $list = array_map('trim', $list);
897
-            if (! in_array($inputVal, $list)) {
898
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
897
+            if (!in_array($inputVal, $list)) {
898
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
899 899
                     return;
900 900
                 }
901 901
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
912 912
             $inputVal = $this->post($inputName);
913 913
     		$regex = $ruleArgs[1];
914
-            if (! preg_match($regex, $inputVal)) {
915
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
914
+            if (!preg_match($regex, $inputVal)) {
915
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
916 916
                     return;
917 917
                 }
918 918
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
 
27 27
 
28
-     class FormValidation{
28
+        class FormValidation{
29 29
 		 
30 30
         /**
31 31
          * The form validation status
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
          */
61 61
         protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
62 62
         
63
-		/**
63
+        /**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 
87 87
         /**
88 88
          * Whether to check the CSRF. This attribute is just a way to allow custom change of the 
89
-		 * CSRF global configuration
90
-		 *
89
+         * CSRF global configuration
90
+         *
91 91
          * @var boolean
92 92
          */
93 93
         public $enableCsrfCheck = false;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
             $this->logger =& class_loader('Log', 'classes');
102 102
             $this->logger->setLogger('Library::FormValidation');
103 103
            
104
-		   //Load form validation language message
104
+            //Load form validation language message
105 105
             Loader::lang('form_validation');
106 106
             $obj = & get_instance();
107 107
             $this->_errorsMessages  = array(
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
             $this->_success              = false;
142 142
             $this->_forceFail            = false;
143 143
             $this->data                  = array();
144
-			$this->enableCsrfCheck       = false;
144
+            $this->enableCsrfCheck       = false;
145 145
         }
146 146
 
147 147
         /**
148 148
          * Set the form validation data
149 149
          * @param array $data the values to be validated
150
-		 *
150
+         *
151 151
          * @return FormValidation Current instance of object.
152 152
          */
153 153
         public function setData(array $data){
154 154
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155 155
             $this->data = $data;
156
-			return $this;
156
+            return $this;
157 157
         }
158 158
 
159 159
         /**
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
             return $this->data;
165 165
         }
166 166
 
167
-		/**
168
-		* Get the validation function name to validate a rule
169
-		*
170
-		* @return string the function name
171
-		*/
167
+        /**
168
+         * Get the validation function name to validate a rule
169
+         *
170
+         * @return string the function name
171
+         */
172 172
         protected function _toCallCase($funcName, $prefix='_validate') {
173 173
             $funcName = strtolower($funcName);
174 174
             $finalFuncName = $prefix;
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
             $this->_forceFail = false;
239 239
 
240 240
             foreach ($this->getData() as $inputName => $inputVal) {
241
-    			if(is_array($this->data[$inputName])){
242
-    				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
243
-    			}
244
-    			else{
245
-    				$this->data[$inputName] = trim($this->data[$inputName]);
246
-    			}
241
+                if(is_array($this->data[$inputName])){
242
+                    $this->data[$inputName] = array_map('trim', $this->data[$inputName]);
243
+                }
244
+                else{
245
+                    $this->data[$inputName] = trim($this->data[$inputName]);
246
+                }
247 247
 
248 248
                 if (array_key_exists($inputName, $this->_rules)) {
249 249
                     foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) {
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
          *
263 263
          * @param string $inputField Name of the field or the data key to add a rule to
264 264
          * @param string $ruleSets PIPE seperated string of rules
265
-		 *
265
+         *
266 266
          * @return FormValidation Current instance of object.
267 267
          */
268 268
         public function setRule($inputField, $inputLabel, $ruleSets) {
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
          * Takes an array of rules and uses setRule() to set them, accepts an array
277 277
          * of rule names rather than a pipe-delimited string as well.
278 278
          * @param array $ruleSets
279
-		 *
280
-		 * @return FormValidation Current instance of object.
279
+         *
280
+         * @return FormValidation Current instance of object.
281 281
          */
282 282
         public function setRules(array $ruleSets) {
283 283
             foreach ($ruleSets as $ruleSet) {
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
          * @param string $start Before block of errors gets displayed, HTML allowed.
300 300
          * @param string $end After the block of errors gets displayed, HTML allowed.
301 301
          *
302
-		 * @return FormValidation Current instance of object.
302
+         * @return FormValidation Current instance of object.
303 303
          */
304 304
         public function setErrorsDelimiter($start, $end) {
305 305
             $this->_allErrorsDelimiter[0] = $start;
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
          * @param string $start Displayed before each error.
315 315
          * @param string $end Displayed after each error.
316 316
          * 
317
-		 * @return FormValidation Current instance of object.
317
+         * @return FormValidation Current instance of object.
318 318
          */
319 319
         public function setErrorDelimiter($start, $end) {
320 320
             $this->_eachErrorDelimiter[0] = $start;
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
             return $this;
323 323
         }
324 324
 
325
-		/**
326
-		* Get the each errors delimiters
327
-		*
328
-		* @return array
329
-		*/
330
-    	public function getErrorDelimiter() {
325
+        /**
326
+         * Get the each errors delimiters
327
+         *
328
+         * @return array
329
+         */
330
+        public function getErrorDelimiter() {
331 331
             return $this->_eachErrorDelimiter;
332 332
         }
333 333
 
334
-		/**
335
-		* Get the all errors delimiters
336
-		*
337
-		* @return array
338
-		*/
339
-    	public function getErrorsDelimiter() {
334
+        /**
335
+         * Get the all errors delimiters
336
+         *
337
+         * @return array
338
+         */
339
+        public function getErrorsDelimiter() {
340 340
             return $this->_allErrorsDelimiter;
341 341
         }
342 342
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
          *
375 375
          * @param string $inputName The form input name or data key
376 376
          * @param string $errorMessage Error to display
377
-		 *
377
+         *
378 378
          * @return formValidation Current instance of the object
379 379
          */
380 380
         public function setCustomError($inputName, $errorMessage) {
@@ -411,17 +411,17 @@  discard block
 block discarded – undo
411 411
          *
412 412
          * @param boolean $limit number of error to display or return
413 413
          * @param boolean $echo Whether or not the values are to be returned or displayed
414
-		 *
414
+         *
415 415
          * @return string Errors formatted for output
416 416
          */
417 417
         public function displayErrors($limit = null, $echo = true) {
418 418
             list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter;
419 419
             list($errorStart, $errorEnd) = $this->_eachErrorDelimiter;
420 420
             $errorOutput = $errorsStart;
421
-    		$i = 0;
421
+            $i = 0;
422 422
             if (!empty($this->_errors)) {
423 423
                 foreach ($this->_errors as $fieldName => $error) {
424
-        	    	if ($i === $limit) { 
424
+                    if ($i === $limit) { 
425 425
                         break; 
426 426
                     }
427 427
                     $errorOutput .= $errorStart;
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
          * Breaks up a PIPE seperated string of rules, and puts them into an array.
450 450
          *
451 451
          * @param string $ruleString String to be parsed.
452
-		 *
452
+         *
453 453
          * @return array Array of each value in original string.
454 454
          */
455 455
         protected function _parseRuleString($ruleString) {
@@ -462,10 +462,10 @@  discard block
 block discarded – undo
462 462
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
463 463
                 preg_match($rule, $ruleString, $regexRule);
464 464
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
465
-                 if(!empty($regexRule[0])){
466
-                     $ruleSets[] = $regexRule[0];
467
-                 }
468
-                 $ruleStringRegex = explode('|', $ruleStringTemp);
465
+                    if(!empty($regexRule[0])){
466
+                        $ruleSets[] = $regexRule[0];
467
+                    }
468
+                    $ruleStringRegex = explode('|', $ruleStringTemp);
469 469
                 foreach ($ruleStringRegex as $rule) {
470 470
                     $rule = trim($rule);
471 471
                     if($rule){
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
                 } else {
482 482
                     $ruleSets[] = $ruleString;
483 483
                 }
484
-             }
484
+                }
485 485
             return $ruleSets;
486 486
         }
487 487
 
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
          * Returns whether or not a field obtains the rule "required".
490 490
          *
491 491
          * @param string $fieldName Field to check if required.
492
-		 *
492
+         *
493 493
          * @return boolean Whether or not the field is required.
494 494
          */
495 495
         protected function _fieldIsRequired($fieldName) {
@@ -524,13 +524,13 @@  discard block
 block discarded – undo
524 524
             return;
525 525
         }
526 526
 
527
-		/**
528
-		* Set error for the given field or key
529
-		*
530
-		* @param string $inputName the input or key name
531
-		* @param string $ruleName the rule name
532
-		* @param array|string $replacements
533
-		*/
527
+        /**
528
+         * Set error for the given field or key
529
+         *
530
+         * @param string $inputName the input or key name
531
+         * @param string $ruleName the rule name
532
+         * @param array|string $replacements
533
+         */
534 534
         protected function _setError($inputName, $ruleName, $replacements = array()) {
535 535
             $rulePhraseKeyParts = explode(',', $ruleName);
536 536
             $rulePhrase = null;
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
             }
548 548
             // Type cast to array in case it's a string
549 549
             $replacements = (array) $replacements;
550
-			$replacementCount = count($replacements);
550
+            $replacementCount = count($replacements);
551 551
             for ($i = 1; $i <= $replacementCount; $i++) {
552 552
                 $key = $i - 1;
553 553
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
@@ -565,11 +565,11 @@  discard block
 block discarded – undo
565 565
          *
566 566
          * @param type $inputArg
567 567
          * @param string $callbackFunc
568
-		 *
568
+         *
569 569
          * @return mixed
570 570
          */
571 571
         protected function _runCallback($inputArg, $callbackFunc) {
572
-			return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
572
+            return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
573 573
         }
574 574
 
575 575
         /**
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
          * arguments.
579 579
          *
580 580
          * @param string $callbackFunc
581
-		 *
581
+         *
582 582
          * @return mixed
583 583
          */
584 584
         protected function _runEmptyCallback($callbackFunc) {
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
          * Gets a specific label of a specific field input name.
590 590
          *
591 591
          * @param string $inputName
592
-		 *
592
+         *
593 593
          * @return string
594 594
          */
595 595
         protected function _getLabel($inputName) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
          * @param  string $ruleName  the rule name for this validation ("required")
603 603
          * @param  array  $ruleArgs  the rules argument
604 604
          */
605
-		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
605
+        protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
606 606
             $inputVal = $this->post($inputName);
607 607
             if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
608 608
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
611 611
                 }
612 612
             } 
613
-			else if($inputVal == '') {
614
-				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
613
+            else if($inputVal == '') {
614
+                $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
615 615
             }
616 616
         }
617 617
 
@@ -635,10 +635,10 @@  discard block
 block discarded – undo
635 635
          */
636 636
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
637 637
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
638
-				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
639
-				if(! $result){
640
-					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
641
-				}
638
+                $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
639
+                if(! $result){
640
+                    $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
641
+                }
642 642
             }
643 643
         }
644 644
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                         continue;
671 671
                     }
672 672
                 } 
673
-				else{
673
+                else{
674 674
                     if ($inputVal == $doNotEqual) {
675 675
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
676 676
                         continue;
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
          * @param  string $ruleName  the rule name for this validation ("less_than")
763 763
          * @param  array  $ruleArgs  the rules argument
764 764
          */
765
-    	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
765
+        protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
766 766
             $inputVal = $this->post($inputName);
767 767
             if ($inputVal >= $ruleArgs[1]) { 
768 768
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
          * @param  string $ruleName  the rule name for this validation ("greater_than")
779 779
          * @param  array  $ruleArgs  the rules argument
780 780
          */
781
-    	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
781
+        protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
782 782
             $inputVal = $this->post($inputName);
783 783
             if ($inputVal <= $ruleArgs[1]) {
784 784
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
          * @param  string $ruleName  the rule name for this validation ("numeric")
795 795
          * @param  array  $ruleArgs  the rules argument
796 796
          */
797
-    	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
797
+        protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
798 798
             $inputVal = $this->post($inputName);
799 799
             if (! is_numeric($inputVal)) {
800 800
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -810,17 +810,17 @@  discard block
 block discarded – undo
810 810
          * @param  string $ruleName  the rule name for this validation ("exists")
811 811
          * @param  array  $ruleArgs  the rules argument
812 812
          */
813
-		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
813
+        protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
814 814
             $inputVal = $this->post($inputName);
815
-    		$obj = & get_instance();
816
-    		if(! isset($obj->database)){
817
-    			return;
818
-    		}
819
-    		list($table, $column) = explode('.', $ruleArgs[1]);
820
-    		$obj->database->from($table)
821
-    			          ->where($column, $inputVal)
822
-    			          ->get();
823
-    		$nb = $obj->database->numRows();
815
+            $obj = & get_instance();
816
+            if(! isset($obj->database)){
817
+                return;
818
+            }
819
+            list($table, $column) = explode('.', $ruleArgs[1]);
820
+            $obj->database->from($table)
821
+                            ->where($column, $inputVal)
822
+                            ->get();
823
+            $nb = $obj->database->numRows();
824 824
             if ($nb == 0) {
825 825
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
826 826
                     return;
@@ -835,17 +835,17 @@  discard block
 block discarded – undo
835 835
          * @param  string $ruleName  the rule name for this validation ("is_unique")
836 836
          * @param  array  $ruleArgs  the rules argument
837 837
          */
838
-    	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
838
+        protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
839 839
             $inputVal = $this->post($inputName);
840
-    		$obj = & get_instance();
841
-    		if(! isset($obj->database)){
842
-    			return;
843
-    		}
844
-    		list($table, $column) = explode('.', $ruleArgs[1]);
845
-    		$obj->database->from($table)
846
-    			          ->where($column, $inputVal)
847
-    			          ->get();
848
-    		$nb = $obj->database->numRows();
840
+            $obj = & get_instance();
841
+            if(! isset($obj->database)){
842
+                return;
843
+            }
844
+            list($table, $column) = explode('.', $ruleArgs[1]);
845
+            $obj->database->from($table)
846
+                            ->where($column, $inputVal)
847
+                            ->get();
848
+            $nb = $obj->database->numRows();
849 849
             if ($nb != 0) {
850 850
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
851 851
                     return;
@@ -860,23 +860,23 @@  discard block
 block discarded – undo
860 860
          * @param  string $ruleName  the rule name for this validation ("is_unique_update")
861 861
          * @param  array  $ruleArgs  the rules argument
862 862
          */
863
-    	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
863
+        protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
864 864
             $inputVal = $this->post($inputName);
865
-    		$obj = & get_instance();
866
-    		if(! isset($obj->database)){
867
-    			return;
868
-    		}
869
-    		$data = explode(',', $ruleArgs[1]);
870
-    		if(count($data) < 2){
871
-    			return;
872
-    		}
873
-    		list($table, $column) = explode('.', $data[0]);
874
-    		list($field, $val) = explode('=', $data[1]);
875
-    		$obj->database->from($table)
876
-    			          ->where($column, $inputVal)
877
-                		  ->where($field, '!=', trim($val))
878
-                		  ->get();
879
-    		$nb = $obj->database->numRows();
865
+            $obj = & get_instance();
866
+            if(! isset($obj->database)){
867
+                return;
868
+            }
869
+            $data = explode(',', $ruleArgs[1]);
870
+            if(count($data) < 2){
871
+                return;
872
+            }
873
+            list($table, $column) = explode('.', $data[0]);
874
+            list($field, $val) = explode('=', $data[1]);
875
+            $obj->database->from($table)
876
+                            ->where($column, $inputVal)
877
+                            ->where($field, '!=', trim($val))
878
+                            ->get();
879
+            $nb = $obj->database->numRows();
880 880
             if ($nb != 0) {
881 881
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
882 882
                     return;
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
          */
894 894
         protected function _validateInList($inputName, $ruleName, array $ruleArgs) {
895 895
             $inputVal = $this->post($inputName);
896
-    		$list = explode(',', $ruleArgs[1]);
896
+            $list = explode(',', $ruleArgs[1]);
897 897
             $list = array_map('trim', $list);
898 898
             if (! in_array($inputVal, $list)) {
899 899
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
          */
912 912
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
913 913
             $inputVal = $this->post($inputName);
914
-    		$regex = $ruleArgs[1];
914
+            $regex = $ruleArgs[1];
915 915
             if (! preg_match($regex, $inputVal)) {
916 916
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
917 917
                     return;
Please login to merge, or discard this patch.
tests/tnhfw/classes/DBSessionHandlerTest.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 		
14 14
 		private static $config = null;
15 15
 		
16
-		public function __construct(){
16
+		public function __construct() {
17 17
 			$this->db = new Database(array(
18 18
 								'driver'    =>  'sqlite',
19 19
 								'database'  =>  TESTS_PATH . 'assets/db_tests.db',
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
 		
51 51
 		
52
-		public function testUsingSessionConfiguration(){
52
+		public function testUsingSessionConfiguration() {
53 53
 			//using value in the configuration
54 54
 			self::$config->set('session_save_path', 'DBSessionModel');
55 55
 			self::$config->set('session_secret', $this->secret);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
76 76
 		}
77 77
 		
78
-		public function testWhenDataIsExpired(){
78
+		public function testWhenDataIsExpired() {
79 79
 			$dbsh = new DBSessionHandler($this->model);
80 80
 			$dbsh->setSessionSecret($this->secret);
81 81
 			
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			$this->assertNull($dbsh->read('foo'));
89 89
 		}
90 90
 		
91
-		public function testWhenDataAlreadyExistDoUpdate(){
91
+		public function testWhenDataAlreadyExistDoUpdate() {
92 92
 			$dbsh = new DBSessionHandler($this->model);
93 93
 			$dbsh->setSessionSecret($this->secret);
94 94
 			
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 			$this->assertEquals($dbsh->read('foo'), '445');	
102 102
 		}
103 103
 		
104
-		public function testUsingCustomModelInstance(){
104
+		public function testUsingCustomModelInstance() {
105 105
 			$dbsh = new DBSessionHandler($this->model);
106 106
 			$dbsh->setSessionSecret($this->secret);
107 107
 			
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		}
130 130
 			
131 131
 			
132
-		public function testUsingCustomLogInstance(){
132
+		public function testUsingCustomLogInstance() {
133 133
 			$dbsh = new DBSessionHandler($this->model, new Log());
134 134
 			$dbsh->setSessionSecret($this->secret);
135 135
 			
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
157 157
 		}
158 158
 		
159
-		public function testUsingCustomLoaderInstance(){
159
+		public function testUsingCustomLoaderInstance() {
160 160
 			$dbsh = new DBSessionHandler($this->model, null, new Loader());
161 161
 			$dbsh->setSessionSecret($this->secret);
162 162
 			
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		}
185 185
 		
186 186
 		
187
-		public function testWhenModelInsanceIsNotSet(){
187
+		public function testWhenModelInsanceIsNotSet() {
188 188
 			$dbsh = new DBSessionHandler(null, null, new Loader());
189 189
 			$dbsh->setSessionSecret($this->secret);
190 190
 			
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 			$this->assertEquals($dbsh->decode($encoded), 'foo');
213 213
 		}
214 214
 		
215
-		public function testWhenModelTableColumnsIsNotSet(){
215
+		public function testWhenModelTableColumnsIsNotSet() {
216 216
 			//session table is empty
217 217
 			$this->model->setSessionTableColumns(array());
218 218
 			$dbsh = new DBSessionHandler($this->model);
Please login to merge, or discard this patch.
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -1,226 +1,226 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class DBSessionHandlerTest extends TestCase
6
-	{	
5
+    class DBSessionHandlerTest extends TestCase
6
+    {	
7 7
 	
8
-		private $db = null;
8
+        private $db = null;
9 9
 		
10
-		private $model = null;
10
+        private $model = null;
11 11
 		
12
-		private $secret = 'bXlzZWNyZXQ';
12
+        private $secret = 'bXlzZWNyZXQ';
13 13
 		
14
-		private static $config = null;
14
+        private static $config = null;
15 15
 		
16
-		public function __construct(){
17
-			$this->db = new Database(array(
18
-								'driver'    =>  'sqlite',
19
-								'database'  =>  TESTS_PATH . 'assets/db_tests.db',
20
-								'charset'   => 'utf8',
21
-								'collation' => 'utf8_general_ci',
22
-							));
16
+        public function __construct(){
17
+            $this->db = new Database(array(
18
+                                'driver'    =>  'sqlite',
19
+                                'database'  =>  TESTS_PATH . 'assets/db_tests.db',
20
+                                'charset'   => 'utf8',
21
+                                'collation' => 'utf8_general_ci',
22
+                            ));
23 23
             $qr = new DatabaseQueryRunner($this->db->getPdo());
24 24
             $qr->setBenchmark(new Benchmark());
25 25
             $qr->setDriver('sqlite');
26 26
             $this->db->setQueryRunner($qr);
27
-		}
27
+        }
28 28
 		
29
-		public static function setUpBeforeClass()
30
-		{
31
-			require APPS_MODEL_PATH . 'DBSessionModel.php';
32
-			self::$config = new Config();
33
-			self::$config->init();
34
-		}
29
+        public static function setUpBeforeClass()
30
+        {
31
+            require APPS_MODEL_PATH . 'DBSessionModel.php';
32
+            self::$config = new Config();
33
+            self::$config->init();
34
+        }
35 35
 		
36 36
 		
37
-		public static function tearDownAfterClass()
38
-		{
37
+        public static function tearDownAfterClass()
38
+        {
39 39
 			
40
-		}
40
+        }
41 41
 		
42
-		protected function setUp()
43
-		{
44
-			$this->model = new DBSessionModel($this->db);
42
+        protected function setUp()
43
+        {
44
+            $this->model = new DBSessionModel($this->db);
45 45
             //to prevent old data conflict
46
-			$this->model->truncate();
47
-		}
46
+            $this->model->truncate();
47
+        }
48 48
 
49
-		protected function tearDown()
50
-		{
51
-		}
49
+        protected function tearDown()
50
+        {
51
+        }
52 52
 
53 53
 		
54 54
 		
55
-		public function testUsingSessionConfiguration(){
56
-			//using value in the configuration
57
-			self::$config->set('session_save_path', 'DBSessionModel');
58
-			self::$config->set('session_secret', $this->secret);
59
-			$dbsh = new DBSessionHandler();
60
-			//assign Database instance manually
61
-			$o = &get_instance();
62
-			$o->database = $this->db;
63
-			
64
-			$this->assertTrue($dbsh->open(null, null));
65
-			$this->assertTrue($dbsh->close());
66
-			$this->assertNull($dbsh->read('foo'));
67
-			$this->assertTrue($dbsh->write('foo', '444'));
68
-			$this->assertNotEmpty($dbsh->read('foo'));
69
-			$this->assertEquals($dbsh->read('foo'), '444');
70
-			//do update of existing data
71
-			$this->assertTrue($dbsh->write('foo', '445'));
72
-			$this->assertEquals($dbsh->read('foo'), '445');	
73
-			$this->assertTrue($dbsh->destroy('foo'));
74
-			$this->assertNull($dbsh->read('foo'));
75
-			$this->assertTrue($dbsh->gc(13));
76
-			$encoded = $dbsh->encode('foo');
77
-			$this->assertNotEmpty($encoded);
78
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
79
-		}
80
-		
81
-		public function testWhenDataIsExpired(){
82
-			$dbsh = new DBSessionHandler($this->model);
83
-			$dbsh->setSessionSecret($this->secret);
84
-			
85
-			$this->assertTrue($dbsh->open(null, null));
86
-			$this->assertTrue($dbsh->write('foo', '444'));
87
-			$this->assertNotEmpty($dbsh->read('foo'));
88
-			$this->assertEquals($dbsh->read('foo'), '444');
89
-			//put it in expired
90
-			$this->model->update('foo', array('s_time' => 1234567));
91
-			$this->assertNull($dbsh->read('foo'));
92
-		}
93
-		
94
-		public function testWhenDataAlreadyExistDoUpdate(){
95
-			$dbsh = new DBSessionHandler($this->model);
96
-			$dbsh->setSessionSecret($this->secret);
97
-			
98
-			$this->assertTrue($dbsh->open(null, null));
99
-			$this->assertTrue($dbsh->write('foo', '444'));
100
-			$this->assertNotEmpty($dbsh->read('foo'));
101
-			$this->assertEquals($dbsh->read('foo'), '444');
102
-			//do update of existing data
103
-			$this->assertTrue($dbsh->write('foo', '445'));
104
-			$this->assertEquals($dbsh->read('foo'), '445');	
105
-		}
106
-		
107
-		public function testUsingCustomModelInstance(){
108
-			$dbsh = new DBSessionHandler($this->model);
109
-			$dbsh->setSessionSecret($this->secret);
110
-			
111
-			$this->assertTrue($dbsh->open(null, null));
112
-			$this->assertTrue($dbsh->close());
113
-			$this->assertNull($dbsh->read('foo'));
114
-			$this->assertTrue($dbsh->write('foo', '444'));
115
-			$this->assertNotEmpty($dbsh->read('foo'));
116
-			$this->assertEquals($dbsh->read('foo'), '444');
117
-			//put it in expired
118
-			$this->model->update('foo', array('s_time' => 1234567));
119
-			
120
-			$this->assertNull($dbsh->read('foo'));
121
-			$this->assertTrue($dbsh->write('foo', '444'));
122
-			
123
-			//do update of existing data
124
-			$this->assertTrue($dbsh->write('foo', '445'));
125
-			$this->assertEquals($dbsh->read('foo'), '445');	
126
-			$this->assertTrue($dbsh->destroy('foo'));
127
-			$this->assertNull($dbsh->read('foo'));
128
-			$this->assertTrue($dbsh->gc(13));
129
-			$encoded = $dbsh->encode('foo');
130
-			$this->assertNotEmpty($encoded);
131
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
132
-		}
133
-			
134
-			
135
-		public function testUsingCustomLogInstance(){
136
-			$dbsh = new DBSessionHandler($this->model, new Log());
137
-			$dbsh->setSessionSecret($this->secret);
138
-			
139
-			$this->assertTrue($dbsh->open(null, null));
140
-			$this->assertTrue($dbsh->close());
141
-			$this->assertNull($dbsh->read('foo'));
142
-			$this->assertTrue($dbsh->write('foo', '444'));
143
-			$this->assertNotEmpty($dbsh->read('foo'));
144
-			$this->assertEquals($dbsh->read('foo'), '444');
145
-			//put it in expired
146
-			$this->model->update('foo', array('s_time' => 1234567));
147
-			
148
-			$this->assertNull($dbsh->read('foo'));
149
-			$this->assertTrue($dbsh->write('foo', '444'));
150
-			
151
-			//do update of existing data
152
-			$this->assertTrue($dbsh->write('foo', '445'));
153
-			$this->assertEquals($dbsh->read('foo'), '445');	
154
-			$this->assertTrue($dbsh->destroy('foo'));
155
-			$this->assertNull($dbsh->read('foo'));
156
-			$this->assertTrue($dbsh->gc(13));
157
-			$encoded = $dbsh->encode('foo');
158
-			$this->assertNotEmpty($encoded);
159
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
160
-		}
161
-		
162
-		public function testUsingCustomLoaderInstance(){
163
-			$dbsh = new DBSessionHandler($this->model, null, new Loader());
164
-			$dbsh->setSessionSecret($this->secret);
165
-			
166
-			$this->assertTrue($dbsh->open(null, null));
167
-			$this->assertTrue($dbsh->close());
168
-			$this->assertNull($dbsh->read('foo'));
169
-			$this->assertTrue($dbsh->write('foo', '444'));
170
-			$this->assertNotEmpty($dbsh->read('foo'));
171
-			$this->assertEquals($dbsh->read('foo'), '444');
172
-			//put it in expired
173
-			$this->model->update('foo', array('s_time' => 1234567));
174
-			
175
-			$this->assertNull($dbsh->read('foo'));
176
-			$this->assertTrue($dbsh->write('foo', '444'));
177
-			
178
-			//do update of existing data
179
-			$this->assertTrue($dbsh->write('foo', '445'));
180
-			$this->assertEquals($dbsh->read('foo'), '445');	
181
-			$this->assertTrue($dbsh->destroy('foo'));
182
-			$this->assertNull($dbsh->read('foo'));
183
-			$this->assertTrue($dbsh->gc(13));
184
-			$encoded = $dbsh->encode('foo');
185
-			$this->assertNotEmpty($encoded);
186
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
187
-		}
188
-		
189
-		
190
-		public function testWhenModelInsanceIsNotSet(){
191
-			$dbsh = new DBSessionHandler(null, null, new Loader());
192
-			$dbsh->setSessionSecret($this->secret);
193
-			
194
-			$this->assertTrue($dbsh->open(null, null));
195
-			$this->assertTrue($dbsh->close());
196
-			$this->assertNull($dbsh->read('foo'));
197
-			$this->assertTrue($dbsh->write('foo', '444'));
198
-			$this->assertNotEmpty($dbsh->read('foo'));
199
-			$this->assertEquals($dbsh->read('foo'), '444');
200
-			//put it in expired
201
-			$this->model->update('foo', array('s_time' => 1234567));
202
-			
203
-			$this->assertNull($dbsh->read('foo'));
204
-			$this->assertTrue($dbsh->write('foo', '444'));
205
-			
206
-			//do update of existing data
207
-			$this->assertTrue($dbsh->write('tnh', '445'));
208
-			$this->assertTrue($dbsh->write('foo', '445'));
209
-			$this->assertEquals($dbsh->read('foo'), '445');	
210
-			$this->assertTrue($dbsh->destroy('foo'));
211
-			$this->assertNull($dbsh->read('foo'));
212
-			$this->assertTrue($dbsh->gc(13));
213
-			$encoded = $dbsh->encode('foo');
214
-			$this->assertNotEmpty($encoded);
215
-			$this->assertEquals($dbsh->decode($encoded), 'foo');
216
-		}
217
-		
218
-		public function testWhenModelTableColumnsIsNotSet(){
219
-			//session table is empty
220
-			$this->model->setSessionTableColumns(array());
221
-			$dbsh = new DBSessionHandler($this->model);
222
-			$this->assertTrue($dbsh->open(null, null));
223
-		}
224
-		
225
-		
226
-	}
227 55
\ No newline at end of file
56
+        public function testUsingSessionConfiguration(){
57
+            //using value in the configuration
58
+            self::$config->set('session_save_path', 'DBSessionModel');
59
+            self::$config->set('session_secret', $this->secret);
60
+            $dbsh = new DBSessionHandler();
61
+            //assign Database instance manually
62
+            $o = &get_instance();
63
+            $o->database = $this->db;
64
+			
65
+            $this->assertTrue($dbsh->open(null, null));
66
+            $this->assertTrue($dbsh->close());
67
+            $this->assertNull($dbsh->read('foo'));
68
+            $this->assertTrue($dbsh->write('foo', '444'));
69
+            $this->assertNotEmpty($dbsh->read('foo'));
70
+            $this->assertEquals($dbsh->read('foo'), '444');
71
+            //do update of existing data
72
+            $this->assertTrue($dbsh->write('foo', '445'));
73
+            $this->assertEquals($dbsh->read('foo'), '445');	
74
+            $this->assertTrue($dbsh->destroy('foo'));
75
+            $this->assertNull($dbsh->read('foo'));
76
+            $this->assertTrue($dbsh->gc(13));
77
+            $encoded = $dbsh->encode('foo');
78
+            $this->assertNotEmpty($encoded);
79
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
80
+        }
81
+		
82
+        public function testWhenDataIsExpired(){
83
+            $dbsh = new DBSessionHandler($this->model);
84
+            $dbsh->setSessionSecret($this->secret);
85
+			
86
+            $this->assertTrue($dbsh->open(null, null));
87
+            $this->assertTrue($dbsh->write('foo', '444'));
88
+            $this->assertNotEmpty($dbsh->read('foo'));
89
+            $this->assertEquals($dbsh->read('foo'), '444');
90
+            //put it in expired
91
+            $this->model->update('foo', array('s_time' => 1234567));
92
+            $this->assertNull($dbsh->read('foo'));
93
+        }
94
+		
95
+        public function testWhenDataAlreadyExistDoUpdate(){
96
+            $dbsh = new DBSessionHandler($this->model);
97
+            $dbsh->setSessionSecret($this->secret);
98
+			
99
+            $this->assertTrue($dbsh->open(null, null));
100
+            $this->assertTrue($dbsh->write('foo', '444'));
101
+            $this->assertNotEmpty($dbsh->read('foo'));
102
+            $this->assertEquals($dbsh->read('foo'), '444');
103
+            //do update of existing data
104
+            $this->assertTrue($dbsh->write('foo', '445'));
105
+            $this->assertEquals($dbsh->read('foo'), '445');	
106
+        }
107
+		
108
+        public function testUsingCustomModelInstance(){
109
+            $dbsh = new DBSessionHandler($this->model);
110
+            $dbsh->setSessionSecret($this->secret);
111
+			
112
+            $this->assertTrue($dbsh->open(null, null));
113
+            $this->assertTrue($dbsh->close());
114
+            $this->assertNull($dbsh->read('foo'));
115
+            $this->assertTrue($dbsh->write('foo', '444'));
116
+            $this->assertNotEmpty($dbsh->read('foo'));
117
+            $this->assertEquals($dbsh->read('foo'), '444');
118
+            //put it in expired
119
+            $this->model->update('foo', array('s_time' => 1234567));
120
+			
121
+            $this->assertNull($dbsh->read('foo'));
122
+            $this->assertTrue($dbsh->write('foo', '444'));
123
+			
124
+            //do update of existing data
125
+            $this->assertTrue($dbsh->write('foo', '445'));
126
+            $this->assertEquals($dbsh->read('foo'), '445');	
127
+            $this->assertTrue($dbsh->destroy('foo'));
128
+            $this->assertNull($dbsh->read('foo'));
129
+            $this->assertTrue($dbsh->gc(13));
130
+            $encoded = $dbsh->encode('foo');
131
+            $this->assertNotEmpty($encoded);
132
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
133
+        }
134
+			
135
+			
136
+        public function testUsingCustomLogInstance(){
137
+            $dbsh = new DBSessionHandler($this->model, new Log());
138
+            $dbsh->setSessionSecret($this->secret);
139
+			
140
+            $this->assertTrue($dbsh->open(null, null));
141
+            $this->assertTrue($dbsh->close());
142
+            $this->assertNull($dbsh->read('foo'));
143
+            $this->assertTrue($dbsh->write('foo', '444'));
144
+            $this->assertNotEmpty($dbsh->read('foo'));
145
+            $this->assertEquals($dbsh->read('foo'), '444');
146
+            //put it in expired
147
+            $this->model->update('foo', array('s_time' => 1234567));
148
+			
149
+            $this->assertNull($dbsh->read('foo'));
150
+            $this->assertTrue($dbsh->write('foo', '444'));
151
+			
152
+            //do update of existing data
153
+            $this->assertTrue($dbsh->write('foo', '445'));
154
+            $this->assertEquals($dbsh->read('foo'), '445');	
155
+            $this->assertTrue($dbsh->destroy('foo'));
156
+            $this->assertNull($dbsh->read('foo'));
157
+            $this->assertTrue($dbsh->gc(13));
158
+            $encoded = $dbsh->encode('foo');
159
+            $this->assertNotEmpty($encoded);
160
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
161
+        }
162
+		
163
+        public function testUsingCustomLoaderInstance(){
164
+            $dbsh = new DBSessionHandler($this->model, null, new Loader());
165
+            $dbsh->setSessionSecret($this->secret);
166
+			
167
+            $this->assertTrue($dbsh->open(null, null));
168
+            $this->assertTrue($dbsh->close());
169
+            $this->assertNull($dbsh->read('foo'));
170
+            $this->assertTrue($dbsh->write('foo', '444'));
171
+            $this->assertNotEmpty($dbsh->read('foo'));
172
+            $this->assertEquals($dbsh->read('foo'), '444');
173
+            //put it in expired
174
+            $this->model->update('foo', array('s_time' => 1234567));
175
+			
176
+            $this->assertNull($dbsh->read('foo'));
177
+            $this->assertTrue($dbsh->write('foo', '444'));
178
+			
179
+            //do update of existing data
180
+            $this->assertTrue($dbsh->write('foo', '445'));
181
+            $this->assertEquals($dbsh->read('foo'), '445');	
182
+            $this->assertTrue($dbsh->destroy('foo'));
183
+            $this->assertNull($dbsh->read('foo'));
184
+            $this->assertTrue($dbsh->gc(13));
185
+            $encoded = $dbsh->encode('foo');
186
+            $this->assertNotEmpty($encoded);
187
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
188
+        }
189
+		
190
+		
191
+        public function testWhenModelInsanceIsNotSet(){
192
+            $dbsh = new DBSessionHandler(null, null, new Loader());
193
+            $dbsh->setSessionSecret($this->secret);
194
+			
195
+            $this->assertTrue($dbsh->open(null, null));
196
+            $this->assertTrue($dbsh->close());
197
+            $this->assertNull($dbsh->read('foo'));
198
+            $this->assertTrue($dbsh->write('foo', '444'));
199
+            $this->assertNotEmpty($dbsh->read('foo'));
200
+            $this->assertEquals($dbsh->read('foo'), '444');
201
+            //put it in expired
202
+            $this->model->update('foo', array('s_time' => 1234567));
203
+			
204
+            $this->assertNull($dbsh->read('foo'));
205
+            $this->assertTrue($dbsh->write('foo', '444'));
206
+			
207
+            //do update of existing data
208
+            $this->assertTrue($dbsh->write('tnh', '445'));
209
+            $this->assertTrue($dbsh->write('foo', '445'));
210
+            $this->assertEquals($dbsh->read('foo'), '445');	
211
+            $this->assertTrue($dbsh->destroy('foo'));
212
+            $this->assertNull($dbsh->read('foo'));
213
+            $this->assertTrue($dbsh->gc(13));
214
+            $encoded = $dbsh->encode('foo');
215
+            $this->assertNotEmpty($encoded);
216
+            $this->assertEquals($dbsh->decode($encoded), 'foo');
217
+        }
218
+		
219
+        public function testWhenModelTableColumnsIsNotSet(){
220
+            //session table is empty
221
+            $this->model->setSessionTableColumns(array());
222
+            $dbsh = new DBSessionHandler($this->model);
223
+            $this->assertTrue($dbsh->open(null, null));
224
+        }
225
+		
226
+		
227
+    }
228 228
\ No newline at end of file
Please login to merge, or discard this patch.