Passed
Push — 1.0.0-dev ( 4efac2...b68981 )
by nguereza
02:49
created
core/classes/Loader.php 2 patches
Indentation   +496 added lines, -496 removed lines patch added patch discarded remove patch
@@ -1,521 +1,521 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
26
-	class Loader{
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26
+    class Loader{
27 27
 		
28
-		/**
29
-		 * List of loaded resources
30
-		 * @var array
31
-		 */
32
-		public static $loaded = array();
28
+        /**
29
+         * List of loaded resources
30
+         * @var array
31
+         */
32
+        public static $loaded = array();
33 33
 		
34
-		/**
35
-		 * The logger instance
36
-		 * @var Log
37
-		 */
38
-		private static $logger;
34
+        /**
35
+         * The logger instance
36
+         * @var Log
37
+         */
38
+        private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
42
-			//add the resources already loaded during application bootstrap
43
-			//in the list to prevent duplicate or loading the resources again.
44
-			static::$loaded = class_loaded();
41
+        public function __construct(){
42
+            //add the resources already loaded during application bootstrap
43
+            //in the list to prevent duplicate or loading the resources again.
44
+            static::$loaded = class_loaded();
45 45
 			
46
-			//Load resources from autoload configuration
47
-			$this->loadResourcesFromAutoloadConfig();
48
-		}
46
+            //Load resources from autoload configuration
47
+            $this->loadResourcesFromAutoloadConfig();
48
+        }
49 49
 
50
-		/**
51
-		 * Get the logger singleton instance
52
-		 * @return Log the logger instance
53
-		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
57
-				self::$logger[0]->setLogger('Library::Loader');
58
-			}
59
-			return self::$logger[0];
60
-		}
50
+        /**
51
+         * Get the logger singleton instance
52
+         * @return Log the logger instance
53
+         */
54
+        private static function getLogger(){
55
+            if(self::$logger == null){
56
+                self::$logger[0] =& class_loader('Log', 'classes');
57
+                self::$logger[0]->setLogger('Library::Loader');
58
+            }
59
+            return self::$logger[0];
60
+        }
61 61
 
62
-		/**
63
-		 * Load the model class
64
-		 *
65
-		 * @param  string $class    the class name to be loaded
66
-		 * @param  string $instance the name of the instance to use in super object
67
-		 *
68
-		 * @return void
69
-		 */
70
-		public static function model($class, $instance = null){
71
-			$logger = static::getLogger();
72
-			$class = str_ireplace('.php', '', $class);
73
-			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
75
-			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
77
-				//for module
78
-				if(strpos($class, '/') !== false){
79
-					$path = explode('/', $class);
80
-					if(isset($path[1])){
81
-						$instance = strtolower($path[1]);
82
-					}
83
-				}
84
-				else{
85
-					$instance = strtolower($class);
86
-				}
87
-			}
88
-			if(isset(static::$loaded[$instance])){
89
-				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90
-				return;
91
-			}
92
-			$classFilePath = APPS_MODEL_PATH . $file;
93
-			//first check if this model is in the module
94
-			$logger->debug('Checking model [' . $class . '] from module list ...');
95
-			$searchModuleName = null;
96
-			$obj = & get_instance();
97
-			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
99
-				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
101
-					$searchModuleName = $path[0];
102
-					$class = ucfirst($path[1]);
103
-				}
104
-			}
105
-			else{
106
-				$class = ucfirst($class);
107
-			}
62
+        /**
63
+         * Load the model class
64
+         *
65
+         * @param  string $class    the class name to be loaded
66
+         * @param  string $instance the name of the instance to use in super object
67
+         *
68
+         * @return void
69
+         */
70
+        public static function model($class, $instance = null){
71
+            $logger = static::getLogger();
72
+            $class = str_ireplace('.php', '', $class);
73
+            $class = trim($class, '/\\');
74
+            $file = ucfirst($class).'.php';
75
+            $logger->debug('Loading model [' . $class . '] ...');
76
+            if(! $instance){
77
+                //for module
78
+                if(strpos($class, '/') !== false){
79
+                    $path = explode('/', $class);
80
+                    if(isset($path[1])){
81
+                        $instance = strtolower($path[1]);
82
+                    }
83
+                }
84
+                else{
85
+                    $instance = strtolower($class);
86
+                }
87
+            }
88
+            if(isset(static::$loaded[$instance])){
89
+                $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90
+                return;
91
+            }
92
+            $classFilePath = APPS_MODEL_PATH . $file;
93
+            //first check if this model is in the module
94
+            $logger->debug('Checking model [' . $class . '] from module list ...');
95
+            $searchModuleName = null;
96
+            $obj = & get_instance();
97
+            //check if the request class contains module name
98
+            if(strpos($class, '/') !== false){
99
+                $path = explode('/', $class);
100
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
101
+                    $searchModuleName = $path[0];
102
+                    $class = ucfirst($path[1]);
103
+                }
104
+            }
105
+            else{
106
+                $class = ucfirst($class);
107
+            }
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
110
-				$searchModuleName = $obj->moduleName;
111
-			}
112
-			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
115
-				$classFilePath = $moduleModelFilePath;
116
-			}
117
-			else{
118
-				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119
-			}
120
-			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
122
-				require_once $classFilePath;
123
-				if(class_exists($class)){
124
-					$c = new $class();
125
-					$obj = & get_instance();
126
-					$obj->{$instance} = $c;
127
-					static::$loaded[$instance] = $class;
128
-					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129
-				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
132
-				}
133
-			}
134
-			else{
135
-				show_error('Unable to find the model [' . $class . ']');
136
-			}
137
-		}
109
+            if(! $searchModuleName && !empty($obj->moduleName)){
110
+                $searchModuleName = $obj->moduleName;
111
+            }
112
+            $moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
+            if($moduleModelFilePath){
114
+                $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
115
+                $classFilePath = $moduleModelFilePath;
116
+            }
117
+            else{
118
+                $logger->info('Cannot find model [' . $class . '] from modules using the default location');
119
+            }
120
+            $logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
+            if(file_exists($classFilePath)){
122
+                require_once $classFilePath;
123
+                if(class_exists($class)){
124
+                    $c = new $class();
125
+                    $obj = & get_instance();
126
+                    $obj->{$instance} = $c;
127
+                    static::$loaded[$instance] = $class;
128
+                    $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129
+                }
130
+                else{
131
+                    show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
132
+                }
133
+            }
134
+            else{
135
+                show_error('Unable to find the model [' . $class . ']');
136
+            }
137
+        }
138 138
 
139 139
 
140
-		/**
141
-		 * Load the library class
142
-		 *
143
-		 * @param  string $class    the library class name to be loaded
144
-		 * @param  string $instance the instance name to use in super object
145
-		 * @param mixed $params the arguments to pass to the constructor
146
-		 *
147
-		 * @return void
148
-		 */
149
-		public static function library($class, $instance = null, array $params = array()){
150
-			$logger = static::getLogger();
151
-			$class = str_ireplace('.php', '', $class);
152
-			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
154
-			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
156
-				//for module
157
-				if(strpos($class, '/') !== false){
158
-					$path = explode('/', $class);
159
-					if(isset($path[1])){
160
-						$instance = strtolower($path[1]);
161
-					}
162
-				}
163
-				else{
164
-					$instance = strtolower($class);
165
-				}
166
-			}
167
-			if(isset(static::$loaded[$instance])){
168
-				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169
-				return;
170
-			}
171
-			$obj = & get_instance();
172
-			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
174
-				$logger->info('This is the Database library ...');
175
-				$dbInstance = & class_loader('Database', 'classes/database', $params);
176
-				$obj->{$instance} = $dbInstance;
177
-				static::$loaded[$instance] = $class;
178
-				$logger->info('Library Database loaded successfully.');
179
-				return;
180
-			}
181
-			$libraryFilePath = null;
182
-			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
184
-				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185
-				$class = ucfirst($class);
186
-				$logger->info('This library is a system library');
187
-			}
188
-			else{
189
-				$logger->info('This library is not a system library');	
190
-				//first check if this library is in the module
191
-				$logger->debug('Checking library [' . $class . '] from module list ...');
192
-				$searchModuleName = null;
193
-				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
195
-					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
197
-						$searchModuleName = $path[0];
198
-						$class = ucfirst($path[1]);
199
-					}
200
-				}
201
-				else{
202
-					$class = ucfirst($class);
203
-				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
205
-					$searchModuleName = $obj->moduleName;
206
-				}
207
-				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
210
-					$libraryFilePath = $moduleLibraryPath;
211
-				}
212
-				else{
213
-					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214
-				}
215
-			}
216
-			if(! $libraryFilePath){
217
-				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
219
-					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
221
-						$libraryFilePath = $filePath;
222
-						//is already found not to continue
223
-						break;
224
-					}
225
-				}
226
-			}
227
-			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
229
-				require_once $libraryFilePath;
230
-				if(class_exists($class)){
231
-					$c = $params ? new $class($params) : new $class();
232
-					$obj = & get_instance();
233
-					$obj->{$instance} = $c;
234
-					static::$loaded[$instance] = $class;
235
-					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236
-				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
239
-				}
240
-			}
241
-			else{
242
-				show_error('Unable to find library class [' . $class . ']');
243
-			}
244
-		}
140
+        /**
141
+         * Load the library class
142
+         *
143
+         * @param  string $class    the library class name to be loaded
144
+         * @param  string $instance the instance name to use in super object
145
+         * @param mixed $params the arguments to pass to the constructor
146
+         *
147
+         * @return void
148
+         */
149
+        public static function library($class, $instance = null, array $params = array()){
150
+            $logger = static::getLogger();
151
+            $class = str_ireplace('.php', '', $class);
152
+            $class = trim($class, '/\\');
153
+            $file = ucfirst($class) .'.php';
154
+            $logger->debug('Loading library [' . $class . '] ...');
155
+            if(! $instance){
156
+                //for module
157
+                if(strpos($class, '/') !== false){
158
+                    $path = explode('/', $class);
159
+                    if(isset($path[1])){
160
+                        $instance = strtolower($path[1]);
161
+                    }
162
+                }
163
+                else{
164
+                    $instance = strtolower($class);
165
+                }
166
+            }
167
+            if(isset(static::$loaded[$instance])){
168
+                $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169
+                return;
170
+            }
171
+            $obj = & get_instance();
172
+            //TODO for Database library
173
+            if(strtolower($class) == 'database'){
174
+                $logger->info('This is the Database library ...');
175
+                $dbInstance = & class_loader('Database', 'classes/database', $params);
176
+                $obj->{$instance} = $dbInstance;
177
+                static::$loaded[$instance] = $class;
178
+                $logger->info('Library Database loaded successfully.');
179
+                return;
180
+            }
181
+            $libraryFilePath = null;
182
+            $logger->debug('Check if this is a system library ...');
183
+            if(file_exists(CORE_LIBRARY_PATH . $file)){
184
+                $libraryFilePath = CORE_LIBRARY_PATH . $file;
185
+                $class = ucfirst($class);
186
+                $logger->info('This library is a system library');
187
+            }
188
+            else{
189
+                $logger->info('This library is not a system library');	
190
+                //first check if this library is in the module
191
+                $logger->debug('Checking library [' . $class . '] from module list ...');
192
+                $searchModuleName = null;
193
+                //check if the request class contains module name
194
+                if(strpos($class, '/') !== false){
195
+                    $path = explode('/', $class);
196
+                    if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
197
+                        $searchModuleName = $path[0];
198
+                        $class = ucfirst($path[1]);
199
+                    }
200
+                }
201
+                else{
202
+                    $class = ucfirst($class);
203
+                }
204
+                if(! $searchModuleName && !empty($obj->moduleName)){
205
+                    $searchModuleName = $obj->moduleName;
206
+                }
207
+                $moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
+                if($moduleLibraryPath){
209
+                    $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
210
+                    $libraryFilePath = $moduleLibraryPath;
211
+                }
212
+                else{
213
+                    $logger->info('Cannot find library [' . $class . '] from modules using the default location');
214
+                }
215
+            }
216
+            if(! $libraryFilePath){
217
+                $searchDir = array(LIBRARY_PATH);
218
+                foreach($searchDir as $dir){
219
+                    $filePath = $dir . $file;
220
+                    if(file_exists($filePath)){
221
+                        $libraryFilePath = $filePath;
222
+                        //is already found not to continue
223
+                        break;
224
+                    }
225
+                }
226
+            }
227
+            $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
+            if($libraryFilePath){
229
+                require_once $libraryFilePath;
230
+                if(class_exists($class)){
231
+                    $c = $params ? new $class($params) : new $class();
232
+                    $obj = & get_instance();
233
+                    $obj->{$instance} = $c;
234
+                    static::$loaded[$instance] = $class;
235
+                    $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236
+                }
237
+                else{
238
+                    show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
239
+                }
240
+            }
241
+            else{
242
+                show_error('Unable to find library class [' . $class . ']');
243
+            }
244
+        }
245 245
 
246
-		/**
247
-		 * Load the helper
248
-		 *
249
-		 * @param  string $function the helper name to be loaded
250
-		 *
251
-		 * @return void
252
-		 */
253
-		public static function functions($function){
254
-			$logger = static::getLogger();
255
-			$function = str_ireplace('.php', '', $function);
256
-			$function = trim($function, '/\\');
257
-			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
259
-			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
261
-				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262
-				return;
263
-			}
264
-			$functionFilePath = null;
265
-			//first check if this helper is in the module
266
-			$logger->debug('Checking helper [' . $function . '] from module list ...');
267
-			$searchModuleName = null;
268
-			$obj = & get_instance();
269
-			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
271
-				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
273
-					$searchModuleName = $path[0];
274
-					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
276
-				}
277
-			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
279
-				$searchModuleName = $obj->moduleName;
280
-			}
281
-			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
284
-				$functionFilePath = $moduleFunctionPath;
285
-			}
286
-			else{
287
-				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288
-			}
289
-			if(! $functionFilePath){
290
-				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
292
-					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
294
-						$functionFilePath = $filePath;
295
-						//is already found not to continue
296
-						break;
297
-					}
298
-				}
299
-			}
300
-			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
302
-				require_once $functionFilePath;
303
-				static::$loaded['function_' . $function] = $functionFilePath;
304
-				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305
-			}
306
-			else{
307
-				show_error('Unable to find helper file [' . $file . ']');
308
-			}
309
-		}
246
+        /**
247
+         * Load the helper
248
+         *
249
+         * @param  string $function the helper name to be loaded
250
+         *
251
+         * @return void
252
+         */
253
+        public static function functions($function){
254
+            $logger = static::getLogger();
255
+            $function = str_ireplace('.php', '', $function);
256
+            $function = trim($function, '/\\');
257
+            $function = str_ireplace('function_', '', $function);
258
+            $file = 'function_'.$function.'.php';
259
+            $logger->debug('Loading helper [' . $function . '] ...');
260
+            if(isset(static::$loaded['function_' . $function])){
261
+                $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262
+                return;
263
+            }
264
+            $functionFilePath = null;
265
+            //first check if this helper is in the module
266
+            $logger->debug('Checking helper [' . $function . '] from module list ...');
267
+            $searchModuleName = null;
268
+            $obj = & get_instance();
269
+            //check if the request class contains module name
270
+            if(strpos($function, '/') !== false){
271
+                $path = explode('/', $function);
272
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
273
+                    $searchModuleName = $path[0];
274
+                    $function = 'function_' . $path[1] . '.php';
275
+                    $file = $path[0] . DS . 'function_'.$function.'.php';
276
+                }
277
+            }
278
+            if(! $searchModuleName && !empty($obj->moduleName)){
279
+                $searchModuleName = $obj->moduleName;
280
+            }
281
+            $moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
+            if($moduleFunctionPath){
283
+                $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
284
+                $functionFilePath = $moduleFunctionPath;
285
+            }
286
+            else{
287
+                $logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288
+            }
289
+            if(! $functionFilePath){
290
+                $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
+                foreach($searchDir as $dir){
292
+                    $filePath = $dir . $file;
293
+                    if(file_exists($filePath)){
294
+                        $functionFilePath = $filePath;
295
+                        //is already found not to continue
296
+                        break;
297
+                    }
298
+                }
299
+            }
300
+            $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
+            if($functionFilePath){
302
+                require_once $functionFilePath;
303
+                static::$loaded['function_' . $function] = $functionFilePath;
304
+                $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305
+            }
306
+            else{
307
+                show_error('Unable to find helper file [' . $file . ']');
308
+            }
309
+        }
310 310
 
311
-		/**
312
-		 * Load the configuration file
313
-		 *
314
-		 * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
315
-		 *
316
-		 * @return void
317
-		 */
318
-		public static function config($filename){
319
-			$logger = static::getLogger();
320
-			$filename = str_ireplace('.php', '', $filename);
321
-			$filename = trim($filename, '/\\');
322
-			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
324
-			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
326
-				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327
-				return;
328
-			}
329
-			$configFilePath = CONFIG_PATH . $file;
330
-			//first check if this config is in the module
331
-			$logger->debug('Checking config [' . $filename . '] from module list ...');
332
-			$searchModuleName = null;
333
-			$obj = & get_instance();
334
-			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
336
-				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
338
-					$searchModuleName = $path[0];
339
-					$filename = $path[1] . '.php';
340
-				}
341
-			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
343
-				$searchModuleName = $obj->moduleName;
344
-			}
345
-			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
348
-				$configFilePath = $moduleConfigPath;
349
-			}
350
-			else{
351
-				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352
-			}
353
-			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
-			$config = array();
355
-			if(file_exists($configFilePath)){
356
-				require_once $configFilePath;
357
-				if(! empty($config) && is_array($config)){
358
-					Config::setAll($config);
359
-				}
360
-			}
361
-			else{
362
-				show_error('Unable to find config file ['. $configFilePath . ']');
363
-			}
364
-			static::$loaded['config_' . $filename] = $configFilePath;
365
-			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
366
-			$logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
367
-			unset($config);
368
-		}
311
+        /**
312
+         * Load the configuration file
313
+         *
314
+         * @param  string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config
315
+         *
316
+         * @return void
317
+         */
318
+        public static function config($filename){
319
+            $logger = static::getLogger();
320
+            $filename = str_ireplace('.php', '', $filename);
321
+            $filename = trim($filename, '/\\');
322
+            $filename = str_ireplace('config_', '', $filename);
323
+            $file = 'config_'.$filename.'.php';
324
+            $logger->debug('Loading configuration [' . $filename . '] ...');
325
+            if(isset(static::$loaded['config_' . $filename])){
326
+                $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327
+                return;
328
+            }
329
+            $configFilePath = CONFIG_PATH . $file;
330
+            //first check if this config is in the module
331
+            $logger->debug('Checking config [' . $filename . '] from module list ...');
332
+            $searchModuleName = null;
333
+            $obj = & get_instance();
334
+            //check if the request class contains module name
335
+            if(strpos($filename, '/') !== false){
336
+                $path = explode('/', $filename);
337
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
338
+                    $searchModuleName = $path[0];
339
+                    $filename = $path[1] . '.php';
340
+                }
341
+            }
342
+            if(! $searchModuleName && !empty($obj->moduleName)){
343
+                $searchModuleName = $obj->moduleName;
344
+            }
345
+            $moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
+            if($moduleConfigPath){
347
+                $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
348
+                $configFilePath = $moduleConfigPath;
349
+            }
350
+            else{
351
+                $logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352
+            }
353
+            $logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
+            $config = array();
355
+            if(file_exists($configFilePath)){
356
+                require_once $configFilePath;
357
+                if(! empty($config) && is_array($config)){
358
+                    Config::setAll($config);
359
+                }
360
+            }
361
+            else{
362
+                show_error('Unable to find config file ['. $configFilePath . ']');
363
+            }
364
+            static::$loaded['config_' . $filename] = $configFilePath;
365
+            $logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
366
+            $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config));
367
+            unset($config);
368
+        }
369 369
 
370 370
 
371
-		/**
372
-		 * Load the language
373
-		 *
374
-		 * @param  string $language the language name to be loaded
375
-		 *
376
-		 * @return void
377
-		 */
378
-		public static function lang($language){
379
-			$logger = static::getLogger();
380
-			$language = str_ireplace('.php', '', $language);
381
-			$language = trim($language, '/\\');
382
-			$language = str_ireplace('lang_', '', $language);
383
-			$file = 'lang_'.$language.'.php';
384
-			$logger->debug('Loading language [' . $language . '] ...');
385
-			if(isset(static::$loaded['lang_' . $language])){
386
-				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387
-				return;
388
-			}
389
-			//determine the current language
390
-			$appLang = get_config('default_language');
391
-			//if the language exists in the cookie use it
392
-			$cfgKey = get_config('language_cookie_name');
393
-			$objCookie = & class_loader('Cookie');
394
-			$cookieLang = $objCookie->get($cfgKey);
395
-			if($cookieLang){
396
-				$appLang = $cookieLang;
397
-			}
398
-			$languageFilePath = null;
399
-			//first check if this language is in the module
400
-			$logger->debug('Checking language [' . $language . '] from module list ...');
401
-			$searchModuleName = null;
402
-			$obj = & get_instance();
403
-			//check if the request class contains module name
404
-			if(strpos($language, '/') !== false){
405
-				$path = explode('/', $language);
406
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
407
-					$searchModuleName = $path[0];
408
-					$language = 'lang_' . $path[1] . '.php';
409
-					$file = $path[0] . DS .$language;
410
-				}
411
-			}
412
-			if(! $searchModuleName && !empty($obj->moduleName)){
413
-				$searchModuleName = $obj->moduleName;
414
-			}
415
-			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
-			if($moduleLanguagePath){
417
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
418
-				$languageFilePath = $moduleLanguagePath;
419
-			}
420
-			else{
421
-				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
422
-			}
423
-			if(! $languageFilePath){
424
-				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
-				foreach($searchDir as $dir){
426
-					$filePath = $dir . $appLang . DS . $file;
427
-					if(file_exists($filePath)){
428
-						$languageFilePath = $filePath;
429
-						//is already found not to continue
430
-						break;
431
-					}
432
-				}
433
-			}
434
-			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
-			if($languageFilePath){
436
-				$lang = array();
437
-				require_once $languageFilePath;
438
-				if(! empty($lang) && is_array($lang)){
439
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
440
-					//Note: may be here the class 'Lang' not yet loaded
441
-					$langObj =& class_loader('Lang', 'classes');
442
-					$langObj->addLangMessages($lang);
443
-					//free the memory
444
-					unset($lang);
445
-				}
446
-				static::$loaded['lang_' . $language] = $languageFilePath;
447
-				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448
-			}
449
-			else{
450
-				show_error('Unable to find language file [' . $file . ']');
451
-			}
452
-		}
371
+        /**
372
+         * Load the language
373
+         *
374
+         * @param  string $language the language name to be loaded
375
+         *
376
+         * @return void
377
+         */
378
+        public static function lang($language){
379
+            $logger = static::getLogger();
380
+            $language = str_ireplace('.php', '', $language);
381
+            $language = trim($language, '/\\');
382
+            $language = str_ireplace('lang_', '', $language);
383
+            $file = 'lang_'.$language.'.php';
384
+            $logger->debug('Loading language [' . $language . '] ...');
385
+            if(isset(static::$loaded['lang_' . $language])){
386
+                $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387
+                return;
388
+            }
389
+            //determine the current language
390
+            $appLang = get_config('default_language');
391
+            //if the language exists in the cookie use it
392
+            $cfgKey = get_config('language_cookie_name');
393
+            $objCookie = & class_loader('Cookie');
394
+            $cookieLang = $objCookie->get($cfgKey);
395
+            if($cookieLang){
396
+                $appLang = $cookieLang;
397
+            }
398
+            $languageFilePath = null;
399
+            //first check if this language is in the module
400
+            $logger->debug('Checking language [' . $language . '] from module list ...');
401
+            $searchModuleName = null;
402
+            $obj = & get_instance();
403
+            //check if the request class contains module name
404
+            if(strpos($language, '/') !== false){
405
+                $path = explode('/', $language);
406
+                if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
407
+                    $searchModuleName = $path[0];
408
+                    $language = 'lang_' . $path[1] . '.php';
409
+                    $file = $path[0] . DS .$language;
410
+                }
411
+            }
412
+            if(! $searchModuleName && !empty($obj->moduleName)){
413
+                $searchModuleName = $obj->moduleName;
414
+            }
415
+            $moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
+            if($moduleLanguagePath){
417
+                $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
418
+                $languageFilePath = $moduleLanguagePath;
419
+            }
420
+            else{
421
+                $logger->info('Cannot find language [' . $language . '] from modules using the default location');
422
+            }
423
+            if(! $languageFilePath){
424
+                $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
+                foreach($searchDir as $dir){
426
+                    $filePath = $dir . $appLang . DS . $file;
427
+                    if(file_exists($filePath)){
428
+                        $languageFilePath = $filePath;
429
+                        //is already found not to continue
430
+                        break;
431
+                    }
432
+                }
433
+            }
434
+            $logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
+            if($languageFilePath){
436
+                $lang = array();
437
+                require_once $languageFilePath;
438
+                if(! empty($lang) && is_array($lang)){
439
+                    $logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
440
+                    //Note: may be here the class 'Lang' not yet loaded
441
+                    $langObj =& class_loader('Lang', 'classes');
442
+                    $langObj->addLangMessages($lang);
443
+                    //free the memory
444
+                    unset($lang);
445
+                }
446
+                static::$loaded['lang_' . $language] = $languageFilePath;
447
+                $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448
+            }
449
+            else{
450
+                show_error('Unable to find language file [' . $file . ']');
451
+            }
452
+        }
453 453
 
454 454
 
455
-		private function getResourcesFromAutoloadConfig(){
456
-			$autoloads = array();
457
-			$autoloads['config']    = array();
458
-			$autoloads['languages'] = array();
459
-			$autoloads['libraries'] = array();
460
-			$autoloads['models']    = array();
461
-			$autoloads['functions'] = array();
462
-			//loading of the resources in autoload.php configuration file
463
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
464
-				$autoload = array();
465
-				require_once CONFIG_PATH . 'autoload.php';
466
-				if(! empty($autoload) && is_array($autoload)){
467
-					$autoloads = array_merge($autoloads, $autoload);
468
-					unset($autoload);
469
-				}
470
-			}
471
-			//loading autoload configuration for modules
472
-			$modulesAutoloads = Module::getModulesAutoloadConfig();
473
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
474
-				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475
-			}
476
-			return $autoloads;
477
-		}
455
+        private function getResourcesFromAutoloadConfig(){
456
+            $autoloads = array();
457
+            $autoloads['config']    = array();
458
+            $autoloads['languages'] = array();
459
+            $autoloads['libraries'] = array();
460
+            $autoloads['models']    = array();
461
+            $autoloads['functions'] = array();
462
+            //loading of the resources in autoload.php configuration file
463
+            if(file_exists(CONFIG_PATH . 'autoload.php')){
464
+                $autoload = array();
465
+                require_once CONFIG_PATH . 'autoload.php';
466
+                if(! empty($autoload) && is_array($autoload)){
467
+                    $autoloads = array_merge($autoloads, $autoload);
468
+                    unset($autoload);
469
+                }
470
+            }
471
+            //loading autoload configuration for modules
472
+            $modulesAutoloads = Module::getModulesAutoloadConfig();
473
+            if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
474
+                $autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475
+            }
476
+            return $autoloads;
477
+        }
478 478
 
479
-		/**
480
-		 * Load the autoload configuration
481
-		 * @return void
482
-		 */
483
-		private function loadResourcesFromAutoloadConfig(){
484
-			$autoloads = array();
485
-			$autoloads['config']    = array();
486
-			$autoloads['languages'] = array();
487
-			$autoloads['libraries'] = array();
488
-			$autoloads['models']    = array();
489
-			$autoloads['functions'] = array();
479
+        /**
480
+         * Load the autoload configuration
481
+         * @return void
482
+         */
483
+        private function loadResourcesFromAutoloadConfig(){
484
+            $autoloads = array();
485
+            $autoloads['config']    = array();
486
+            $autoloads['languages'] = array();
487
+            $autoloads['libraries'] = array();
488
+            $autoloads['models']    = array();
489
+            $autoloads['functions'] = array();
490 490
 
491
-			$list = $this->getResourcesFromAutoloadConfig();
492
-			$autoloads = array_merge($autoloads, $list);
491
+            $list = $this->getResourcesFromAutoloadConfig();
492
+            $autoloads = array_merge($autoloads, $list);
493 493
 			
494
-			//config autoload
495
-			$this->loadAutoloadResourcesArray('config', $autoloads['config']);
494
+            //config autoload
495
+            $this->loadAutoloadResourcesArray('config', $autoloads['config']);
496 496
 			
497
-			//languages autoload
498
-			$this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
497
+            //languages autoload
498
+            $this->loadAutoloadResourcesArray('lang', $autoloads['languages']);
499 499
 			
500
-			//libraries autoload
501
-			$this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
500
+            //libraries autoload
501
+            $this->loadAutoloadResourcesArray('library', $autoloads['libraries']);
502 502
 
503
-			//models autoload
504
-			$this->loadAutoloadResourcesArray('model', $autoloads['models']);
503
+            //models autoload
504
+            $this->loadAutoloadResourcesArray('model', $autoloads['models']);
505 505
 			
506
-			//functions autoload
507
-			$this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
508
-		}
506
+            //functions autoload
507
+            $this->loadAutoloadResourcesArray('functions', $autoloads['functions']);
508
+        }
509 509
 
510
-		/**
511
-		 * Load the resources autoload array
512
-		 * @param  string $method    this object method name to call
513
-		 * @param  array  $resources the resource to load
514
-		 * @return void            
515
-		 */
516
-		private function loadAutoloadResourcesArray($method, array $resources){
517
-			foreach ($resources as $name) {
518
-				$this->{$method}($name);
519
-			}
520
-		}
521
-	}
510
+        /**
511
+         * Load the resources autoload array
512
+         * @param  string $method    this object method name to call
513
+         * @param  array  $resources the resource to load
514
+         * @return void            
515
+         */
516
+        private function loadAutoloadResourcesArray($method, array $resources){
517
+            foreach ($resources as $name) {
518
+                $this->{$method}($name);
519
+            }
520
+        }
521
+    }
Please login to merge, or discard this patch.
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		 * Get the logger singleton instance
52 52
 		 * @return Log the logger instance
53 53
 		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
54
+		private static function getLogger() {
55
+			if (self::$logger == null) {
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Loader');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -67,25 +67,25 @@  discard block
 block discarded – undo
67 67
 		 *
68 68
 		 * @return void
69 69
 		 */
70
-		public static function model($class, $instance = null){
70
+		public static function model($class, $instance = null) {
71 71
 			$logger = static::getLogger();
72 72
 			$class = str_ireplace('.php', '', $class);
73 73
 			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
74
+			$file = ucfirst($class) . '.php';
75 75
 			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
76
+			if (!$instance) {
77 77
 				//for module
78
-				if(strpos($class, '/') !== false){
78
+				if (strpos($class, '/') !== false) {
79 79
 					$path = explode('/', $class);
80
-					if(isset($path[1])){
80
+					if (isset($path[1])) {
81 81
 						$instance = strtolower($path[1]);
82 82
 					}
83 83
 				}
84
-				else{
84
+				else {
85 85
 					$instance = strtolower($class);
86 86
 				}
87 87
 			}
88
-			if(isset(static::$loaded[$instance])){
88
+			if (isset(static::$loaded[$instance])) {
89 89
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90 90
 				return;
91 91
 			}
@@ -95,43 +95,43 @@  discard block
 block discarded – undo
95 95
 			$searchModuleName = null;
96 96
 			$obj = & get_instance();
97 97
 			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
98
+			if (strpos($class, '/') !== false) {
99 99
 				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
100
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
101 101
 					$searchModuleName = $path[0];
102 102
 					$class = ucfirst($path[1]);
103 103
 				}
104 104
 			}
105
-			else{
105
+			else {
106 106
 				$class = ucfirst($class);
107 107
 			}
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
109
+			if (!$searchModuleName && !empty($obj->moduleName)) {
110 110
 				$searchModuleName = $obj->moduleName;
111 111
 			}
112 112
 			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
113
+			if ($moduleModelFilePath) {
114
+				$logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it');
115 115
 				$classFilePath = $moduleModelFilePath;
116 116
 			}
117
-			else{
117
+			else {
118 118
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119 119
 			}
120 120
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
121
+			if (file_exists($classFilePath)) {
122 122
 				require_once $classFilePath;
123
-				if(class_exists($class)){
123
+				if (class_exists($class)) {
124 124
 					$c = new $class();
125 125
 					$obj = & get_instance();
126 126
 					$obj->{$instance} = $c;
127 127
 					static::$loaded[$instance] = $class;
128 128
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129 129
 				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
130
+				else {
131
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
132 132
 				}
133 133
 			}
134
-			else{
134
+			else {
135 135
 				show_error('Unable to find the model [' . $class . ']');
136 136
 			}
137 137
 		}
@@ -146,31 +146,31 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return void
148 148
 		 */
149
-		public static function library($class, $instance = null, array $params = array()){
149
+		public static function library($class, $instance = null, array $params = array()) {
150 150
 			$logger = static::getLogger();
151 151
 			$class = str_ireplace('.php', '', $class);
152 152
 			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
153
+			$file = ucfirst($class) . '.php';
154 154
 			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
155
+			if (!$instance) {
156 156
 				//for module
157
-				if(strpos($class, '/') !== false){
157
+				if (strpos($class, '/') !== false) {
158 158
 					$path = explode('/', $class);
159
-					if(isset($path[1])){
159
+					if (isset($path[1])) {
160 160
 						$instance = strtolower($path[1]);
161 161
 					}
162 162
 				}
163
-				else{
163
+				else {
164 164
 					$instance = strtolower($class);
165 165
 				}
166 166
 			}
167
-			if(isset(static::$loaded[$instance])){
167
+			if (isset(static::$loaded[$instance])) {
168 168
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169 169
 				return;
170 170
 			}
171 171
 			$obj = & get_instance();
172 172
 			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
173
+			if (strtolower($class) == 'database') {
174 174
 				$logger->info('This is the Database library ...');
175 175
 				$dbInstance = & class_loader('Database', 'classes/database', $params);
176 176
 				$obj->{$instance} = $dbInstance;
@@ -180,44 +180,44 @@  discard block
 block discarded – undo
180 180
 			}
181 181
 			$libraryFilePath = null;
182 182
 			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
183
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
184 184
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185 185
 				$class = ucfirst($class);
186 186
 				$logger->info('This library is a system library');
187 187
 			}
188
-			else{
188
+			else {
189 189
 				$logger->info('This library is not a system library');	
190 190
 				//first check if this library is in the module
191 191
 				$logger->debug('Checking library [' . $class . '] from module list ...');
192 192
 				$searchModuleName = null;
193 193
 				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
194
+				if (strpos($class, '/') !== false) {
195 195
 					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
196
+					if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
197 197
 						$searchModuleName = $path[0];
198 198
 						$class = ucfirst($path[1]);
199 199
 					}
200 200
 				}
201
-				else{
201
+				else {
202 202
 					$class = ucfirst($class);
203 203
 				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
204
+				if (!$searchModuleName && !empty($obj->moduleName)) {
205 205
 					$searchModuleName = $obj->moduleName;
206 206
 				}
207 207
 				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
208
+				if ($moduleLibraryPath) {
209
+					$logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it');
210 210
 					$libraryFilePath = $moduleLibraryPath;
211 211
 				}
212
-				else{
212
+				else {
213 213
 					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214 214
 				}
215 215
 			}
216
-			if(! $libraryFilePath){
216
+			if (!$libraryFilePath) {
217 217
 				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
218
+				foreach ($searchDir as $dir) {
219 219
 					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
220
+					if (file_exists($filePath)) {
221 221
 						$libraryFilePath = $filePath;
222 222
 						//is already found not to continue
223 223
 						break;
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
 				}
226 226
 			}
227 227
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
228
+			if ($libraryFilePath) {
229 229
 				require_once $libraryFilePath;
230
-				if(class_exists($class)){
230
+				if (class_exists($class)) {
231 231
 					$c = $params ? new $class($params) : new $class();
232 232
 					$obj = & get_instance();
233 233
 					$obj->{$instance} = $c;
234 234
 					static::$loaded[$instance] = $class;
235 235
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236 236
 				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
237
+				else {
238
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
239 239
 				}
240 240
 			}
241
-			else{
241
+			else {
242 242
 				show_error('Unable to find library class [' . $class . ']');
243 243
 			}
244 244
 		}
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 		 *
251 251
 		 * @return void
252 252
 		 */
253
-		public static function functions($function){
253
+		public static function functions($function) {
254 254
 			$logger = static::getLogger();
255 255
 			$function = str_ireplace('.php', '', $function);
256 256
 			$function = trim($function, '/\\');
257 257
 			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
258
+			$file = 'function_' . $function . '.php';
259 259
 			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
260
+			if (isset(static::$loaded['function_' . $function])) {
261 261
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262 262
 				return;
263 263
 			}
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
 			$searchModuleName = null;
268 268
 			$obj = & get_instance();
269 269
 			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
270
+			if (strpos($function, '/') !== false) {
271 271
 				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
272
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
273 273
 					$searchModuleName = $path[0];
274 274
 					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
275
+					$file = $path[0] . DS . 'function_' . $function . '.php';
276 276
 				}
277 277
 			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
278
+			if (!$searchModuleName && !empty($obj->moduleName)) {
279 279
 				$searchModuleName = $obj->moduleName;
280 280
 			}
281 281
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
282
+			if ($moduleFunctionPath) {
283
+				$logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it');
284 284
 				$functionFilePath = $moduleFunctionPath;
285 285
 			}
286
-			else{
286
+			else {
287 287
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288 288
 			}
289
-			if(! $functionFilePath){
289
+			if (!$functionFilePath) {
290 290
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
291
+				foreach ($searchDir as $dir) {
292 292
 					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
293
+					if (file_exists($filePath)) {
294 294
 						$functionFilePath = $filePath;
295 295
 						//is already found not to continue
296 296
 						break;
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 				}
299 299
 			}
300 300
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
301
+			if ($functionFilePath) {
302 302
 				require_once $functionFilePath;
303 303
 				static::$loaded['function_' . $function] = $functionFilePath;
304 304
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305 305
 			}
306
-			else{
306
+			else {
307 307
 				show_error('Unable to find helper file [' . $file . ']');
308 308
 			}
309 309
 		}
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 		 *
316 316
 		 * @return void
317 317
 		 */
318
-		public static function config($filename){
318
+		public static function config($filename) {
319 319
 			$logger = static::getLogger();
320 320
 			$filename = str_ireplace('.php', '', $filename);
321 321
 			$filename = trim($filename, '/\\');
322 322
 			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
323
+			$file = 'config_' . $filename . '.php';
324 324
 			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
325
+			if (isset(static::$loaded['config_' . $filename])) {
326 326
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327 327
 				return;
328 328
 			}
@@ -332,34 +332,34 @@  discard block
 block discarded – undo
332 332
 			$searchModuleName = null;
333 333
 			$obj = & get_instance();
334 334
 			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
335
+			if (strpos($filename, '/') !== false) {
336 336
 				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
337
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
338 338
 					$searchModuleName = $path[0];
339 339
 					$filename = $path[1] . '.php';
340 340
 				}
341 341
 			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
342
+			if (!$searchModuleName && !empty($obj->moduleName)) {
343 343
 				$searchModuleName = $obj->moduleName;
344 344
 			}
345 345
 			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
346
+			if ($moduleConfigPath) {
347
+				$logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it');
348 348
 				$configFilePath = $moduleConfigPath;
349 349
 			}
350
-			else{
350
+			else {
351 351
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352 352
 			}
353 353
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354 354
 			$config = array();
355
-			if(file_exists($configFilePath)){
355
+			if (file_exists($configFilePath)) {
356 356
 				require_once $configFilePath;
357
-				if(! empty($config) && is_array($config)){
357
+				if (!empty($config) && is_array($config)) {
358 358
 					Config::setAll($config);
359 359
 				}
360 360
 			}
361
-			else{
362
-				show_error('Unable to find config file ['. $configFilePath . ']');
361
+			else {
362
+				show_error('Unable to find config file [' . $configFilePath . ']');
363 363
 			}
364 364
 			static::$loaded['config_' . $filename] = $configFilePath;
365 365
 			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
 		 *
376 376
 		 * @return void
377 377
 		 */
378
-		public static function lang($language){
378
+		public static function lang($language) {
379 379
 			$logger = static::getLogger();
380 380
 			$language = str_ireplace('.php', '', $language);
381 381
 			$language = trim($language, '/\\');
382 382
 			$language = str_ireplace('lang_', '', $language);
383
-			$file = 'lang_'.$language.'.php';
383
+			$file = 'lang_' . $language . '.php';
384 384
 			$logger->debug('Loading language [' . $language . '] ...');
385
-			if(isset(static::$loaded['lang_' . $language])){
385
+			if (isset(static::$loaded['lang_' . $language])) {
386 386
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
387 387
 				return;
388 388
 			}
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 			$cfgKey = get_config('language_cookie_name');
393 393
 			$objCookie = & class_loader('Cookie');
394 394
 			$cookieLang = $objCookie->get($cfgKey);
395
-			if($cookieLang){
395
+			if ($cookieLang) {
396 396
 				$appLang = $cookieLang;
397 397
 			}
398 398
 			$languageFilePath = null;
@@ -401,30 +401,30 @@  discard block
 block discarded – undo
401 401
 			$searchModuleName = null;
402 402
 			$obj = & get_instance();
403 403
 			//check if the request class contains module name
404
-			if(strpos($language, '/') !== false){
404
+			if (strpos($language, '/') !== false) {
405 405
 				$path = explode('/', $language);
406
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
406
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
407 407
 					$searchModuleName = $path[0];
408 408
 					$language = 'lang_' . $path[1] . '.php';
409
-					$file = $path[0] . DS .$language;
409
+					$file = $path[0] . DS . $language;
410 410
 				}
411 411
 			}
412
-			if(! $searchModuleName && !empty($obj->moduleName)){
412
+			if (!$searchModuleName && !empty($obj->moduleName)) {
413 413
 				$searchModuleName = $obj->moduleName;
414 414
 			}
415 415
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
416
-			if($moduleLanguagePath){
417
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
416
+			if ($moduleLanguagePath) {
417
+				$logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it');
418 418
 				$languageFilePath = $moduleLanguagePath;
419 419
 			}
420
-			else{
420
+			else {
421 421
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
422 422
 			}
423
-			if(! $languageFilePath){
423
+			if (!$languageFilePath) {
424 424
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
425
-				foreach($searchDir as $dir){
425
+				foreach ($searchDir as $dir) {
426 426
 					$filePath = $dir . $appLang . DS . $file;
427
-					if(file_exists($filePath)){
427
+					if (file_exists($filePath)) {
428 428
 						$languageFilePath = $filePath;
429 429
 						//is already found not to continue
430 430
 						break;
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
 				}
433 433
 			}
434 434
 			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
435
-			if($languageFilePath){
435
+			if ($languageFilePath) {
436 436
 				$lang = array();
437 437
 				require_once $languageFilePath;
438
-				if(! empty($lang) && is_array($lang)){
439
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
438
+				if (!empty($lang) && is_array($lang)) {
439
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
440 440
 					//Note: may be here the class 'Lang' not yet loaded
441
-					$langObj =& class_loader('Lang', 'classes');
441
+					$langObj = & class_loader('Lang', 'classes');
442 442
 					$langObj->addLangMessages($lang);
443 443
 					//free the memory
444 444
 					unset($lang);
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
 				static::$loaded['lang_' . $language] = $languageFilePath;
447 447
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
448 448
 			}
449
-			else{
449
+			else {
450 450
 				show_error('Unable to find language file [' . $file . ']');
451 451
 			}
452 452
 		}
453 453
 
454 454
 
455
-		private function getResourcesFromAutoloadConfig(){
455
+		private function getResourcesFromAutoloadConfig() {
456 456
 			$autoloads = array();
457 457
 			$autoloads['config']    = array();
458 458
 			$autoloads['languages'] = array();
@@ -460,17 +460,17 @@  discard block
 block discarded – undo
460 460
 			$autoloads['models']    = array();
461 461
 			$autoloads['functions'] = array();
462 462
 			//loading of the resources in autoload.php configuration file
463
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
463
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
464 464
 				$autoload = array();
465 465
 				require_once CONFIG_PATH . 'autoload.php';
466
-				if(! empty($autoload) && is_array($autoload)){
466
+				if (!empty($autoload) && is_array($autoload)) {
467 467
 					$autoloads = array_merge($autoloads, $autoload);
468 468
 					unset($autoload);
469 469
 				}
470 470
 			}
471 471
 			//loading autoload configuration for modules
472 472
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
473
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
473
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
474 474
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
475 475
 			}
476 476
 			return $autoloads;
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		 * Load the autoload configuration
481 481
 		 * @return void
482 482
 		 */
483
-		private function loadResourcesFromAutoloadConfig(){
483
+		private function loadResourcesFromAutoloadConfig() {
484 484
 			$autoloads = array();
485 485
 			$autoloads['config']    = array();
486 486
 			$autoloads['languages'] = array();
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 		 * @param  array  $resources the resource to load
514 514
 		 * @return void            
515 515
 		 */
516
-		private function loadAutoloadResourcesArray($method, array $resources){
516
+		private function loadAutoloadResourcesArray($method, array $resources) {
517 517
 			foreach ($resources as $name) {
518 518
 				$this->{$method}($name);
519 519
 			}
Please login to merge, or discard this patch.
core/libraries/Assets.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,168 +1,168 @@
 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 Assets.php
29
-	 *    
30
-	 *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
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
-	 *  @since 1.0.0
39
-	 *  @filesource
40
-	 */
41
-	class Assets{
27
+    /**
28
+     *  @file Assets.php
29
+     *    
30
+     *  This class contains static methods for generating static content links (images, Javascript, CSS, etc.).
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
+     *  @since 1.0.0
39
+     *  @filesource
40
+     */
41
+    class Assets{
42 42
 		
43
-		/**
44
-		 * The logger instance
45
-		 * @var Log
46
-		 */
47
-		private static $logger;
43
+        /**
44
+         * The logger instance
45
+         * @var Log
46
+         */
47
+        private static $logger;
48 48
 
49
-		/**
50
-		 * The signleton of the logger
51
-		 * @return Object the Log instance
52
-		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
55
-				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
57
-				self::$logger[0]->setLogger('Library::Assets');
58
-			}
59
-			return self::$logger[0];
60
-		}
49
+        /**
50
+         * The signleton of the logger
51
+         * @return Object the Log instance
52
+         */
53
+        private static function getLogger(){
54
+            if(self::$logger == null){
55
+                //can't assign reference to static variable
56
+                self::$logger[0] =& class_loader('Log', 'classes');
57
+                self::$logger[0]->setLogger('Library::Assets');
58
+            }
59
+            return self::$logger[0];
60
+        }
61 61
 
62 62
 
63
-		/**
64
-		 *  Generate the link of the assets file.
65
-		 *  
66
-		 *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
-		 *  For example :
68
-		 *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
-		 *  Note:
70
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
-		 *  
72
-		 *  @param string $asset the name of the assets file path with the extension.
73
-		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
-		 */
75
-		public static function path($asset){
76
-			$logger = self::getLogger();	
77
-			$path = ASSETS_PATH . $asset;
63
+        /**
64
+         *  Generate the link of the assets file.
65
+         *  
66
+         *  Generates the absolute link of a file inside ASSETS_PATH folder.
67
+         *  For example :
68
+         *  	echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css
69
+         *  Note:
70
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
71
+         *  
72
+         *  @param string $asset the name of the assets file path with the extension.
73
+         *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74
+         */
75
+        public static function path($asset){
76
+            $logger = self::getLogger();	
77
+            $path = ASSETS_PATH . $asset;
78 78
 			
79
-			$logger->debug('Including the Assets file [' . $path . ']');
80
-			//Check if the file exists
81
-			if(file_exists($path)){
82
-				$logger->info('Assets file [' . $path . '] included successfully');
83
-				return Url::base_url($path);
84
-			}
85
-			$logger->warning('Assets file [' . $path . '] does not exist');
86
-			return null;
87
-		}
79
+            $logger->debug('Including the Assets file [' . $path . ']');
80
+            //Check if the file exists
81
+            if(file_exists($path)){
82
+                $logger->info('Assets file [' . $path . '] included successfully');
83
+                return Url::base_url($path);
84
+            }
85
+            $logger->warning('Assets file [' . $path . '] does not exist');
86
+            return null;
87
+        }
88 88
 		
89
-		/**
90
-		 *  Generate the link of the css file.
91
-		 *  
92
-		 *  Generates the absolute link of a file containing the CSS style.
93
-		 *  For example :
94
-		 *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
-		 *  Note:
96
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
-		 *  
98
-		 *  @param $path the name of the css file without the extension.
99
-		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
-		 */
101
-		public static function css($path){
102
-			$logger = self::getLogger();
103
-			/*
89
+        /**
90
+         *  Generate the link of the css file.
91
+         *  
92
+         *  Generates the absolute link of a file containing the CSS style.
93
+         *  For example :
94
+         *  	echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css
95
+         *  Note:
96
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
97
+         *  
98
+         *  @param $path the name of the css file without the extension.
99
+         *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100
+         */
101
+        public static function css($path){
102
+            $logger = self::getLogger();
103
+            /*
104 104
 			* if the file name contains the ".css" extension, replace it with 
105 105
 			* an empty string for better processing.
106 106
 			*/
107
-			$path = str_ireplace('.css', '', $path);
108
-			$path = ASSETS_PATH . 'css/' . $path . '.css';
107
+            $path = str_ireplace('.css', '', $path);
108
+            $path = ASSETS_PATH . 'css/' . $path . '.css';
109 109
 			
110
-			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111
-			//Check if the file exists
112
-			if(file_exists($path)){
113
-				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114
-				return Url::base_url($path);
115
-			}
116
-			$logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
-			return null;
118
-		}
110
+            $logger->debug('Including the Assets file [' . $path . '] for CSS');
111
+            //Check if the file exists
112
+            if(file_exists($path)){
113
+                $logger->info('Assets file [' . $path . '] for CSS included successfully');
114
+                return Url::base_url($path);
115
+            }
116
+            $logger->warning('Assets file [' . $path . '] for CSS does not exist');
117
+            return null;
118
+        }
119 119
 
120
-		/**
121
-		 *  Generate the link of the javascript file.
122
-		 *  
123
-		 *  Generates the absolute link of a file containing the javascript.
124
-		 *  For example :
125
-		 *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
-		 *  Note:
127
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
-		 *  
129
-		 *  @param $path the name of the javascript file without the extension.
130
-		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
-		 */
132
-		public static function js($path){
133
-			$logger = self::getLogger();
134
-			$path = str_ireplace('.js', '', $path);
135
-			$path = ASSETS_PATH . 'js/' . $path . '.js';
136
-			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
138
-				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
-				return Url::base_url($path);
140
-			}
141
-			$logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
-			return null;
143
-		}
120
+        /**
121
+         *  Generate the link of the javascript file.
122
+         *  
123
+         *  Generates the absolute link of a file containing the javascript.
124
+         *  For example :
125
+         *  	echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js
126
+         *  Note:
127
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
128
+         *  
129
+         *  @param $path the name of the javascript file without the extension.
130
+         *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131
+         */
132
+        public static function js($path){
133
+            $logger = self::getLogger();
134
+            $path = str_ireplace('.js', '', $path);
135
+            $path = ASSETS_PATH . 'js/' . $path . '.js';
136
+            $logger->debug('Including the Assets file [' . $path . '] for javascript');
137
+            if(file_exists($path)){
138
+                $logger->info('Assets file [' . $path . '] for Javascript included successfully');
139
+                return Url::base_url($path);
140
+            }
141
+            $logger->warning('Assets file [' . $path . '] for Javascript does not exist');
142
+            return null;
143
+        }
144 144
 
145
-		/**
146
-		 *  Generate the link of the image file.
147
-		 *  
148
-		 *  Generates the absolute link of a file containing the image.
149
-		 *  For example :
150
-		 *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
-		 *  Note:
152
-		 *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
-		 *  
154
-		 *  @param $path the name of the image file with the extension.
155
-		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
-		 */
157
-		public static function img($path){
158
-			$logger = self::getLogger();
159
-			$path = ASSETS_PATH . 'images/' . $path;
160
-			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
162
-				$logger->info('Assets file [' . $path . '] for image included successfully');
163
-				return Url::base_url($path);
164
-			}
165
-			$logger->warning('Assets file [' . $path . '] for image does not exist');
166
-			return null;
167
-		}
168
-	}
145
+        /**
146
+         *  Generate the link of the image file.
147
+         *  
148
+         *  Generates the absolute link of a file containing the image.
149
+         *  For example :
150
+         *  	echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png
151
+         *  Note:
152
+         *  The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH.
153
+         *  
154
+         *  @param $path the name of the image file with the extension.
155
+         *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156
+         */
157
+        public static function img($path){
158
+            $logger = self::getLogger();
159
+            $path = ASSETS_PATH . 'images/' . $path;
160
+            $logger->debug('Including the Assets file [' . $path . '] for image');
161
+            if(file_exists($path)){
162
+                $logger->info('Assets file [' . $path . '] for image included successfully');
163
+                return Url::base_url($path);
164
+            }
165
+            $logger->warning('Assets file [' . $path . '] for image does not exist');
166
+            return null;
167
+        }
168
+    }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *  @since 1.0.0
39 39
 	 *  @filesource
40 40
 	 */
41
-	class Assets{
41
+	class Assets {
42 42
 		
43 43
 		/**
44 44
 		 * The logger instance
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 		 * The signleton of the logger
51 51
 		 * @return Object the Log instance
52 52
 		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
53
+		private static function getLogger() {
54
+			if (self::$logger == null) {
55 55
 				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Assets');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 		 *  @param string $asset the name of the assets file path with the extension.
73 73
 		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74 74
 		 */
75
-		public static function path($asset){
75
+		public static function path($asset) {
76 76
 			$logger = self::getLogger();	
77 77
 			$path = ASSETS_PATH . $asset;
78 78
 			
79 79
 			$logger->debug('Including the Assets file [' . $path . ']');
80 80
 			//Check if the file exists
81
-			if(file_exists($path)){
81
+			if (file_exists($path)) {
82 82
 				$logger->info('Assets file [' . $path . '] included successfully');
83 83
 				return Url::base_url($path);
84 84
 			}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 *  @param $path the name of the css file without the extension.
99 99
 		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100 100
 		 */
101
-		public static function css($path){
101
+		public static function css($path) {
102 102
 			$logger = self::getLogger();
103 103
 			/*
104 104
 			* if the file name contains the ".css" extension, replace it with 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			
110 110
 			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111 111
 			//Check if the file exists
112
-			if(file_exists($path)){
112
+			if (file_exists($path)) {
113 113
 				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114 114
 				return Url::base_url($path);
115 115
 			}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		 *  @param $path the name of the javascript file without the extension.
130 130
 		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131 131
 		 */
132
-		public static function js($path){
132
+		public static function js($path) {
133 133
 			$logger = self::getLogger();
134 134
 			$path = str_ireplace('.js', '', $path);
135 135
 			$path = ASSETS_PATH . 'js/' . $path . '.js';
136 136
 			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
137
+			if (file_exists($path)) {
138 138
 				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139 139
 				return Url::base_url($path);
140 140
 			}
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		 *  @param $path the name of the image file with the extension.
155 155
 		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156 156
 		 */
157
-		public static function img($path){
157
+		public static function img($path) {
158 158
 			$logger = self::getLogger();
159 159
 			$path = ASSETS_PATH . 'images/' . $path;
160 160
 			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
161
+			if (file_exists($path)) {
162 162
 				$logger->info('Assets file [' . $path . '] for image included successfully');
163 163
 				return Url::base_url($path);
164 164
 			}
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
 
27 27
 
28
-     class FormValidation{
28
+        class FormValidation{
29 29
 		 
30 30
         /**
31 31
          * The form validation status
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
          */
61 61
         protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
62 62
         
63
-		/**
63
+        /**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 
87 87
         /**
88 88
          * Whether to check the CSRF. This attribute is just a way to allow custom change of the 
89
-		 * CSRF global configuration
90
-		 *
89
+         * CSRF global configuration
90
+         *
91 91
          * @var boolean
92 92
          */
93 93
         public $enableCsrfCheck = false;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
             $this->logger =& class_loader('Log', 'classes');
102 102
             $this->logger->setLogger('Library::FormValidation');
103 103
            
104
-		   //Load form validation language message
104
+            //Load form validation language message
105 105
             Loader::lang('form_validation');
106 106
             $obj = & get_instance();
107 107
             $this->_errorsMessages  = array(
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
             $this->_success              = false;
142 142
             $this->_forceFail            = false;
143 143
             $this->data                  = array();
144
-			$this->enableCsrfCheck       = false;
144
+            $this->enableCsrfCheck       = false;
145 145
         }
146 146
 
147 147
         /**
148 148
          * Set the form validation data
149 149
          * @param array $data the values to be validated
150
-		 *
150
+         *
151 151
          * @return FormValidation Current instance of object.
152 152
          */
153 153
         public function setData(array $data){
154 154
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155 155
             $this->data = $data;
156
-			return $this;
156
+            return $this;
157 157
         }
158 158
 
159 159
         /**
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
             return $this->data;
165 165
         }
166 166
 
167
-		/**
168
-		* Get the validation function name to validate a rule
169
-		*
170
-		* @return string the function name
171
-		*/
167
+        /**
168
+         * Get the validation function name to validate a rule
169
+         *
170
+         * @return string the function name
171
+         */
172 172
         protected function _toCallCase($funcName, $prefix='_validate') {
173 173
             $funcName = strtolower($funcName);
174 174
             $finalFuncName = $prefix;
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
             $this->_forceFail = false;
239 239
 
240 240
             foreach ($this->getData() as $inputName => $inputVal) {
241
-    			if(is_array($this->data[$inputName])){
242
-    				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
243
-    			}
244
-    			else{
245
-    				$this->data[$inputName] = trim($this->data[$inputName]);
246
-    			}
241
+                if(is_array($this->data[$inputName])){
242
+                    $this->data[$inputName] = array_map('trim', $this->data[$inputName]);
243
+                }
244
+                else{
245
+                    $this->data[$inputName] = trim($this->data[$inputName]);
246
+                }
247 247
 
248 248
                 if (array_key_exists($inputName, $this->_rules)) {
249 249
                     foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) {
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
          *
263 263
          * @param string $inputField Name of the field or the data key to add a rule to
264 264
          * @param string $ruleSets PIPE seperated string of rules
265
-		 *
265
+         *
266 266
          * @return FormValidation Current instance of object.
267 267
          */
268 268
         public function setRule($inputField, $inputLabel, $ruleSets) {
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
          * Takes an array of rules and uses setRule() to set them, accepts an array
277 277
          * of rule names rather than a pipe-delimited string as well.
278 278
          * @param array $ruleSets
279
-		 *
280
-		 * @return FormValidation Current instance of object.
279
+         *
280
+         * @return FormValidation Current instance of object.
281 281
          */
282 282
         public function setRules(array $ruleSets) {
283 283
             foreach ($ruleSets as $ruleSet) {
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
          * @param string $start Before block of errors gets displayed, HTML allowed.
300 300
          * @param string $end After the block of errors gets displayed, HTML allowed.
301 301
          *
302
-		 * @return FormValidation Current instance of object.
302
+         * @return FormValidation Current instance of object.
303 303
          */
304 304
         public function setErrorsDelimiter($start, $end) {
305 305
             $this->_allErrorsDelimiter[0] = $start;
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
          * @param string $start Displayed before each error.
315 315
          * @param string $end Displayed after each error.
316 316
          * 
317
-		 * @return FormValidation Current instance of object.
317
+         * @return FormValidation Current instance of object.
318 318
          */
319 319
         public function setErrorDelimiter($start, $end) {
320 320
             $this->_eachErrorDelimiter[0] = $start;
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
             return $this;
323 323
         }
324 324
 
325
-		/**
326
-		* Get the each errors delimiters
327
-		*
328
-		* @return array
329
-		*/
330
-    	public function getErrorDelimiter() {
325
+        /**
326
+         * Get the each errors delimiters
327
+         *
328
+         * @return array
329
+         */
330
+        public function getErrorDelimiter() {
331 331
             return $this->_eachErrorDelimiter;
332 332
         }
333 333
 
334
-		/**
335
-		* Get the all errors delimiters
336
-		*
337
-		* @return array
338
-		*/
339
-    	public function getErrorsDelimiter() {
334
+        /**
335
+         * Get the all errors delimiters
336
+         *
337
+         * @return array
338
+         */
339
+        public function getErrorsDelimiter() {
340 340
             return $this->_allErrorsDelimiter;
341 341
         }
342 342
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
          *
375 375
          * @param string $inputName The form input name or data key
376 376
          * @param string $errorMessage Error to display
377
-		 *
377
+         *
378 378
          * @return formValidation Current instance of the object
379 379
          */
380 380
         public function setCustomError($inputName, $errorMessage) {
@@ -411,17 +411,17 @@  discard block
 block discarded – undo
411 411
          *
412 412
          * @param boolean $limit number of error to display or return
413 413
          * @param boolean $echo Whether or not the values are to be returned or displayed
414
-		 *
414
+         *
415 415
          * @return string Errors formatted for output
416 416
          */
417 417
         public function displayErrors($limit = null, $echo = true) {
418 418
             list($errorsStart, $errorsEnd) = $this->_allErrorsDelimiter;
419 419
             list($errorStart, $errorEnd) = $this->_eachErrorDelimiter;
420 420
             $errorOutput = $errorsStart;
421
-    		$i = 0;
421
+            $i = 0;
422 422
             if (!empty($this->_errors)) {
423 423
                 foreach ($this->_errors as $fieldName => $error) {
424
-        	    	if ($i === $limit) { 
424
+                    if ($i === $limit) { 
425 425
                         break; 
426 426
                     }
427 427
                     $errorOutput .= $errorStart;
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
          * Breaks up a PIPE seperated string of rules, and puts them into an array.
450 450
          *
451 451
          * @param string $ruleString String to be parsed.
452
-		 *
452
+         *
453 453
          * @return array Array of each value in original string.
454 454
          */
455 455
         protected function _parseRuleString($ruleString) {
@@ -462,10 +462,10 @@  discard block
 block discarded – undo
462 462
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
463 463
                 preg_match($rule, $ruleString, $regexRule);
464 464
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
465
-                 if(!empty($regexRule[0])){
466
-                     $ruleSets[] = $regexRule[0];
467
-                 }
468
-                 $ruleStringRegex = explode('|', $ruleStringTemp);
465
+                    if(!empty($regexRule[0])){
466
+                        $ruleSets[] = $regexRule[0];
467
+                    }
468
+                    $ruleStringRegex = explode('|', $ruleStringTemp);
469 469
                 foreach ($ruleStringRegex as $rule) {
470 470
                     $rule = trim($rule);
471 471
                     if($rule){
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
                 } else {
482 482
                     $ruleSets[] = $ruleString;
483 483
                 }
484
-             }
484
+                }
485 485
             return $ruleSets;
486 486
         }
487 487
 
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
          * Returns whether or not a field obtains the rule "required".
490 490
          *
491 491
          * @param string $fieldName Field to check if required.
492
-		 *
492
+         *
493 493
          * @return boolean Whether or not the field is required.
494 494
          */
495 495
         protected function _fieldIsRequired($fieldName) {
@@ -524,13 +524,13 @@  discard block
 block discarded – undo
524 524
             return;
525 525
         }
526 526
 
527
-		/**
528
-		* Set error for the given field or key
529
-		*
530
-		* @param string $inputName the input or key name
531
-		* @param string $ruleName the rule name
532
-		* @param array|string $replacements
533
-		*/
527
+        /**
528
+         * Set error for the given field or key
529
+         *
530
+         * @param string $inputName the input or key name
531
+         * @param string $ruleName the rule name
532
+         * @param array|string $replacements
533
+         */
534 534
         protected function _setError($inputName, $ruleName, $replacements = array()) {
535 535
             $rulePhraseKeyParts = explode(',', $ruleName);
536 536
             $rulePhrase = null;
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
             }
548 548
             // Type cast to array in case it's a string
549 549
             $replacements = (array) $replacements;
550
-			$replacementCount = count($replacements);
550
+            $replacementCount = count($replacements);
551 551
             for ($i = 1; $i <= $replacementCount; $i++) {
552 552
                 $key = $i - 1;
553 553
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
@@ -565,11 +565,11 @@  discard block
 block discarded – undo
565 565
          *
566 566
          * @param type $inputArg
567 567
          * @param string $callbackFunc
568
-		 *
568
+         *
569 569
          * @return mixed
570 570
          */
571 571
         protected function _runCallback($inputArg, $callbackFunc) {
572
-			return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
572
+            return eval('return ' . $callbackFunc . '("' . $inputArg . '");');
573 573
         }
574 574
 
575 575
         /**
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
          * arguments.
579 579
          *
580 580
          * @param string $callbackFunc
581
-		 *
581
+         *
582 582
          * @return mixed
583 583
          */
584 584
         protected function _runEmptyCallback($callbackFunc) {
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
          * Gets a specific label of a specific field input name.
590 590
          *
591 591
          * @param string $inputName
592
-		 *
592
+         *
593 593
          * @return string
594 594
          */
595 595
         protected function _getLabel($inputName) {
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
          * @param  string $ruleName  the rule name for this validation ("required")
603 603
          * @param  array  $ruleArgs  the rules argument
604 604
          */
605
-		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
605
+        protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
606 606
             $inputVal = $this->post($inputName);
607 607
             if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
608 608
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
611 611
                 }
612 612
             } 
613
-			else if($inputVal == '') {
614
-				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
613
+            else if($inputVal == '') {
614
+                $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
615 615
             }
616 616
         }
617 617
 
@@ -635,10 +635,10 @@  discard block
 block discarded – undo
635 635
          */
636 636
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
637 637
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
638
-				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
639
-				if(! $result){
640
-					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
641
-				}
638
+                $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
639
+                if(! $result){
640
+                    $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
641
+                }
642 642
             }
643 643
         }
644 644
 
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
                         continue;
671 671
                     }
672 672
                 } 
673
-				else{
673
+                else{
674 674
                     if ($inputVal == $doNotEqual) {
675 675
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
676 676
                         continue;
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
          * @param  string $ruleName  the rule name for this validation ("less_than")
763 763
          * @param  array  $ruleArgs  the rules argument
764 764
          */
765
-    	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
765
+        protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
766 766
             $inputVal = $this->post($inputName);
767 767
             if ($inputVal >= $ruleArgs[1]) { 
768 768
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
          * @param  string $ruleName  the rule name for this validation ("greater_than")
779 779
          * @param  array  $ruleArgs  the rules argument
780 780
          */
781
-    	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
781
+        protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
782 782
             $inputVal = $this->post($inputName);
783 783
             if ($inputVal <= $ruleArgs[1]) {
784 784
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
          * @param  string $ruleName  the rule name for this validation ("numeric")
795 795
          * @param  array  $ruleArgs  the rules argument
796 796
          */
797
-    	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
797
+        protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
798 798
             $inputVal = $this->post($inputName);
799 799
             if (! is_numeric($inputVal)) {
800 800
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -810,17 +810,17 @@  discard block
 block discarded – undo
810 810
          * @param  string $ruleName  the rule name for this validation ("exists")
811 811
          * @param  array  $ruleArgs  the rules argument
812 812
          */
813
-		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
813
+        protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
814 814
             $inputVal = $this->post($inputName);
815
-    		$obj = & get_instance();
816
-    		if(! isset($obj->database)){
817
-    			return;
818
-    		}
819
-    		list($table, $column) = explode('.', $ruleArgs[1]);
820
-    		$obj->database->from($table)
821
-    			          ->where($column, $inputVal)
822
-    			          ->get();
823
-    		$nb = $obj->database->numRows();
815
+            $obj = & get_instance();
816
+            if(! isset($obj->database)){
817
+                return;
818
+            }
819
+            list($table, $column) = explode('.', $ruleArgs[1]);
820
+            $obj->database->from($table)
821
+                            ->where($column, $inputVal)
822
+                            ->get();
823
+            $nb = $obj->database->numRows();
824 824
             if ($nb == 0) {
825 825
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
826 826
                     return;
@@ -835,17 +835,17 @@  discard block
 block discarded – undo
835 835
          * @param  string $ruleName  the rule name for this validation ("is_unique")
836 836
          * @param  array  $ruleArgs  the rules argument
837 837
          */
838
-    	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
838
+        protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
839 839
             $inputVal = $this->post($inputName);
840
-    		$obj = & get_instance();
841
-    		if(! isset($obj->database)){
842
-    			return;
843
-    		}
844
-    		list($table, $column) = explode('.', $ruleArgs[1]);
845
-    		$obj->database->from($table)
846
-    			          ->where($column, $inputVal)
847
-    			          ->get();
848
-    		$nb = $obj->database->numRows();
840
+            $obj = & get_instance();
841
+            if(! isset($obj->database)){
842
+                return;
843
+            }
844
+            list($table, $column) = explode('.', $ruleArgs[1]);
845
+            $obj->database->from($table)
846
+                            ->where($column, $inputVal)
847
+                            ->get();
848
+            $nb = $obj->database->numRows();
849 849
             if ($nb != 0) {
850 850
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
851 851
                     return;
@@ -860,23 +860,23 @@  discard block
 block discarded – undo
860 860
          * @param  string $ruleName  the rule name for this validation ("is_unique_update")
861 861
          * @param  array  $ruleArgs  the rules argument
862 862
          */
863
-    	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
863
+        protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
864 864
             $inputVal = $this->post($inputName);
865
-    		$obj = & get_instance();
866
-    		if(! isset($obj->database)){
867
-    			return;
868
-    		}
869
-    		$data = explode(',', $ruleArgs[1]);
870
-    		if(count($data) < 2){
871
-    			return;
872
-    		}
873
-    		list($table, $column) = explode('.', $data[0]);
874
-    		list($field, $val) = explode('=', $data[1]);
875
-    		$obj->database->from($table)
876
-    			          ->where($column, $inputVal)
877
-                		  ->where($field, '!=', trim($val))
878
-                		  ->get();
879
-    		$nb = $obj->database->numRows();
865
+            $obj = & get_instance();
866
+            if(! isset($obj->database)){
867
+                return;
868
+            }
869
+            $data = explode(',', $ruleArgs[1]);
870
+            if(count($data) < 2){
871
+                return;
872
+            }
873
+            list($table, $column) = explode('.', $data[0]);
874
+            list($field, $val) = explode('=', $data[1]);
875
+            $obj->database->from($table)
876
+                            ->where($column, $inputVal)
877
+                            ->where($field, '!=', trim($val))
878
+                            ->get();
879
+            $nb = $obj->database->numRows();
880 880
             if ($nb != 0) {
881 881
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
882 882
                     return;
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
          */
894 894
         protected function _validateInList($inputName, $ruleName, array $ruleArgs) {
895 895
             $inputVal = $this->post($inputName);
896
-    		$list = explode(',', $ruleArgs[1]);
896
+            $list = explode(',', $ruleArgs[1]);
897 897
             $list = array_map('trim', $list);
898 898
             if (! in_array($inputVal, $list)) {
899 899
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
          */
912 912
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
913 913
             $inputVal = $this->post($inputName);
914
-    		$regex = $ruleArgs[1];
914
+            $regex = $ruleArgs[1];
915 915
             if (! preg_match($regex, $inputVal)) {
916 916
                 if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
917 917
                     return;
Please login to merge, or discard this patch.