Passed
Push — 1.0.0-dev ( 9c9ab7...066288 )
by nguereza
02:38
created
core/classes/Loader.php 1 patch
Spacing   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 		 * The signleton of the logger
52 52
 		 * @return object the Log instance
53 53
 		 */
54
-		public static function getLogger(){
55
-			if(self::$logger == null){
54
+		public static function getLogger() {
55
+			if (self::$logger == null) {
56 56
 				$logger = array();
57
-				$logger[0] =& class_loader('Log', 'classes');
57
+				$logger[0] = & class_loader('Log', 'classes');
58 58
 				$logger[0]->setLogger('Library::Loader');
59 59
 				self::$logger = $logger[0];
60 60
 			}
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		 * @param object $logger the log object
67 67
 		 * @return object the log instance
68 68
 		 */
69
-		public static function setLogger($logger){
69
+		public static function setLogger($logger) {
70 70
 			self::$logger = $logger;
71 71
 			return self::$logger;
72 72
 		}
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
 		 *
81 81
 		 * @return void
82 82
 		 */
83
-		public static function model($class, $instance = null){
83
+		public static function model($class, $instance = null) {
84 84
 			$logger = static::getLogger();
85 85
 			$class = str_ireplace('.php', '', $class);
86 86
 			$class = trim($class, '/\\');
87
-			$file = ucfirst($class).'.php';
87
+			$file = ucfirst($class) . '.php';
88 88
 			$logger->debug('Loading model [' . $class . '] ...');
89 89
 			//************
90
-			if (! $instance){
90
+			if (!$instance) {
91 91
 				$instance = self::getModelLibraryInstanceName($class);
92 92
 			}
93 93
 			//****************
94
-			if (isset(static::$loaded[$instance])){
94
+			if (isset(static::$loaded[$instance])) {
95 95
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
96 96
 				return;
97 97
 			}
@@ -104,28 +104,28 @@  discard block
 block discarded – undo
104 104
 			$class  = $moduleInfo['class'];
105 105
 			
106 106
 			$moduleModelFilePath = Module::findModelFullPath($class, $module);
107
-			if ($moduleModelFilePath){
108
-				$logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it');
107
+			if ($moduleModelFilePath) {
108
+				$logger->info('Found model [' . $class . '] from module [' . $module . '], the file path is [' . $moduleModelFilePath . '] we will used it');
109 109
 				$classFilePath = $moduleModelFilePath;
110 110
 			}
111
-			else{
111
+			else {
112 112
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
113 113
 			}
114 114
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
115
-			if (file_exists($classFilePath)){
115
+			if (file_exists($classFilePath)) {
116 116
 				require_once $classFilePath;
117
-				if (class_exists($class)){
117
+				if (class_exists($class)) {
118 118
 					$c = new $class();
119 119
 					$obj = & get_instance();
120 120
 					$obj->{$instance} = $c;
121 121
 					static::$loaded[$instance] = $class;
122 122
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
123 123
 				}
124
-				else{
125
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
124
+				else {
125
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
126 126
 				}
127 127
 			}
128
-			else{
128
+			else {
129 129
 				show_error('Unable to find the model [' . $class . ']');
130 130
 			}
131 131
 		}
@@ -140,22 +140,22 @@  discard block
 block discarded – undo
140 140
 		 *
141 141
 		 * @return void
142 142
 		 */
143
-		public static function library($class, $instance = null, array $params = array()){
143
+		public static function library($class, $instance = null, array $params = array()) {
144 144
 			$logger = static::getLogger();
145 145
 			$class = str_ireplace('.php', '', $class);
146 146
 			$class = trim($class, '/\\');
147
-			$file = ucfirst($class) .'.php';
147
+			$file = ucfirst($class) . '.php';
148 148
 			$logger->debug('Loading library [' . $class . '] ...');
149
-			if (! $instance){
149
+			if (!$instance) {
150 150
 				$instance = self::getModelLibraryInstanceName($class);
151 151
 			}
152
-			if (isset(static::$loaded[$instance])){
152
+			if (isset(static::$loaded[$instance])) {
153 153
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
154 154
 				return;
155 155
 			}
156 156
 			$obj = & get_instance();
157 157
 			//Check and load Database library
158
-			if (strtolower($class) == 'database'){
158
+			if (strtolower($class) == 'database') {
159 159
 				$logger->info('This is the Database library ...');
160 160
 				$obj->{$instance} = & class_loader('Database', 'classes/database', $params);
161 161
 				static::$loaded[$instance] = $class;
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 			}
165 165
 			$libraryFilePath = null;
166 166
 			$logger->debug('Check if this is a system library ...');
167
-			if (file_exists(CORE_LIBRARY_PATH . $file)){
167
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
168 168
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
169 169
 				$class = ucfirst($class);
170 170
 				$logger->info('This library is a system library');
171 171
 			}
172
-			else{
172
+			else {
173 173
 				$logger->info('This library is not a system library');	
174 174
 				//first check if this library is in the module
175 175
 				$libraryFilePath = self::getLibraryPathUsingModuleInfo($class);
176 176
 				//***************
177 177
 			}
178
-			if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){
178
+			if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) {
179 179
 				$libraryFilePath = LIBRARY_PATH . $file;
180 180
 			}
181 181
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 		 *
191 191
 		 * @return void
192 192
 		 */
193
-		public static function functions($function){
193
+		public static function functions($function) {
194 194
 			$logger = static::getLogger();
195 195
 			$function = str_ireplace('.php', '', $function);
196 196
 			$function = trim($function, '/\\');
197 197
 			$function = str_ireplace('function_', '', $function);
198
-			$file = 'function_'.$function.'.php';
198
+			$file = 'function_' . $function . '.php';
199 199
 			$logger->debug('Loading helper [' . $function . '] ...');
200
-			if (isset(static::$loaded['function_' . $function])){
200
+			if (isset(static::$loaded['function_' . $function])) {
201 201
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
202 202
 				return;
203 203
 			}
@@ -207,22 +207,22 @@  discard block
 block discarded – undo
207 207
 			$moduleInfo = self::getModuleInfoForFunction($function);
208 208
 			$module    = $moduleInfo['module'];
209 209
 			$function  = $moduleInfo['function'];
210
-			if(! empty($moduleInfo['file'])){
210
+			if (!empty($moduleInfo['file'])) {
211 211
 				$file = $moduleInfo['file'];
212 212
 			}
213 213
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $module);
214
-			if ($moduleFunctionPath){
215
-				$logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it');
214
+			if ($moduleFunctionPath) {
215
+				$logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it');
216 216
 				$functionFilePath = $moduleFunctionPath;
217 217
 			}
218
-			else{
218
+			else {
219 219
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
220 220
 			}
221
-			if (! $functionFilePath){
221
+			if (!$functionFilePath) {
222 222
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
223
-				foreach($searchDir as $dir){
223
+				foreach ($searchDir as $dir) {
224 224
 					$filePath = $dir . $file;
225
-					if (file_exists($filePath)){
225
+					if (file_exists($filePath)) {
226 226
 						$functionFilePath = $filePath;
227 227
 						//is already found not to continue
228 228
 						break;
@@ -230,12 +230,12 @@  discard block
 block discarded – undo
230 230
 				}
231 231
 			}
232 232
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
233
-			if ($functionFilePath){
233
+			if ($functionFilePath) {
234 234
 				require_once $functionFilePath;
235 235
 				static::$loaded['function_' . $function] = $functionFilePath;
236 236
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
237 237
 			}
238
-			else{
238
+			else {
239 239
 				show_error('Unable to find helper file [' . $file . ']');
240 240
 			}
241 241
 		}
@@ -247,14 +247,14 @@  discard block
 block discarded – undo
247 247
 		 *
248 248
 		 * @return void
249 249
 		 */
250
-		public static function config($filename){
250
+		public static function config($filename) {
251 251
 			$logger = static::getLogger();
252 252
 			$filename = str_ireplace('.php', '', $filename);
253 253
 			$filename = trim($filename, '/\\');
254 254
 			$filename = str_ireplace('config_', '', $filename);
255
-			$file = 'config_'.$filename.'.php';
255
+			$file = 'config_' . $filename . '.php';
256 256
 			$logger->debug('Loading configuration [' . $filename . '] ...');
257
-			if (isset(static::$loaded['config_' . $filename])){
257
+			if (isset(static::$loaded['config_' . $filename])) {
258 258
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
259 259
 				return;
260 260
 			}
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 			$module    = $moduleInfo['module'];
266 266
 			$filename  = $moduleInfo['filename'];
267 267
 			$moduleConfigPath = Module::findConfigFullPath($filename, $module);
268
-			if ($moduleConfigPath){
269
-				$logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it');
268
+			if ($moduleConfigPath) {
269
+				$logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it');
270 270
 				$configFilePath = $moduleConfigPath;
271 271
 			}
272
-			else{
272
+			else {
273 273
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
274 274
 			}
275 275
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
276 276
 			$config = array();
277
-			if (file_exists($configFilePath)){
277
+			if (file_exists($configFilePath)) {
278 278
 				require_once $configFilePath;
279
-				if (! empty($config) && is_array($config)){
279
+				if (!empty($config) && is_array($config)) {
280 280
 					Config::setAll($config);
281 281
 					static::$loaded['config_' . $filename] = $configFilePath;
282 282
 					$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 					unset($config);
285 285
 				}
286 286
 			}
287
-			else{
288
-				show_error('Unable to find config file ['. $configFilePath . ']');
287
+			else {
288
+				show_error('Unable to find config file [' . $configFilePath . ']');
289 289
 			}
290 290
 		}
291 291
 
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
 		 *
298 298
 		 * @return void
299 299
 		 */
300
-		public static function lang($language){
300
+		public static function lang($language) {
301 301
 			$logger = static::getLogger();
302 302
 			$language = str_ireplace('.php', '', $language);
303 303
 			$language = trim($language, '/\\');
304 304
 			$language = str_ireplace('lang_', '', $language);
305
-			$file = 'lang_'.$language.'.php';
305
+			$file = 'lang_' . $language . '.php';
306 306
 			$logger->debug('Loading language [' . $language . '] ...');
307
-			if (isset(static::$loaded['lang_' . $language])){
307
+			if (isset(static::$loaded['lang_' . $language])) {
308 308
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
309 309
 				return;
310 310
 			}
@@ -316,22 +316,22 @@  discard block
 block discarded – undo
316 316
 			$moduleInfo = self::getModuleInfoForLanguage($language);
317 317
 			$module    = $moduleInfo['module'];
318 318
 			$language  = $moduleInfo['language'];
319
-			if(! empty($moduleInfo['file'])){
319
+			if (!empty($moduleInfo['file'])) {
320 320
 				$file = $moduleInfo['file'];
321 321
 			}
322 322
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang);
323
-			if ($moduleLanguagePath){
324
-				$logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it');
323
+			if ($moduleLanguagePath) {
324
+				$logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it');
325 325
 				$languageFilePath = $moduleLanguagePath;
326 326
 			}
327
-			else{
327
+			else {
328 328
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
329 329
 			}
330
-			if (! $languageFilePath){
330
+			if (!$languageFilePath) {
331 331
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
332
-				foreach($searchDir as $dir){
332
+				foreach ($searchDir as $dir) {
333 333
 					$filePath = $dir . $appLang . DS . $file;
334
-					if (file_exists($filePath)){
334
+					if (file_exists($filePath)) {
335 335
 						$languageFilePath = $filePath;
336 336
 						//already found no need continue
337 337
 						break;
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
 		 * if can not found will use the default value from configuration
348 348
 		 * @return string the app language like "en", "fr"
349 349
 		 */
350
-		protected static function getAppLang(){
350
+		protected static function getAppLang() {
351 351
 			//determine the current language
352 352
 			$appLang = get_config('default_language');
353 353
 			//if the language exists in the cookie use it
354 354
 			$cfgKey = get_config('language_cookie_name');
355 355
 			$objCookie = & class_loader('Cookie');
356 356
 			$cookieLang = $objCookie->get($cfgKey);
357
-			if ($cookieLang){
357
+			if ($cookieLang) {
358 358
 				$appLang = $cookieLang;
359 359
 			}
360 360
 			return $appLang;
@@ -368,20 +368,20 @@  discard block
 block discarded – undo
368 368
 		 * 	'class' => 'class_name'
369 369
 		 * )
370 370
 		 */
371
-		protected static function getModuleInfoForModelLibrary($class){
371
+		protected static function getModuleInfoForModelLibrary($class) {
372 372
 			$module = null;
373 373
 			$obj = & get_instance();
374
-			if (strpos($class, '/') !== false){
374
+			if (strpos($class, '/') !== false) {
375 375
 				$path = explode('/', $class);
376
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
376
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
377 377
 					$module = $path[0];
378 378
 					$class = ucfirst($path[1]);
379 379
 				}
380 380
 			}
381
-			else{
381
+			else {
382 382
 				$class = ucfirst($class);
383 383
 			}
384
-			if (! $module && !empty($obj->moduleName)){
384
+			if (!$module && !empty($obj->moduleName)) {
385 385
 				$module = $obj->moduleName;
386 386
 			}
387 387
 			return array(
@@ -400,20 +400,20 @@  discard block
 block discarded – undo
400 400
 		 * 	'file' => 'file'
401 401
 		 * )
402 402
 		 */
403
-		protected static function getModuleInfoForFunction($function){
403
+		protected static function getModuleInfoForFunction($function) {
404 404
 			$module = null;
405 405
 			$file = null;
406 406
 			$obj = & get_instance();
407 407
 			//check if the request class contains module name
408
-			if (strpos($function, '/') !== false){
408
+			if (strpos($function, '/') !== false) {
409 409
 				$path = explode('/', $function);
410
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
410
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
411 411
 					$module = $path[0];
412 412
 					$function = 'function_' . $path[1];
413
-					$file = $path[0] . DS . $function.'.php';
413
+					$file = $path[0] . DS . $function . '.php';
414 414
 				}
415 415
 			}
416
-			if (! $module && !empty($obj->moduleName)){
416
+			if (!$module && !empty($obj->moduleName)) {
417 417
 				$module = $obj->moduleName;
418 418
 			}
419 419
 			return array(
@@ -433,20 +433,20 @@  discard block
 block discarded – undo
433 433
 		 * 	'file' => 'file'
434 434
 		 * )
435 435
 		 */
436
-		protected static function getModuleInfoForLanguage($language){
436
+		protected static function getModuleInfoForLanguage($language) {
437 437
 			$module = null;
438 438
 			$file = null;
439 439
 			$obj = & get_instance();
440 440
 			//check if the request class contains module name
441
-			if (strpos($language, '/') !== false){
441
+			if (strpos($language, '/') !== false) {
442 442
 				$path = explode('/', $language);
443
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
443
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
444 444
 					$module = $path[0];
445 445
 					$language = 'lang_' . $path[1] . '.php';
446
-					$file = $path[0] . DS .$language;
446
+					$file = $path[0] . DS . $language;
447 447
 				}
448 448
 			}
449
-			if (! $module && !empty($obj->moduleName)){
449
+			if (!$module && !empty($obj->moduleName)) {
450 450
 				$module = $obj->moduleName;
451 451
 			}
452 452
 			return array(
@@ -466,18 +466,18 @@  discard block
 block discarded – undo
466 466
 		 * 	'filename' => 'filename'
467 467
 		 * )
468 468
 		 */
469
-		protected static function getModuleInfoForConfig($filename){
469
+		protected static function getModuleInfoForConfig($filename) {
470 470
 			$module = null;
471 471
 			$obj = & get_instance();
472 472
 			//check if the request class contains module name
473
-			if (strpos($filename, '/') !== false){
473
+			if (strpos($filename, '/') !== false) {
474 474
 				$path = explode('/', $filename);
475
-				if (isset($path[0]) && in_array($path[0], Module::getModuleList())){
475
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
476 476
 					$module = $path[0];
477 477
 					$filename = $path[1] . '.php';
478 478
 				}
479 479
 			}
480
-			if (! $module && !empty($obj->moduleName)){
480
+			if (!$module && !empty($obj->moduleName)) {
481 481
 				$module = $obj->moduleName;
482 482
 			}
483 483
 			return array(
@@ -491,16 +491,16 @@  discard block
 block discarded – undo
491 491
 		 * @param  string $class the class name to determine the instance
492 492
 		 * @return string        the instance name
493 493
 		 */
494
-		protected static function getModelLibraryInstanceName($class){
494
+		protected static function getModelLibraryInstanceName($class) {
495 495
 			//for module
496 496
 			$instance = null;
497
-			if (strpos($class, '/') !== false){
497
+			if (strpos($class, '/') !== false) {
498 498
 				$path = explode('/', $class);
499
-				if (isset($path[1])){
499
+				if (isset($path[1])) {
500 500
 					$instance = strtolower($path[1]);
501 501
 				}
502 502
 			}
503
-			else{
503
+			else {
504 504
 				$instance = strtolower($class);
505 505
 			}
506 506
 			return $instance;
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		 * @param  string $class the class name
512 512
 		 * @return string|null        the library file path otherwise null will be returned
513 513
 		 */
514
-		protected static function getLibraryPathUsingModuleInfo($class){
514
+		protected static function getLibraryPathUsingModuleInfo($class) {
515 515
 			$logger = static::getLogger();
516 516
 			$libraryFilePath = null;
517 517
 			$logger->debug('Checking library [' . $class . '] from module list ...');
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
 			$module = $moduleInfo['module'];
520 520
 			$class  = $moduleInfo['class'];
521 521
 			$moduleLibraryPath = Module::findLibraryFullPath($class, $module);
522
-			if ($moduleLibraryPath){
523
-				$logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it');
522
+			if ($moduleLibraryPath) {
523
+				$logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it');
524 524
 				$libraryFilePath = $moduleLibraryPath;
525 525
 			}
526
-			else{
526
+			else {
527 527
 				$logger->info('Cannot find library [' . $class . '] from modules using the default location');
528 528
 			}
529 529
 			return $libraryFilePath;
@@ -537,22 +537,22 @@  discard block
 block discarded – undo
537 537
 		 * @param  array  $params          the parameter to use
538 538
 		 * @return void
539 539
 		 */
540
-		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){
541
-			if ($libraryFilePath){
540
+		protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) {
541
+			if ($libraryFilePath) {
542 542
 				$logger = static::getLogger();
543 543
 				require_once $libraryFilePath;
544
-				if (class_exists($class)){
544
+				if (class_exists($class)) {
545 545
 					$c = $params ? new $class($params) : new $class();
546 546
 					$obj = & get_instance();
547 547
 					$obj->{$instance} = $c;
548 548
 					static::$loaded[$instance] = $class;
549 549
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
550 550
 				}
551
-				else{
552
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
551
+				else {
552
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
553 553
 				}
554 554
 			}
555
-			else{
555
+			else {
556 556
 				show_error('Unable to find library class [' . $class . ']');
557 557
 			}
558 558
 		}
@@ -563,15 +563,15 @@  discard block
 block discarded – undo
563 563
 		 * @param  string $language           the language name
564 564
 		 * @return void
565 565
 		 */
566
-		protected static function loadLanguage($languageFilePath, $language){
567
-			if ($languageFilePath){
566
+		protected static function loadLanguage($languageFilePath, $language) {
567
+			if ($languageFilePath) {
568 568
 				$logger = static::getLogger();
569 569
 				$lang = array();
570 570
 				require_once $languageFilePath;
571
-				if (! empty($lang) && is_array($lang)){
572
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
571
+				if (!empty($lang) && is_array($lang)) {
572
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
573 573
 					//Note: may be here the class 'Lang' not yet loaded
574
-					$langObj =& class_loader('Lang', 'classes');
574
+					$langObj = & class_loader('Lang', 'classes');
575 575
 					$langObj->addLangMessages($lang);
576 576
 					//free the memory
577 577
 					unset($lang);
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 				static::$loaded['lang_' . $language] = $languageFilePath;
580 580
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
581 581
 			}
582
-			else{
582
+			else {
583 583
 				show_error('Unable to find language [' . $language . ']');
584 584
 			}
585 585
 		}
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 		 * Get all the autoload using the configuration file
589 589
 		 * @return array
590 590
 		 */
591
-		private function getResourcesFromAutoloadConfig(){
591
+		private function getResourcesFromAutoloadConfig() {
592 592
 			$autoloads = array();
593 593
 			$autoloads['config']    = array();
594 594
 			$autoloads['languages'] = array();
@@ -596,17 +596,17 @@  discard block
 block discarded – undo
596 596
 			$autoloads['models']    = array();
597 597
 			$autoloads['functions'] = array();
598 598
 			//loading of the resources from autoload configuration file
599
-			if (file_exists(CONFIG_PATH . 'autoload.php')){
599
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
600 600
 				$autoload = array();
601 601
 				require_once CONFIG_PATH . 'autoload.php';
602
-				if (! empty($autoload) && is_array($autoload)){
602
+				if (!empty($autoload) && is_array($autoload)) {
603 603
 					$autoloads = array_merge($autoloads, $autoload);
604 604
 					unset($autoload);
605 605
 				}
606 606
 			}
607 607
 			//loading autoload configuration for modules
608 608
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
609
-			if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){
609
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
610 610
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
611 611
 			}
612 612
 			return $autoloads;
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 		 * Load the autoload configuration
617 617
 		 * @return void
618 618
 		 */
619
-		private function loadResourcesFromAutoloadConfig(){
619
+		private function loadResourcesFromAutoloadConfig() {
620 620
 			$autoloads = array();
621 621
 			$autoloads['config']    = array();
622 622
 			$autoloads['languages'] = array();
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 		 * @param  array  $resources the resource to load
650 650
 		 * @return void            
651 651
 		 */
652
-		private function loadAutoloadResourcesArray($method, array $resources){
652
+		private function loadAutoloadResourcesArray($method, array $resources) {
653 653
 			foreach ($resources as $name) {
654 654
 				$this->{$method}($name);
655 655
 			}
Please login to merge, or discard this patch.
core/libraries/Html.php 1 patch
Spacing   +53 added lines, -53 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 Html{
27
+	class Html {
28 28
 
29 29
 		/**
30 30
 		 * Generate the html anchor link
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
 		 *
36 36
 		 * @return string|void             the anchor link generated html if $return is true or display it if not
37 37
 		 */
38
-		public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){
38
+		public static function a($link = '', $anchor = null, array $attributes = array(), $return = true) {
39 39
 			$link = Url::site_url($link);
40
-			if(! $anchor){
40
+			if (!$anchor) {
41 41
 				$anchor = $link;
42 42
 			}
43 43
 			$str = null;
44
-			$str .= '<a href = "'.$link.'"';
44
+			$str .= '<a href = "' . $link . '"';
45 45
 			$str .= attributes_to_string($attributes);
46 46
 			$str .= '>';
47 47
 			$str .= $anchor;
48 48
 			$str .= '</a>';
49 49
 
50
-			if($return){
50
+			if ($return) {
51 51
 				return $str;
52 52
 			}
53 53
 			echo $str;
@@ -62,18 +62,18 @@  discard block
 block discarded – undo
62 62
 		 *
63 63
 		 * @return string|void             the generated html for mailto link if $return is true or display it if not
64 64
 		 */
65
-		public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){
66
-			if(! $anchor){
65
+		public static function mailto($link, $anchor = null, array $attributes = array(), $return = true) {
66
+			if (!$anchor) {
67 67
 				$anchor = $link;
68 68
 			}
69 69
 			$str = null;
70
-			$str .= '<a href = "mailto:'.$link.'"';
70
+			$str .= '<a href = "mailto:' . $link . '"';
71 71
 			$str .= attributes_to_string($attributes);
72 72
 			$str .= '>';
73 73
 			$str .= $anchor;
74 74
 			$str .= '</a>';
75 75
 
76
-			if($return){
76
+			if ($return) {
77 77
 				return $str;
78 78
 			}
79 79
 			echo $str;
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
 		 *
87 87
 		 * @return string|void      the generated "br" html if $return is true or display it if not
88 88
 		 */
89
-		public static function br($nb = 1, $return = true){
89
+		public static function br($nb = 1, $return = true) {
90 90
 			$nb = (int) $nb;
91 91
 			$str = null;
92 92
 			for ($i = 1; $i <= $nb; $i++) {
93 93
 				$str .= '<br />';
94 94
 			}
95 95
 
96
-			if($return){
96
+			if ($return) {
97 97
 				return $str;
98 98
 			}
99 99
 			echo $str;
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
 		 *
108 108
 		 * @return string|void the generated "hr" html if $return is true or display it if not.
109 109
 		 */
110
-		public static function hr($nb = 1, array $attributes = array(), $return = true){
110
+		public static function hr($nb = 1, array $attributes = array(), $return = true) {
111 111
 			$nb = (int) $nb;
112 112
 			$str = null;
113 113
 			for ($i = 1; $i <= $nb; $i++) {
114
-				$str .= '<hr' .attributes_to_string($attributes). ' />';
114
+				$str .= '<hr' . attributes_to_string($attributes) . ' />';
115 115
 			}
116
-			if($return){
116
+			if ($return) {
117 117
 				return $str;
118 118
 			}
119 119
 			echo $str;
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 		 *
130 130
 		 * @return string|void the generated header html if $return is true or display it if not.
131 131
 		 */
132
-		public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){
132
+		public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true) {
133 133
 			$nb = (int) $nb;
134 134
 			$type = (int) $type;
135 135
 			$str = null;
136 136
 			for ($i = 1; $i <= $nb; $i++) {
137
-				$str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>';
137
+				$str .= '<h' . $type . attributes_to_string($attributes) . '>' . $text . '</h' . $type . '>';
138 138
 			}
139
-			if($return){
139
+			if ($return) {
140 140
 				return $str;
141 141
 			}
142 142
 			echo $str;
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 		 *
152 152
 		 * @return string|void the generated "ul" html  if $return is true or display it if not.
153 153
 		 */
154
-		public static function ul($data = array(), $attributes = array(), $return = true){
155
-			if($return){
154
+		public static function ul($data = array(), $attributes = array(), $return = true) {
155
+			if ($return) {
156 156
 				return self::buildUlOl($data, $attributes, true, 'ul');
157 157
 			}
158 158
 			self::buildUlOl($data, $attributes, false, 'ul');
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 		 * @param  boolean $return whether need return the generated html or just display it directly
167 167
 		 * @return string|void the generated "ol" html  if $return is true or display it if not.
168 168
 		 */
169
-		public static function ol($data = array(), $attributes = array(), $return = true){
170
-			if($return){
169
+		public static function ol($data = array(), $attributes = array(), $return = true) {
170
+			if ($return) {
171 171
 				return self::buildUlOl($data, $attributes, true, 'ol');
172 172
 			}
173 173
 			self::buildUlOl($data, $attributes, false, 'ol');
@@ -186,23 +186,23 @@  discard block
 block discarded – undo
186 186
 		 * @param  boolean $return whether need return the generated html or just display it directly
187 187
 		 * @return string|void the generated "table" html  if $return is true or display it if not.
188 188
 		 */
189
-		public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){
189
+		public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true) {
190 190
 			$headers = (array) $headers;
191 191
 			$body = (array) $body;
192 192
 			$str = null;
193 193
 			$tableAttributes = '';
194
-			if(! empty($attributes['table'])){
194
+			if (!empty($attributes['table'])) {
195 195
 				$tableAttributes = ' ' . attributes_to_string($attributes['table']);
196 196
 			}
197 197
 			$str .= '<table' . $tableAttributes . '>';
198 198
 			$str .= self::buildTableHeader($headers, $attributes);
199 199
 			$str .= self::buildTableBody($body, $attributes);
200 200
 
201
-			if($use_footer){
201
+			if ($use_footer) {
202 202
 				$str .= self::buildTableFooter($headers, $attributes);
203 203
 			}
204 204
 			$str .= '</table>';
205
-			if($return){
205
+			if ($return) {
206 206
 				return $str;
207 207
 			}
208 208
 			echo $str;
@@ -213,24 +213,24 @@  discard block
 block discarded – undo
213 213
 		 * @see  Html::table 
214 214
 		 * @return string|null
215 215
 		 */
216
-		protected static function buildTableHeader(array $headers, $attributes = array()){
216
+		protected static function buildTableHeader(array $headers, $attributes = array()) {
217 217
 			$str = null;
218 218
 			$theadAttributes = '';
219
-			if(! empty($attributes['thead'])){
219
+			if (!empty($attributes['thead'])) {
220 220
 				$theadAttributes = ' ' . attributes_to_string($attributes['thead']);
221 221
 			}
222 222
 			$theadtrAttributes = '';
223
-			if(! empty($attributes['thead_tr'])){
223
+			if (!empty($attributes['thead_tr'])) {
224 224
 				$theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']);
225 225
 			}
226 226
 			$thAttributes = '';
227
-			if(! empty($attributes['thead_th'])){
227
+			if (!empty($attributes['thead_th'])) {
228 228
 				$thAttributes = ' ' . attributes_to_string($attributes['thead_th']);
229 229
 			}
230
-			$str .= '<thead' . $theadAttributes .'>';
231
-			$str .= '<tr' . $theadtrAttributes .'>';
230
+			$str .= '<thead' . $theadAttributes . '>';
231
+			$str .= '<tr' . $theadtrAttributes . '>';
232 232
 			foreach ($headers as $value) {
233
-				$str .= '<th' . $thAttributes .'>' .$value. '</th>';
233
+				$str .= '<th' . $thAttributes . '>' . $value . '</th>';
234 234
 			}
235 235
 			$str .= '</tr>';
236 236
 			$str .= '</thead>';
@@ -242,21 +242,21 @@  discard block
 block discarded – undo
242 242
 		 * @see  Html::table 
243 243
 		 * @return string|null
244 244
 		 */
245
-		protected static function buildTableBody(array $body, $attributes = array()){
245
+		protected static function buildTableBody(array $body, $attributes = array()) {
246 246
 			$str = null;
247 247
 			$tbodyAttributes = '';
248
-			if(! empty($attributes['tbody'])){
248
+			if (!empty($attributes['tbody'])) {
249 249
 				$tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']);
250 250
 			}
251 251
 			$tbodytrAttributes = '';
252
-			if(! empty($attributes['tbody_tr'])){
252
+			if (!empty($attributes['tbody_tr'])) {
253 253
 				$tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']);
254 254
 			}
255 255
 			$tbodytdAttributes = '';
256
-			if(! empty($attributes['tbody_td'])){
256
+			if (!empty($attributes['tbody_td'])) {
257 257
 				$tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']);
258 258
 			}
259
-			$str .= '<tbody' . $tbodyAttributes .'>';
259
+			$str .= '<tbody' . $tbodyAttributes . '>';
260 260
 			$str .= self::buildTableBodyContent($body, $tbodytrAttributes, $tbodytdAttributes);
261 261
 			$str .= '</tbody>';
262 262
 			return $str;
@@ -269,13 +269,13 @@  discard block
 block discarded – undo
269 269
 		 * @param  string $tbodytdAttributes the html attributes for each td in tbody
270 270
 		 * @return string                    
271 271
 		 */
272
-		protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes){
272
+		protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes) {
273 273
 			$str = null;
274 274
 			foreach ($body as $row) {
275
-				if(is_array($row)){
276
-					$str .= '<tr' . $tbodytrAttributes .'>';
275
+				if (is_array($row)) {
276
+					$str .= '<tr' . $tbodytrAttributes . '>';
277 277
 					foreach ($row as $value) {
278
-						$str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>';	
278
+						$str .= '<td' . $tbodytdAttributes . '>' . $value . '</td>';	
279 279
 					}
280 280
 					$str .= '</tr>';
281 281
 				}
@@ -288,24 +288,24 @@  discard block
 block discarded – undo
288 288
 		 * @see  Html::table 
289 289
 		 * @return string|null
290 290
 		 */
291
-		protected static function buildTableFooter(array $footers, $attributes = array()){
291
+		protected static function buildTableFooter(array $footers, $attributes = array()) {
292 292
 			$str = null;
293 293
 			$tfootAttributes = '';
294
-			if(! empty($attributes['tfoot'])){
294
+			if (!empty($attributes['tfoot'])) {
295 295
 				$tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']);
296 296
 			}
297 297
 			$tfoottrAttributes = '';
298
-			if(! empty($attributes['tfoot_tr'])){
298
+			if (!empty($attributes['tfoot_tr'])) {
299 299
 				$tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']);
300 300
 			}
301 301
 			$thAttributes = '';
302
-			if(! empty($attributes['tfoot_th'])){
302
+			if (!empty($attributes['tfoot_th'])) {
303 303
 				$thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']);
304 304
 			}
305
-			$str .= '<tfoot' . $tfootAttributes .'>';
306
-				$str .= '<tr' . $tfoottrAttributes .'>';
305
+			$str .= '<tfoot' . $tfootAttributes . '>';
306
+				$str .= '<tr' . $tfoottrAttributes . '>';
307 307
 				foreach ($footers as $value) {
308
-					$str .= '<th' . $thAttributes .'>' .$value. '</th>';
308
+					$str .= '<th' . $thAttributes . '>' . $value . '</th>';
309 309
 				}
310 310
 				$str .= '</tr>';
311 311
 				$str .= '</tfoot>';
@@ -319,23 +319,23 @@  discard block
 block discarded – undo
319 319
 		 * @param  string  $olul   the type 'ol' or 'ul'
320 320
 		 * @return void|string
321 321
 		 */
322
-		protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul'){
322
+		protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul') {
323 323
 			$data = (array) $data;
324 324
 			$str = null;
325 325
 			$olulAttributes = '';
326
-			if(! empty($attributes[$olul])){
326
+			if (!empty($attributes[$olul])) {
327 327
 				$olulAttributes = ' ' . attributes_to_string($attributes[$olul]);
328 328
 			}
329 329
 			$liAttributes = '';
330
-			if(! empty($attributes['li'])){
330
+			if (!empty($attributes['li'])) {
331 331
 				$liAttributes = ' ' . attributes_to_string($attributes['li']);
332 332
 			}
333 333
 			$str .= '<' . $olul . $olulAttributes . '>';
334 334
 			foreach ($data as $row) {
335
-				$str .= '<li' . $liAttributes .'>' .$row. '</li>';
335
+				$str .= '<li' . $liAttributes . '>' . $row . '</li>';
336 336
 			}
337 337
 			$str .= '</' . $olul . '>';
338
-			if($return){
338
+			if ($return) {
339 339
 				return $str;
340 340
 			}
341 341
 			echo $str;
Please login to merge, or discard this patch.
core/classes/model/Model.php 1 patch
Spacing   +44 added lines, -44 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
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
          * Initialise the model, tie into the CodeIgniter superobject and
146 146
          * try our best to guess the table name.
147 147
          */
148
-        public function __construct(Database $db = null){
149
-            if (is_object($db)){
148
+        public function __construct(Database $db = null) {
149
+            if (is_object($db)) {
150 150
                 $this->setDatabaseInstance($db);
151 151
             }
152
-            else{
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 156
                     * NOTE: Need use "clone" because some Model need have the personal instance of the database library
157 157
                     * to prevent duplication
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 
188 188
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
189 189
             {
190
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
190
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
191 191
             }
192 192
     		$this->_set_where($where);
193 193
 
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
             $this->trigger('before_get');
230 230
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
231 231
             {
232
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
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 236
 			$result = $this->_database->getAll($type);
237 237
             $this->_temporary_return_type = $this->return_type;
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                 $insert_id = $this->_database->insertId();
265 265
                 $this->trigger('after_create', $insert_id);
266 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;
267
+				return !$insert_id ? true : $insert_id;
268 268
             }
269 269
             else
270 270
             {
@@ -341,13 +341,13 @@  discard block
 block discarded – undo
341 341
         {
342 342
             $args = func_get_args();
343 343
             $data = array();
344
-            if (count($args) == 2){
345
-                if (is_array($args[1])){
344
+            if (count($args) == 2) {
345
+                if (is_array($args[1])) {
346 346
                     $data = array_pop($args);
347 347
                 }
348 348
             }
349
-            else if (count($args) == 3){
350
-                if (is_array($args[2])){
349
+            else if (count($args) == 3) {
350
+                if (is_array($args[2])) {
351 351
                     $data = array_pop($args);
352 352
                 }
353 353
             }
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
             if ($this->soft_delete)
387 387
             {
388 388
                 $this->getQueryBuilder()->from($this->_table);	
389
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
389
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
390 390
             }
391 391
             else
392 392
             {
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
             if ($this->soft_delete)
411 411
             {
412 412
                 $this->getQueryBuilder()->from($this->_table);	
413
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
413
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
414 414
             }
415 415
             else
416 416
             {
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
             if ($this->soft_delete)
433 433
             {
434 434
                 $this->getQueryBuilder()->from($this->_table);	
435
-				$result = $this->_database->update(array( $this->soft_delete_key => TRUE ));
435
+				$result = $this->_database->update(array($this->soft_delete_key => TRUE));
436 436
             }
437 437
             else
438 438
             {
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
                 $key = $this->primary_key;
503 503
                 $value = $args[0];
504 504
             }
505
-            $this->trigger('before_dropdown', array( $key, $value ));
505
+            $this->trigger('before_dropdown', array($key, $value));
506 506
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
507 507
             {
508 508
                 $this->getQueryBuilder()->where($this->soft_delete_key, FALSE);
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
         {
528 528
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
529 529
             {
530
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
530
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
531 531
             }
532 532
             $where = func_get_args();
533 533
             $this->_set_where($where);
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
         {
544 544
             if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE)
545 545
             {
546
-                $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted);
546
+                $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted);
547 547
             }
548 548
 			$this->getQueryBuilder()->from($this->_table);
549 549
 			$this->_database->getAll();
@@ -553,8 +553,8 @@  discard block
 block discarded – undo
553 553
 		/**
554 554
 		* Enabled cache temporary
555 555
 		*/
556
-		public function cached($ttl = 0){
557
-		  if ($ttl > 0){
556
+		public function cached($ttl = 0) {
557
+		  if ($ttl > 0) {
558 558
 			$this->_database = $this->_database->cached($ttl);
559 559
 		  }
560 560
 		  return $this;
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
             {
709 709
                 if (is_object($row))
710 710
                 {
711
-					if (isset($row->$attr)){
711
+					if (isset($row->$attr)) {
712 712
 						unset($row->$attr);
713 713
 					}
714 714
                 }
715 715
                 else
716 716
                 {
717
-					if (isset($row[$attr])){
717
+					if (isset($row[$attr])) {
718 718
 						unset($row[$attr]);
719 719
 					}
720 720
                 }
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
          * Return the database instance
727 727
          * @return Database the database instance
728 728
          */
729
-        public function getDatabaseInstance(){
729
+        public function getDatabaseInstance() {
730 730
             return $this->_database;
731 731
         }
732 732
 
@@ -734,9 +734,9 @@  discard block
 block discarded – undo
734 734
          * set the Database instance for future use
735 735
          * @param Database $db the database object
736 736
          */
737
-         public function setDatabaseInstance($db){
737
+         public function setDatabaseInstance($db) {
738 738
             $this->_database = $db;
739
-            if ($this->dbCacheTime > 0){
739
+            if ($this->dbCacheTime > 0) {
740 740
                 $this->_database->setCache($this->dbCacheTime);
741 741
             }
742 742
             return $this;
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
          * Return the loader instance
747 747
          * @return Loader the loader instance
748 748
          */
749
-        public function getLoader(){
749
+        public function getLoader() {
750 750
             return $this->loaderInstance;
751 751
         }
752 752
 
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
          * @param Loader $loader the loader object
756 756
 		 * @return object
757 757
          */
758
-         public function setLoader($loader){
758
+         public function setLoader($loader) {
759 759
             $this->loaderInstance = $loader;
760 760
             return $this;
761 761
         }
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
          * Return the queryBuilder instance this is the shortcut to database queryBuilder
765 765
          * @return object the DatabaseQueryBuilder instance
766 766
          */
767
-        public function getQueryBuilder(){
767
+        public function getQueryBuilder() {
768 768
             return $this->_database->getQueryBuilder();
769 769
         }
770 770
 
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
          * @param object $queryBuilder the DatabaseQueryBuilder object
774 774
 		 * @return object
775 775
          */
776
-         public function setQueryBuilder($queryBuilder){
776
+         public function setQueryBuilder($queryBuilder) {
777 777
             $this->_database->setQueryBuilder($queryBuilder);
778 778
             return $this;
779 779
         }
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
          * Return the FormValidation instance
784 784
          * @return FormValidation the form validation instance
785 785
          */
786
-        public function getFormValidation(){
786
+        public function getFormValidation() {
787 787
             return $this->formValidationInstance;
788 788
         }
789 789
 
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
          * @param FormValidation $fv the form validation object
793 793
 		 * @return object
794 794
          */
795
-         public function setFormValidation($fv){
795
+         public function setFormValidation($fv) {
796 796
             $this->formValidationInstance = $fv;
797 797
             return $this;
798 798
         }
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
          */
807 807
         public function order_by($criteria, $order = 'ASC')
808 808
         {
809
-            if ( is_array($criteria) )
809
+            if (is_array($criteria))
810 810
             {
811 811
                 foreach ($criteria as $key => $value)
812 812
                 {
@@ -837,13 +837,13 @@  discard block
 block discarded – undo
837 837
 		* relate for the relation "belongs_to"
838 838
 		* @return mixed
839 839
 		*/
840
-		protected function relateBelongsTo($row){
840
+		protected function relateBelongsTo($row) {
841 841
 			foreach ($this->belongs_to as $key => $value)
842 842
             {
843 843
                 if (is_string($value))
844 844
                 {
845 845
                     $relationship = $value;
846
-                    $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' );
846
+                    $options = array('primary_key' => $value . '_id', 'model' => $value . '_model');
847 847
                 }
848 848
                 else
849 849
                 {
@@ -853,10 +853,10 @@  discard block
 block discarded – undo
853 853
 
854 854
                 if (in_array($relationship, $this->_with))
855 855
                 {
856
-                    if (is_object($this->loaderInstance)){
856
+                    if (is_object($this->loaderInstance)) {
857 857
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
858 858
                     }
859
-                    else{
859
+                    else {
860 860
                         Loader::model($options['model'], $relationship . '_model');    
861 861
                     }
862 862
                     if (is_object($row))
@@ -876,13 +876,13 @@  discard block
 block discarded – undo
876 876
 		* relate for the relation "has_many"
877 877
 		* @return mixed
878 878
 		*/
879
-		protected function relateHasMany($row){
879
+		protected function relateHasMany($row) {
880 880
 			foreach ($this->has_many as $key => $value)
881 881
             {
882 882
                 if (is_string($value))
883 883
                 {
884 884
                     $relationship = $value;
885
-                    $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' );
885
+                    $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model');
886 886
                 }
887 887
                 else
888 888
                 {
@@ -892,10 +892,10 @@  discard block
 block discarded – undo
892 892
 
893 893
                 if (in_array($relationship, $this->_with))
894 894
                 {
895
-                    if (is_object($this->loaderInstance)){
895
+                    if (is_object($this->loaderInstance)) {
896 896
                         $this->loaderInstance->model($options['model'], $relationship . '_model');
897 897
                     }
898
-                    else{
898
+                    else {
899 899
                         Loader::model($options['model'], $relationship . '_model');    
900 900
                     }
901 901
                     if (is_object($row))
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
                 return $data;
945 945
             }
946 946
             $fv = $this->formValidationInstance;
947
-            if (! is_object($fv)){
947
+            if (!is_object($fv)) {
948 948
                  Loader::library('FormValidation');
949 949
                 $fv = $this->formvalidation;
950 950
                 $this->setFormValidation($fv);  
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 		* Set WHERE parameters, when is array
965 965
 		* @param array $params
966 966
 		*/
967
-		protected function _set_where_array(array $params){
967
+		protected function _set_where_array(array $params) {
968 968
 			foreach ($params as $field => $filter)
969 969
 			{
970 970
 				if (is_array($filter))
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
         /**
1031 1031
             Shortcut to controller
1032 1032
         */
1033
-        public function __get($key){
1033
+        public function __get($key) {
1034 1034
             return get_instance()->{$key};
1035 1035
         }
1036 1036
 
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Spacing   +78 added lines, -78 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 Response{
27
+	class Response {
28 28
 
29 29
 		/**
30 30
 		 * The list of request header to send with response
@@ -65,15 +65,15 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Construct new response instance
67 67
 		 */
68
-		public function __construct(){
68
+		public function __construct() {
69 69
 			$currentUrl = '';
70
-			if (! empty($_SERVER['REQUEST_URI'])){
70
+			if (!empty($_SERVER['REQUEST_URI'])) {
71 71
 				$currentUrl = $_SERVER['REQUEST_URI'];
72 72
 			}
73
-			if (! empty($_SERVER['QUERY_STRING'])){
73
+			if (!empty($_SERVER['QUERY_STRING'])) {
74 74
 				$currentUrl .= '?' . $_SERVER['QUERY_STRING'];
75 75
 			}
76
-			$this->_currentUrl =  $currentUrl;
76
+			$this->_currentUrl = $currentUrl;
77 77
 					
78 78
 			$this->_currentUrlCacheKey = md5($this->_currentUrl);
79 79
 			
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
 		 * The signleton of the logger
90 90
 		 * @return Object the Log instance
91 91
 		 */
92
-		public static function getLogger(){
93
-			if(self::$logger == null){
92
+		public static function getLogger() {
93
+			if (self::$logger == null) {
94 94
 				$logger = array();
95
-				$logger[0] =& class_loader('Log', 'classes');
95
+				$logger[0] = & class_loader('Log', 'classes');
96 96
 				$logger[0]->setLogger('Library::Response');
97 97
 				self::$logger = $logger[0];
98 98
 			}
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		 * @param object $logger the log object
105 105
 		 * @return object the log instance
106 106
 		 */
107
-		public static function setLogger($logger){
107
+		public static function setLogger($logger) {
108 108
 			self::$logger = $logger;
109 109
 			return self::$logger;
110 110
 		}
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
 		 * @param  integer $httpCode the HTTP status code
116 116
 		 * @param  array   $headers   the additional headers to add to the existing headers list
117 117
 		 */
118
-		public static function sendHeaders($httpCode = 200, array $headers = array()){
118
+		public static function sendHeaders($httpCode = 200, array $headers = array()) {
119 119
 			set_http_status_header($httpCode);
120 120
 			self::setHeaders($headers);
121
-			if(! headers_sent()){
122
-				foreach(self::getHeaders() as $key => $value){
123
-					header($key .': '.$value);
121
+			if (!headers_sent()) {
122
+				foreach (self::getHeaders() as $key => $value) {
123
+					header($key . ': ' . $value);
124 124
 				}
125 125
 			}
126 126
 		}
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		 * Get the list of the headers
130 130
 		 * @return array the headers list
131 131
 		 */
132
-		public static function getHeaders(){
132
+		public static function getHeaders() {
133 133
 			return self::$headers;
134 134
 		}
135 135
 
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 		 * @param  string $name the header name
139 139
 		 * @return string|null       the header value
140 140
 		 */
141
-		public static function getHeader($name){
142
-			if(array_key_exists($name, self::$headers)){
141
+		public static function getHeader($name) {
142
+			if (array_key_exists($name, self::$headers)) {
143 143
 				return self::$headers[$name];
144 144
 			}
145 145
 			return null;
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		 * @param string $name  the header name
152 152
 		 * @param string $value the header value to be set
153 153
 		 */
154
-		public static function setHeader($name, $value){
154
+		public static function setHeader($name, $value) {
155 155
 			self::$headers[$name] = $value;
156 156
 		}
157 157
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 * @param array $headers the list of the headers to set. 
161 161
 		 * Note: this will merge with the existing headers
162 162
 		 */
163
-		public static function setHeaders(array $headers){
163
+		public static function setHeaders(array $headers) {
164 164
 			self::$headers = array_merge(self::getHeaders(), $headers);
165 165
 		}
166 166
 		
@@ -168,16 +168,16 @@  discard block
 block discarded – undo
168 168
 		 * Redirect user to the specified page
169 169
 		 * @param  string $path the URL or URI to be redirect to
170 170
 		 */
171
-		public static function redirect($path = ''){
171
+		public static function redirect($path = '') {
172 172
 			$logger = self::getLogger();
173 173
 			$url = Url::site_url($path);
174
-			$logger->info('Redirect to URL [' .$url. ']');
175
-			if(! headers_sent()){
176
-				header('Location: '.$url);
174
+			$logger->info('Redirect to URL [' . $url . ']');
175
+			if (!headers_sent()) {
176
+				header('Location: ' . $url);
177 177
 				exit;
178 178
 			}
179 179
 			echo '<script>
180
-					location.href = "'.$url.'";
180
+					location.href = "'.$url . '";
181 181
 				</script>';
182 182
 		}
183 183
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 		 * @return void|string          if $return is true will return the view content otherwise
190 190
 		 * will display the view content.
191 191
 		 */
192
-		public function render($view, $data = null, $return = false){
192
+		public function render($view, $data = null, $return = false) {
193 193
 			$logger = self::getLogger();
194 194
 			//convert data to an array
195 195
 			$data = (array) $data;
@@ -201,22 +201,22 @@  discard block
 block discarded – undo
201 201
 			//check in module first
202 202
 			$logger->debug('Checking the view [' . $view . '] from module list ...');
203 203
 			$moduleInfo = $this->getModuleInfoForView($view);
204
-			$module    = $moduleInfo['module'];
205
-			$view  = $moduleInfo['view'];
204
+			$module = $moduleInfo['module'];
205
+			$view = $moduleInfo['view'];
206 206
 			
207 207
 			$moduleViewPath = Module::findViewFullPath($view, $module);
208
-			if($moduleViewPath){
208
+			if ($moduleViewPath) {
209 209
 				$path = $moduleViewPath;
210
-				$logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it');
210
+				$logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $moduleViewPath . '] we will used it');
211 211
 			}
212
-			else{
213
-				$logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location');
212
+			else {
213
+				$logger->info('Cannot find view [' . $view . '] in module [' . $module . '] using the default location');
214 214
 			}
215 215
 			
216 216
 			$logger->info('The view file path to be loaded is [' . $path . ']');
217 217
 			
218 218
 			/////////
219
-			if($return){
219
+			if ($return) {
220 220
 				return $this->loadView($path, $data, true);
221 221
 			}
222 222
 			$this->loadView($path, $data, false);
@@ -226,36 +226,36 @@  discard block
 block discarded – undo
226 226
 		/**
227 227
 		* Send the final page output to user
228 228
 		*/
229
-		public function renderFinalPage(){
229
+		public function renderFinalPage() {
230 230
 			$logger = self::getLogger();
231 231
 			$obj = & get_instance();
232 232
 			$cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
233 233
 			$dispatcher = $obj->eventdispatcher;
234 234
 			$content = $this->_pageRender;
235
-			if(! $content){
235
+			if (!$content) {
236 236
 				$logger->warning('The final view content is empty.');
237 237
 				return;
238 238
 			}
239 239
 			//dispatch
240 240
 			$event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
241 241
 			$content = null;
242
-			if(! empty($event->payload)){
242
+			if (!empty($event->payload)) {
243 243
 				$content = $event->payload;
244 244
 			}
245
-			if(empty($content)){
245
+			if (empty($content)) {
246 246
 				$logger->warning('The view content is empty after dispatch to event listeners.');
247 247
 			}
248 248
 			//remove unsed space in the content
249 249
 			$content = preg_replace('~>\s*\n\s*<~', '><', $content);
250 250
 			//check whether need save the page into cache.
251
-			if($cachePageStatus){
251
+			if ($cachePageStatus) {
252 252
 				$this->savePageContentIntoCache($content);
253 253
 			}
254 254
 			$content = $this->replaceElapseTimeAndMemoryUsage($content);
255 255
 
256 256
 			//compress the output if is available
257 257
 			$type = null;
258
-			if (self::$_canCompressOutput){
258
+			if (self::$_canCompressOutput) {
259 259
 				$type = 'ob_gzhandler';
260 260
 			}
261 261
 			ob_start($type);
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		*
272 272
 		* @return boolean whether the page content if available or not
273 273
 		*/
274
-		public function renderFinalPageFromCache(&$cache){
274
+		public function renderFinalPageFromCache(&$cache) {
275 275
 			$logger = self::getLogger();
276 276
 			//the current page cache key for identification
277 277
 			$pageCacheKey = $this->_currentUrlCacheKey;
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 			$logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...');
280 280
 			//get the cache information to prepare header to send to browser
281 281
 			$cacheInfo = $cache->getInfo($pageCacheKey);
282
-			if($cacheInfo){
282
+			if ($cacheInfo) {
283 283
 				$status = $this->sendCacheNotYetExpireInfo($cacheInfo);
284
-				if($status === false){
284
+				if ($status === false) {
285 285
 					return $this->sendCachePageContentToBrowser($cache);
286 286
 				}
287 287
 				return true;
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 		* Get the final page to be rendered
295 295
 		* @return string
296 296
 		*/
297
-		public function getFinalPageRendered(){
297
+		public function getFinalPageRendered() {
298 298
 			return $this->_pageRender;
299 299
 		}
300 300
 
@@ -302,14 +302,14 @@  discard block
 block discarded – undo
302 302
 		 * Send the HTTP 404 error if can not found the 
303 303
 		 * routing information for the current request
304 304
 		 */
305
-		public static function send404(){
305
+		public static function send404() {
306 306
 			/********* for logs **************/
307 307
 			//can't use $obj = & get_instance()  here because the global super object will be available until
308 308
 			//the main controller is loaded even for Loader::library('xxxx');
309 309
 			$logger = self::getLogger();
310
-			$request =& class_loader('Request', 'classes');
311
-			$userAgent =& class_loader('Browser');
312
-			$browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion();
310
+			$request = & class_loader('Request', 'classes');
311
+			$userAgent = & class_loader('Browser');
312
+			$browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion();
313 313
 			
314 314
 			//here can't use Loader::functions just include the helper manually
315 315
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
 			$logger->error($str);
320 320
 			/***********************************/
321 321
 			$path = CORE_VIEWS_PATH . '404.php';
322
-			if(file_exists($path)){
322
+			if (file_exists($path)) {
323 323
 				//compress the output if is available
324 324
 				$type = null;
325
-				if (self::$_canCompressOutput){
325
+				if (self::$_canCompressOutput) {
326 326
 					$type = 'ob_gzhandler';
327 327
 				}
328 328
 				ob_start($type);
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
 				self::sendHeaders(404);
332 332
 				echo $output;
333 333
 			}
334
-			else{
335
-				show_error('The 404 view [' .$path. '] does not exist');
334
+			else {
335
+				show_error('The 404 view [' . $path . '] does not exist');
336 336
 			}
337 337
 		}
338 338
 
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 		 * Display the error to user
341 341
 		 * @param  array  $data the error information
342 342
 		 */
343
-		public static function sendError(array $data = array()){
343
+		public static function sendError(array $data = array()) {
344 344
 			$path = CORE_VIEWS_PATH . 'errors.php';
345
-			if(file_exists($path)){
345
+			if (file_exists($path)) {
346 346
 				//compress the output if is available
347 347
 				$type = null;
348
-				if (self::$_canCompressOutput){
348
+				if (self::$_canCompressOutput) {
349 349
 					$type = 'ob_gzhandler';
350 350
 				}
351 351
 				ob_start($type);
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 				self::sendHeaders(503);
356 356
 				echo $output;
357 357
 			}
358
-			else{
358
+			else {
359 359
 				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
360 360
 				set_http_status_header(503);
361 361
 				echo 'The error view [' . $path . '] does not exist';
@@ -367,17 +367,17 @@  discard block
 block discarded – undo
367 367
 		 * @param  array $cacheInfo the cache information
368 368
 		 * @return boolean            true if the information is sent otherwise false
369 369
 		 */
370
-		protected function sendCacheNotYetExpireInfo($cacheInfo){
371
-			if(! empty($cacheInfo)){
370
+		protected function sendCacheNotYetExpireInfo($cacheInfo) {
371
+			if (!empty($cacheInfo)) {
372 372
 				$logger = self::getLogger();
373 373
 				$lastModified = $cacheInfo['mtime'];
374 374
 				$expire = $cacheInfo['expire'];
375 375
 				$maxAge = $expire - $_SERVER['REQUEST_TIME'];
376 376
 				self::setHeader('Pragma', 'public');
377 377
 				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
378
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
379
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');
380
-				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
378
+				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
379
+				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
380
+				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
381 381
 					$logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser');
382 382
 					self::sendHeaders(304);
383 383
 					return true;
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 		 * @return string          the page content after replace 
393 393
 		 * '{elapsed_time}', '{memory_usage}'
394 394
 		 */
395
-		protected function replaceElapseTimeAndMemoryUsage($content){
395
+		protected function replaceElapseTimeAndMemoryUsage($content) {
396 396
 			//load benchmark class
397 397
 			$benchmark = & class_loader('Benchmark');
398 398
 			
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		 * @param object $cache the cache instance
409 409
 		 * @return boolean     the status of the operation
410 410
 		 */
411
-		protected function sendCachePageContentToBrowser(&$cache){
411
+		protected function sendCachePageContentToBrowser(&$cache) {
412 412
 			$logger = self::getLogger();
413 413
 			$logger->info('The cache page content is expired or the browser doesn\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser');
414 414
 			self::sendHeaders(200);
@@ -416,13 +416,13 @@  discard block
 block discarded – undo
416 416
 			$pageCacheKey = $this->_currentUrlCacheKey;
417 417
 			//get the cache content
418 418
 			$content = $cache->get($pageCacheKey);
419
-			if($content){
419
+			if ($content) {
420 420
 				$logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it');
421 421
 				$content = $this->replaceElapseTimeAndMemoryUsage($content);
422 422
 				///display the final output
423 423
 				//compress the output if is available
424 424
 				$type = null;
425
-				if (self::$_canCompressOutput){
425
+				if (self::$_canCompressOutput) {
426 426
 					$type = 'ob_gzhandler';
427 427
 				}
428 428
 				ob_start($type);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 		 * @param  string $content the page content to be saved
441 441
 		 * @return void
442 442
 		 */
443
-		protected function savePageContentIntoCache($content){
443
+		protected function savePageContentIntoCache($content) {
444 444
 			$obj = & get_instance();
445 445
 			$logger = self::getLogger();
446 446
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 			$url = $this->_currentUrl;
449 449
 			//Cache view Time to live in second
450 450
 			$viewCacheTtl = get_config('cache_ttl');
451
-			if (!empty($obj->view_cache_ttl)){
451
+			if (!empty($obj->view_cache_ttl)) {
452 452
 				$viewCacheTtl = $obj->view_cache_ttl;
453 453
 			}
454 454
 			//the cache handler instance
@@ -460,14 +460,14 @@  discard block
 block discarded – undo
460 460
 			
461 461
 			//get the cache information to prepare header to send to browser
462 462
 			$cacheInfo = $cacheInstance->getInfo($cacheKey);
463
-			if($cacheInfo){
463
+			if ($cacheInfo) {
464 464
 				$lastModified = $cacheInfo['mtime'];
465 465
 				$expire = $cacheInfo['expire'];
466 466
 				$maxAge = $expire - time();
467 467
 				self::setHeader('Pragma', 'public');
468 468
 				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
469
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
470
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');	
469
+				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
470
+				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');	
471 471
 			}
472 472
 		}
473 473
 		
@@ -483,21 +483,21 @@  discard block
 block discarded – undo
483 483
 		 * 	'viewFile' => 'view_file'
484 484
 		 * )
485 485
 		 */
486
-		protected  function getModuleInfoForView($view){
486
+		protected  function getModuleInfoForView($view) {
487 487
 			$module = null;
488 488
 			$viewFile = null;
489 489
 			$obj = & get_instance();
490 490
 			//check if the request class contains module name
491
-			if(strpos($view, '/') !== false){
491
+			if (strpos($view, '/') !== false) {
492 492
 				$viewPath = explode('/', $view);
493
-				if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){
493
+				if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) {
494 494
 					$module = $viewPath[0];
495 495
 					array_shift($viewPath);
496 496
 					$view = implode('/', $viewPath);
497 497
 					$viewFile = $view . '.php';
498 498
 				}
499 499
 			}
500
-			if(! $module && !empty($obj->moduleName)){
500
+			if (!$module && !empty($obj->moduleName)) {
501 501
 				$module = $obj->moduleName;
502 502
 			}
503 503
 			return array(
@@ -512,13 +512,13 @@  discard block
 block discarded – undo
512 512
 		 * @see  Response::render
513 513
 		 * @return void|string
514 514
 		 */
515
-		protected  function loadView($path, array $data = array(), $return = false){
515
+		protected  function loadView($path, array $data = array(), $return = false) {
516 516
 			$found = false;
517
-			if(file_exists($path)){
517
+			if (file_exists($path)) {
518 518
 				//super instance
519 519
 				$obj = & get_instance();
520
-				foreach(get_object_vars($obj) as $key => $value){
521
-					if(! isset($this->{$key})){
520
+				foreach (get_object_vars($obj) as $key => $value) {
521
+					if (!isset($this->{$key})) {
522 522
 						$this->{$key} = & $obj->{$key};
523 523
 					}
524 524
 				}
@@ -527,14 +527,14 @@  discard block
 block discarded – undo
527 527
 				//need use require() instead of require_once because can load this view many time
528 528
 				require $path;
529 529
 				$content = ob_get_clean();
530
-				if($return){
530
+				if ($return) {
531 531
 					return $content;
532 532
 				}
533 533
 				$this->_pageRender .= $content;
534 534
 				$found = true;
535 535
 			}
536
-			if(! $found){
537
-				show_error('Unable to find view [' .$view . ']');
536
+			if (!$found) {
537
+				show_error('Unable to find view [' . $view . ']');
538 538
 			}
539 539
 		}
540 540
 
Please login to merge, or discard this patch.
core/classes/Log.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Log{
27
+	class Log {
28 28
 		
29 29
 		/**
30 30
 		 * The defined constante for Log level
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 		/**
53 53
 		 * Create new Log instance
54 54
 		 */
55
-		public function __construct(){
55
+		public function __construct() {
56 56
 		}
57 57
 
58 58
 		/**
59 59
 		 * Set the logger to identify each message in the log
60 60
 		 * @param string $logger the logger name
61 61
 		 */
62
-		public  function setLogger($logger){
62
+		public  function setLogger($logger) {
63 63
 			$this->logger = $logger;
64 64
 		}
65 65
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 * @see Log::writeLog for more detail
69 69
 		 * @param  string $message the log message to save
70 70
 		 */
71
-		public function fatal($message){
71
+		public function fatal($message) {
72 72
 			$this->writeLog($message, self::FATAL);
73 73
 		} 
74 74
 		
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		 * @see Log::writeLog for more detail
78 78
 		 * @param  string $message the log message to save
79 79
 		 */
80
-		public function error($message){
80
+		public function error($message) {
81 81
 			$this->writeLog($message, self::ERROR);
82 82
 		} 
83 83
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		 * @see Log::writeLog for more detail
87 87
 		 * @param  string $message the log message to save
88 88
 		 */
89
-		public function warning($message){
89
+		public function warning($message) {
90 90
 			$this->writeLog($message, self::WARNING);
91 91
 		} 
92 92
 		
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * @see Log::writeLog for more detail
96 96
 		 * @param  string $message the log message to save
97 97
 		 */
98
-		public function info($message){
98
+		public function info($message) {
99 99
 			$this->writeLog($message, self::INFO);
100 100
 		} 
101 101
 		
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		 * @see Log::writeLog for more detail
105 105
 		 * @param  string $message the log message to save
106 106
 		 */
107
-		public function debug($message){
107
+		public function debug($message) {
108 108
 			$this->writeLog($message, self::DEBUG);
109 109
 		} 
110 110
 		
@@ -115,31 +115,31 @@  discard block
 block discarded – undo
115 115
 		 * @param  integer|string $level   the log level in integer or string format, if is string will convert into integer
116 116
 		 * to allow check the log level threshold.
117 117
 		 */
118
-		public function writeLog($message, $level = self::INFO){
118
+		public function writeLog($message, $level = self::INFO) {
119 119
 			$configLogLevel = get_config('log_level');
120
-			if(! $configLogLevel){
120
+			if (!$configLogLevel) {
121 121
 				//so means no need log just stop here
122 122
 				return;
123 123
 			}
124 124
 			//check config log level
125
-			if(! self::isValidConfigLevel($configLogLevel)){
125
+			if (!self::isValidConfigLevel($configLogLevel)) {
126 126
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
127 127
 				show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false);	
128 128
 			}
129 129
 			
130 130
 			//check if config log_logger_name and current log can save log data
131
-			if(! $this->canSaveLogDataForLogger()){
131
+			if (!$this->canSaveLogDataForLogger()) {
132 132
 				return;
133 133
 			}
134 134
 			
135 135
 			//if $level is not an integer
136
-			if(! is_numeric($level)){
136
+			if (!is_numeric($level)) {
137 137
 				$level = self::getLevelValue($level);
138 138
 			}
139 139
 			
140 140
 			//check if can logging regarding the log level config
141 141
 			$configLevel = self::getLevelValue($configLogLevel);
142
-			if($configLevel > $level){
142
+			if ($configLevel > $level) {
143 143
 				//can't log
144 144
 				return;
145 145
 			}
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		 * @param  string $message the log message to save
157 157
 		 * @return void
158 158
 		 */
159
-		protected function saveLogData($path, $level, $message){
159
+		protected function saveLogData($path, $level, $message) {
160 160
 			//may be at this time helper user_agent not yet included
161 161
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
162 162
 			
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 			$ip = get_ip();
170 170
 			
171 171
 			//if $level is not an integer
172
-			if(! is_numeric($level)){
172
+			if (!is_numeric($level)) {
173 173
 				$level = self::getLevelValue($level);
174 174
 			}
175 175
 
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 			//debug info
180 180
 			$dtrace = debug_backtrace();
181 181
 			$fileInfo = $dtrace[0];
182
-			if ($dtrace[0]['file'] == __FILE__){
182
+			if ($dtrace[0]['file'] == __FILE__) {
183 183
 				$fileInfo = $dtrace[1];
184 184
 			}
185 185
 			
186 186
 			$str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n";
187 187
 			$fp = fopen($path, 'a+');
188
-			if(is_resource($fp)){
188
+			if (is_resource($fp)) {
189 189
 				flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed
190 190
 				fwrite($fp, $str);
191 191
 				fclose($fp);
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
 		 * of logger filter
198 198
 		 * @return boolean
199 199
 		 */
200
-		protected function canSaveLogDataForLogger(){
201
-			if(! empty($this->logger)){
200
+		protected function canSaveLogDataForLogger() {
201
+			if (!empty($this->logger)) {
202 202
 				$configLoggersName = get_config('log_logger_name', array());
203 203
 				if (!empty($configLoggersName)) {
204 204
 					//for best comparaison put all string to lowercase
205 205
 					$configLoggersName = array_map('strtolower', $configLoggersName);
206
-					if(! in_array(strtolower($this->logger), $configLoggersName)){
206
+					if (!in_array(strtolower($this->logger), $configLoggersName)) {
207 207
 						return false;
208 208
 					}
209 209
 				}
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
 		 * Check the file and directory 
216 216
 		 * @return string the log file path
217 217
 		 */
218
-		protected function checkAndSetLogFileDirectory(){
218
+		protected function checkAndSetLogFileDirectory() {
219 219
 			$logSavePath = get_config('log_save_path');
220
-			if(! $logSavePath){
220
+			if (!$logSavePath) {
221 221
 				$logSavePath = LOGS_PATH;
222 222
 			}
223 223
 			
224
-			if(! is_dir($logSavePath) || !is_writable($logSavePath)){
224
+			if (!is_dir($logSavePath) || !is_writable($logSavePath)) {
225 225
 				//NOTE: here need put the show_error() "logging" to false to prevent loop
226 226
 				show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false);
227 227
 			}
228 228
 			
229 229
 			$path = $logSavePath . 'logs-' . date('Y-m-d') . '.log';
230
-			if(! file_exists($path)){
230
+			if (!file_exists($path)) {
231 231
 				touch($path);
232 232
 			}
233 233
 			return $path;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 		 *
241 241
 		 * @return boolean        true if the given log level is valid, false if not
242 242
 		 */
243
-		protected static function isValidConfigLevel($level){
243
+		protected static function isValidConfigLevel($level) {
244 244
 			$level = strtolower($level);
245 245
 			return in_array($level, self::$validConfigLevel);
246 246
 		}
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		 * 
252 252
 		 * @return int        the log level in integer format using the predefined constants
253 253
 		 */
254
-		protected static function getLevelValue($level){
254
+		protected static function getLevelValue($level) {
255 255
 			$level = strtolower($level);
256 256
 			$levelMaps = array(
257 257
 				'fatal'   => self::FATAL,
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 			);
265 265
 			//the default value is NONE, so means no need test for NONE
266 266
 			$value = self::NONE;
267
-			if(isset($levelMaps[$level])){
267
+			if (isset($levelMaps[$level])) {
268 268
 				$value = $levelMaps[$level];
269 269
 			}
270 270
 			return $value;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		 * @param  integer $level the log level in integer format
276 276
 		 * @return string        the log level in string format
277 277
 		 */
278
-		protected static function getLevelName($level){
278
+		protected static function getLevelName($level) {
279 279
 			$levelMaps = array(
280 280
 				self::FATAL   => 'FATAL',
281 281
 				self::ERROR   => 'ERROR',
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 				self::DEBUG   => 'DEBUG'
285 285
 			);
286 286
 			$value = '';
287
-			if(isset($levelMaps[$level])){
287
+			if (isset($levelMaps[$level])) {
288 288
 				$value = $levelMaps[$level];
289 289
 			}
290 290
 			return $value;
Please login to merge, or discard this patch.
core/bootstrap.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	
43 43
 	//if the application is running in CLI mode $_SESSION global variable is not available
44
-	if(IS_CLI){
44
+	if (IS_CLI) {
45 45
 		$_SESSION = array();
46 46
 	}
47 47
 		
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	 * The Benchmark class
62 62
 	 */
63
-	$BENCHMARK =& class_loader('Benchmark');
63
+	$BENCHMARK = & class_loader('Benchmark');
64 64
 	
65 65
 	$BENCHMARK->mark('APP_EXECUTION_START');
66 66
 	
67 67
 	/**
68 68
     * instance of the Log class
69 69
     */
70
-    $LOGGER =& class_loader('Log', 'classes');
70
+    $LOGGER = & class_loader('Log', 'classes');
71 71
 
72 72
     $LOGGER->setLogger('ApplicationBootstrap');
73 73
 
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
 	/**
77 77
 	* Verification of the PHP environment: minimum and maximum version
78 78
 	*/
79
-	if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){
79
+	if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')) {
80 80
 		show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment');	
81 81
 	}
82
-	else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){
82
+	else if (version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')) {
83 83
 		show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment');	
84 84
 	}
85 85
 	$LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue');
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
 	
102 102
 	//if user have some composer packages
103 103
 	$LOGGER->debug('Check for composer autoload');
104
-	if(file_exists(VENDOR_PATH . 'autoload.php')){
104
+	if (file_exists(VENDOR_PATH . 'autoload.php')) {
105 105
 		$LOGGER->info('The composer autoload file exists include it');
106 106
 		require_once VENDOR_PATH . 'autoload.php';
107 107
 	}
108
-	else{
108
+	else {
109 109
 		$LOGGER->info('The composer autoload file does not exist skipping');
110 110
 	}
111 111
 	
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	* Load configurations and using the 
123 123
 	* static method "init()" to initialize the Config class .
124 124
 	*/
125
-	$CONFIG =& class_loader('Config', 'classes');	
125
+	$CONFIG = & class_loader('Config', 'classes');	
126 126
 	$CONFIG->init();
127 127
 	$BENCHMARK->mark('CONFIG_INIT_END');
128 128
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	* Load modules and using the 
132 132
 	* static method "init()" to initialize the Module class.
133 133
 	*/
134
-	$MODULE =& class_loader('Module', 'classes');
134
+	$MODULE = & class_loader('Module', 'classes');
135 135
 	$MODULE->init();
136 136
 	$BENCHMARK->mark('MODULE_INIT_END');
137 137
 
@@ -150,36 +150,36 @@  discard block
 block discarded – undo
150 150
 	/**
151 151
 	* Loading Security class
152 152
 	*/
153
-	$SECURITY =& class_loader('Security', 'classes');
153
+	$SECURITY = & class_loader('Security', 'classes');
154 154
 	$SECURITY->checkWhiteListIpAccess();
155 155
 	
156 156
 	/**
157 157
 	* Loading Url class
158 158
 	*/
159
-	$URL =& class_loader('Url', 'classes');
159
+	$URL = & class_loader('Url', 'classes');
160 160
 	
161
-	if(get_config('cache_enable', false)){
161
+	if (get_config('cache_enable', false)) {
162 162
 		/**
163 163
 		 * Load Cache interface file
164 164
 		 */
165 165
 		require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php';
166 166
 		$cacheHandler = get_config('cache_handler');
167
-		if(! $cacheHandler){
167
+		if (!$cacheHandler) {
168 168
 			show_error('The cache feature is enabled in the configuration but the cache handler class is not set.');
169 169
 		}
170 170
 		$CACHE = null;
171 171
 		//first check if the cache handler is the system driver
172
-		if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){
173
-			$CACHE =& class_loader($cacheHandler, 'classes/cache');
172
+		if (file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')) {
173
+			$CACHE = & class_loader($cacheHandler, 'classes/cache');
174 174
 		}
175
-		else{
175
+		else {
176 176
 			//it's not a system driver use user library
177
-			$CACHE =& class_loader($cacheHandler);
177
+			$CACHE = & class_loader($cacheHandler);
178 178
 		}
179 179
 		//check if the page already cached
180
-		if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){
180
+		if (!empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
181 181
 			$RESPONSE = & class_loader('Response', 'classes');
182
-			if ($RESPONSE->renderFinalPageFromCache($CACHE)){
182
+			if ($RESPONSE->renderFinalPageFromCache($CACHE)) {
183 183
 				return;
184 184
 			}
185 185
 		}
Please login to merge, or discard this patch.