Passed
Push — 1.0.0-dev ( 83bedf...ceb5d8 )
by nguereza
02:34
created
tests/hmvc/models/DBSessionModel.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	class DBSessionModel extends DBSessionHandlerModel{
2
+	class DBSessionModel extends DBSessionHandlerModel {
3 3
 		
4 4
 		protected $_table = 'ses';
5 5
 		protected $primary_key = 's_id';
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 			'skey' => 'test_id' //VARCHAR(255) 
15 15
 		);
16 16
 		
17
-		public function deleteByTime($time){
17
+		public function deleteByTime($time) {
18 18
 			$this->getQueryBuilder()->from($this->_table)
19 19
 									->where('s_time', '<', $time);
20 20
 			$this->_database->delete();
21 21
 		}
22 22
 
23 23
 		
24
-		public function getKeyValue(){
24
+		public function getKeyValue() {
25 25
 			$user_id = 0;
26 26
 			return $user_id;
27 27
 		}
Please login to merge, or discard this patch.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1 1
 <?php
2
-	class DBSessionModel extends DBSessionHandlerModel{
2
+    class DBSessionModel extends DBSessionHandlerModel{
3 3
 		
4
-		protected $_table = 'ses';
5
-		protected $primary_key = 's_id';
4
+        protected $_table = 'ses';
5
+        protected $primary_key = 's_id';
6 6
 		
7
-		protected $sessionTableColumns = array(
8
-			'sid' => 's_id', //VARCHAR(255)
9
-			'sdata' => 's_data', //TEXT
10
-			'stime' => 's_time', //unix timestamp (INT|BIGINT)
11
-			'shost' => 's_host', //VARCHAR(255)
12
-			'sip' => 's_ip', //VARCHAR(255) 
13
-			'sbrowser' => 's_browser', //VARCHAR(255) 
14
-			'skey' => 'test_id' //VARCHAR(255) 
15
-		);
7
+        protected $sessionTableColumns = array(
8
+            'sid' => 's_id', //VARCHAR(255)
9
+            'sdata' => 's_data', //TEXT
10
+            'stime' => 's_time', //unix timestamp (INT|BIGINT)
11
+            'shost' => 's_host', //VARCHAR(255)
12
+            'sip' => 's_ip', //VARCHAR(255) 
13
+            'sbrowser' => 's_browser', //VARCHAR(255) 
14
+            'skey' => 'test_id' //VARCHAR(255) 
15
+        );
16 16
 		
17
-		public function deleteByTime($time){
18
-			$this->getQueryBuilder()->from($this->_table)
19
-									->where('s_time', '<', $time);
20
-			$this->_database->delete();
21
-		}
17
+        public function deleteByTime($time){
18
+            $this->getQueryBuilder()->from($this->_table)
19
+                                    ->where('s_time', '<', $time);
20
+            $this->_database->delete();
21
+        }
22 22
 
23 23
 		
24
-		public function getKeyValue(){
25
-			$user_id = 0;
26
-			return $user_id;
27
-		}
28
-	}
29 24
\ No newline at end of file
25
+        public function getKeyValue(){
26
+            $user_id = 0;
27
+            return $user_id;
28
+        }
29
+    }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
tests/include/autoloader.php 3 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 	//Autoload function
3
-	function tests_autoload($class){
3
+	function tests_autoload($class) {
4 4
 		$classesMap = array(
5 5
 			//Caches
6 6
 			'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php',
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 			'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php',
41 41
 			'Upload' => CORE_LIBRARY_PATH . 'Upload.php',
42 42
 		);
43
-		if(isset($classesMap[$class])){
44
-			if(file_exists($classesMap[$class])){
43
+		if (isset($classesMap[$class])) {
44
+			if (file_exists($classesMap[$class])) {
45 45
 				require_once $classesMap[$class];
46 46
 			}
47
-			else{
47
+			else {
48 48
 				echo 'File for class ' . $class . ' not found';
49 49
 			}
50 50
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,8 +43,7 @@
 block discarded – undo
43 43
 		if(isset($classesMap[$class])){
44 44
 			if(file_exists($classesMap[$class])){
45 45
 				require_once $classesMap[$class];
46
-			}
47
-			else{
46
+			} else{
48 47
 				echo 'File for class ' . $class . ' not found';
49 48
 			}
50 49
 		}
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,54 +1,54 @@
 block discarded – undo
1 1
 <?php
2
-	//Autoload function
3
-	function tests_autoload($class){
4
-		$classesMap = array(
5
-			//Caches
6
-			'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php',
7
-			'CacheInterface' => CORE_CLASSES_CACHE_PATH . 'CacheInterface.php',
8
-			'FileCache' => CORE_CLASSES_CACHE_PATH . 'FileCache.php',
9
-			//models
10
-			'DBSessionHandlerModel' => CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php',
11
-			'Model' => CORE_CLASSES_MODEL_PATH . 'Model.php',
12
-			//Core classes
13
-			'Config' => CORE_CLASSES_PATH . 'Config.php',
14
-			'Controller' => CORE_CLASSES_PATH . 'Controller.php',
15
-			'Database' => CORE_CLASSES_DATABASE_PATH . 'Database.php',
16
-			'DatabaseQueryBuilder' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryBuilder.php',
17
-			'DatabaseQueryResult' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryResult.php',
18
-			'DatabaseQueryRunner' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryRunner.php',
19
-			'DBSessionHandler' => CORE_CLASSES_PATH . 'DBSessionHandler.php',
20
-			'EventInfo' => CORE_CLASSES_PATH . 'EventInfo.php',
21
-			'EventDispatcher' => CORE_CLASSES_PATH . 'EventDispatcher.php',
22
-			'Lang' => CORE_CLASSES_PATH . 'Lang.php',
23
-			'Loader' => CORE_CLASSES_PATH . 'Loader.php',
24
-			'Log' => CORE_CLASSES_PATH . 'Log.php',
25
-			'Module' => CORE_CLASSES_PATH . 'Module.php',
26
-			'Request' => CORE_CLASSES_PATH . 'Request.php',
27
-			'Response' => CORE_CLASSES_PATH . 'Response.php',
28
-			'Router' => CORE_CLASSES_PATH . 'Router.php',
29
-			'Security' => CORE_CLASSES_PATH . 'Security.php',
30
-			'Session' => CORE_CLASSES_PATH . 'Session.php',
31
-			'Url' => CORE_CLASSES_PATH . 'Url.php',
32
-			//Core libraries
33
-			'Assets' => CORE_LIBRARY_PATH . 'Assets.php',
34
-			'Benchmark' => CORE_LIBRARY_PATH . 'Benchmark.php',
35
-			'Browser' => CORE_LIBRARY_PATH . 'Browser.php',
36
-			'Cookie' => CORE_LIBRARY_PATH . 'Cookie.php',
37
-			'Email' => CORE_LIBRARY_PATH . 'Email.php',
38
-			'Form' => CORE_LIBRARY_PATH . 'Form.php',
39
-			'FormValidation' => CORE_LIBRARY_PATH . 'FormValidation.php',
40
-			'Html' => CORE_LIBRARY_PATH . 'Html.php',
41
-			'Pagination' => CORE_LIBRARY_PATH . 'Pagination.php',
42
-			'PDF' => CORE_LIBRARY_PATH . 'PDF.php',
43
-			'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php',
44
-			'Upload' => CORE_LIBRARY_PATH . 'Upload.php',
45
-		);
46
-		if(isset($classesMap[$class])){
47
-			if(file_exists($classesMap[$class])){
48
-				require_once $classesMap[$class];
49
-			}
50
-			else{
51
-				echo 'File for class ' . $class . ' not found';
52
-			}
53
-		}
54
-	}
55 2
\ No newline at end of file
3
+    //Autoload function
4
+    function tests_autoload($class){
5
+        $classesMap = array(
6
+            //Caches
7
+            'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php',
8
+            'CacheInterface' => CORE_CLASSES_CACHE_PATH . 'CacheInterface.php',
9
+            'FileCache' => CORE_CLASSES_CACHE_PATH . 'FileCache.php',
10
+            //models
11
+            'DBSessionHandlerModel' => CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php',
12
+            'Model' => CORE_CLASSES_MODEL_PATH . 'Model.php',
13
+            //Core classes
14
+            'Config' => CORE_CLASSES_PATH . 'Config.php',
15
+            'Controller' => CORE_CLASSES_PATH . 'Controller.php',
16
+            'Database' => CORE_CLASSES_DATABASE_PATH . 'Database.php',
17
+            'DatabaseQueryBuilder' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryBuilder.php',
18
+            'DatabaseQueryResult' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryResult.php',
19
+            'DatabaseQueryRunner' => CORE_CLASSES_DATABASE_PATH . 'DatabaseQueryRunner.php',
20
+            'DBSessionHandler' => CORE_CLASSES_PATH . 'DBSessionHandler.php',
21
+            'EventInfo' => CORE_CLASSES_PATH . 'EventInfo.php',
22
+            'EventDispatcher' => CORE_CLASSES_PATH . 'EventDispatcher.php',
23
+            'Lang' => CORE_CLASSES_PATH . 'Lang.php',
24
+            'Loader' => CORE_CLASSES_PATH . 'Loader.php',
25
+            'Log' => CORE_CLASSES_PATH . 'Log.php',
26
+            'Module' => CORE_CLASSES_PATH . 'Module.php',
27
+            'Request' => CORE_CLASSES_PATH . 'Request.php',
28
+            'Response' => CORE_CLASSES_PATH . 'Response.php',
29
+            'Router' => CORE_CLASSES_PATH . 'Router.php',
30
+            'Security' => CORE_CLASSES_PATH . 'Security.php',
31
+            'Session' => CORE_CLASSES_PATH . 'Session.php',
32
+            'Url' => CORE_CLASSES_PATH . 'Url.php',
33
+            //Core libraries
34
+            'Assets' => CORE_LIBRARY_PATH . 'Assets.php',
35
+            'Benchmark' => CORE_LIBRARY_PATH . 'Benchmark.php',
36
+            'Browser' => CORE_LIBRARY_PATH . 'Browser.php',
37
+            'Cookie' => CORE_LIBRARY_PATH . 'Cookie.php',
38
+            'Email' => CORE_LIBRARY_PATH . 'Email.php',
39
+            'Form' => CORE_LIBRARY_PATH . 'Form.php',
40
+            'FormValidation' => CORE_LIBRARY_PATH . 'FormValidation.php',
41
+            'Html' => CORE_LIBRARY_PATH . 'Html.php',
42
+            'Pagination' => CORE_LIBRARY_PATH . 'Pagination.php',
43
+            'PDF' => CORE_LIBRARY_PATH . 'PDF.php',
44
+            'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php',
45
+            'Upload' => CORE_LIBRARY_PATH . 'Upload.php',
46
+        );
47
+        if(isset($classesMap[$class])){
48
+            if(file_exists($classesMap[$class])){
49
+                require_once $classesMap[$class];
50
+            }
51
+            else{
52
+                echo 'File for class ' . $class . ' not found';
53
+            }
54
+        }
55
+    }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
core/common.php 3 patches
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 		//put the first letter of class to upper case 
54 54
 		$class = ucfirst($class);
55 55
 		static $classes = array();
56
-		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){
56
+		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') {
57 57
 			return $classes[$class];
58 58
 		}
59 59
 		$found = false;
60 60
 		foreach (array(ROOT_PATH, CORE_PATH) as $path) {
61 61
 			$file = $path . $dir . '/' . $class . '.php';
62
-			if (file_exists($file)){
63
-				if (class_exists($class, false) === false){
62
+			if (file_exists($file)) {
63
+				if (class_exists($class, false) === false) {
64 64
 					require_once $file;
65 65
 				}
66 66
 				//already found
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 				break;
69 69
 			}
70 70
 		}
71
-		if (! $found){
71
+		if (!$found) {
72 72
 			//can't use show_error() at this time because some dependencies not yet loaded
73 73
 			set_http_status_header(503);
74 74
 			echo 'Cannot find the class [' . $class . ']';
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		/*
79 79
 		   TODO use the best method to get the Log instance
80 80
 		 */
81
-		if ($class == 'Log'){
81
+		if ($class == 'Log') {
82 82
 			//can't use the instruction like "return new Log()" 
83 83
 			//because we need return the reference instance of the loaded class.
84 84
 			$log = new Log();
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	function & class_loaded($class = null){
104 104
 		static $list = array();
105
-		if ($class !== null){
105
+		if ($class !== null) {
106 106
 			$list[strtolower($class)] = $class;
107 107
 		}
108 108
 		return $list;
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	function & load_configurations(array $overwrite_values = array()){
119 119
 		static $config;
120
-		if (empty($config)){
120
+		if (empty($config)) {
121 121
 			$file = CONFIG_PATH . 'config.php';
122 122
 			$found = false;
123
-			if (file_exists($file)){
123
+			if (file_exists($file)) {
124 124
 				require_once $file;
125 125
 				$found = true;
126 126
 			}
127
-			if (! $found){
127
+			if (!$found) {
128 128
 				set_http_status_header(503);
129 129
 				echo 'Unable to find the configuration file [' . $file . ']';
130 130
 				die();
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
 	 * 
145 145
 	 * @return mixed          the config value
146 146
 	 */
147
-	function get_config($key, $default = null){
147
+	function get_config($key, $default = null) {
148 148
 		static $cfg;
149
-		if (empty($cfg)){
149
+		if (empty($cfg)) {
150 150
 			$cfg[0] = & load_configurations();
151 151
 		}
152 152
 		return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
 	 * 
161 161
 	 * @codeCoverageIgnore
162 162
 	 */
163
-	function save_to_log($level, $message, $logger = null){
164
-		$log =& class_loader('Log', 'classes');
165
-		if ($logger){
163
+	function save_to_log($level, $message, $logger = null) {
164
+		$log = & class_loader('Log', 'classes');
165
+		if ($logger) {
166 166
 			$log->setLogger($logger);
167 167
 		}
168 168
 		$log->writeLog($message, $level);
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 * 
176 176
 	 * @codeCoverageIgnore
177 177
 	 */
178
-	function set_http_status_header($code = 200, $text = null){
179
-		if (empty($text)){
178
+	function set_http_status_header($code = 200, $text = null) {
179
+		if (empty($text)) {
180 180
 			$http_status = array(
181 181
 								100 => 'Continue',
182 182
 								101 => 'Switching Protocols',
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
 								504 => 'Gateway Timeout',
225 225
 								505 => 'HTTP Version Not Supported',
226 226
 							);
227
-			if (isset($http_status[$code])){
227
+			if (isset($http_status[$code])) {
228 228
 				$text = $http_status[$code];
229 229
 			}
230
-			else{
230
+			else {
231 231
 				show_error('No HTTP status text found for your code please check it.');
232 232
 			}
233 233
 		}
234 234
 		
235
-		if (strpos(php_sapi_name(), 'cgi') === 0){
235
+		if (strpos(php_sapi_name(), 'cgi') === 0) {
236 236
 			header('Status: ' . $code . ' ' . $text, TRUE);
237 237
 		}
238
-		else{
238
+		else {
239 239
 			$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
240 240
 			header($proto . ' ' . $code . ' ' . $text, TRUE, $code);
241 241
 		}
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 	 *  
251 251
 	 *  @codeCoverageIgnore
252 252
 	 */
253
-	function show_error($msg, $title = 'error', $logging = true){
253
+	function show_error($msg, $title = 'error', $logging = true) {
254 254
 		$title = strtoupper($title);
255 255
 		$data = array();
256 256
 		$data['error'] = $msg;
257 257
 		$data['title'] = $title;
258
-		if ($logging){
259
-			save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR');
258
+		if ($logging) {
259
+			save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR');
260 260
 		}
261 261
 		$response = & class_loader('Response', 'classes');
262 262
 		$response->sendError($data);
@@ -270,18 +270,18 @@  discard block
 block discarded – undo
270 270
 	 *  
271 271
 	 *  @return boolean true if the web server uses the https protocol, false if not.
272 272
 	 */
273
-	function is_https(){
273
+	function is_https() {
274 274
 		/*
275 275
 		* some servers pass the "HTTPS" parameter in the server variable,
276 276
 		* if is the case, check if the value is "on", "true", "1".
277 277
 		*/
278
-		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){
278
+		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
279 279
 			return true;
280 280
 		}
281
-		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
281
+		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
282 282
 			return true;
283 283
 		}
284
-		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
284
+		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
285 285
 			return true;
286 286
 		}
287 287
 		return false;
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 *  
297 297
 	 *  @return boolean true if is a valid URL address or false.
298 298
 	 */
299
-	function is_url($url){
299
+	function is_url($url) {
300 300
 		return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1;
301 301
 	}
302 302
 	
@@ -306,8 +306,8 @@  discard block
 block discarded – undo
306 306
 	 *  @param string $controllerClass the controller class name to be loaded
307 307
 	 *  @codeCoverageIgnore
308 308
 	 */
309
-	function autoload_controller($controllerClass){
310
-		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){
309
+	function autoload_controller($controllerClass) {
310
+		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) {
311 311
 			require_once $path;
312 312
 		}
313 313
 	}
@@ -321,11 +321,11 @@  discard block
 block discarded – undo
321 321
 	 *  
322 322
 	 *  @return boolean
323 323
 	 */
324
-	function php_exception_handler($ex){
325
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
326
-			show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
324
+	function php_exception_handler($ex) {
325
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
326
+			show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
327 327
 		}
328
-		else{
328
+		else {
329 329
 			save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception');
330 330
 		}
331 331
 		return true;
@@ -342,16 +342,16 @@  discard block
 block discarded – undo
342 342
 	 *  
343 343
 	 *  @return boolean	
344 344
 	 */
345
-	function php_error_handler($errno , $errstr, $errfile , $errline){
345
+	function php_error_handler($errno, $errstr, $errfile, $errline) {
346 346
 		$isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno);
347
-		if ($isError){
347
+		if ($isError) {
348 348
 			set_http_status_header(500);
349 349
 		}
350
-		if (! (error_reporting() & $errno)) {
350
+		if (!(error_reporting() & $errno)) {
351 351
 			save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR');
352 352
 			return;
353 353
 		}
354
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
354
+		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) {
355 355
 			$errorType = 'error';
356 356
 			switch ($errno) {
357 357
 				case E_USER_ERROR:
@@ -367,9 +367,9 @@  discard block
 block discarded – undo
367 367
 					$errorType = 'error';
368 368
 					break;
369 369
 			}
370
-			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType);
370
+			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType);
371 371
 		}
372
-		if ($isError){
372
+		if ($isError) {
373 373
 			die();
374 374
 		}
375 375
 		return true;
@@ -379,10 +379,10 @@  discard block
 block discarded – undo
379 379
 	 * This function is used to run in shutdown situation of the script
380 380
 	 * @codeCoverageIgnore
381 381
 	 */
382
-	function php_shudown_handler(){
382
+	function php_shudown_handler() {
383 383
 		$lastError = error_get_last();
384 384
 		if (isset($lastError) &&
385
-			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){
385
+			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) {
386 386
 			php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
387 387
 		}
388 388
 	}
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 *   
401 401
 	 *  @return string string of the HTML attribute.
402 402
 	 */
403
-	function attributes_to_string(array $attributes){
403
+	function attributes_to_string(array $attributes) {
404 404
 		$str = ' ';
405 405
 		//we check that the array passed as an argument is not empty.
406
-		if (! empty($attributes)){
407
-			foreach($attributes as $key => $value){
406
+		if (!empty($attributes)) {
407
+			foreach ($attributes as $key => $value) {
408 408
 				$key = trim(htmlspecialchars($key));
409 409
 				$value = trim(htmlspecialchars($value));
410 410
 				/*
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
 				* 	$attr = array('placeholder' => 'I am a "puple"')
415 415
 				* 	$str = attributes_to_string($attr); => placeholder = "I am a \"puple\""
416 416
 				 */
417
-				if ($value && strpos('"', $value) !== false){
417
+				if ($value && strpos('"', $value) !== false) {
418 418
 					$value = addslashes($value);
419 419
 				}
420
-				$str .= $key.' = "'.$value.'" ';
420
+				$str .= $key . ' = "' . $value . '" ';
421 421
 			}
422 422
 		}
423 423
 		//remove the space after using rtrim()
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	*
434 434
 	* @return string the stringfy value
435 435
 	*/
436
-	function stringfy_vars($var){
436
+	function stringfy_vars($var) {
437 437
 		return print_r($var, true);
438 438
 	}
439 439
 
@@ -444,18 +444,18 @@  discard block
 block discarded – undo
444 444
 	 * 
445 445
 	 * @return mixed   the sanitize value
446 446
 	 */
447
-	function clean_input($str){
448
-		if (is_array($str)){
447
+	function clean_input($str) {
448
+		if (is_array($str)) {
449 449
 			$str = array_map('clean_input', $str);
450 450
 		}
451
-		else if (is_object($str)){
451
+		else if (is_object($str)) {
452 452
 			$obj = $str;
453 453
 			foreach ($str as $var => $value) {
454 454
 				$obj->$var = clean_input($value);
455 455
 			}
456 456
 			$str = $obj;
457 457
 		}
458
-		else{
458
+		else {
459 459
 			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
460 460
 		}
461 461
 		return $str;
@@ -473,11 +473,11 @@  discard block
 block discarded – undo
473 473
 	 * 
474 474
 	 * @return string the string with the hidden part.
475 475
 	 */
476
-	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
476
+	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') {
477 477
 		//get the string length
478 478
 		$len = strlen($str);
479 479
 		//if str is empty
480
-		if ($len <= 0){
480
+		if ($len <= 0) {
481 481
 			return str_repeat($hiddenChar, 6);
482 482
 		}
483 483
 		//if the length is less than startCount and endCount
@@ -485,14 +485,14 @@  discard block
 block discarded – undo
485 485
 		//or startCount is negative or endCount is negative
486 486
 		//return the full string hidden
487 487
 		
488
-		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
488
+		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) {
489 489
 			return str_repeat($hiddenChar, $len);
490 490
 		}
491 491
 		//the start non hidden string
492 492
 		$startNonHiddenStr = substr($str, 0, $startCount);
493 493
 		//the end non hidden string
494 494
 		$endNonHiddenStr = null;
495
-		if ($endCount > 0){
495
+		if ($endCount > 0) {
496 496
 			$endNonHiddenStr = substr($str, - $endCount);
497 497
 		}
498 498
 		//the hidden string
@@ -505,40 +505,40 @@  discard block
 block discarded – undo
505 505
 	 * This function is used to set the initial session config regarding the configuration
506 506
 	 * @codeCoverageIgnore
507 507
 	 */
508
-	function set_session_config(){
508
+	function set_session_config() {
509 509
 		//$_SESSION is not available on cli mode 
510
-		if (! IS_CLI){
511
-			$logger =& class_loader('Log', 'classes');
510
+		if (!IS_CLI) {
511
+			$logger = & class_loader('Log', 'classes');
512 512
 			$logger->setLogger('PHPSession');
513 513
 			//set session params
514 514
 			$sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files
515 515
 			$sessionName = get_config('session_name');
516
-			if ($sessionName){
516
+			if ($sessionName) {
517 517
 				session_name($sessionName);
518 518
 			}
519 519
 			$logger->info('Session handler: ' . $sessionHandler);
520 520
 			$logger->info('Session name: ' . $sessionName);
521 521
 
522
-			if ($sessionHandler == 'files'){
522
+			if ($sessionHandler == 'files') {
523 523
 				$sessionSavePath = get_config('session_save_path');
524
-				if ($sessionSavePath){
525
-					if (! is_dir($sessionSavePath)){
524
+				if ($sessionSavePath) {
525
+					if (!is_dir($sessionSavePath)) {
526 526
 						mkdir($sessionSavePath, 1773);
527 527
 					}
528 528
 					session_save_path($sessionSavePath);
529 529
 					$logger->info('Session save path: ' . $sessionSavePath);
530 530
 				}
531 531
 			}
532
-			else if ($sessionHandler == 'database'){
532
+			else if ($sessionHandler == 'database') {
533 533
 				//load database session handle library
534 534
 				//Database Session handler Model
535 535
 				require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php';
536 536
 
537
-				$DBS =& class_loader('DBSessionHandler', 'classes');
537
+				$DBS = & class_loader('DBSessionHandler', 'classes');
538 538
 				session_set_save_handler($DBS, true);
539 539
 				$logger->info('session save path: ' . get_config('session_save_path'));
540 540
 			}
541
-			else{
541
+			else {
542 542
 				show_error('Invalid session handler configuration');
543 543
 			}
544 544
 			$lifetime = get_config('session_cookie_lifetime', 0);
@@ -561,9 +561,9 @@  discard block
 block discarded – undo
561 561
 			$logger->info('Session lifetime: ' . $lifetime);
562 562
 			$logger->info('Session cookie path: ' . $path);
563 563
 			$logger->info('Session domain: ' . $domain);
564
-			$logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE'));
564
+			$logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE'));
565 565
 			
566
-			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){
566
+			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) {
567 567
 				$logger->info('Session not yet start, start it now');
568 568
 				session_start();
569 569
 			}
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -226,16 +226,14 @@  discard block
 block discarded – undo
226 226
 							);
227 227
 			if (isset($http_status[$code])){
228 228
 				$text = $http_status[$code];
229
-			}
230
-			else{
229
+			} else{
231 230
 				show_error('No HTTP status text found for your code please check it.');
232 231
 			}
233 232
 		}
234 233
 		
235 234
 		if (strpos(php_sapi_name(), 'cgi') === 0){
236 235
 			header('Status: ' . $code . ' ' . $text, TRUE);
237
-		}
238
-		else{
236
+		} else{
239 237
 			$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
240 238
 			header($proto . ' ' . $code . ' ' . $text, TRUE, $code);
241 239
 		}
@@ -277,11 +275,9 @@  discard block
 block discarded – undo
277 275
 		*/
278 276
 		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){
279 277
 			return true;
280
-		}
281
-		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
278
+		} else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
282 279
 			return true;
283
-		}
284
-		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
280
+		} else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
285 281
 			return true;
286 282
 		}
287 283
 		return false;
@@ -324,8 +320,7 @@  discard block
 block discarded – undo
324 320
 	function php_exception_handler($ex){
325 321
 		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
326 322
 			show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
327
-		}
328
-		else{
323
+		} else{
329 324
 			save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception');
330 325
 		}
331 326
 		return true;
@@ -447,15 +442,13 @@  discard block
 block discarded – undo
447 442
 	function clean_input($str){
448 443
 		if (is_array($str)){
449 444
 			$str = array_map('clean_input', $str);
450
-		}
451
-		else if (is_object($str)){
445
+		} else if (is_object($str)){
452 446
 			$obj = $str;
453 447
 			foreach ($str as $var => $value) {
454 448
 				$obj->$var = clean_input($value);
455 449
 			}
456 450
 			$str = $obj;
457
-		}
458
-		else{
451
+		} else{
459 452
 			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
460 453
 		}
461 454
 		return $str;
@@ -528,8 +521,7 @@  discard block
 block discarded – undo
528 521
 					session_save_path($sessionSavePath);
529 522
 					$logger->info('Session save path: ' . $sessionSavePath);
530 523
 				}
531
-			}
532
-			else if ($sessionHandler == 'database'){
524
+			} else if ($sessionHandler == 'database'){
533 525
 				//load database session handle library
534 526
 				//Database Session handler Model
535 527
 				require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php';
@@ -537,8 +529,7 @@  discard block
 block discarded – undo
537 529
 				$DBS =& class_loader('DBSessionHandler', 'classes');
538 530
 				session_set_save_handler($DBS, true);
539 531
 				$logger->info('session save path: ' . get_config('session_save_path'));
540
-			}
541
-			else{
532
+			} else{
542 533
 				show_error('Invalid session handler configuration');
543 534
 			}
544 535
 			$lifetime = get_config('session_cookie_lifetime', 0);
Please login to merge, or discard this patch.
Indentation   +536 added lines, -536 removed lines patch added patch discarded remove patch
@@ -1,585 +1,585 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 *  @file common.php
29
-	 *  
30
-	 *  Contains most of the commons functions used by the system
31
-	 *  
32
-	 *  @package	core
33
-	 *  @author	Tony NGUEREZA
34
-	 *  @copyright	Copyright (c) 2017
35
-	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
-	 *  @link	http://www.iacademy.cf
37
-	 *  @version 1.0.0
38
-	 *  @filesource
39
-	 */
27
+    /**
28
+     *  @file common.php
29
+     *  
30
+     *  Contains most of the commons functions used by the system
31
+     *  
32
+     *  @package	core
33
+     *  @author	Tony NGUEREZA
34
+     *  @copyright	Copyright (c) 2017
35
+     *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
36
+     *  @link	http://www.iacademy.cf
37
+     *  @version 1.0.0
38
+     *  @filesource
39
+     */
40 40
 	
41 41
 
42
-	/**
43
-	 * This function is the class loader helper is used if the library "Loader" not yet loaded
44
-	 * he load the class once
45
-	 * @param  string $class  the class name to be loaded
46
-	 * @param  string $dir    the directory where to find the class
47
-	 * @param  mixed $params the parameter to pass as argument to the constructor of the class
48
-	 * @codeCoverageIgnore
49
-	 * 
50
-	 * @return object         the instance of the loaded class
51
-	 */
52
-	function & class_loader($class, $dir = 'libraries', $params = null){
53
-		//put the first letter of class to upper case 
54
-		$class = ucfirst($class);
55
-		static $classes = array();
56
-		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){
57
-			return $classes[$class];
58
-		}
59
-		$found = false;
60
-		foreach (array(ROOT_PATH, CORE_PATH) as $path) {
61
-			$file = $path . $dir . '/' . $class . '.php';
62
-			if (file_exists($file)){
63
-				if (class_exists($class, false) === false){
64
-					require_once $file;
65
-				}
66
-				//already found
67
-				$found = true;
68
-				break;
69
-			}
70
-		}
71
-		if (! $found){
72
-			//can't use show_error() at this time because some dependencies not yet loaded
73
-			set_http_status_header(503);
74
-			echo 'Cannot find the class [' . $class . ']';
75
-			die();
76
-		}
42
+    /**
43
+     * This function is the class loader helper is used if the library "Loader" not yet loaded
44
+     * he load the class once
45
+     * @param  string $class  the class name to be loaded
46
+     * @param  string $dir    the directory where to find the class
47
+     * @param  mixed $params the parameter to pass as argument to the constructor of the class
48
+     * @codeCoverageIgnore
49
+     * 
50
+     * @return object         the instance of the loaded class
51
+     */
52
+    function & class_loader($class, $dir = 'libraries', $params = null){
53
+        //put the first letter of class to upper case 
54
+        $class = ucfirst($class);
55
+        static $classes = array();
56
+        if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){
57
+            return $classes[$class];
58
+        }
59
+        $found = false;
60
+        foreach (array(ROOT_PATH, CORE_PATH) as $path) {
61
+            $file = $path . $dir . '/' . $class . '.php';
62
+            if (file_exists($file)){
63
+                if (class_exists($class, false) === false){
64
+                    require_once $file;
65
+                }
66
+                //already found
67
+                $found = true;
68
+                break;
69
+            }
70
+        }
71
+        if (! $found){
72
+            //can't use show_error() at this time because some dependencies not yet loaded
73
+            set_http_status_header(503);
74
+            echo 'Cannot find the class [' . $class . ']';
75
+            die();
76
+        }
77 77
 		
78
-		/*
78
+        /*
79 79
 		   TODO use the best method to get the Log instance
80 80
 		 */
81
-		if ($class == 'Log'){
82
-			//can't use the instruction like "return new Log()" 
83
-			//because we need return the reference instance of the loaded class.
84
-			$log = new Log();
85
-			return $log;
86
-		}
87
-		//track of loaded classes
88
-		class_loaded($class);
81
+        if ($class == 'Log'){
82
+            //can't use the instruction like "return new Log()" 
83
+            //because we need return the reference instance of the loaded class.
84
+            $log = new Log();
85
+            return $log;
86
+        }
87
+        //track of loaded classes
88
+        class_loaded($class);
89 89
 		
90
-		//record the class instance
91
-		$classes[$class] = isset($params) ? new $class($params) : new $class();
90
+        //record the class instance
91
+        $classes[$class] = isset($params) ? new $class($params) : new $class();
92 92
 		
93
-		return $classes[$class];
94
-	}
93
+        return $classes[$class];
94
+    }
95 95
 
96
-	/**
97
-	 * This function is the helper to record the loaded classes
98
-	 * @param  string $class the loaded class name
99
-	 * @codeCoverageIgnore
100
-	 * 
101
-	 * @return array        the list of the loaded classes
102
-	 */
103
-	function & class_loaded($class = null){
104
-		static $list = array();
105
-		if ($class !== null){
106
-			$list[strtolower($class)] = $class;
107
-		}
108
-		return $list;
109
-	}
96
+    /**
97
+     * This function is the helper to record the loaded classes
98
+     * @param  string $class the loaded class name
99
+     * @codeCoverageIgnore
100
+     * 
101
+     * @return array        the list of the loaded classes
102
+     */
103
+    function & class_loaded($class = null){
104
+        static $list = array();
105
+        if ($class !== null){
106
+            $list[strtolower($class)] = $class;
107
+        }
108
+        return $list;
109
+    }
110 110
 
111
-	/**
112
-	 * This function is used to load the configurations in the case the "Config" library not yet loaded
113
-	 * @param  array  $overwrite_values if need overwrite the existing configuration
114
-	 * @codeCoverageIgnore
115
-	 * 
116
-	 * @return array                   the configurations values
117
-	 */
118
-	function & load_configurations(array $overwrite_values = array()){
119
-		static $config;
120
-		if (empty($config)){
121
-			$file = CONFIG_PATH . 'config.php';
122
-			$found = false;
123
-			if (file_exists($file)){
124
-				require_once $file;
125
-				$found = true;
126
-			}
127
-			if (! $found){
128
-				set_http_status_header(503);
129
-				echo 'Unable to find the configuration file [' . $file . ']';
130
-				die();
131
-			}
132
-		}
133
-		foreach ($overwrite_values as $key => $value) {
134
-			$config[$key] = $value;
135
-		}
136
-		return $config;
137
-	}
111
+    /**
112
+     * This function is used to load the configurations in the case the "Config" library not yet loaded
113
+     * @param  array  $overwrite_values if need overwrite the existing configuration
114
+     * @codeCoverageIgnore
115
+     * 
116
+     * @return array                   the configurations values
117
+     */
118
+    function & load_configurations(array $overwrite_values = array()){
119
+        static $config;
120
+        if (empty($config)){
121
+            $file = CONFIG_PATH . 'config.php';
122
+            $found = false;
123
+            if (file_exists($file)){
124
+                require_once $file;
125
+                $found = true;
126
+            }
127
+            if (! $found){
128
+                set_http_status_header(503);
129
+                echo 'Unable to find the configuration file [' . $file . ']';
130
+                die();
131
+            }
132
+        }
133
+        foreach ($overwrite_values as $key => $value) {
134
+            $config[$key] = $value;
135
+        }
136
+        return $config;
137
+    }
138 138
 
139
-	/**
140
-	 * This function is the helper to get the config value in case the "Config" library not yet loaded
141
-	 * @param  string $key     the config item to get the vale
142
-	 * @param  mixed $default the default value to return if can't find the config item in the configuration
143
-	 * @test
144
-	 * 
145
-	 * @return mixed          the config value
146
-	 */
147
-	function get_config($key, $default = null){
148
-		static $cfg;
149
-		if (empty($cfg)){
150
-			$cfg[0] = & load_configurations();
151
-		}
152
-		return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
153
-	}
139
+    /**
140
+     * This function is the helper to get the config value in case the "Config" library not yet loaded
141
+     * @param  string $key     the config item to get the vale
142
+     * @param  mixed $default the default value to return if can't find the config item in the configuration
143
+     * @test
144
+     * 
145
+     * @return mixed          the config value
146
+     */
147
+    function get_config($key, $default = null){
148
+        static $cfg;
149
+        if (empty($cfg)){
150
+            $cfg[0] = & load_configurations();
151
+        }
152
+        return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
153
+    }
154 154
 
155
-	/**
156
-	 * This function is a helper to logging message
157
-	 * @param  string $level   the log level "ERROR", "DEBUG", "INFO", etc.
158
-	 * @param  string $message the log message to be saved
159
-	 * @param  string $logger  the logger to use if is set
160
-	 * 
161
-	 * @codeCoverageIgnore
162
-	 */
163
-	function save_to_log($level, $message, $logger = null){
164
-		$log =& class_loader('Log', 'classes');
165
-		if ($logger){
166
-			$log->setLogger($logger);
167
-		}
168
-		$log->writeLog($message, $level);
169
-	}
155
+    /**
156
+     * This function is a helper to logging message
157
+     * @param  string $level   the log level "ERROR", "DEBUG", "INFO", etc.
158
+     * @param  string $message the log message to be saved
159
+     * @param  string $logger  the logger to use if is set
160
+     * 
161
+     * @codeCoverageIgnore
162
+     */
163
+    function save_to_log($level, $message, $logger = null){
164
+        $log =& class_loader('Log', 'classes');
165
+        if ($logger){
166
+            $log->setLogger($logger);
167
+        }
168
+        $log->writeLog($message, $level);
169
+    }
170 170
 
171
-	/**
172
-	 * Set the HTTP status header
173
-	 * @param integer $code the HTTP status code
174
-	 * @param string  $text the HTTP status text
175
-	 * 
176
-	 * @codeCoverageIgnore
177
-	 */
178
-	function set_http_status_header($code = 200, $text = null){
179
-		if (empty($text)){
180
-			$http_status = array(
181
-								100 => 'Continue',
182
-								101 => 'Switching Protocols',
171
+    /**
172
+     * Set the HTTP status header
173
+     * @param integer $code the HTTP status code
174
+     * @param string  $text the HTTP status text
175
+     * 
176
+     * @codeCoverageIgnore
177
+     */
178
+    function set_http_status_header($code = 200, $text = null){
179
+        if (empty($text)){
180
+            $http_status = array(
181
+                                100 => 'Continue',
182
+                                101 => 'Switching Protocols',
183 183
 
184
-								200 => 'OK',
185
-								201 => 'Created',
186
-								202 => 'Accepted',
187
-								203 => 'Non-Authoritative Information',
188
-								204 => 'No Content',
189
-								205 => 'Reset Content',
190
-								206 => 'Partial Content',
184
+                                200 => 'OK',
185
+                                201 => 'Created',
186
+                                202 => 'Accepted',
187
+                                203 => 'Non-Authoritative Information',
188
+                                204 => 'No Content',
189
+                                205 => 'Reset Content',
190
+                                206 => 'Partial Content',
191 191
 
192
-								300 => 'Multiple Choices',
193
-								301 => 'Moved Permanently',
194
-								302 => 'Found',
195
-								303 => 'See Other',
196
-								304 => 'Not Modified',
197
-								305 => 'Use Proxy',
198
-								307 => 'Temporary Redirect',
192
+                                300 => 'Multiple Choices',
193
+                                301 => 'Moved Permanently',
194
+                                302 => 'Found',
195
+                                303 => 'See Other',
196
+                                304 => 'Not Modified',
197
+                                305 => 'Use Proxy',
198
+                                307 => 'Temporary Redirect',
199 199
 
200
-								400 => 'Bad Request',
201
-								401 => 'Unauthorized',
202
-								402 => 'Payment Required',
203
-								403 => 'Forbidden',
204
-								404 => 'Not Found',
205
-								405 => 'Method Not Allowed',
206
-								406 => 'Not Acceptable',
207
-								407 => 'Proxy Authentication Required',
208
-								408 => 'Request Timeout',
209
-								409 => 'Conflict',
210
-								410 => 'Gone',
211
-								411 => 'Length Required',
212
-								412 => 'Precondition Failed',
213
-								413 => 'Request Entity Too Large',
214
-								414 => 'Request-URI Too Long',
215
-								415 => 'Unsupported Media Type',
216
-								416 => 'Requested Range Not Satisfiable',
217
-								417 => 'Expectation Failed',
218
-								418 => 'I\'m a teapot',
200
+                                400 => 'Bad Request',
201
+                                401 => 'Unauthorized',
202
+                                402 => 'Payment Required',
203
+                                403 => 'Forbidden',
204
+                                404 => 'Not Found',
205
+                                405 => 'Method Not Allowed',
206
+                                406 => 'Not Acceptable',
207
+                                407 => 'Proxy Authentication Required',
208
+                                408 => 'Request Timeout',
209
+                                409 => 'Conflict',
210
+                                410 => 'Gone',
211
+                                411 => 'Length Required',
212
+                                412 => 'Precondition Failed',
213
+                                413 => 'Request Entity Too Large',
214
+                                414 => 'Request-URI Too Long',
215
+                                415 => 'Unsupported Media Type',
216
+                                416 => 'Requested Range Not Satisfiable',
217
+                                417 => 'Expectation Failed',
218
+                                418 => 'I\'m a teapot',
219 219
 
220
-								500 => 'Internal Server Error',
221
-								501 => 'Not Implemented',
222
-								502 => 'Bad Gateway',
223
-								503 => 'Service Unavailable',
224
-								504 => 'Gateway Timeout',
225
-								505 => 'HTTP Version Not Supported',
226
-							);
227
-			if (isset($http_status[$code])){
228
-				$text = $http_status[$code];
229
-			}
230
-			else{
231
-				show_error('No HTTP status text found for your code please check it.');
232
-			}
233
-		}
220
+                                500 => 'Internal Server Error',
221
+                                501 => 'Not Implemented',
222
+                                502 => 'Bad Gateway',
223
+                                503 => 'Service Unavailable',
224
+                                504 => 'Gateway Timeout',
225
+                                505 => 'HTTP Version Not Supported',
226
+                            );
227
+            if (isset($http_status[$code])){
228
+                $text = $http_status[$code];
229
+            }
230
+            else{
231
+                show_error('No HTTP status text found for your code please check it.');
232
+            }
233
+        }
234 234
 		
235
-		if (strpos(php_sapi_name(), 'cgi') === 0){
236
-			header('Status: ' . $code . ' ' . $text, TRUE);
237
-		}
238
-		else{
239
-			$proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
240
-			header($proto . ' ' . $code . ' ' . $text, TRUE, $code);
241
-		}
242
-	}
235
+        if (strpos(php_sapi_name(), 'cgi') === 0){
236
+            header('Status: ' . $code . ' ' . $text, TRUE);
237
+        }
238
+        else{
239
+            $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
240
+            header($proto . ' ' . $code . ' ' . $text, TRUE, $code);
241
+        }
242
+    }
243 243
 
244
-	/**
245
-	 *  This function displays an error message to the user and ends the execution of the script.
246
-	 *  
247
-	 *  @param string $msg the message to display
248
-	 *  @param string $title the message title: "error", "info", "warning", etc.
249
-	 *  @param boolean $logging either to save error in log
250
-	 *  
251
-	 *  @codeCoverageIgnore
252
-	 */
253
-	function show_error($msg, $title = 'error', $logging = true){
254
-		$title = strtoupper($title);
255
-		$data = array();
256
-		$data['error'] = $msg;
257
-		$data['title'] = $title;
258
-		if ($logging){
259
-			save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR');
260
-		}
261
-		$response = & class_loader('Response', 'classes');
262
-		$response->sendError($data);
263
-		die();
264
-	}
244
+    /**
245
+     *  This function displays an error message to the user and ends the execution of the script.
246
+     *  
247
+     *  @param string $msg the message to display
248
+     *  @param string $title the message title: "error", "info", "warning", etc.
249
+     *  @param boolean $logging either to save error in log
250
+     *  
251
+     *  @codeCoverageIgnore
252
+     */
253
+    function show_error($msg, $title = 'error', $logging = true){
254
+        $title = strtoupper($title);
255
+        $data = array();
256
+        $data['error'] = $msg;
257
+        $data['title'] = $title;
258
+        if ($logging){
259
+            save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR');
260
+        }
261
+        $response = & class_loader('Response', 'classes');
262
+        $response->sendError($data);
263
+        die();
264
+    }
265 265
 
266
-	/**
267
-	 *  Check whether the protocol used is "https" or not
268
-	 *  That is, the web server is configured to use a secure connection.
269
-	 *  @codeCoverageIgnore
270
-	 *  
271
-	 *  @return boolean true if the web server uses the https protocol, false if not.
272
-	 */
273
-	function is_https(){
274
-		/*
266
+    /**
267
+     *  Check whether the protocol used is "https" or not
268
+     *  That is, the web server is configured to use a secure connection.
269
+     *  @codeCoverageIgnore
270
+     *  
271
+     *  @return boolean true if the web server uses the https protocol, false if not.
272
+     */
273
+    function is_https(){
274
+        /*
275 275
 		* some servers pass the "HTTPS" parameter in the server variable,
276 276
 		* if is the case, check if the value is "on", "true", "1".
277 277
 		*/
278
-		if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){
279
-			return true;
280
-		}
281
-		else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
282
-			return true;
283
-		}
284
-		else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
285
-			return true;
286
-		}
287
-		return false;
288
-	}
278
+        if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){
279
+            return true;
280
+        }
281
+        else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){
282
+            return true;
283
+        }
284
+        else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){
285
+            return true;
286
+        }
287
+        return false;
288
+    }
289 289
 	
290
-	/**
291
-	 *  This function is used to check the URL format of the given string argument. 
292
-	 *  The address is valid if the protocol is http, https, ftp, etc.
293
-	 *
294
-	 *  @param string $url the URL address to check
295
-	 *  @test
296
-	 *  
297
-	 *  @return boolean true if is a valid URL address or false.
298
-	 */
299
-	function is_url($url){
300
-		return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1;
301
-	}
290
+    /**
291
+     *  This function is used to check the URL format of the given string argument. 
292
+     *  The address is valid if the protocol is http, https, ftp, etc.
293
+     *
294
+     *  @param string $url the URL address to check
295
+     *  @test
296
+     *  
297
+     *  @return boolean true if is a valid URL address or false.
298
+     */
299
+    function is_url($url){
300
+        return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1;
301
+    }
302 302
 	
303
-	/**
304
-	 *  Function defined to load controller
305
-	 *  
306
-	 *  @param string $controllerClass the controller class name to be loaded
307
-	 *  @codeCoverageIgnore
308
-	 */
309
-	function autoload_controller($controllerClass){
310
-		if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){
311
-			require_once $path;
312
-		}
313
-	}
303
+    /**
304
+     *  Function defined to load controller
305
+     *  
306
+     *  @param string $controllerClass the controller class name to be loaded
307
+     *  @codeCoverageIgnore
308
+     */
309
+    function autoload_controller($controllerClass){
310
+        if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){
311
+            require_once $path;
312
+        }
313
+    }
314 314
 	
315
-	/**
316
-	 *  Function defined for handling PHP exception error message, 
317
-	 *  it displays an error message using the function "show_error"
318
-	 *  
319
-	 *  @param object $ex instance of the "Exception" class or a derived class
320
-	 *  @codeCoverageIgnore
321
-	 *  
322
-	 *  @return boolean
323
-	 */
324
-	function php_exception_handler($ex){
325
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
326
-			show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
327
-		}
328
-		else{
329
-			save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception');
330
-		}
331
-		return true;
332
-	}
315
+    /**
316
+     *  Function defined for handling PHP exception error message, 
317
+     *  it displays an error message using the function "show_error"
318
+     *  
319
+     *  @param object $ex instance of the "Exception" class or a derived class
320
+     *  @codeCoverageIgnore
321
+     *  
322
+     *  @return boolean
323
+     */
324
+    function php_exception_handler($ex){
325
+        if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
326
+            show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode());
327
+        }
328
+        else{
329
+            save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception');
330
+        }
331
+        return true;
332
+    }
333 333
 	
334
-	/**
335
-	 *  Function defined for PHP error message handling
336
-	 *  			
337
-	 *  @param int $errno the type of error for example: E_USER_ERROR, E_USER_WARNING, etc.
338
-	 *  @param string $errstr the error message
339
-	 *  @param string $errfile the file where the error occurred
340
-	 *  @param int $errline the line number where the error occurred
341
-	 *  @codeCoverageIgnore
342
-	 *  
343
-	 *  @return boolean	
344
-	 */
345
-	function php_error_handler($errno , $errstr, $errfile , $errline){
346
-		$isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno);
347
-		if ($isError){
348
-			set_http_status_header(500);
349
-		}
350
-		if (! (error_reporting() & $errno)) {
351
-			save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR');
352
-			return;
353
-		}
354
-		if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
355
-			$errorType = 'error';
356
-			switch ($errno) {
357
-				case E_USER_ERROR:
358
-					$errorType = 'error';
359
-					break;
360
-				case E_USER_WARNING:
361
-					$errorType = 'warning';
362
-					break;
363
-				case E_USER_NOTICE:
364
-					$errorType = 'notice';
365
-					break;
366
-				default:
367
-					$errorType = 'error';
368
-					break;
369
-			}
370
-			show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType);
371
-		}
372
-		if ($isError){
373
-			die();
374
-		}
375
-		return true;
376
-	}
334
+    /**
335
+     *  Function defined for PHP error message handling
336
+     *  			
337
+     *  @param int $errno the type of error for example: E_USER_ERROR, E_USER_WARNING, etc.
338
+     *  @param string $errstr the error message
339
+     *  @param string $errfile the file where the error occurred
340
+     *  @param int $errline the line number where the error occurred
341
+     *  @codeCoverageIgnore
342
+     *  
343
+     *  @return boolean	
344
+     */
345
+    function php_error_handler($errno , $errstr, $errfile , $errline){
346
+        $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno);
347
+        if ($isError){
348
+            set_http_status_header(500);
349
+        }
350
+        if (! (error_reporting() & $errno)) {
351
+            save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR');
352
+            return;
353
+        }
354
+        if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){
355
+            $errorType = 'error';
356
+            switch ($errno) {
357
+                case E_USER_ERROR:
358
+                    $errorType = 'error';
359
+                    break;
360
+                case E_USER_WARNING:
361
+                    $errorType = 'warning';
362
+                    break;
363
+                case E_USER_NOTICE:
364
+                    $errorType = 'notice';
365
+                    break;
366
+                default:
367
+                    $errorType = 'error';
368
+                    break;
369
+            }
370
+            show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType);
371
+        }
372
+        if ($isError){
373
+            die();
374
+        }
375
+        return true;
376
+    }
377 377
 
378
-	/**
379
-	 * This function is used to run in shutdown situation of the script
380
-	 * @codeCoverageIgnore
381
-	 */
382
-	function php_shudown_handler(){
383
-		$lastError = error_get_last();
384
-		if (isset($lastError) &&
385
-			($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){
386
-			php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
387
-		}
388
-	}
378
+    /**
379
+     * This function is used to run in shutdown situation of the script
380
+     * @codeCoverageIgnore
381
+     */
382
+    function php_shudown_handler(){
383
+        $lastError = error_get_last();
384
+        if (isset($lastError) &&
385
+            ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){
386
+            php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
387
+        }
388
+    }
389 389
 
390 390
 
391
-	/**
392
-	 *  Convert array attributes to string
393
-	 *
394
-	 *  This function converts an associative array into HTML attributes.
395
-	 *  For example :
396
-	 *  $a = array('name' => 'Foo', 'type' => 'text'); => produces the following string:
397
-	 *  name = "Foo" type = "text"
398
-	 *
399
-	 *  @param array $attributes associative array to convert to a string attribute.
400
-	 *   
401
-	 *  @return string string of the HTML attribute.
402
-	 */
403
-	function attributes_to_string(array $attributes){
404
-		$str = ' ';
405
-		//we check that the array passed as an argument is not empty.
406
-		if (! empty($attributes)){
407
-			foreach($attributes as $key => $value){
408
-				$key = trim(htmlspecialchars($key));
409
-				$value = trim(htmlspecialchars($value));
410
-				/*
391
+    /**
392
+     *  Convert array attributes to string
393
+     *
394
+     *  This function converts an associative array into HTML attributes.
395
+     *  For example :
396
+     *  $a = array('name' => 'Foo', 'type' => 'text'); => produces the following string:
397
+     *  name = "Foo" type = "text"
398
+     *
399
+     *  @param array $attributes associative array to convert to a string attribute.
400
+     *   
401
+     *  @return string string of the HTML attribute.
402
+     */
403
+    function attributes_to_string(array $attributes){
404
+        $str = ' ';
405
+        //we check that the array passed as an argument is not empty.
406
+        if (! empty($attributes)){
407
+            foreach($attributes as $key => $value){
408
+                $key = trim(htmlspecialchars($key));
409
+                $value = trim(htmlspecialchars($value));
410
+                /*
411 411
 				* To predict the case where the string to convert contains the character "
412 412
 				* we check if this is the case we add a slash to solve this problem.
413 413
 				* For example:
414 414
 				* 	$attr = array('placeholder' => 'I am a "puple"')
415 415
 				* 	$str = attributes_to_string($attr); => placeholder = "I am a \"puple\""
416 416
 				 */
417
-				if ($value && strpos('"', $value) !== false){
418
-					$value = addslashes($value);
419
-				}
420
-				$str .= $key.' = "'.$value.'" ';
421
-			}
422
-		}
423
-		//remove the space after using rtrim()
424
-		return rtrim($str);
425
-	}
417
+                if ($value && strpos('"', $value) !== false){
418
+                    $value = addslashes($value);
419
+                }
420
+                $str .= $key.' = "'.$value.'" ';
421
+            }
422
+        }
423
+        //remove the space after using rtrim()
424
+        return rtrim($str);
425
+    }
426 426
 
427 427
 
428
-	/**
429
-	* Function to stringfy PHP variable, useful in debug situation
430
-	*
431
-	* @param mixed $var the variable to stringfy
432
-	* @codeCoverageIgnore
433
-	*
434
-	* @return string the stringfy value
435
-	*/
436
-	function stringfy_vars($var){
437
-		return print_r($var, true);
438
-	}
428
+    /**
429
+     * Function to stringfy PHP variable, useful in debug situation
430
+     *
431
+     * @param mixed $var the variable to stringfy
432
+     * @codeCoverageIgnore
433
+     *
434
+     * @return string the stringfy value
435
+     */
436
+    function stringfy_vars($var){
437
+        return print_r($var, true);
438
+    }
439 439
 
440
-	/**
441
-	 * Clean the user input
442
-	 * @param  mixed $str the value to clean
443
-	 * @test
444
-	 * 
445
-	 * @return mixed   the sanitize value
446
-	 */
447
-	function clean_input($str){
448
-		if (is_array($str)){
449
-			$str = array_map('clean_input', $str);
450
-		}
451
-		else if (is_object($str)){
452
-			$obj = $str;
453
-			foreach ($str as $var => $value) {
454
-				$obj->$var = clean_input($value);
455
-			}
456
-			$str = $obj;
457
-		}
458
-		else{
459
-			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
460
-		}
461
-		return $str;
462
-	}
440
+    /**
441
+     * Clean the user input
442
+     * @param  mixed $str the value to clean
443
+     * @test
444
+     * 
445
+     * @return mixed   the sanitize value
446
+     */
447
+    function clean_input($str){
448
+        if (is_array($str)){
449
+            $str = array_map('clean_input', $str);
450
+        }
451
+        else if (is_object($str)){
452
+            $obj = $str;
453
+            foreach ($str as $var => $value) {
454
+                $obj->$var = clean_input($value);
455
+            }
456
+            $str = $obj;
457
+        }
458
+        else{
459
+            $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
460
+        }
461
+        return $str;
462
+    }
463 463
 	
464
-	/**
465
-	 * This function is used to hidden some part of the given string. Helpful if you need hide some confidential 
466
-	 * Information like credit card number, password, etc.
467
-	 *
468
-	 * @param  string $str the string you want to hide some part
469
-	 * @param  int $startCount the length of non hidden for the beginning char
470
-	 * @param  int $endCount the length of non hidden for the ending char
471
-	 * @param  string $hiddenChar the char used to hide the given string
472
-	 * @test
473
-	 * 
474
-	 * @return string the string with the hidden part.
475
-	 */
476
-	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
477
-		//get the string length
478
-		$len = strlen($str);
479
-		//if str is empty
480
-		if ($len <= 0){
481
-			return str_repeat($hiddenChar, 6);
482
-		}
483
-		//if the length is less than startCount and endCount
484
-		//or the startCount and endCount length is 0
485
-		//or startCount is negative or endCount is negative
486
-		//return the full string hidden
464
+    /**
465
+     * This function is used to hidden some part of the given string. Helpful if you need hide some confidential 
466
+     * Information like credit card number, password, etc.
467
+     *
468
+     * @param  string $str the string you want to hide some part
469
+     * @param  int $startCount the length of non hidden for the beginning char
470
+     * @param  int $endCount the length of non hidden for the ending char
471
+     * @param  string $hiddenChar the char used to hide the given string
472
+     * @test
473
+     * 
474
+     * @return string the string with the hidden part.
475
+     */
476
+    function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
477
+        //get the string length
478
+        $len = strlen($str);
479
+        //if str is empty
480
+        if ($len <= 0){
481
+            return str_repeat($hiddenChar, 6);
482
+        }
483
+        //if the length is less than startCount and endCount
484
+        //or the startCount and endCount length is 0
485
+        //or startCount is negative or endCount is negative
486
+        //return the full string hidden
487 487
 		
488
-		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
489
-			return str_repeat($hiddenChar, $len);
490
-		}
491
-		//the start non hidden string
492
-		$startNonHiddenStr = substr($str, 0, $startCount);
493
-		//the end non hidden string
494
-		$endNonHiddenStr = null;
495
-		if ($endCount > 0){
496
-			$endNonHiddenStr = substr($str, - $endCount);
497
-		}
498
-		//the hidden string
499
-		$hiddenStr = str_repeat($hiddenChar, $len - ($startCount + $endCount));
488
+        if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
489
+            return str_repeat($hiddenChar, $len);
490
+        }
491
+        //the start non hidden string
492
+        $startNonHiddenStr = substr($str, 0, $startCount);
493
+        //the end non hidden string
494
+        $endNonHiddenStr = null;
495
+        if ($endCount > 0){
496
+            $endNonHiddenStr = substr($str, - $endCount);
497
+        }
498
+        //the hidden string
499
+        $hiddenStr = str_repeat($hiddenChar, $len - ($startCount + $endCount));
500 500
 		
501
-		return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr;
502
-	}
501
+        return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr;
502
+    }
503 503
 	
504
-	/**
505
-	 * This function is used to set the initial session config regarding the configuration
506
-	 * @codeCoverageIgnore
507
-	 */
508
-	function set_session_config(){
509
-		//$_SESSION is not available on cli mode 
510
-		if (! IS_CLI){
511
-			$logger =& class_loader('Log', 'classes');
512
-			$logger->setLogger('PHPSession');
513
-			//set session params
514
-			$sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files
515
-			$sessionName = get_config('session_name');
516
-			if ($sessionName){
517
-				session_name($sessionName);
518
-			}
519
-			$logger->info('Session handler: ' . $sessionHandler);
520
-			$logger->info('Session name: ' . $sessionName);
504
+    /**
505
+     * This function is used to set the initial session config regarding the configuration
506
+     * @codeCoverageIgnore
507
+     */
508
+    function set_session_config(){
509
+        //$_SESSION is not available on cli mode 
510
+        if (! IS_CLI){
511
+            $logger =& class_loader('Log', 'classes');
512
+            $logger->setLogger('PHPSession');
513
+            //set session params
514
+            $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files
515
+            $sessionName = get_config('session_name');
516
+            if ($sessionName){
517
+                session_name($sessionName);
518
+            }
519
+            $logger->info('Session handler: ' . $sessionHandler);
520
+            $logger->info('Session name: ' . $sessionName);
521 521
 
522
-			if ($sessionHandler == 'files'){
523
-				$sessionSavePath = get_config('session_save_path');
524
-				if ($sessionSavePath){
525
-					if (! is_dir($sessionSavePath)){
526
-						mkdir($sessionSavePath, 1773);
527
-					}
528
-					session_save_path($sessionSavePath);
529
-					$logger->info('Session save path: ' . $sessionSavePath);
530
-				}
531
-			}
532
-			else if ($sessionHandler == 'database'){
533
-				//load database session handle library
534
-				//Database Session handler Model
535
-				require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php';
522
+            if ($sessionHandler == 'files'){
523
+                $sessionSavePath = get_config('session_save_path');
524
+                if ($sessionSavePath){
525
+                    if (! is_dir($sessionSavePath)){
526
+                        mkdir($sessionSavePath, 1773);
527
+                    }
528
+                    session_save_path($sessionSavePath);
529
+                    $logger->info('Session save path: ' . $sessionSavePath);
530
+                }
531
+            }
532
+            else if ($sessionHandler == 'database'){
533
+                //load database session handle library
534
+                //Database Session handler Model
535
+                require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php';
536 536
 
537
-				$DBS =& class_loader('DBSessionHandler', 'classes');
538
-				session_set_save_handler($DBS, true);
539
-				$logger->info('session save path: ' . get_config('session_save_path'));
540
-			}
541
-			else{
542
-				show_error('Invalid session handler configuration');
543
-			}
544
-			$lifetime = get_config('session_cookie_lifetime', 0);
545
-			$path = get_config('session_cookie_path', '/');
546
-			$domain = get_config('session_cookie_domain', '');
547
-			$secure = get_config('session_cookie_secure', false);
548
-			session_set_cookie_params(
549
-				$lifetime,
550
-				$path,
551
-				$domain,
552
-				$secure,
553
-				$httponly = true /*for security for access to cookie via javascript or XSS attack*/
554
-			);
555
-			//to prevent attack of Session Fixation 
556
-			//thank to https://www.phparch.com/2018/01/php-sessions-in-depth/
557
-			ini_set('session.use_strict_mode ', 1);
558
-			ini_set('session.use_only_cookies', 1);
559
-			ini_set('session.use_trans_sid ', 0);
537
+                $DBS =& class_loader('DBSessionHandler', 'classes');
538
+                session_set_save_handler($DBS, true);
539
+                $logger->info('session save path: ' . get_config('session_save_path'));
540
+            }
541
+            else{
542
+                show_error('Invalid session handler configuration');
543
+            }
544
+            $lifetime = get_config('session_cookie_lifetime', 0);
545
+            $path = get_config('session_cookie_path', '/');
546
+            $domain = get_config('session_cookie_domain', '');
547
+            $secure = get_config('session_cookie_secure', false);
548
+            session_set_cookie_params(
549
+                $lifetime,
550
+                $path,
551
+                $domain,
552
+                $secure,
553
+                $httponly = true /*for security for access to cookie via javascript or XSS attack*/
554
+            );
555
+            //to prevent attack of Session Fixation 
556
+            //thank to https://www.phparch.com/2018/01/php-sessions-in-depth/
557
+            ini_set('session.use_strict_mode ', 1);
558
+            ini_set('session.use_only_cookies', 1);
559
+            ini_set('session.use_trans_sid ', 0);
560 560
 			
561
-			$logger->info('Session lifetime: ' . $lifetime);
562
-			$logger->info('Session cookie path: ' . $path);
563
-			$logger->info('Session domain: ' . $domain);
564
-			$logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE'));
561
+            $logger->info('Session lifetime: ' . $lifetime);
562
+            $logger->info('Session cookie path: ' . $path);
563
+            $logger->info('Session domain: ' . $domain);
564
+            $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE'));
565 565
 			
566
-			if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){
567
-				$logger->info('Session not yet start, start it now');
568
-				session_start();
569
-			}
570
-		}
571
-	}
566
+            if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){
567
+                $logger->info('Session not yet start, start it now');
568
+                session_start();
569
+            }
570
+        }
571
+    }
572 572
 	
573
-	/**
574
-	* This function is very useful, it allows to recover the instance of the global controller.
575
-	* Note this function always returns the address of the super instance.
576
-	* For example :
577
-	* $obj = & get_instance();
578
-	* 
579
-	* @codeCoverageIgnore
580
-	*  
581
-	* @return object the instance of the "Controller" class
582
-	*/
583
-	function & get_instance(){
584
-		return Controller::get_instance();
585
-	}
573
+    /**
574
+     * This function is very useful, it allows to recover the instance of the global controller.
575
+     * Note this function always returns the address of the super instance.
576
+     * For example :
577
+     * $obj = & get_instance();
578
+     * 
579
+     * @codeCoverageIgnore
580
+     *  
581
+     * @return object the instance of the "Controller" class
582
+     */
583
+    function & get_instance(){
584
+        return Controller::get_instance();
585
+    }
Please login to merge, or discard this patch.
core/classes/model/Model.php 3 patches
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net>
34 34
      */
35 35
 
36
-    class Model{
36
+    class Model {
37 37
 
38 38
         /* --------------------------------------------------------------
39 39
          * VARIABLES
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
          * Initialise the model, tie into the CodeIgniter superobject and
141 141
          * try our best to guess the table name.
142 142
          */
143
-        public function __construct(Database $db = null){
144
-            if (is_object($db)){
143
+        public function __construct(Database $db = null) {
144
+            if (is_object($db)) {
145 145
                 $this->setDatabaseInstance($db);
146 146
             }
147
-            else{
147
+            else {
148 148
                 $obj = & get_instance();
149
-        		if (isset($obj->database) && is_object($obj->database)){
149
+        		if (isset($obj->database) && is_object($obj->database)) {
150 150
                     /**
151 151
                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
152 152
                     * to prevent duplication
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
184 184
             {
185
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
185
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
186 186
             }
187 187
     		$this->_set_where($where);
188 188
 
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
             $this->trigger('before_get');
225 225
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
226 226
             {
227
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
227
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
228 228
             }
229
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
229
+			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
230 230
             $this->getQueryBuilder()->from($this->_table);
231 231
 			$result = $this->_database->getAll($type);
232 232
             $this->_temporary_return_type = $this->return_type;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                 $insert_id = $this->_database->insertId();
260 260
                 $this->trigger('after_create', $insert_id);
261 261
 				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
262
-				return ! $insert_id ? true : $insert_id;
262
+				return !$insert_id ? true : $insert_id;
263 263
             }
264 264
             else
265 265
             {
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
         {
337 337
             $args = func_get_args();
338 338
             $data = array();
339
-            if (count($args) == 2){
340
-                if (is_array($args[1])){
339
+            if (count($args) == 2) {
340
+                if (is_array($args[1])) {
341 341
                     $data = array_pop($args);
342 342
                 }
343 343
             }
344
-            else if (count($args) == 3){
345
-                if (is_array($args[2])){
344
+            else if (count($args) == 3) {
345
+                if (is_array($args[2])) {
346 346
                     $data = array_pop($args);
347 347
                 }
348 348
             }
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
             if ($this->soft_delete)
385 385
             {
386 386
                 $this->getQueryBuilder()->from($this->_table);	
387
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
387
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
388 388
             }
389 389
             else
390 390
             {
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
             if ($this->soft_delete)
409 409
             {
410 410
                 $this->getQueryBuilder()->from($this->_table);	
411
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
411
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
412 412
             }
413 413
             else
414 414
             {
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
             if ($this->soft_delete)
431 431
             {
432 432
                 $this->getQueryBuilder()->from($this->_table);	
433
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
433
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
434 434
             }
435 435
             else
436 436
             {
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
                 $key = $this->primary_key;
501 501
                 $value = $args[0];
502 502
             }
503
-            $this->trigger('before_dropdown', array( $key, $value ));
503
+            $this->trigger('before_dropdown', array($key, $value));
504 504
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
505 505
             {
506 506
                 $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
         {
526 526
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
527 527
             {
528
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
528
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
529 529
             }
530 530
             $where = func_get_args();
531 531
             $this->_set_where($where);
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
         {
542 542
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
543 543
             {
544
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
544
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
545 545
             }
546 546
 			$this->getQueryBuilder()->from($this->_table);
547 547
 			$this->_database->getAll();
@@ -551,8 +551,8 @@  discard block
 block discarded – undo
551 551
 		/**
552 552
 		* Enabled cache temporary
553 553
 		*/
554
-		public function cached($ttl = 0){
555
-		  if ($ttl > 0){
554
+		public function cached($ttl = 0) {
555
+		  if ($ttl > 0) {
556 556
 			$this->_database = $this->_database->cached($ttl);
557 557
 		  }
558 558
 		  return $this;
@@ -706,13 +706,13 @@  discard block
 block discarded – undo
706 706
             {
707 707
                 if (is_object($row))
708 708
                 {
709
-					if (isset($row->$attr)){
709
+					if (isset($row->$attr)) {
710 710
 						unset($row->$attr);
711 711
 					}
712 712
                 }
713 713
                 else
714 714
                 {
715
-					if (isset($row[$attr])){
715
+					if (isset($row[$attr])) {
716 716
 						unset($row[$attr]);
717 717
 					}
718 718
                 }
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
          * Return the database instance
725 725
          * @return Database the database instance
726 726
          */
727
-        public function getDatabaseInstance(){
727
+        public function getDatabaseInstance() {
728 728
             return $this->_database;
729 729
         }
730 730
 
@@ -732,9 +732,9 @@  discard block
 block discarded – undo
732 732
          * set the Database instance for future use
733 733
          * @param Database $db the database object
734 734
          */
735
-         public function setDatabaseInstance($db){
735
+         public function setDatabaseInstance($db) {
736 736
             $this->_database = $db;
737
-            if ($this->dbCacheTime > 0){
737
+            if ($this->dbCacheTime > 0) {
738 738
                 $this->_database->setCache($this->dbCacheTime);
739 739
             }
740 740
             return $this;
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
          * Return the loader instance
745 745
          * @return Loader the loader instance
746 746
          */
747
-        public function getLoader(){
747
+        public function getLoader() {
748 748
             return $this->loaderInstance;
749 749
         }
750 750
 
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
          * @param Loader $loader the loader object
754 754
 		 * @return object
755 755
          */
756
-         public function setLoader($loader){
756
+         public function setLoader($loader) {
757 757
             $this->loaderInstance = $loader;
758 758
             return $this;
759 759
         }
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
          * Return the queryBuilder instance this is the shortcut to database queryBuilder
763 763
          * @return object the DatabaseQueryBuilder instance
764 764
          */
765
-        public function getQueryBuilder(){
765
+        public function getQueryBuilder() {
766 766
             return $this->_database->getQueryBuilder();
767 767
         }
768 768
 
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
          * @param object $queryBuilder the DatabaseQueryBuilder object
772 772
 		 * @return object
773 773
          */
774
-         public function setQueryBuilder($queryBuilder){
774
+         public function setQueryBuilder($queryBuilder) {
775 775
             $this->_database->setQueryBuilder($queryBuilder);
776 776
             return $this;
777 777
         }
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
          * Return the FormValidation instance
782 782
          * @return FormValidation the form validation instance
783 783
          */
784
-        public function getFormValidation(){
784
+        public function getFormValidation() {
785 785
             return $this->formValidationInstance;
786 786
         }
787 787
 
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
          * @param FormValidation $fv the form validation object
791 791
 		 * @return object
792 792
          */
793
-         public function setFormValidation($fv){
793
+         public function setFormValidation($fv) {
794 794
             $this->formValidationInstance = $fv;
795 795
             return $this;
796 796
         }
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
          */
805 805
         public function order_by($criteria, $order = 'ASC')
806 806
         {
807
-            if ( is_array($criteria) )
807
+            if (is_array($criteria))
808 808
             {
809 809
                 foreach ($criteria as $key => $value)
810 810
                 {
@@ -835,13 +835,13 @@  discard block
 block discarded – undo
835 835
 		* relate for the relation "belongs_to"
836 836
 		* @return mixed
837 837
 		*/
838
-		protected function relateBelongsTo($row){
838
+		protected function relateBelongsTo($row) {
839 839
 			foreach ($this->belongs_to as $key => $value)
840 840
             {
841 841
                 if (is_string($value))
842 842
                 {
843 843
                     $relationship = $value;
844
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
844
+                    $options = array('primary_key' => $value . '_id', 'model' => $value . '_model');
845 845
                 }
846 846
                 else
847 847
                 {
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
 
852 852
                 if (in_array($relationship, $this->_with))
853 853
                 {
854
-                    if (is_object($this->loaderInstance)){
854
+                    if (is_object($this->loaderInstance)) {
855 855
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
856 856
                     }
857
-                    else{
857
+                    else {
858 858
                         Loader::model($options['model'], $relationship . '_model');    
859 859
                     }
860 860
                     if (is_object($row))
@@ -874,13 +874,13 @@  discard block
 block discarded – undo
874 874
 		* relate for the relation "has_many"
875 875
 		* @return mixed
876 876
 		*/
877
-		protected function relateHasMany($row){
877
+		protected function relateHasMany($row) {
878 878
 			foreach ($this->has_many as $key => $value)
879 879
             {
880 880
                 if (is_string($value))
881 881
                 {
882 882
                     $relationship = $value;
883
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
883
+                    $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model');
884 884
                 }
885 885
                 else
886 886
                 {
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
 
891 891
                 if (in_array($relationship, $this->_with))
892 892
                 {
893
-                    if (is_object($this->loaderInstance)){
893
+                    if (is_object($this->loaderInstance)) {
894 894
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
895 895
                     }
896
-                    else{
896
+                    else {
897 897
                         Loader::model($options['model'], $relationship . '_model');    
898 898
                     }
899 899
                     if (is_object($row))
@@ -944,10 +944,10 @@  discard block
 block discarded – undo
944 944
             if (!empty($this->validate))
945 945
             {
946 946
                 $fv = null;
947
-                if (is_object($this->formValidationInstance)){
947
+                if (is_object($this->formValidationInstance)) {
948 948
                     $fv = $this->formValidationInstance;
949 949
                 }
950
-                else{
950
+                else {
951 951
                     Loader::library('FormValidation');
952 952
                     $fv = $this->formvalidation;
953 953
                     $this->setFormValidation($fv);
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
 		* Set WHERE parameters, when is array
977 977
 		* @param array $params
978 978
 		*/
979
-		protected function _set_where_array(array $params){
979
+		protected function _set_where_array(array $params) {
980 980
 			foreach ($params as $field => $filter)
981 981
 			{
982 982
 				if (is_array($filter))
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
         /**
1043 1043
             Shortcut to controller
1044 1044
         */
1045
-        public function __get($key){
1045
+        public function __get($key) {
1046 1046
             return get_instance()->{$key};
1047 1047
         }
1048 1048
 
Please login to merge, or discard this patch.
Braces   +32 added lines, -64 removed lines patch added patch discarded remove patch
@@ -143,8 +143,7 @@  discard block
 block discarded – undo
143 143
         public function __construct(Database $db = null){
144 144
             if (is_object($db)){
145 145
                 $this->setDatabaseInstance($db);
146
-            }
147
-            else{
146
+            } else{
148 147
                 $obj = & get_instance();
149 148
         		if (isset($obj->database) && is_object($obj->database)){
150 149
                     /**
@@ -260,8 +259,7 @@  discard block
 block discarded – undo
260 259
                 $this->trigger('after_create', $insert_id);
261 260
 				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
262 261
 				return ! $insert_id ? true : $insert_id;
263
-            }
264
-            else
262
+            } else
265 263
             {
266 264
                 return FALSE;
267 265
             }
@@ -298,8 +296,7 @@  discard block
 block discarded – undo
298 296
                 $result = $this->_database->update($data, $escape);
299 297
                 $this->trigger('after_update', array($data, $result));
300 298
                 return $result;
301
-            }
302
-            else
299
+            } else
303 300
             {
304 301
                 return FALSE;
305 302
             }
@@ -322,8 +319,7 @@  discard block
 block discarded – undo
322 319
 				$result = $this->_database->update($data, $escape);
323 320
                 $this->trigger('after_update', array($data, $result));
324 321
                 return $result;
325
-            }
326
-            else
322
+            } else
327 323
             {
328 324
                 return FALSE;
329 325
             }
@@ -340,8 +336,7 @@  discard block
 block discarded – undo
340 336
                 if (is_array($args[1])){
341 337
                     $data = array_pop($args);
342 338
                 }
343
-            }
344
-            else if (count($args) == 3){
339
+            } else if (count($args) == 3){
345 340
                 if (is_array($args[2])){
346 341
                     $data = array_pop($args);
347 342
                 }
@@ -354,8 +349,7 @@  discard block
 block discarded – undo
354 349
 				$result = $this->_database->update($data);
355 350
                 $this->trigger('after_update', array($data, $result));
356 351
                 return $result;
357
-            }
358
-            else
352
+            } else
359 353
             {
360 354
                 return FALSE;
361 355
             }
@@ -385,8 +379,7 @@  discard block
 block discarded – undo
385 379
             {
386 380
                 $this->getQueryBuilder()->from($this->_table);	
387 381
 				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
388
-            }
389
-            else
382
+            } else
390 383
             {
391 384
                 $this->getQueryBuilder()->from($this->_table); 
392 385
 				$result = $this->_database->delete();
@@ -409,8 +402,7 @@  discard block
 block discarded – undo
409 402
             {
410 403
                 $this->getQueryBuilder()->from($this->_table);	
411 404
 				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
412
-            }
413
-            else
405
+            } else
414 406
             {
415 407
                 $this->getQueryBuilder()->from($this->_table); 
416 408
 				$result = $this->_database->delete();
@@ -431,8 +423,7 @@  discard block
 block discarded – undo
431 423
             {
432 424
                 $this->getQueryBuilder()->from($this->_table);	
433 425
 				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
434
-            }
435
-            else
426
+            } else
436 427
             {
437 428
                 $this->getQueryBuilder()->from($this->_table); 
438 429
 				$result = $this->_database->delete();
@@ -494,8 +485,7 @@  discard block
 block discarded – undo
494 485
             if (count($args) == 2)
495 486
             {
496 487
                 list($key, $value) = $args;
497
-            }
498
-            else
488
+            } else
499 489
             {
500 490
                 $key = $this->primary_key;
501 491
                 $value = $args[0];
@@ -647,8 +637,7 @@  discard block
 block discarded – undo
647 637
             if (is_object($row))
648 638
             {
649 639
                 $row->created_at = date('Y-m-d H:i:s');
650
-            }
651
-            else
640
+            } else
652 641
             {
653 642
                 $row['created_at'] = date('Y-m-d H:i:s');
654 643
             }
@@ -660,8 +649,7 @@  discard block
 block discarded – undo
660 649
             if (is_object($row))
661 650
             {
662 651
                 $row->updated_at = date('Y-m-d H:i:s');
663
-            }
664
-            else
652
+            } else
665 653
             {
666 654
                 $row['updated_at'] = date('Y-m-d H:i:s');
667 655
             }
@@ -688,8 +676,7 @@  discard block
 block discarded – undo
688 676
                 if (is_array($row))
689 677
                 {
690 678
                     $row[$column] = unserialize($row[$column]);
691
-                }
692
-                else
679
+                } else
693 680
                 {
694 681
                     $row->$column = unserialize($row->$column);
695 682
                 }
@@ -709,8 +696,7 @@  discard block
 block discarded – undo
709 696
 					if (isset($row->$attr)){
710 697
 						unset($row->$attr);
711 698
 					}
712
-                }
713
-                else
699
+                } else
714 700
                 {
715 701
 					if (isset($row[$attr])){
716 702
 						unset($row[$attr]);
@@ -810,8 +796,7 @@  discard block
 block discarded – undo
810 796
                 {
811 797
                     $this->getQueryBuilder()->orderBy($key, $value);
812 798
                 }
813
-            }
814
-            else
799
+            } else
815 800
             {
816 801
                 $this->getQueryBuilder()->orderBy($criteria, $order);
817 802
             }
@@ -842,8 +827,7 @@  discard block
 block discarded – undo
842 827
                 {
843 828
                     $relationship = $value;
844 829
                     $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
845
-                }
846
-                else
830
+                } else
847 831
                 {
848 832
                     $relationship = $key;
849 833
                     $options = $value;
@@ -853,15 +837,13 @@  discard block
 block discarded – undo
853 837
                 {
854 838
                     if (is_object($this->loaderInstance)){
855 839
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
856
-                    }
857
-                    else{
840
+                    } else{
858 841
                         Loader::model($options['model'], $relationship . '_model');    
859 842
                     }
860 843
                     if (is_object($row))
861 844
                     {
862 845
                         $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']});
863
-                    }
864
-                    else
846
+                    } else
865 847
                     {
866 848
                         $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]);
867 849
                     }
@@ -881,8 +863,7 @@  discard block
 block discarded – undo
881 863
                 {
882 864
                     $relationship = $value;
883 865
                     $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
884
-                }
885
-                else
866
+                } else
886 867
                 {
887 868
                     $relationship = $key;
888 869
                     $options = $value;
@@ -892,15 +873,13 @@  discard block
 block discarded – undo
892 873
                 {
893 874
                     if (is_object($this->loaderInstance)){
894 875
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
895
-                    }
896
-                    else{
876
+                    } else{
897 877
                         Loader::model($options['model'], $relationship . '_model');    
898 878
                     }
899 879
                     if (is_object($row))
900 880
                     {
901 881
                         $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key});
902
-                    }
903
-                    else
882
+                    } else
904 883
                     {
905 884
                         $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]);
906 885
                     }
@@ -946,8 +925,7 @@  discard block
 block discarded – undo
946 925
                 $fv = null;
947 926
                 if (is_object($this->formValidationInstance)){
948 927
                     $fv = $this->formValidationInstance;
949
-                }
950
-                else{
928
+                } else{
951 929
                     Loader::library('FormValidation');
952 930
                     $fv = $this->formvalidation;
953 931
                     $this->setFormValidation($fv);
@@ -959,13 +937,11 @@  discard block
 block discarded – undo
959 937
                 if ($fv->run())
960 938
                 {
961 939
                     return $data;
962
-                }
963
-                else
940
+                } else
964 941
                 {
965 942
                     return FALSE;
966 943
                 }
967
-            }
968
-            else
944
+            } else
969 945
             {
970 946
                 return $data;
971 947
             }
@@ -982,14 +958,12 @@  discard block
 block discarded – undo
982 958
 				if (is_array($filter))
983 959
 				{
984 960
 					$this->getQueryBuilder()->in($field, $filter);
985
-				}
986
-				else
961
+				} else
987 962
 				{
988 963
 					if (is_int($field))
989 964
 					{
990 965
 						$this->getQueryBuilder()->where($filter);
991
-					}
992
-					else
966
+					} else
993 967
 					{
994 968
 						$this->getQueryBuilder()->where($field, $filter);
995 969
 					}
@@ -1006,33 +980,27 @@  discard block
 block discarded – undo
1006 980
             if (count($params) == 1 && is_array($params[0]))
1007 981
             {
1008 982
                 $this->_set_where_array($params[0]);
1009
-            }
1010
-            else if (count($params) == 1)
983
+            } else if (count($params) == 1)
1011 984
             {
1012 985
                 $this->getQueryBuilder()->where($params[0]);
1013
-            }
1014
-        	else if (count($params) == 2)
986
+            } else if (count($params) == 2)
1015 987
     		{
1016 988
                 if (is_array($params[1]))
1017 989
                 {
1018 990
                     $this->getQueryBuilder()->in($params[0], $params[1]);
1019
-                }
1020
-                else
991
+                } else
1021 992
                 {
1022 993
                     $this->getQueryBuilder()->where($params[0], $params[1]);
1023 994
                 }
1024
-    		}
1025
-    		else if (count($params) == 3)
995
+    		} else if (count($params) == 3)
1026 996
     		{
1027 997
     			$this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1028
-    		}
1029
-            else
998
+    		} else
1030 999
             {
1031 1000
                 if (is_array($params[1]))
1032 1001
                 {
1033 1002
                     $this->getQueryBuilder()->in($params[0], $params[1]);
1034
-                }
1035
-                else
1003
+                } else
1036 1004
                 {
1037 1005
                     $this->getQueryBuilder()->where($params[0], $params[1]);
1038 1006
                 }
Please login to merge, or discard this patch.
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
 
27 27
 
28 28
     /**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
         protected $_temporary_return_type = NULL;
121 121
     	
122 122
     	
123
-    	/**
123
+        /**
124 124
     		The database cache time 
125
-    	*/
126
-    	protected $dbCacheTime = 0;
125
+         */
126
+        protected $dbCacheTime = 0;
127 127
 
128 128
         /**
129 129
          * Instance of the Loader class
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
             }
152 152
             else{
153 153
                 $obj = & get_instance();
154
-        		if (isset($obj->database) && is_object($obj->database)){
154
+                if (isset($obj->database) && is_object($obj->database)){
155 155
                     /**
156
-                    * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
-                    * to prevent duplication
158
-                    */
159
-        			$this->setDatabaseInstance(clone $obj->database);
156
+                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157
+                     * to prevent duplication
158
+                     */
159
+                    $this->setDatabaseInstance(clone $obj->database);
160 160
                 }
161 161
             }
162 162
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
          */
175 175
         public function get($primary_value)
176 176
         {
177
-    		return $this->get_by($this->primary_key, $primary_value);
177
+            return $this->get_by($this->primary_key, $primary_value);
178 178
         }
179 179
 
180 180
         /**
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
             {
190 190
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
191 191
             }
192
-    		$this->_set_where($where);
192
+            $this->_set_where($where);
193 193
 
194 194
             $this->trigger('before_get');
195
-			$type = $this->_temporary_return_type == 'array' ? 'array' : false;
195
+            $type = $this->_temporary_return_type == 'array' ? 'array' : false;
196 196
             $this->getQueryBuilder()->from($this->_table);
197
-			$row = $this->_database->get($type);
197
+            $row = $this->_database->get($type);
198 198
             $this->_temporary_return_type = $this->return_type;
199 199
             $row = $this->trigger('after_get', $row);
200 200
             $this->_with = array();
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
             {
232 232
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
233 233
             }
234
-			$type = $this->_temporary_return_type == 'array' ? 'array':false;
234
+            $type = $this->_temporary_return_type == 'array' ? 'array':false;
235 235
             $this->getQueryBuilder()->from($this->_table);
236
-			$result = $this->_database->getAll($type);
236
+            $result = $this->_database->getAll($type);
237 237
             $this->_temporary_return_type = $this->return_type;
238 238
 
239 239
             foreach ($result as $key => &$row)
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
         /**
248 248
          * Insert a new row into the table. $data should be an associative array
249 249
          * of data to be inserted. Returns newly created ID.
250
-		 * @see Database::insert
250
+         * @see Database::insert
251 251
          */
252 252
         public function insert($data = array(), $skip_validation = FALSE, $escape = true)
253 253
         {
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
             {
261 261
                 $data = $this->trigger('before_create', $data);
262 262
                 $this->getQueryBuilder()->from($this->_table);
263
-				$this->_database->insert($data, $escape);
263
+                $this->_database->insert($data, $escape);
264 264
                 $insert_id = $this->_database->insertId();
265 265
                 $this->trigger('after_create', $insert_id);
266
-				//if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
-				return ! $insert_id ? true : $insert_id;
266
+                //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
267
+                return ! $insert_id ? true : $insert_id;
268 268
             }
269 269
             else
270 270
             {
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
             {
325 325
                 $this->getQueryBuilder()->in($this->primary_key, $primary_values)
326 326
                                         ->from($this->_table);
327
-				$result = $this->_database->update($data, $escape);
327
+                $result = $this->_database->update($data, $escape);
328 328
                 $this->trigger('after_update', array($data, $result));
329 329
                 return $result;
330 330
             }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
             {
357 357
                 $this->_set_where($args);
358 358
                 $this->getQueryBuilder()->from($this->_table);
359
-				$result = $this->_database->update($data);
359
+                $result = $this->_database->update($data);
360 360
                 $this->trigger('after_update', array($data, $result));
361 361
                 return $result;
362 362
             }
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
         {
374 374
             $data = $this->trigger('before_update', $data);
375 375
             $this->getQueryBuilder()->from($this->_table);
376
-			$result = $this->_database->update($data, $escape);
376
+            $result = $this->_database->update($data, $escape);
377 377
             $this->trigger('after_update', array($data, $result));
378 378
             return $result;
379 379
         }
@@ -385,16 +385,16 @@  discard block
 block discarded – undo
385 385
         {
386 386
             $this->trigger('before_delete', $id);
387 387
             $this->getQueryBuilder()->where($this->primary_key, $id);
388
-			$result = false;
388
+            $result = false;
389 389
             if ($this->soft_delete)
390 390
             {
391 391
                 $this->getQueryBuilder()->from($this->_table);	
392
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
392
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
393 393
             }
394 394
             else
395 395
             {
396 396
                 $this->getQueryBuilder()->from($this->_table); 
397
-				$result = $this->_database->delete();
397
+                $result = $this->_database->delete();
398 398
             }
399 399
 
400 400
             $this->trigger('after_delete', $result);
@@ -407,18 +407,18 @@  discard block
 block discarded – undo
407 407
         public function delete_by()
408 408
         {
409 409
             $where = func_get_args();
410
-    	    $where = $this->trigger('before_delete', $where);
410
+            $where = $this->trigger('before_delete', $where);
411 411
             $this->_set_where($where);
412
-			$result = false;
412
+            $result = false;
413 413
             if ($this->soft_delete)
414 414
             {
415 415
                 $this->getQueryBuilder()->from($this->_table);	
416
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
416
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
417 417
             }
418 418
             else
419 419
             {
420 420
                 $this->getQueryBuilder()->from($this->_table); 
421
-				$result = $this->_database->delete();
421
+                $result = $this->_database->delete();
422 422
             }
423 423
             $this->trigger('after_delete', $result);
424 424
             return $result;
@@ -431,16 +431,16 @@  discard block
 block discarded – undo
431 431
         {
432 432
             $primary_values = $this->trigger('before_delete', $primary_values);
433 433
             $this->getQueryBuilder()->in($this->primary_key, $primary_values);
434
-			$result = false;
434
+            $result = false;
435 435
             if ($this->soft_delete)
436 436
             {
437 437
                 $this->getQueryBuilder()->from($this->_table);	
438
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
438
+                $result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
439 439
             }
440 440
             else
441 441
             {
442 442
                 $this->getQueryBuilder()->from($this->_table); 
443
-				$result = $this->_database->delete();
443
+                $result = $this->_database->delete();
444 444
             }
445 445
             $this->trigger('after_delete', $result);
446 446
             return $result;
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
          */
453 453
         public function truncate()
454 454
         {
455
-			$this->getQueryBuilder()->from($this->_table); 
456
-			$result = $this->_database->delete();
455
+            $this->getQueryBuilder()->from($this->_table); 
456
+            $result = $this->_database->delete();
457 457
             return $result;
458 458
         }
459 459
 
@@ -471,14 +471,14 @@  discard block
 block discarded – undo
471 471
             return $this;
472 472
         }
473 473
 		
474
-		/**
475
-		* Relationship
476
-		*/
474
+        /**
475
+         * Relationship
476
+         */
477 477
         public function relate($row)
478 478
         {
479
-    		if (empty($row))
479
+            if (empty($row))
480 480
             {
481
-    		    return $row;
481
+                return $row;
482 482
             }
483 483
 
484 484
             $row = $this->relateBelongsTo($row);
@@ -511,9 +511,9 @@  discard block
 block discarded – undo
511 511
                 $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
512 512
             }
513 513
             $this->getQueryBuilder()
514
-									 ->select(array($key, $value))
515
-									 ->from($this->_table);
516
-			$result = $this->_database->getAll();
514
+                                        ->select(array($key, $value))
515
+                                        ->from($this->_table);
516
+            $result = $this->_database->getAll();
517 517
             $options = array();
518 518
             foreach ($result as $row)
519 519
             {
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
             $where = func_get_args();
536 536
             $this->_set_where($where);
537 537
             $this->getQueryBuilder()->from($this->_table);
538
-			$this->_database->getAll();
538
+            $this->_database->getAll();
539 539
             return $this->_database->numRows();
540 540
         }
541 541
 
@@ -548,20 +548,20 @@  discard block
 block discarded – undo
548 548
             {
549 549
                 $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
550 550
             }
551
-			$this->getQueryBuilder()->from($this->_table);
552
-			$this->_database->getAll();
551
+            $this->getQueryBuilder()->from($this->_table);
552
+            $this->_database->getAll();
553 553
             return $this->_database->numRows();
554 554
         }
555 555
 		
556
-		/**
557
-		* Enabled cache temporary
558
-		*/
559
-		public function cached($ttl = 0){
560
-		  if ($ttl > 0){
561
-			$this->_database = $this->_database->cached($ttl);
562
-		  }
563
-		  return $this;
564
-		}
556
+        /**
557
+         * Enabled cache temporary
558
+         */
559
+        public function cached($ttl = 0){
560
+            if ($ttl > 0){
561
+            $this->_database = $this->_database->cached($ttl);
562
+            }
563
+            return $this;
564
+        }
565 565
 
566 566
         /**
567 567
          * Tell the class to skip the insert validation
@@ -585,10 +585,10 @@  discard block
 block discarded – undo
585 585
          */
586 586
         public function get_next_id()
587 587
         {
588
-			$this->getQueryBuilder()->select('AUTO_INCREMENT')
589
-									->from('information_schema.TABLES')
590
-									->where('TABLE_NAME', $this->_table)
591
-									->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
588
+            $this->getQueryBuilder()->select('AUTO_INCREMENT')
589
+                                    ->from('information_schema.TABLES')
590
+                                    ->where('TABLE_NAME', $this->_table)
591
+                                    ->where('TABLE_SCHEMA', $this->_database->getDatabaseName());
592 592
             return (int) $this->_database->get()->AUTO_INCREMENT;
593 593
         }
594 594
 
@@ -711,24 +711,24 @@  discard block
 block discarded – undo
711 711
             {
712 712
                 if (is_object($row))
713 713
                 {
714
-					if (isset($row->$attr)){
715
-						unset($row->$attr);
716
-					}
714
+                    if (isset($row->$attr)){
715
+                        unset($row->$attr);
716
+                    }
717 717
                 }
718 718
                 else
719 719
                 {
720
-					if (isset($row[$attr])){
721
-						unset($row[$attr]);
722
-					}
720
+                    if (isset($row[$attr])){
721
+                        unset($row[$attr]);
722
+                    }
723 723
                 }
724 724
             }
725 725
             return $row;
726 726
         }
727 727
 		
728
-		 /**
729
-         * Return the database instance
730
-         * @return Database the database instance
731
-         */
728
+            /**
729
+             * Return the database instance
730
+             * @return Database the database instance
731
+             */
732 732
         public function getDatabaseInstance(){
733 733
             return $this->_database;
734 734
         }
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
          * set the Database instance for future use
738 738
          * @param Database $db the database object
739 739
          */
740
-         public function setDatabaseInstance($db){
740
+            public function setDatabaseInstance($db){
741 741
             $this->_database = $db;
742 742
             if ($this->dbCacheTime > 0){
743 743
                 $this->_database->setCache($this->dbCacheTime);
@@ -756,14 +756,14 @@  discard block
 block discarded – undo
756 756
         /**
757 757
          * Set the loader instance for future use
758 758
          * @param Loader $loader the loader object
759
-		 * @return object
759
+         * @return object
760 760
          */
761
-         public function setLoader($loader){
761
+            public function setLoader($loader){
762 762
             $this->loaderInstance = $loader;
763 763
             return $this;
764 764
         }
765 765
 
766
-		/**
766
+        /**
767 767
          * Return the queryBuilder instance this is the shortcut to database queryBuilder
768 768
          * @return object the DatabaseQueryBuilder instance
769 769
          */
@@ -774,9 +774,9 @@  discard block
 block discarded – undo
774 774
         /**
775 775
          * Set the DatabaseQueryBuilder instance for future use
776 776
          * @param object $queryBuilder the DatabaseQueryBuilder object
777
-		 * @return object
777
+         * @return object
778 778
          */
779
-         public function setQueryBuilder($queryBuilder){
779
+            public function setQueryBuilder($queryBuilder){
780 780
             $this->_database->setQueryBuilder($queryBuilder);
781 781
             return $this;
782 782
         }
@@ -793,9 +793,9 @@  discard block
 block discarded – undo
793 793
         /**
794 794
          * Set the form validation instance for future use
795 795
          * @param FormValidation $fv the form validation object
796
-		 * @return object
796
+         * @return object
797 797
          */
798
-         public function setFormValidation($fv){
798
+            public function setFormValidation($fv){
799 799
             $this->formValidationInstance = $fv;
800 800
             return $this;
801 801
         }
@@ -836,12 +836,12 @@  discard block
 block discarded – undo
836 836
          * INTERNAL METHODS
837 837
          * ------------------------------------------------------------ */
838 838
 
839
-		/**
840
-		* relate for the relation "belongs_to"
841
-		* @return mixed
842
-		*/
843
-		protected function relateBelongsTo($row){
844
-			foreach ($this->belongs_to as $key => $value)
839
+        /**
840
+         * relate for the relation "belongs_to"
841
+         * @return mixed
842
+         */
843
+        protected function relateBelongsTo($row){
844
+            foreach ($this->belongs_to as $key => $value)
845 845
             {
846 846
                 if (is_string($value))
847 847
                 {
@@ -872,15 +872,15 @@  discard block
 block discarded – undo
872 872
                     }
873 873
                 }
874 874
             }
875
-			return $row;
876
-		}
877
-
878
-		/**
879
-		* relate for the relation "has_many"
880
-		* @return mixed
881
-		*/
882
-		protected function relateHasMany($row){
883
-			foreach ($this->has_many as $key => $value)
875
+            return $row;
876
+        }
877
+
878
+        /**
879
+         * relate for the relation "has_many"
880
+         * @return mixed
881
+         */
882
+        protected function relateHasMany($row){
883
+            foreach ($this->has_many as $key => $value)
884 884
             {
885 885
                 if (is_string($value))
886 886
                 {
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
                     }
912 912
                 }
913 913
             }
914
-			return $row;
915
-		}
914
+            return $row;
915
+        }
916 916
 		
917 917
         /**
918 918
          * Trigger an event and call its observers. Pass through the event name
@@ -977,30 +977,30 @@  discard block
 block discarded – undo
977 977
         }
978 978
 		
979 979
 		
980
-		/**
981
-		* Set WHERE parameters, when is array
982
-		* @param array $params
983
-		*/
984
-		protected function _set_where_array(array $params){
985
-			foreach ($params as $field => $filter)
986
-			{
987
-				if (is_array($filter))
988
-				{
989
-					$this->getQueryBuilder()->in($field, $filter);
990
-				}
991
-				else
992
-				{
993
-					if (is_int($field))
994
-					{
995
-						$this->getQueryBuilder()->where($filter);
996
-					}
997
-					else
998
-					{
999
-						$this->getQueryBuilder()->where($field, $filter);
1000
-					}
1001
-				}
1002
-			}
1003
-		}
980
+        /**
981
+         * Set WHERE parameters, when is array
982
+         * @param array $params
983
+         */
984
+        protected function _set_where_array(array $params){
985
+            foreach ($params as $field => $filter)
986
+            {
987
+                if (is_array($filter))
988
+                {
989
+                    $this->getQueryBuilder()->in($field, $filter);
990
+                }
991
+                else
992
+                {
993
+                    if (is_int($field))
994
+                    {
995
+                        $this->getQueryBuilder()->where($filter);
996
+                    }
997
+                    else
998
+                    {
999
+                        $this->getQueryBuilder()->where($field, $filter);
1000
+                    }
1001
+                }
1002
+            }
1003
+        }
1004 1004
 
1005 1005
 
1006 1006
         /**
@@ -1016,8 +1016,8 @@  discard block
 block discarded – undo
1016 1016
             {
1017 1017
                 $this->getQueryBuilder()->where($params[0]);
1018 1018
             }
1019
-        	else if (count($params) == 2)
1020
-    		{
1019
+            else if (count($params) == 2)
1020
+            {
1021 1021
                 if (is_array($params[1]))
1022 1022
                 {
1023 1023
                     $this->getQueryBuilder()->in($params[0], $params[1]);
@@ -1026,11 +1026,11 @@  discard block
 block discarded – undo
1026 1026
                 {
1027 1027
                     $this->getQueryBuilder()->where($params[0], $params[1]);
1028 1028
                 }
1029
-    		}
1030
-    		else if (count($params) == 3)
1031
-    		{
1032
-    			$this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
-    		}
1029
+            }
1030
+            else if (count($params) == 3)
1031
+            {
1032
+                $this->getQueryBuilder()->where($params[0], $params[1], $params[2]);
1033
+            }
1034 1034
             else
1035 1035
             {
1036 1036
                 if (is_array($params[1]))
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
 
1047 1047
         /**
1048 1048
             Shortcut to controller
1049
-        */
1049
+         */
1050 1050
         public function __get($key){
1051 1051
             return get_instance()->{$key};
1052 1052
         }
Please login to merge, or discard this patch.
core/classes/Module.php 3 patches
Spacing   +76 added lines, -76 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 Module{
27
+	class Module {
28 28
 		
29 29
 		/**
30 30
 		 * list of loaded module
@@ -42,9 +42,9 @@  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){
47
-				self::$logger[0] =& class_loader('Log', 'classes');
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47
+				self::$logger[0] = & class_loader('Log', 'classes');
48 48
 				self::$logger[0]->setLogger('Library::Module');
49 49
 			}
50 50
 			return self::$logger[0];
@@ -53,24 +53,24 @@  discard block
 block discarded – undo
53 53
 		/**
54 54
 		 * Initialise the module list by scanning the directory MODULE_PATH
55 55
 		 */
56
-		public function init(){
56
+		public function init() {
57 57
 			$logger = self::getLogger();
58 58
 			$logger->debug('Check if the application contains the modules ...');
59 59
 			$moduleDir = opendir(MODULE_PATH);
60
-			if(is_resource($moduleDir)){
61
-				while(($module = readdir($moduleDir)) !== false){
62
-					if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
60
+			if (is_resource($moduleDir)) {
61
+				while (($module = readdir($moduleDir)) !== false) {
62
+					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) {
63 63
 						self::$list[] = $module;
64 64
 					}
65
-					else{
66
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
65
+					else {
66
+						$logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name');
67 67
 					}
68 68
 				}
69 69
 				closedir($moduleDir);
70 70
 			}
71 71
 			ksort(self::$list);
72 72
 			
73
-			if(self::hasModule()){
73
+			if (self::hasModule()) {
74 74
 				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
75 75
 			}
76 76
 		}
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 		 * Get the list of the custom autoload configuration from module if exists
80 80
 		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
81 81
 		 */
82
-		public static function getModulesAutoloadConfig(){
82
+		public static function getModulesAutoloadConfig() {
83 83
 			$logger = self::getLogger();
84
-			if(! self::hasModule()){
84
+			if (!self::hasModule()) {
85 85
 				$logger->info('No module was loaded skipping.');
86 86
 				return false;
87 87
 			}
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
 			
95 95
 			foreach (self::$list as $module) {
96 96
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
97
-				if(file_exists($file)){
97
+				if (file_exists($file)) {
98 98
 					$autoload = array();
99 99
 					require_once $file;
100
-					if(! empty($autoload) && is_array($autoload)){
100
+					if (!empty($autoload) && is_array($autoload)) {
101 101
 						$autoloads = array_merge_recursive($autoloads, $autoload);
102 102
 						unset($autoload);
103 103
 					}
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
 		 * Get the list of the custom routes configuration from module if exists
111 111
 		 * @return array|boolean the routes list or false if no module contains the routes configuration
112 112
 		 */
113
-		public static function getModulesRoutes(){
113
+		public static function getModulesRoutes() {
114 114
 			$logger = self::getLogger();
115
-			if(! self::hasModule()){
115
+			if (!self::hasModule()) {
116 116
 				$logger->info('No module was loaded skipping.');
117 117
 				return false;
118 118
 			}
119 119
 			$routes = array();
120 120
 			foreach (self::$list as $module) {
121 121
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
122
-				if(file_exists($file)){
122
+				if (file_exists($file)) {
123 123
 					$route = array();
124 124
 					require_once $file;
125
-					if(! empty($route) && is_array($route)){
125
+					if (!empty($route) && is_array($route)) {
126 126
 						$routes = array_merge($routes, $route);
127 127
 						unset($route);
128 128
 					}
@@ -138,23 +138,23 @@  discard block
 block discarded – undo
138 138
 		 * @param  string $module  the module name
139 139
 		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
140 140
 		 */
141
-		public static function findControllerFullPath($class, $module = null){
141
+		public static function findControllerFullPath($class, $module = null) {
142 142
 			$logger = self::getLogger();
143
-			if(! self::hasModule()){
143
+			if (!self::hasModule()) {
144 144
 				$logger->info('No module was loaded skiping.');
145 145
 				return false;
146 146
 			}
147 147
 			$class = str_ireplace('.php', '', $class);
148 148
 			$class = ucfirst($class);
149
-			$classFile = $class.'.php';
150
-			$logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...');
149
+			$classFile = $class . '.php';
150
+			$logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...');
151 151
 			$filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile;
152
-			if(file_exists($filePath)){
153
-				$logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
152
+			if (file_exists($filePath)) {
153
+				$logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
154 154
 				return $filePath;
155 155
 			}
156
-			else{
157
-				$logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
156
+			else {
157
+				$logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']');
158 158
 				return false;
159 159
 			}
160 160
 		}
@@ -165,23 +165,23 @@  discard block
 block discarded – undo
165 165
 		 * @param string $module the module name
166 166
 		 * @return boolean|string  false or null if no module have this model, return the full path of this model
167 167
 		 */
168
-		public static function findModelFullPath($class, $module = null){
168
+		public static function findModelFullPath($class, $module = null) {
169 169
 			$logger = self::getLogger();
170
-			if(! self::hasModule()){
170
+			if (!self::hasModule()) {
171 171
 				$logger->info('No module was loaded skiping.');
172 172
 				return false;
173 173
 			}
174 174
 			$class = str_ireplace('.php', '', $class);
175 175
 			$class = ucfirst($class);
176
-			$classFile = $class.'.php';
177
-			$logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...');
176
+			$classFile = $class . '.php';
177
+			$logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...');
178 178
 			$filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile;
179
-			if(file_exists($filePath)){
180
-				$logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
179
+			if (file_exists($filePath)) {
180
+				$logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
181 181
 				return $filePath;
182 182
 			}
183
-			else{
184
-				$logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
183
+			else {
184
+				$logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']');
185 185
 				return false;
186 186
 			}
187 187
 		}
@@ -192,22 +192,22 @@  discard block
 block discarded – undo
192 192
 		 * @param string $module the module name
193 193
 		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
194 194
 		 */
195
-		public static function findConfigFullPath($configuration, $module = null){
195
+		public static function findConfigFullPath($configuration, $module = null) {
196 196
 			$logger = self::getLogger();
197
-			if(! self::hasModule()){
197
+			if (!self::hasModule()) {
198 198
 				$logger->info('No module was loaded skiping.');
199 199
 				return false;
200 200
 			}
201 201
 			$configuration = str_ireplace('.php', '', $configuration);
202
-			$file = $configuration.'.php';
203
-			$logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...');
202
+			$file = $configuration . '.php';
203
+			$logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...');
204 204
 			$filePath = MODULE_PATH . $module . DS . 'config' . DS . $file;
205
-			if(file_exists($filePath)){
206
-				$logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
205
+			if (file_exists($filePath)) {
206
+				$logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']');
207 207
 				return $filePath;
208 208
 			}
209
-			else{
210
-				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
209
+			else {
210
+				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']');
211 211
 				return false;
212 212
 			}
213 213
 		}
@@ -218,23 +218,23 @@  discard block
 block discarded – undo
218 218
 		 * @param string $module the module name
219 219
 		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
220 220
 		 */
221
-		public static function findFunctionFullPath($helper, $module = null){
221
+		public static function findFunctionFullPath($helper, $module = null) {
222 222
 			$logger = self::getLogger();
223
-			if(! self::hasModule()){
223
+			if (!self::hasModule()) {
224 224
 				$logger->info('No module was loaded skiping.');
225 225
 				return false;
226 226
 			}
227 227
 			$helper = str_ireplace('.php', '', $helper);
228 228
 			$helper = str_ireplace('function_', '', $helper);
229
-			$file = 'function_'.$helper.'.php';
230
-			$logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...');
229
+			$file = 'function_' . $helper . '.php';
230
+			$logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...');
231 231
 			$filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file;
232
-			if(file_exists($filePath)){
233
-				$logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
232
+			if (file_exists($filePath)) {
233
+				$logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']');
234 234
 				return $filePath;
235 235
 			}
236
-			else{
237
-				$logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
236
+			else {
237
+				$logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']');
238 238
 				return false;
239 239
 			}
240 240
 		}
@@ -246,22 +246,22 @@  discard block
 block discarded – undo
246 246
 		 * @param string $module the module name
247 247
 		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
248 248
 		 */
249
-		public static function findLibraryFullPath($class, $module = null){
249
+		public static function findLibraryFullPath($class, $module = null) {
250 250
 			$logger = self::getLogger();
251
-			if(! self::hasModule()){
251
+			if (!self::hasModule()) {
252 252
 				$logger->info('No module was loaded skiping.');
253 253
 				return false;
254 254
 			}
255 255
 			$class = str_ireplace('.php', '', $class);
256
-			$file = $class.'.php';
257
-			$logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...');
256
+			$file = $class . '.php';
257
+			$logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...');
258 258
 			$filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file;
259
-			if(file_exists($filePath)){
260
-				$logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
259
+			if (file_exists($filePath)) {
260
+				$logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']');
261 261
 				return $filePath;
262 262
 			}
263
-			else{
264
-				$logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
263
+			else {
264
+				$logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']');
265 265
 				return false;
266 266
 			}
267 267
 		}
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 		 * @param string $module the module name to check
274 274
 		 * @return boolean|string  false or null if no module have this view, path the full path of the view
275 275
 		 */
276
-		public static function findViewFullPath($view, $module = null){
276
+		public static function findViewFullPath($view, $module = null) {
277 277
 			$logger = self::getLogger();
278
-			if(! self::hasModule()){
278
+			if (!self::hasModule()) {
279 279
 				$logger->info('No module was loaded skiping.');
280 280
 				return false;
281 281
 			}
@@ -283,14 +283,14 @@  discard block
 block discarded – undo
283 283
 			$view = trim($view, '/\\');
284 284
 			$view = str_ireplace('/', DS, $view);
285 285
 			$viewFile = $view . '.php';
286
-			$logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...');
286
+			$logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...');
287 287
 			$filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile;
288
-			if(file_exists($filePath)){
289
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
288
+			if (file_exists($filePath)) {
289
+				$logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']');
290 290
 				return $filePath;
291 291
 			}
292
-			else{
293
-				$logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
292
+			else {
293
+				$logger->info('View [' . $view . '] does not exist in the module [' . $module . ']');
294 294
 				return false;
295 295
 			}
296 296
 		}
@@ -302,23 +302,23 @@  discard block
 block discarded – undo
302 302
 		 * @param string $appLang the application language like 'en', 'fr'
303 303
 		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
304 304
 		 */
305
-		public static function findLanguageFullPath($language, $module = null, $appLang){
305
+		public static function findLanguageFullPath($language, $module = null, $appLang) {
306 306
 			$logger = self::getLogger();
307
-			if(! self::hasModule()){
307
+			if (!self::hasModule()) {
308 308
 				$logger->info('No module was loaded skiping.');
309 309
 				return false;
310 310
 			}
311 311
 			$language = str_ireplace('.php', '', $language);
312 312
 			$language = str_ireplace('lang_', '', $language);
313
-			$file = 'lang_'.$language.'.php';
314
-			$logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...');
313
+			$file = 'lang_' . $language . '.php';
314
+			$logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...');
315 315
 			$filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file;
316
-			if(file_exists($filePath)){
317
-				$logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
316
+			if (file_exists($filePath)) {
317
+				$logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']');
318 318
 				return $filePath;
319 319
 			}
320
-			else{
321
-				$logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
320
+			else {
321
+				$logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']');
322 322
 				return false;
323 323
 			}
324 324
 		}
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 		 * Get the list of module loaded
328 328
 		 * @return array the module list
329 329
 		 */
330
-		public static function getModuleList(){
330
+		public static function getModuleList() {
331 331
 			return self::$list;
332 332
 		}
333 333
 
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 		 * Check if the application has an module
336 336
 		 * @return boolean
337 337
 		 */
338
-		public static function hasModule(){
338
+		public static function hasModule() {
339 339
 			return !empty(self::$list);
340 340
 		}
341 341
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -61,8 +61,7 @@  discard block
 block discarded – undo
61 61
 				while(($module = readdir($moduleDir)) !== false){
62 62
 					if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
63 63
 						self::$list[] = $module;
64
-					}
65
-					else{
64
+					} else{
66 65
 						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
67 66
 					}
68 67
 				}
@@ -152,8 +151,7 @@  discard block
 block discarded – undo
152 151
 			if(file_exists($filePath)){
153 152
 				$logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
154 153
 				return $filePath;
155
-			}
156
-			else{
154
+			} else{
157 155
 				$logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
158 156
 				return false;
159 157
 			}
@@ -179,8 +177,7 @@  discard block
 block discarded – undo
179 177
 			if(file_exists($filePath)){
180 178
 				$logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
181 179
 				return $filePath;
182
-			}
183
-			else{
180
+			} else{
184 181
 				$logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
185 182
 				return false;
186 183
 			}
@@ -205,8 +202,7 @@  discard block
 block discarded – undo
205 202
 			if(file_exists($filePath)){
206 203
 				$logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
207 204
 				return $filePath;
208
-			}
209
-			else{
205
+			} else{
210 206
 				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
211 207
 				return false;
212 208
 			}
@@ -232,8 +228,7 @@  discard block
 block discarded – undo
232 228
 			if(file_exists($filePath)){
233 229
 				$logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
234 230
 				return $filePath;
235
-			}
236
-			else{
231
+			} else{
237 232
 				$logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
238 233
 				return false;
239 234
 			}
@@ -259,8 +254,7 @@  discard block
 block discarded – undo
259 254
 			if(file_exists($filePath)){
260 255
 				$logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
261 256
 				return $filePath;
262
-			}
263
-			else{
257
+			} else{
264 258
 				$logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
265 259
 				return false;
266 260
 			}
@@ -288,8 +282,7 @@  discard block
 block discarded – undo
288 282
 			if(file_exists($filePath)){
289 283
 				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
290 284
 				return $filePath;
291
-			}
292
-			else{
285
+			} else{
293 286
 				$logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
294 287
 				return false;
295 288
 			}
@@ -316,8 +309,7 @@  discard block
 block discarded – undo
316 309
 			if(file_exists($filePath)){
317 310
 				$logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
318 311
 				return $filePath;
319
-			}
320
-			else{
312
+			} else{
321 313
 				$logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
322 314
 				return false;
323 315
 			}
Please login to merge, or discard this patch.
Indentation   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4 4
      * TNH Framework
5 5
      *
6 6
      * A simple PHP framework using HMVC architecture
@@ -22,321 +22,321 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
    
27
-	class Module{
27
+    class Module{
28 28
 		
29
-		/**
30
-		 * list of loaded module
31
-		 * @var array
32
-		 */
33
-		private static $list = array();
29
+        /**
30
+         * list of loaded module
31
+         * @var array
32
+         */
33
+        private static $list = array();
34 34
 
35
-		/**
36
-		 * logger instance
37
-		 * @var Log
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * logger instance
37
+         * @var Log
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * The signleton of the logger
43
-		 * @return Object the Log instance
44
-		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
47
-				self::$logger[0] =& class_loader('Log', 'classes');
48
-				self::$logger[0]->setLogger('Library::Module');
49
-			}
50
-			return self::$logger[0];
51
-		}
41
+        /**
42
+         * The signleton of the logger
43
+         * @return Object the Log instance
44
+         */
45
+        private static function getLogger(){
46
+            if(self::$logger == null){
47
+                self::$logger[0] =& class_loader('Log', 'classes');
48
+                self::$logger[0]->setLogger('Library::Module');
49
+            }
50
+            return self::$logger[0];
51
+        }
52 52
 
53
-		/**
54
-		 * Initialise the module list by scanning the directory MODULE_PATH
55
-		 */
56
-		public function init(){
57
-			$logger = self::getLogger();
58
-			$logger->debug('Check if the application contains the modules ...');
59
-			$moduleDir = opendir(MODULE_PATH);
60
-			if(is_resource($moduleDir)){
61
-				while(($module = readdir($moduleDir)) !== false){
62
-					if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
63
-						self::$list[] = $module;
64
-					}
65
-					else{
66
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
67
-					}
68
-				}
69
-				closedir($moduleDir);
70
-			}
71
-			ksort(self::$list);
53
+        /**
54
+         * Initialise the module list by scanning the directory MODULE_PATH
55
+         */
56
+        public function init(){
57
+            $logger = self::getLogger();
58
+            $logger->debug('Check if the application contains the modules ...');
59
+            $moduleDir = opendir(MODULE_PATH);
60
+            if(is_resource($moduleDir)){
61
+                while(($module = readdir($moduleDir)) !== false){
62
+                    if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
63
+                        self::$list[] = $module;
64
+                    }
65
+                    else{
66
+                        $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
67
+                    }
68
+                }
69
+                closedir($moduleDir);
70
+            }
71
+            ksort(self::$list);
72 72
 			
73
-			if(self::hasModule()){
74
-				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
75
-			}
76
-		}
73
+            if(self::hasModule()){
74
+                $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
75
+            }
76
+        }
77 77
 		
78
-		/**
79
-		 * Get the list of the custom autoload configuration from module if exists
80
-		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
81
-		 */
82
-		public static function getModulesAutoloadConfig(){
83
-			$logger = self::getLogger();
84
-			if(! self::hasModule()){
85
-				$logger->info('No module was loaded skipping.');
86
-				return false;
87
-			}
88
-			$autoloads = array();
89
-			$autoloads['libraries'] = array();
90
-			$autoloads['config']    = array();
91
-			$autoloads['models']    = array();
92
-			$autoloads['functions'] = array();
93
-			$autoloads['languages'] = array();
78
+        /**
79
+         * Get the list of the custom autoload configuration from module if exists
80
+         * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
81
+         */
82
+        public static function getModulesAutoloadConfig(){
83
+            $logger = self::getLogger();
84
+            if(! self::hasModule()){
85
+                $logger->info('No module was loaded skipping.');
86
+                return false;
87
+            }
88
+            $autoloads = array();
89
+            $autoloads['libraries'] = array();
90
+            $autoloads['config']    = array();
91
+            $autoloads['models']    = array();
92
+            $autoloads['functions'] = array();
93
+            $autoloads['languages'] = array();
94 94
 			
95
-			foreach (self::$list as $module) {
96
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
97
-				if(file_exists($file)){
98
-					$autoload = array();
99
-					require_once $file;
100
-					if(! empty($autoload) && is_array($autoload)){
101
-						$autoloads = array_merge_recursive($autoloads, $autoload);
102
-						unset($autoload);
103
-					}
104
-				}
105
-			}
106
-			return $autoloads;
107
-		}
95
+            foreach (self::$list as $module) {
96
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
97
+                if(file_exists($file)){
98
+                    $autoload = array();
99
+                    require_once $file;
100
+                    if(! empty($autoload) && is_array($autoload)){
101
+                        $autoloads = array_merge_recursive($autoloads, $autoload);
102
+                        unset($autoload);
103
+                    }
104
+                }
105
+            }
106
+            return $autoloads;
107
+        }
108 108
 
109
-		/**
110
-		 * Get the list of the custom routes configuration from module if exists
111
-		 * @return array|boolean the routes list or false if no module contains the routes configuration
112
-		 */
113
-		public static function getModulesRoutes(){
114
-			$logger = self::getLogger();
115
-			if(! self::hasModule()){
116
-				$logger->info('No module was loaded skipping.');
117
-				return false;
118
-			}
119
-			$routes = array();
120
-			foreach (self::$list as $module) {
121
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
122
-				if(file_exists($file)){
123
-					$route = array();
124
-					require_once $file;
125
-					if(! empty($route) && is_array($route)){
126
-						$routes = array_merge($routes, $route);
127
-						unset($route);
128
-					}
129
-				}
130
-			}
131
-			return $routes;
132
-		}
109
+        /**
110
+         * Get the list of the custom routes configuration from module if exists
111
+         * @return array|boolean the routes list or false if no module contains the routes configuration
112
+         */
113
+        public static function getModulesRoutes(){
114
+            $logger = self::getLogger();
115
+            if(! self::hasModule()){
116
+                $logger->info('No module was loaded skipping.');
117
+                return false;
118
+            }
119
+            $routes = array();
120
+            foreach (self::$list as $module) {
121
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
122
+                if(file_exists($file)){
123
+                    $route = array();
124
+                    require_once $file;
125
+                    if(! empty($route) && is_array($route)){
126
+                        $routes = array_merge($routes, $route);
127
+                        unset($route);
128
+                    }
129
+                }
130
+            }
131
+            return $routes;
132
+        }
133 133
 
134 134
 
135
-		/**
136
-		 * Check if in module list can have this controller
137
-		 * @param  string $class the controller class
138
-		 * @param  string $module  the module name
139
-		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
140
-		 */
141
-		public static function findControllerFullPath($class, $module = null){
142
-			$logger = self::getLogger();
143
-			if(! self::hasModule()){
144
-				$logger->info('No module was loaded skiping.');
145
-				return false;
146
-			}
147
-			$class = str_ireplace('.php', '', $class);
148
-			$class = ucfirst($class);
149
-			$classFile = $class.'.php';
150
-			$logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...');
151
-			$filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile;
152
-			if(file_exists($filePath)){
153
-				$logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
154
-				return $filePath;
155
-			}
156
-			else{
157
-				$logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
158
-				return false;
159
-			}
160
-		}
135
+        /**
136
+         * Check if in module list can have this controller
137
+         * @param  string $class the controller class
138
+         * @param  string $module  the module name
139
+         * @return boolean|string  false or null if no module have this controller, path the full path of the controller
140
+         */
141
+        public static function findControllerFullPath($class, $module = null){
142
+            $logger = self::getLogger();
143
+            if(! self::hasModule()){
144
+                $logger->info('No module was loaded skiping.');
145
+                return false;
146
+            }
147
+            $class = str_ireplace('.php', '', $class);
148
+            $class = ucfirst($class);
149
+            $classFile = $class.'.php';
150
+            $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...');
151
+            $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile;
152
+            if(file_exists($filePath)){
153
+                $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
154
+                return $filePath;
155
+            }
156
+            else{
157
+                $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']');
158
+                return false;
159
+            }
160
+        }
161 161
 
162
-		/**
163
-		 * Check if in module list can have this model
164
-		 * @param  string $class the model class
165
-		 * @param string $module the module name
166
-		 * @return boolean|string  false or null if no module have this model, return the full path of this model
167
-		 */
168
-		public static function findModelFullPath($class, $module = null){
169
-			$logger = self::getLogger();
170
-			if(! self::hasModule()){
171
-				$logger->info('No module was loaded skiping.');
172
-				return false;
173
-			}
174
-			$class = str_ireplace('.php', '', $class);
175
-			$class = ucfirst($class);
176
-			$classFile = $class.'.php';
177
-			$logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...');
178
-			$filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile;
179
-			if(file_exists($filePath)){
180
-				$logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
181
-				return $filePath;
182
-			}
183
-			else{
184
-				$logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
185
-				return false;
186
-			}
187
-		}
162
+        /**
163
+         * Check if in module list can have this model
164
+         * @param  string $class the model class
165
+         * @param string $module the module name
166
+         * @return boolean|string  false or null if no module have this model, return the full path of this model
167
+         */
168
+        public static function findModelFullPath($class, $module = null){
169
+            $logger = self::getLogger();
170
+            if(! self::hasModule()){
171
+                $logger->info('No module was loaded skiping.');
172
+                return false;
173
+            }
174
+            $class = str_ireplace('.php', '', $class);
175
+            $class = ucfirst($class);
176
+            $classFile = $class.'.php';
177
+            $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...');
178
+            $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile;
179
+            if(file_exists($filePath)){
180
+                $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
181
+                return $filePath;
182
+            }
183
+            else{
184
+                $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']');
185
+                return false;
186
+            }
187
+        }
188 188
 		
189
-		/**
190
-		 * Check if in module list can have this config
191
-		 * @param  string $configuration the config name
192
-		 * @param string $module the module name
193
-		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
194
-		 */
195
-		public static function findConfigFullPath($configuration, $module = null){
196
-			$logger = self::getLogger();
197
-			if(! self::hasModule()){
198
-				$logger->info('No module was loaded skiping.');
199
-				return false;
200
-			}
201
-			$configuration = str_ireplace('.php', '', $configuration);
202
-			$file = $configuration.'.php';
203
-			$logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...');
204
-			$filePath = MODULE_PATH . $module . DS . 'config' . DS . $file;
205
-			if(file_exists($filePath)){
206
-				$logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
207
-				return $filePath;
208
-			}
209
-			else{
210
-				$logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
211
-				return false;
212
-			}
213
-		}
189
+        /**
190
+         * Check if in module list can have this config
191
+         * @param  string $configuration the config name
192
+         * @param string $module the module name
193
+         * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
194
+         */
195
+        public static function findConfigFullPath($configuration, $module = null){
196
+            $logger = self::getLogger();
197
+            if(! self::hasModule()){
198
+                $logger->info('No module was loaded skiping.');
199
+                return false;
200
+            }
201
+            $configuration = str_ireplace('.php', '', $configuration);
202
+            $file = $configuration.'.php';
203
+            $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...');
204
+            $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file;
205
+            if(file_exists($filePath)){
206
+                $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']');
207
+                return $filePath;
208
+            }
209
+            else{
210
+                $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']');
211
+                return false;
212
+            }
213
+        }
214 214
 
215
-		/**
216
-		 * Check if in module list can have this helper
217
-		 * @param  string $helper the helper name
218
-		 * @param string $module the module name
219
-		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
220
-		 */
221
-		public static function findFunctionFullPath($helper, $module = null){
222
-			$logger = self::getLogger();
223
-			if(! self::hasModule()){
224
-				$logger->info('No module was loaded skiping.');
225
-				return false;
226
-			}
227
-			$helper = str_ireplace('.php', '', $helper);
228
-			$helper = str_ireplace('function_', '', $helper);
229
-			$file = 'function_'.$helper.'.php';
230
-			$logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...');
231
-			$filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file;
232
-			if(file_exists($filePath)){
233
-				$logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
234
-				return $filePath;
235
-			}
236
-			else{
237
-				$logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
238
-				return false;
239
-			}
240
-		}
215
+        /**
216
+         * Check if in module list can have this helper
217
+         * @param  string $helper the helper name
218
+         * @param string $module the module name
219
+         * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
220
+         */
221
+        public static function findFunctionFullPath($helper, $module = null){
222
+            $logger = self::getLogger();
223
+            if(! self::hasModule()){
224
+                $logger->info('No module was loaded skiping.');
225
+                return false;
226
+            }
227
+            $helper = str_ireplace('.php', '', $helper);
228
+            $helper = str_ireplace('function_', '', $helper);
229
+            $file = 'function_'.$helper.'.php';
230
+            $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...');
231
+            $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file;
232
+            if(file_exists($filePath)){
233
+                $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']');
234
+                return $filePath;
235
+            }
236
+            else{
237
+                $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']');
238
+                return false;
239
+            }
240
+        }
241 241
 
242 242
 
243
-		/**
244
-		 * Check if in module list can have this library
245
-		 * @param  string $class the library name
246
-		 * @param string $module the module name
247
-		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
248
-		 */
249
-		public static function findLibraryFullPath($class, $module = null){
250
-			$logger = self::getLogger();
251
-			if(! self::hasModule()){
252
-				$logger->info('No module was loaded skiping.');
253
-				return false;
254
-			}
255
-			$class = str_ireplace('.php', '', $class);
256
-			$file = $class.'.php';
257
-			$logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...');
258
-			$filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file;
259
-			if(file_exists($filePath)){
260
-				$logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
261
-				return $filePath;
262
-			}
263
-			else{
264
-				$logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
265
-				return false;
266
-			}
267
-		}
243
+        /**
244
+         * Check if in module list can have this library
245
+         * @param  string $class the library name
246
+         * @param string $module the module name
247
+         * @return boolean|string  false or null if no module have this library,  return the full path of this library
248
+         */
249
+        public static function findLibraryFullPath($class, $module = null){
250
+            $logger = self::getLogger();
251
+            if(! self::hasModule()){
252
+                $logger->info('No module was loaded skiping.');
253
+                return false;
254
+            }
255
+            $class = str_ireplace('.php', '', $class);
256
+            $file = $class.'.php';
257
+            $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...');
258
+            $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file;
259
+            if(file_exists($filePath)){
260
+                $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']');
261
+                return $filePath;
262
+            }
263
+            else{
264
+                $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']');
265
+                return false;
266
+            }
267
+        }
268 268
 
269 269
 
270
-		/**
271
-		 * Check if in module list can have this view
272
-		 * @param  string $view the view path
273
-		 * @param string $module the module name to check
274
-		 * @return boolean|string  false or null if no module have this view, path the full path of the view
275
-		 */
276
-		public static function findViewFullPath($view, $module = null){
277
-			$logger = self::getLogger();
278
-			if(! self::hasModule()){
279
-				$logger->info('No module was loaded skiping.');
280
-				return false;
281
-			}
282
-			$view = str_ireplace('.php', '', $view);
283
-			$view = trim($view, '/\\');
284
-			$view = str_ireplace('/', DS, $view);
285
-			$viewFile = $view . '.php';
286
-			$logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...');
287
-			$filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile;
288
-			if(file_exists($filePath)){
289
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
290
-				return $filePath;
291
-			}
292
-			else{
293
-				$logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
294
-				return false;
295
-			}
296
-		}
270
+        /**
271
+         * Check if in module list can have this view
272
+         * @param  string $view the view path
273
+         * @param string $module the module name to check
274
+         * @return boolean|string  false or null if no module have this view, path the full path of the view
275
+         */
276
+        public static function findViewFullPath($view, $module = null){
277
+            $logger = self::getLogger();
278
+            if(! self::hasModule()){
279
+                $logger->info('No module was loaded skiping.');
280
+                return false;
281
+            }
282
+            $view = str_ireplace('.php', '', $view);
283
+            $view = trim($view, '/\\');
284
+            $view = str_ireplace('/', DS, $view);
285
+            $viewFile = $view . '.php';
286
+            $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...');
287
+            $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile;
288
+            if(file_exists($filePath)){
289
+                $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']');
290
+                return $filePath;
291
+            }
292
+            else{
293
+                $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']');
294
+                return false;
295
+            }
296
+        }
297 297
 
298
-		/**
299
-		 * Check if in module list can have this language
300
-		 * @param  string $language the language name
301
-		 * @param string $module the module name
302
-		 * @param string $appLang the application language like 'en', 'fr'
303
-		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
304
-		 */
305
-		public static function findLanguageFullPath($language, $module = null, $appLang){
306
-			$logger = self::getLogger();
307
-			if(! self::hasModule()){
308
-				$logger->info('No module was loaded skiping.');
309
-				return false;
310
-			}
311
-			$language = str_ireplace('.php', '', $language);
312
-			$language = str_ireplace('lang_', '', $language);
313
-			$file = 'lang_'.$language.'.php';
314
-			$logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...');
315
-			$filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file;
316
-			if(file_exists($filePath)){
317
-				$logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
318
-				return $filePath;
319
-			}
320
-			else{
321
-				$logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
322
-				return false;
323
-			}
324
-		}
298
+        /**
299
+         * Check if in module list can have this language
300
+         * @param  string $language the language name
301
+         * @param string $module the module name
302
+         * @param string $appLang the application language like 'en', 'fr'
303
+         * @return boolean|string  false or null if no module have this language,  return the full path of this language
304
+         */
305
+        public static function findLanguageFullPath($language, $module = null, $appLang){
306
+            $logger = self::getLogger();
307
+            if(! self::hasModule()){
308
+                $logger->info('No module was loaded skiping.');
309
+                return false;
310
+            }
311
+            $language = str_ireplace('.php', '', $language);
312
+            $language = str_ireplace('lang_', '', $language);
313
+            $file = 'lang_'.$language.'.php';
314
+            $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...');
315
+            $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file;
316
+            if(file_exists($filePath)){
317
+                $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']');
318
+                return $filePath;
319
+            }
320
+            else{
321
+                $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']');
322
+                return false;
323
+            }
324
+        }
325 325
 
326
-		/**
327
-		 * Get the list of module loaded
328
-		 * @return array the module list
329
-		 */
330
-		public static function getModuleList(){
331
-			return self::$list;
332
-		}
326
+        /**
327
+         * Get the list of module loaded
328
+         * @return array the module list
329
+         */
330
+        public static function getModuleList(){
331
+            return self::$list;
332
+        }
333 333
 
334
-		/**
335
-		 * Check if the application has an module
336
-		 * @return boolean
337
-		 */
338
-		public static function hasModule(){
339
-			return !empty(self::$list);
340
-		}
334
+        /**
335
+         * Check if the application has an module
336
+         * @return boolean
337
+         */
338
+        public static function hasModule(){
339
+            return !empty(self::$list);
340
+        }
341 341
 
342
-	}
342
+    }
Please login to merge, or discard this patch.
core/libraries/Upload.php 3 patches
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     *    @package FileUpload
38 38
     *    @version 1.5
39 39
     */
40
-    class Upload{
40
+    class Upload {
41 41
 
42 42
         /**
43 43
         *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         *    @version    1.0
70 70
         *    @var        array
71 71
         */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
         *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         *    @version    1.0
120 120
         *    @var        float
121 121
         */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
         *    List of allowed mime types
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
         *    @return    object
218 218
         *    @method    object    __construct
219 219
         */
220
-        public function __construct(){
221
-            $this->logger =& class_loader('Log', 'classes');
220
+        public function __construct() {
221
+            $this->logger = & class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
223 223
 
224 224
             Loader::lang('file_upload');
225
-            $obj =& get_instance();
225
+            $obj = & get_instance();
226 226
 
227 227
             $this->error_messages = array(
228 228
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
             );
240 240
 
241 241
             $this->file = array(
242
-                'status'                =>    false,    // True: success upload
243
-                'mime'                  =>    '',       // Empty string
244
-                'filename'              =>    '',       // Empty string
245
-                'original'              =>    '',       // Empty string
246
-                'size'                  =>    0,        // 0 Bytes
247
-                'sizeFormated'          =>    '0B',     // 0 Bytes
248
-                'destination'           =>    './',     // Default: ./
249
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
250
-                'error'                 =>    null,        // File error
242
+                'status'                =>    false, // True: success upload
243
+                'mime'                  =>    '', // Empty string
244
+                'filename'              =>    '', // Empty string
245
+                'original'              =>    '', // Empty string
246
+                'size'                  =>    0, // 0 Bytes
247
+                'sizeFormated'          =>    '0B', // 0 Bytes
248
+                'destination'           =>    './', // Default: ./
249
+                'allowed_mime_types'    =>    array(), // Allowed mime types
250
+                'error'                 =>    null, // File error
251 251
             );
252 252
 
253 253
             // Change dir to current dir
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
             if (isset($_FILES) && is_array($_FILES)) {
258 258
                 $this->file_array = $_FILES;
259 259
             }
260
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
260
+            $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array));
261 261
         }
262 262
         /**
263 263
         *    Set input.
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         */
274 274
         public function setInput($input)
275 275
         {
276
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
276
+            if (!empty($input) && (is_string($input) || is_numeric($input))) {
277 277
                 $this->input = $input;
278 278
             }
279 279
             return $this;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         */
310 310
         public function setAutoFilename()
311 311
         {
312
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
312
+            $this->filename = sha1(mt_rand(1, 9999) . uniqid());
313 313
             $this->filename .= time();
314 314
             return $this;
315 315
         }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                 $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize'));
331 331
                 // Calculate difference
332 332
                 if ($php_size < $file_size) {
333
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
333
+                    $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']');
334 334
                 }
335 335
                 $this->max_file_size = $file_size;
336 336
             }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
         public function setAllowedMimeTypes(array $mimes)
349 349
         {
350 350
             if (count($mimes) > 0) {
351
-                array_map(array($this , 'setAllowMimeType'), $mimes);
351
+                array_map(array($this, 'setAllowMimeType'), $mimes);
352 352
             }
353 353
             return $this;
354 354
         }
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         {
414 414
             if (!empty($name) && is_string($name)) {
415 415
                 if (array_key_exists($name, $this->mime_helping)) {
416
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
416
+                    return $this->setAllowedMimeTypes($this->mime_helping[$name]);
417 417
                 }
418 418
             }
419 419
             return $this;
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
         */
433 433
         public function setUploadFunction($function)
434 434
         {
435
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
436
-                if (is_callable( $function)) {
435
+            if (!empty($function) && (is_array($function) || is_string($function))) {
436
+                if (is_callable($function)) {
437 437
                     $this->upload_function = $function;
438 438
                 }
439 439
             }
@@ -478,8 +478,8 @@  discard block
 block discarded – undo
478 478
                         $this->destination_directory = $destination_directory;
479 479
                         chdir($destination_directory);
480 480
                     }
481
-                    else{
482
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
481
+                    else {
482
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
483 483
                     }
484 484
                 }
485 485
             }
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
         public function isFilename($filename)
530 530
         {
531 531
             $filename = basename($filename);
532
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
532
+            return (!empty($filename) && (is_string($filename) || is_numeric($filename)));
533 533
         }
534 534
         /**
535 535
         *    Validate mime type with allowed mime types,
@@ -571,11 +571,11 @@  discard block
 block discarded – undo
571 571
         */
572 572
         public function isDirpath($path)
573 573
         {
574
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
574
+            if (!empty($path) && (is_string($path) || is_numeric($path))) {
575 575
                 if (DIRECTORY_SEPARATOR == '/') {
576
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
576
+                    return (preg_match('/^[^*?"<>|:]*$/', $path) == 1);
577 577
                 } else {
578
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
578
+                    return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1);
579 579
                 }
580 580
             }
581 581
             return false;
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
         */
604 604
         public function getInfo()
605 605
         {
606
-            return (object)$this->file;
606
+            return (object) $this->file;
607 607
         }
608 608
 
609 609
 
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
          * Check if the file is uploaded
612 612
          * @return boolean
613 613
          */
614
-        public function isUploaded(){
614
+        public function isUploaded() {
615 615
             return isset($this->file_array[$this->input])
616 616
             && is_uploaded_file($this->file_array[$this->input]['tmp_name']);
617 617
         }
@@ -625,13 +625,13 @@  discard block
 block discarded – undo
625 625
         *    @return    boolean
626 626
         *    @method    boolean    save
627 627
         */
628
-        public function save(){
628
+        public function save() {
629 629
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
630 630
                 // set original filename if not have a new name
631 631
                 if (empty($this->filename)) {
632 632
                     $this->filename = $this->file_array[$this->input]['name'];
633 633
                 }
634
-                else{
634
+                else {
635 635
                     // Replace %s for extension in filename
636 636
                     // Before: /[\w\d]*(.[\d\w]+)$/i
637 637
                     // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -655,10 +655,10 @@  discard block
 block discarded – undo
655 655
                 $this->file['filename']     = $this->filename;
656 656
                 $this->file['error']        = $this->file_array[$this->input]['error'];
657 657
 
658
-                $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
658
+                $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file));
659 659
 
660 660
                 $error = $this->uploadHasError();
661
-                if($error){
661
+                if ($error) {
662 662
                     return false;
663 663
                 }
664 664
                 // Execute input callback
@@ -692,10 +692,10 @@  discard block
 block discarded – undo
692 692
         */
693 693
         public function sizeFormat($size, $precision = 2)
694 694
         {
695
-            if($size > 0){
695
+            if ($size > 0) {
696 696
                 $base       = log($size) / log(1024);
697 697
                 $suffixes   = array('B', 'K', 'M', 'G', 'T');
698
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
698
+                return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
699 699
             }
700 700
             return null;
701 701
         }
@@ -719,14 +719,14 @@  discard block
 block discarded – undo
719 719
             if (array_key_exists('unit', $matches)) {
720 720
                 $unit = strtoupper($matches['unit']);
721 721
             }
722
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
722
+            return (floatval($matches['size']) * pow(1024, $units[$unit]));
723 723
         }
724 724
 
725 725
         /**
726 726
          * Get the upload error message
727 727
          * @return string
728 728
          */
729
-        public function getError(){
729
+        public function getError() {
730 730
             return $this->error;
731 731
         }
732 732
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
          * Set the upload error message
735 735
          * @param string $message the upload error message to set
736 736
          */
737
-        public function setError($message){
737
+        public function setError($message) {
738 738
             $this->logger->info('The file upload got error : ' . $message);
739 739
             $this->error = $message;
740 740
         }
@@ -744,9 +744,9 @@  discard block
 block discarded – undo
744 744
          * @param string $type the type of callback "input" or "output"
745 745
          * @return void 
746 746
          */
747
-        protected function runCallback($type){
748
-            if (!empty( $this->callbacks[$type])) {
749
-                call_user_func($this->callbacks[$type], (object)$this->file);
747
+        protected function runCallback($type) {
748
+            if (!empty($this->callbacks[$type])) {
749
+                call_user_func($this->callbacks[$type], (object) $this->file);
750 750
             }
751 751
         }
752 752
 
@@ -754,21 +754,21 @@  discard block
 block discarded – undo
754 754
          * Check if file upload has error
755 755
          * @return boolean
756 756
          */
757
-        protected function uploadHasError(){
757
+        protected function uploadHasError() {
758 758
             //check if file upload is  allowed in the configuration
759
-            if(! ini_get('file_uploads')){
759
+            if (!ini_get('file_uploads')) {
760 760
                 $this->setError($this->error_messages['file_uploads']);
761 761
                 return true;
762 762
             }
763 763
 
764 764
              //check for php upload error
765
-            if(is_numeric($this->file['error']) && $this->file['error'] > 0){
765
+            if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
766 766
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
767 767
                 return true;
768 768
             }
769 769
             
770 770
             //check for mime type
771
-            if (! $this->checkMimeType($this->file['mime'])) {
771
+            if (!$this->checkMimeType($this->file['mime'])) {
772 772
                 $this->setError($this->error_messages['accept_file_types']);
773 773
                 return true;
774 774
             }
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
          * @param  int $code the error code
793 793
          * @return string the error message
794 794
          */
795
-        private function getPhpUploadErrorMessageByCode($code){
795
+        private function getPhpUploadErrorMessageByCode($code) {
796 796
             $codeMessageMaps = array(
797 797
                 1 => $this->error_messages['upload_err_ini_size'],
798 798
                 2 => $this->error_messages['upload_err_form_size'],
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -477,8 +477,7 @@  discard block
 block discarded – undo
477 477
                     if (mkdir($destination_directory, 0775, true)) {
478 478
                         $this->destination_directory = $destination_directory;
479 479
                         chdir($destination_directory);
480
-                    }
481
-                    else{
480
+                    } else{
482 481
                         $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
483 482
                     }
484 483
                 }
@@ -630,8 +629,7 @@  discard block
 block discarded – undo
630 629
                 // set original filename if not have a new name
631 630
                 if (empty($this->filename)) {
632 631
                     $this->filename = $this->file_array[$this->input]['name'];
633
-                }
634
-                else{
632
+                } else{
635 633
                     // Replace %s for extension in filename
636 634
                     // Before: /[\w\d]*(.[\d\w]+)$/i
637 635
                     // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
Please login to merge, or discard this patch.
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -22,139 +22,139 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
 
27 27
 
28 28
 
29 29
     /**
30
-    *    Upload
31
-    *
32
-    *    A complete class to upload files with php 5 or higher, but the best: very simple to use.
33
-    *
34
-    *    @author Olaf Erlandsen <[email protected]>
35
-    *    @author http://www.webdevfreelance.com/
36
-    *
37
-    *    @package FileUpload
38
-    *    @version 1.5
39
-    */
30
+     *    Upload
31
+     *
32
+     *    A complete class to upload files with php 5 or higher, but the best: very simple to use.
33
+     *
34
+     *    @author Olaf Erlandsen <[email protected]>
35
+     *    @author http://www.webdevfreelance.com/
36
+     *
37
+     *    @package FileUpload
38
+     *    @version 1.5
39
+     */
40 40
     class Upload{
41 41
 
42 42
         /**
43
-        *   Version
44
-        *
45
-        *   @since      1.5
46
-        *   @version    1.0
47
-        */
43
+         *   Version
44
+         *
45
+         *   @since      1.5
46
+         *   @version    1.0
47
+         */
48 48
         const VERSION = '1.5';
49 49
 
50 50
         /**
51
-        *    Upload function name
52
-        *    Remember:
53
-        *        Default function: move_uploaded_file
54
-        *        Native options:
55
-        *            - move_uploaded_file (Default and best option)
56
-        *            - copy
57
-        *
58
-        *    @since        1.0
59
-        *    @version    1.0
60
-        *    @var        string
61
-        */
51
+         *    Upload function name
52
+         *    Remember:
53
+         *        Default function: move_uploaded_file
54
+         *        Native options:
55
+         *            - move_uploaded_file (Default and best option)
56
+         *            - copy
57
+         *
58
+         *    @since        1.0
59
+         *    @version    1.0
60
+         *    @var        string
61
+         */
62 62
         private $upload_function = 'move_uploaded_file';
63 63
 
64 64
         /**
65
-        *    Array with the information obtained from the
66
-        *    variable $_FILES or $HTTP_POST_FILES.
67
-        *
68
-        *    @since        1.0
69
-        *    @version    1.0
70
-        *    @var        array
71
-        */
65
+         *    Array with the information obtained from the
66
+         *    variable $_FILES or $HTTP_POST_FILES.
67
+         *
68
+         *    @since        1.0
69
+         *    @version    1.0
70
+         *    @var        array
71
+         */
72 72
         private $file_array    = array();
73 73
 
74 74
         /**
75
-        *    If the file you are trying to upload already exists it will
76
-        *    be overwritten if you set the variable to true.
77
-        *
78
-        *    @since        1.0
79
-        *    @version    1.0
80
-        *    @var        boolean
81
-        */
75
+         *    If the file you are trying to upload already exists it will
76
+         *    be overwritten if you set the variable to true.
77
+         *
78
+         *    @since        1.0
79
+         *    @version    1.0
80
+         *    @var        boolean
81
+         */
82 82
         private $overwrite_file = false;
83 83
 
84 84
         /**
85
-        *    Input element
86
-        *    Example:
87
-        *        <input type="file" name="file" />
88
-        *    Result:
89
-        *        FileUpload::$input = file
90
-        *
91
-        *    @since        1.0
92
-        *    @version    1.0
93
-        *    @var        string
94
-        */
85
+         *    Input element
86
+         *    Example:
87
+         *        <input type="file" name="file" />
88
+         *    Result:
89
+         *        FileUpload::$input = file
90
+         *
91
+         *    @since        1.0
92
+         *    @version    1.0
93
+         *    @var        string
94
+         */
95 95
         private $input;
96 96
 
97 97
         /**
98
-        *    Path output
99
-        *
100
-        *    @since        1.0
101
-        *    @version    1.0
102
-        *    @var        string
103
-        */
98
+         *    Path output
99
+         *
100
+         *    @since        1.0
101
+         *    @version    1.0
102
+         *    @var        string
103
+         */
104 104
         private $destination_directory;
105 105
 
106 106
         /**
107
-        *    Output filename
108
-        *
109
-        *    @since        1.0
110
-        *    @version    1.0
111
-        *    @var        string
112
-        */
107
+         *    Output filename
108
+         *
109
+         *    @since        1.0
110
+         *    @version    1.0
111
+         *    @var        string
112
+         */
113 113
         private $filename;
114 114
 
115 115
         /**
116
-        *    Max file size
117
-        *
118
-        *    @since        1.0
119
-        *    @version    1.0
120
-        *    @var        float
121
-        */
116
+         *    Max file size
117
+         *
118
+         *    @since        1.0
119
+         *    @version    1.0
120
+         *    @var        float
121
+         */
122 122
         private $max_file_size= 0.0;
123 123
 
124 124
         /**
125
-        *    List of allowed mime types
126
-        *
127
-        *    @since        1.0
128
-        *    @version    1.0
129
-        *    @var        array
130
-        */
125
+         *    List of allowed mime types
126
+         *
127
+         *    @since        1.0
128
+         *    @version    1.0
129
+         *    @var        array
130
+         */
131 131
         private $allowed_mime_types = array();
132 132
 
133 133
         /**
134
-        *    Callbacks
135
-        *
136
-        *    @since        1.0
137
-        *    @version    1.0
138
-        *    @var        array
139
-        */
134
+         *    Callbacks
135
+         *
136
+         *    @since        1.0
137
+         *    @version    1.0
138
+         *    @var        array
139
+         */
140 140
         private $callbacks = array('before' => null, 'after' => null);
141 141
 
142 142
         /**
143
-        *    File object
144
-        *
145
-        *    @since        1.0
146
-        *    @version    1.0
147
-        *    @var        object
148
-        */
143
+         *    File object
144
+         *
145
+         *    @since        1.0
146
+         *    @version    1.0
147
+         *    @var        object
148
+         */
149 149
         private $file;
150 150
 
151 151
         /**
152
-        *    Helping mime types
153
-        *
154
-        *    @since        1.0
155
-        *    @version    1.0
156
-        *    @var        array
157
-        */
152
+         *    Helping mime types
153
+         *
154
+         *    @since        1.0
155
+         *    @version    1.0
156
+         *    @var        array
157
+         */
158 158
         private $mime_helping = array(
159 159
             'text'      =>    array('text/plain',),
160 160
             'image'     =>    array(
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
 
211 211
 
212 212
         /**
213
-        *    Construct
214
-        *
215
-        *    @since     0.1
216
-        *    @version   1.0.1
217
-        *    @return    object
218
-        *    @method    object    __construct
219
-        */
213
+         *    Construct
214
+         *
215
+         *    @since     0.1
216
+         *    @version   1.0.1
217
+         *    @return    object
218
+         *    @method    object    __construct
219
+         */
220 220
         public function __construct(){
221 221
             $this->logger =& class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
             $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
261 261
         }
262 262
         /**
263
-        *    Set input.
264
-        *    If you have $_FILES["file"], you must use the key "file"
265
-        *    Example:
266
-        *        $object->setInput("file");
267
-        *
268
-        *    @since     1.0
269
-        *    @version   1.0
270
-        *    @param     string      $input
271
-        *    @return    object
272
-        *    @method    boolean     setInput
273
-        */
263
+         *    Set input.
264
+         *    If you have $_FILES["file"], you must use the key "file"
265
+         *    Example:
266
+         *        $object->setInput("file");
267
+         *
268
+         *    @since     1.0
269
+         *    @version   1.0
270
+         *    @param     string      $input
271
+         *    @return    object
272
+         *    @method    boolean     setInput
273
+         */
274 274
         public function setInput($input)
275 275
         {
276 276
             if (!empty($input) && (is_string($input) || is_numeric($input) )) {
@@ -279,18 +279,18 @@  discard block
 block discarded – undo
279 279
             return $this;
280 280
         }
281 281
         /**
282
-        *    Set new filename
283
-        *    Example:
284
-        *        FileUpload::setFilename("new file.txt")
285
-        *    Remember:
286
-        *        Use %s to retrive file extension
287
-        *
288
-        *    @since     1.0
289
-        *    @version   1.0
290
-        *    @param     string      $filename
291
-        *    @return    object
292
-        *    @method    boolean     setFilename
293
-        */
282
+         *    Set new filename
283
+         *    Example:
284
+         *        FileUpload::setFilename("new file.txt")
285
+         *    Remember:
286
+         *        Use %s to retrive file extension
287
+         *
288
+         *    @since     1.0
289
+         *    @version   1.0
290
+         *    @param     string      $filename
291
+         *    @return    object
292
+         *    @method    boolean     setFilename
293
+         */
294 294
         public function setFilename($filename)
295 295
         {
296 296
             if ($this->isFilename($filename)) {
@@ -299,14 +299,14 @@  discard block
 block discarded – undo
299 299
             return $this;
300 300
         }
301 301
         /**
302
-        *    Set automatic filename
303
-        *
304
-        *    @since     1.0
305
-        *    @version   1.5
306
-        *    @param     string      $extension
307
-        *    @return    object
308
-        *    @method    boolean     setAutoFilename
309
-        */
302
+         *    Set automatic filename
303
+         *
304
+         *    @since     1.0
305
+         *    @version   1.5
306
+         *    @param     string      $extension
307
+         *    @return    object
308
+         *    @method    boolean     setAutoFilename
309
+         */
310 310
         public function setAutoFilename()
311 311
         {
312 312
             $this->filename = sha1(mt_rand(1, 9999).uniqid());
@@ -314,14 +314,14 @@  discard block
 block discarded – undo
314 314
             return $this;
315 315
         }
316 316
         /**
317
-        *    Set file size limit
318
-        *
319
-        *    @since     1.0
320
-        *    @version   1.0
321
-        *    @param     double     $file_size
322
-        *    @return    object
323
-        *    @method    boolean     setMaxFileSize
324
-        */
317
+         *    Set file size limit
318
+         *
319
+         *    @since     1.0
320
+         *    @version   1.0
321
+         *    @param     double     $file_size
322
+         *    @return    object
323
+         *    @method    boolean     setMaxFileSize
324
+         */
325 325
         public function setMaxFileSize($file_size)
326 326
         {
327 327
             $file_size = $this->sizeInBytes($file_size);
@@ -337,14 +337,14 @@  discard block
 block discarded – undo
337 337
             return $this;
338 338
         }
339 339
         /**
340
-        *    Set array mime types
341
-        *
342
-        *    @since     1.0
343
-        *    @version   1.0
344
-        *    @param     array       $mimes
345
-        *    @return    object
346
-        *    @method    boolean     setAllowedMimeTypes
347
-        */
340
+         *    Set array mime types
341
+         *
342
+         *    @since     1.0
343
+         *    @version   1.0
344
+         *    @param     array       $mimes
345
+         *    @return    object
346
+         *    @method    boolean     setAllowedMimeTypes
347
+         */
348 348
         public function setAllowedMimeTypes(array $mimes)
349 349
         {
350 350
             if (count($mimes) > 0) {
@@ -353,14 +353,14 @@  discard block
 block discarded – undo
353 353
             return $this;
354 354
         }
355 355
         /**
356
-        *    Set input callback
357
-        *
358
-        *    @since     1.0
359
-        *    @version   1.0
360
-        *    @param     mixed       $callback
361
-        *    @return    object
362
-        *    @method    boolean     setCallbackInput
363
-        */
356
+         *    Set input callback
357
+         *
358
+         *    @since     1.0
359
+         *    @version   1.0
360
+         *    @param     mixed       $callback
361
+         *    @return    object
362
+         *    @method    boolean     setCallbackInput
363
+         */
364 364
         public function setCallbackInput($callback)
365 365
         {
366 366
             if (is_callable($callback, false)) {
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
             return $this;
370 370
         }
371 371
         /**
372
-        *    Set output callback
373
-        *
374
-        *    @since     1.0
375
-        *    @version   1.0
376
-        *    @param     mixed       $callback
377
-        *    @return    object
378
-        *    @method    boolean     setCallbackOutput
379
-        */
372
+         *    Set output callback
373
+         *
374
+         *    @since     1.0
375
+         *    @version   1.0
376
+         *    @param     mixed       $callback
377
+         *    @return    object
378
+         *    @method    boolean     setCallbackOutput
379
+         */
380 380
         public function setCallbackOutput($callback)
381 381
         {
382 382
             if (is_callable($callback, false)) {
@@ -385,14 +385,14 @@  discard block
 block discarded – undo
385 385
             return $this;
386 386
         }
387 387
         /**
388
-        *    Append a mime type to allowed mime types
389
-        *
390
-        *    @since     1.0
391
-        *    @version   1.0.1
392
-        *    @param     string      $mime
393
-        *    @return    object
394
-        *    @method    boolean     setAllowMimeType
395
-        */
388
+         *    Append a mime type to allowed mime types
389
+         *
390
+         *    @since     1.0
391
+         *    @version   1.0.1
392
+         *    @param     string      $mime
393
+         *    @return    object
394
+         *    @method    boolean     setAllowMimeType
395
+         */
396 396
         public function setAllowMimeType($mime)
397 397
         {
398 398
             if (!empty($mime) && is_string($mime)) {
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
             return $this;
403 403
         }
404 404
         /**
405
-        *    Set allowed mime types from mime helping
406
-        *
407
-        *    @since     1.0.1
408
-        *    @version   1.0.1
409
-        *    @return    object
410
-        *    @method    boolean    setMimeHelping
411
-        */
405
+         *    Set allowed mime types from mime helping
406
+         *
407
+         *    @since     1.0.1
408
+         *    @version   1.0.1
409
+         *    @return    object
410
+         *    @method    boolean    setMimeHelping
411
+         */
412 412
         public function setMimeHelping($name)
413 413
         {
414 414
             if (!empty($name) && is_string($name)) {
@@ -419,17 +419,17 @@  discard block
 block discarded – undo
419 419
             return $this;
420 420
         }
421 421
         /**
422
-        *    Set function to upload file
423
-        *    Examples:
424
-        *        1.- FileUpload::setUploadFunction("move_uploaded_file");
425
-        *        2.- FileUpload::setUploadFunction("copy");
426
-        *
427
-        *    @since     1.0
428
-        *    @version   1.0
429
-        *    @param     string      $function
430
-        *    @return    object
431
-        *    @method    boolean     setUploadFunction
432
-        */
422
+         *    Set function to upload file
423
+         *    Examples:
424
+         *        1.- FileUpload::setUploadFunction("move_uploaded_file");
425
+         *        2.- FileUpload::setUploadFunction("copy");
426
+         *
427
+         *    @since     1.0
428
+         *    @version   1.0
429
+         *    @param     string      $function
430
+         *    @return    object
431
+         *    @method    boolean     setUploadFunction
432
+         */
433 433
         public function setUploadFunction($function)
434 434
         {
435 435
             if (!empty($function) && (is_array($function) || is_string($function) )) {
@@ -440,13 +440,13 @@  discard block
 block discarded – undo
440 440
             return $this;
441 441
         }
442 442
         /**
443
-        *    Clear allowed mime types cache
444
-        *
445
-        *    @since     1.0
446
-        *    @version   1.0
447
-        *    @return    object
448
-        *    @method    boolean    clearAllowedMimeTypes
449
-        */
443
+         *    Clear allowed mime types cache
444
+         *
445
+         *    @since     1.0
446
+         *    @version   1.0
447
+         *    @return    object
448
+         *    @method    boolean    clearAllowedMimeTypes
449
+         */
450 450
         public function clearAllowedMimeTypes()
451 451
         {
452 452
             $this->allowed_mime_types = array();
@@ -454,15 +454,15 @@  discard block
 block discarded – undo
454 454
             return $this;
455 455
         }
456 456
         /**
457
-        *    Set destination output
458
-        *
459
-        *    @since     1.0
460
-        *    @version   1.0
461
-        *    @param     string      $destination_directory      Destination path
462
-        *    @param     boolean     $create_if_not_exist
463
-        *    @return    object
464
-        *    @method    boolean     setDestinationDirectory
465
-        */
457
+         *    Set destination output
458
+         *
459
+         *    @since     1.0
460
+         *    @version   1.0
461
+         *    @param     string      $destination_directory      Destination path
462
+         *    @param     boolean     $create_if_not_exist
463
+         *    @return    object
464
+         *    @method    boolean     setDestinationDirectory
465
+         */
466 466
         public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) {
467 467
             $destination_directory = realpath($destination_directory);
468 468
             if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) {
@@ -486,14 +486,14 @@  discard block
 block discarded – undo
486 486
             return $this;
487 487
         }
488 488
         /**
489
-        *    Check file exists
490
-        *
491
-        *    @since      1.0
492
-        *    @version    1.0.1
493
-        *    @param      string     $file_destination
494
-        *    @return     boolean
495
-        *    @method     boolean    fileExists
496
-        */
489
+         *    Check file exists
490
+         *
491
+         *    @since      1.0
492
+         *    @version    1.0.1
493
+         *    @param      string     $file_destination
494
+         *    @return     boolean
495
+         *    @method     boolean    fileExists
496
+         */
497 497
         public function fileExists($file_destination)
498 498
         {
499 499
             if ($this->isFilename($file_destination)) {
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
             return false;
503 503
         }
504 504
         /**
505
-        *    Check dir exists
506
-        *
507
-        *    @since        1.0
508
-        *    @version    1.0.1
509
-        *    @param      string     $path
510
-        *    @return     boolean
511
-        *    @method     boolean    dirExists
512
-        */
505
+         *    Check dir exists
506
+         *
507
+         *    @since        1.0
508
+         *    @version    1.0.1
509
+         *    @param      string     $path
510
+         *    @return     boolean
511
+         *    @method     boolean    dirExists
512
+         */
513 513
         public function dirExists($path)
514 514
         {
515 515
             if ($this->isDirpath($path)) {
@@ -518,29 +518,29 @@  discard block
 block discarded – undo
518 518
             return false;
519 519
         }
520 520
         /**
521
-        *    Check valid filename
522
-        *
523
-        *    @since     1.0
524
-        *    @version   1.0.1
525
-        *    @param     string      $filename
526
-        *    @return    boolean
527
-        *    @method    boolean     isFilename
528
-        */
521
+         *    Check valid filename
522
+         *
523
+         *    @since     1.0
524
+         *    @version   1.0.1
525
+         *    @param     string      $filename
526
+         *    @return    boolean
527
+         *    @method    boolean     isFilename
528
+         */
529 529
         public function isFilename($filename)
530 530
         {
531 531
             $filename = basename($filename);
532 532
             return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
533 533
         }
534 534
         /**
535
-        *    Validate mime type with allowed mime types,
536
-        *    but if allowed mime types is empty, this method return true
537
-        *
538
-        *    @since     1.0
539
-        *    @version   1.0
540
-        *    @param     string      $mime
541
-        *    @return    boolean
542
-        *    @method    boolean     checkMimeType
543
-        */
535
+         *    Validate mime type with allowed mime types,
536
+         *    but if allowed mime types is empty, this method return true
537
+         *
538
+         *    @since     1.0
539
+         *    @version   1.0
540
+         *    @param     string      $mime
541
+         *    @return    boolean
542
+         *    @method    boolean     checkMimeType
543
+         */
544 544
         public function checkMimeType($mime)
545 545
         {
546 546
             if (count($this->allowed_mime_types) == 0) {
@@ -549,26 +549,26 @@  discard block
 block discarded – undo
549 549
             return in_array(strtolower($mime), $this->allowed_mime_types);
550 550
         }
551 551
         /**
552
-        *    Retrive status of upload
553
-        *
554
-        *    @since     1.0
555
-        *    @version   1.0
556
-        *    @return    boolean
557
-        *    @method    boolean    getStatus
558
-        */
552
+         *    Retrive status of upload
553
+         *
554
+         *    @since     1.0
555
+         *    @version   1.0
556
+         *    @return    boolean
557
+         *    @method    boolean    getStatus
558
+         */
559 559
         public function getStatus()
560 560
         {
561 561
             return $this->file['status'];
562 562
         }
563 563
         /**
564
-        *    Check valid path
565
-        *
566
-        *    @since        1.0
567
-        *    @version    1.0.1
568
-        *    @param        string    $filename
569
-        *    @return     boolean
570
-        *    @method     boolean    isDirpath
571
-        */
564
+         *    Check valid path
565
+         *
566
+         *    @since        1.0
567
+         *    @version    1.0.1
568
+         *    @param        string    $filename
569
+         *    @return     boolean
570
+         *    @method     boolean    isDirpath
571
+         */
572 572
         public function isDirpath($path)
573 573
         {
574 574
             if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
@@ -581,26 +581,26 @@  discard block
 block discarded – undo
581 581
             return false;
582 582
         }
583 583
         /**
584
-        *    Allow overwriting files
585
-        *
586
-        *    @since      1.0
587
-        *    @version    1.0
588
-        *    @return     object
589
-        *    @method     boolean    allowOverwriting
590
-        */
584
+         *    Allow overwriting files
585
+         *
586
+         *    @since      1.0
587
+         *    @version    1.0
588
+         *    @return     object
589
+         *    @method     boolean    allowOverwriting
590
+         */
591 591
         public function allowOverwriting()
592 592
         {
593 593
             $this->overwrite_file = true;
594 594
             return $this;
595 595
         }
596 596
         /**
597
-        *    File info
598
-        *
599
-        *    @since      1.0
600
-        *    @version    1.0
601
-        *    @return     object
602
-        *    @method     object    getInfo
603
-        */
597
+         *    File info
598
+         *
599
+         *    @since      1.0
600
+         *    @version    1.0
601
+         *    @return     object
602
+         *    @method     object    getInfo
603
+         */
604 604
         public function getInfo()
605 605
         {
606 606
             return (object)$this->file;
@@ -618,13 +618,13 @@  discard block
 block discarded – undo
618 618
 
619 619
         
620 620
         /**
621
-        *    Upload file
622
-        *
623
-        *    @since     1.0
624
-        *    @version   1.0.1
625
-        *    @return    boolean
626
-        *    @method    boolean    save
627
-        */
621
+         *    Upload file
622
+         *
623
+         *    @since     1.0
624
+         *    @version   1.0.1
625
+         *    @return    boolean
626
+         *    @method    boolean    save
627
+         */
628 628
         public function save(){
629 629
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
630 630
                 // set original filename if not have a new name
@@ -681,15 +681,15 @@  discard block
 block discarded – undo
681 681
 
682 682
 
683 683
         /**
684
-        *    File size for humans.
685
-        *
686
-        *    @since      1.0
687
-        *    @version    1.0
688
-        *    @param      integer    $bytes
689
-        *    @param      integer    $precision
690
-        *    @return     string
691
-        *    @method     string     sizeFormat
692
-        */
684
+         *    File size for humans.
685
+         *
686
+         *    @since      1.0
687
+         *    @version    1.0
688
+         *    @param      integer    $bytes
689
+         *    @param      integer    $precision
690
+         *    @return     string
691
+         *    @method     string     sizeFormat
692
+         */
693 693
         public function sizeFormat($size, $precision = 2)
694 694
         {
695 695
             if($size > 0){
@@ -702,14 +702,14 @@  discard block
 block discarded – undo
702 702
 
703 703
         
704 704
         /**
705
-        *    Convert human file size to bytes
706
-        *
707
-        *    @since      1.0
708
-        *    @version    1.0.1
709
-        *    @param      integer|double    $size
710
-        *    @return     integer|double
711
-        *    @method     string     sizeInBytes
712
-        */
705
+         *    Convert human file size to bytes
706
+         *
707
+         *    @since      1.0
708
+         *    @version    1.0.1
709
+         *    @param      integer|double    $size
710
+         *    @return     integer|double
711
+         *    @method     string     sizeInBytes
712
+         */
713 713
         public function sizeInBytes($size)
714 714
         {
715 715
             $unit = 'B';
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
                 return true;
762 762
             }
763 763
 
764
-             //check for php upload error
764
+                //check for php upload error
765 765
             if(is_numeric($this->file['error']) && $this->file['error'] > 0){
766 766
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
767 767
                 return true;
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
                 return true;
774 774
             }
775 775
 
776
-             // Check file size
776
+                // Check file size
777 777
             if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) {
778 778
                 $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size)));
779 779
                 return true;
Please login to merge, or discard this patch.
classes/controllers/Home.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,25 +1,25 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
2
+    defined('ROOT_PATH') || exit('Access denied');
3 3
 
4
-	/**
5
-	 * 
6
-	 */
7
-	class Home extends Controller {
4
+    /**
5
+     * 
6
+     */
7
+    class Home extends Controller {
8 8
 
9
-		/**
10
-		 * the class constructor
11
-		 */
12
-		public function __construct() {
13
-			parent::__construct();
14
-		}
9
+        /**
10
+         * the class constructor
11
+         */
12
+        public function __construct() {
13
+            parent::__construct();
14
+        }
15 15
 
16
-		/**
17
-		 * The default method
18
-		 * @return null
19
-		 */
20
-		public function index() {
21
-			Loader::library('Assets');
22
-			Loader::library('Html');
23
-			$this->response->render('home');
24
-		}
25
-	}
16
+        /**
17
+         * The default method
18
+         * @return null
19
+         */
20
+        public function index() {
21
+            Loader::library('Assets');
22
+            Loader::library('Html');
23
+            $this->response->render('home');
24
+        }
25
+    }
Please login to merge, or discard this patch.
tests/tnhfw/classes/RequestTest.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,31 +1,31 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class RequestTest extends TestCase
6
-	{	
5
+    class RequestTest 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
-		public function testNotYet()
27
-		{
28
-			$this->markTestSkipped();
29
-		}
26
+        public function testNotYet()
27
+        {
28
+            $this->markTestSkipped();
29
+        }
30 30
 
31
-	}
32 31
\ No newline at end of file
32
+    }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
tests/tnhfw/classes/LoaderTest.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,31 +1,31 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3
-	use PHPUnit\Framework\TestCase;
3
+    use PHPUnit\Framework\TestCase;
4 4
 
5
-	class LoaderTest extends TestCase
6
-	{	
5
+    class LoaderTest 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
-		public function testNotYet()
27
-		{
28
-			$this->markTestSkipped();
29
-		}
26
+        public function testNotYet()
27
+        {
28
+            $this->markTestSkipped();
29
+        }
30 30
 
31
-	}
32 31
\ No newline at end of file
32
+    }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.