Passed
Push — 1.0.0-dev ( 066288...93958a )
by nguereza
09:45
created
core/classes/Module.php 3 patches
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4 4
      * TNH Framework
5 5
      *
6 6
      * A simple PHP framework using HMVC architecture
@@ -22,283 +22,283 @@  discard block
 block discarded – undo
22 22
      * You should have received a copy of the GNU General Public License
23 23
      * along with this program; if not, write to the Free Software
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-    */
25
+     */
26 26
    
27
-	class Module{
27
+    class Module{
28 28
 		
29
-		/**
30
-		 * list of loaded module
31
-		 * @var array
32
-		 */
33
-		private static $list = array();
29
+        /**
30
+         * list of loaded module
31
+         * @var array
32
+         */
33
+        private static $list = array();
34 34
 
35
-		/**
36
-		 * logger instance
37
-		 * @var object
38
-		 */
39
-		private static $logger;
35
+        /**
36
+         * logger instance
37
+         * @var object
38
+         */
39
+        private static $logger;
40 40
 
41
-		/**
42
-		 * Initialise the module list by scanning the directory MODULE_PATH
43
-		 */
44
-		public function init(){
45
-			$logger = self::getLogger();
46
-			$logger->debug('Check if the application contains the modules ...');
47
-			$moduleDir = opendir(MODULE_PATH);
48
-			if (is_resource($moduleDir)){
49
-				while(($module = readdir($moduleDir)) !== false){
50
-					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
51
-						self::$list[] = $module;
52
-					}
53
-					else{
54
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
55
-					}
56
-				}
57
-				closedir($moduleDir);
58
-			}
59
-			ksort(self::$list);
41
+        /**
42
+         * Initialise the module list by scanning the directory MODULE_PATH
43
+         */
44
+        public function init(){
45
+            $logger = self::getLogger();
46
+            $logger->debug('Check if the application contains the modules ...');
47
+            $moduleDir = opendir(MODULE_PATH);
48
+            if (is_resource($moduleDir)){
49
+                while(($module = readdir($moduleDir)) !== false){
50
+                    if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
51
+                        self::$list[] = $module;
52
+                    }
53
+                    else{
54
+                        $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
55
+                    }
56
+                }
57
+                closedir($moduleDir);
58
+            }
59
+            ksort(self::$list);
60 60
 			
61
-			if (! empty(self::$list)){
62
-				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
63
-			}
64
-		}
61
+            if (! empty(self::$list)){
62
+                $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
63
+            }
64
+        }
65 65
 
66
-		/**
67
-		 * The signleton of the logger
68
-		 * @return Object the Log instance
69
-		 */
70
-		public static function getLogger(){
71
-			if (self::$logger == null){
72
-				$logger = array();
73
-				$logger[0] =& class_loader('Log', 'classes');
74
-				$logger[0]->setLogger('Library::Module');
75
-				self::$logger = $logger[0];
76
-			}
77
-			return self::$logger;			
78
-		}
66
+        /**
67
+         * The signleton of the logger
68
+         * @return Object the Log instance
69
+         */
70
+        public static function getLogger(){
71
+            if (self::$logger == null){
72
+                $logger = array();
73
+                $logger[0] =& class_loader('Log', 'classes');
74
+                $logger[0]->setLogger('Library::Module');
75
+                self::$logger = $logger[0];
76
+            }
77
+            return self::$logger;			
78
+        }
79 79
 
80
-		/**
81
-		 * Set the log instance for future use
82
-		 * @param object $logger the log object
83
-		 * @return object the log instance
84
-		 */
85
-		public static function setLogger($logger){
86
-			self::$logger = $logger;
87
-			return self::$logger;
88
-		}
80
+        /**
81
+         * Set the log instance for future use
82
+         * @param object $logger the log object
83
+         * @return object the log instance
84
+         */
85
+        public static function setLogger($logger){
86
+            self::$logger = $logger;
87
+            return self::$logger;
88
+        }
89 89
 
90 90
 		
91 91
 
92
-		/**
93
-		 * Add new module in the list
94
-		 * @param string $name the name of the module
95
-		 *
96
-		 * @return object the current instance
97
-		 */
98
-		public function add($name){
99
-			self::$list[] = $name;
100
-			return $this;
101
-		}
92
+        /**
93
+         * Add new module in the list
94
+         * @param string $name the name of the module
95
+         *
96
+         * @return object the current instance
97
+         */
98
+        public function add($name){
99
+            self::$list[] = $name;
100
+            return $this;
101
+        }
102 102
 		
103
-		/**
104
-		 * Get the list of the custom autoload configuration from module if exists
105
-		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
106
-		 */
107
-		public static function getModulesAutoloadConfig(){
108
-			$logger = self::getLogger();
109
-			if (empty(self::$list)){
110
-				$logger->info('No module was loaded skipping.');
111
-				return false;
112
-			}
113
-			$autoloads = array();
114
-			$autoloads['libraries'] = array();
115
-			$autoloads['config']    = array();
116
-			$autoloads['models']    = array();
117
-			$autoloads['functions'] = array();
118
-			$autoloads['languages'] = array();
103
+        /**
104
+         * Get the list of the custom autoload configuration from module if exists
105
+         * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
106
+         */
107
+        public static function getModulesAutoloadConfig(){
108
+            $logger = self::getLogger();
109
+            if (empty(self::$list)){
110
+                $logger->info('No module was loaded skipping.');
111
+                return false;
112
+            }
113
+            $autoloads = array();
114
+            $autoloads['libraries'] = array();
115
+            $autoloads['config']    = array();
116
+            $autoloads['models']    = array();
117
+            $autoloads['functions'] = array();
118
+            $autoloads['languages'] = array();
119 119
 			
120
-			foreach (self::$list as $module) {
121
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
122
-				if (file_exists($file)){
123
-					$autoload = array();
124
-					require_once $file;
125
-					if (! empty($autoload) && is_array($autoload)){
126
-						$autoloads = array_merge_recursive($autoloads, $autoload);
127
-						unset($autoload);
128
-					}
129
-				}
130
-			}
131
-			return $autoloads;
132
-		}
120
+            foreach (self::$list as $module) {
121
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
122
+                if (file_exists($file)){
123
+                    $autoload = array();
124
+                    require_once $file;
125
+                    if (! empty($autoload) && is_array($autoload)){
126
+                        $autoloads = array_merge_recursive($autoloads, $autoload);
127
+                        unset($autoload);
128
+                    }
129
+                }
130
+            }
131
+            return $autoloads;
132
+        }
133 133
 
134
-		/**
135
-		 * Get the list of the custom routes configuration from module if exists
136
-		 * @return array|boolean the routes list or false if no module contains the routes configuration
137
-		 */
138
-		public static function getModulesRoutesConfig(){
139
-			$logger = self::getLogger();
140
-			if (empty(self::$list)){
141
-				$logger->info('No module was loaded skipping.');
142
-				return false;
143
-			}
144
-			$routes = array();
145
-			foreach (self::$list as $module) {
146
-				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
147
-				if (file_exists($file)){
148
-					$route = array();
149
-					require_once $file;
150
-					if (! empty($route) && is_array($route)){
151
-						$routes = array_merge($routes, $route);
152
-						unset($route);
153
-					}
154
-				}
155
-			}
156
-			return $routes;
157
-		}
134
+        /**
135
+         * Get the list of the custom routes configuration from module if exists
136
+         * @return array|boolean the routes list or false if no module contains the routes configuration
137
+         */
138
+        public static function getModulesRoutesConfig(){
139
+            $logger = self::getLogger();
140
+            if (empty(self::$list)){
141
+                $logger->info('No module was loaded skipping.');
142
+                return false;
143
+            }
144
+            $routes = array();
145
+            foreach (self::$list as $module) {
146
+                $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
147
+                if (file_exists($file)){
148
+                    $route = array();
149
+                    require_once $file;
150
+                    if (! empty($route) && is_array($route)){
151
+                        $routes = array_merge($routes, $route);
152
+                        unset($route);
153
+                    }
154
+                }
155
+            }
156
+            return $routes;
157
+        }
158 158
 
159 159
 
160
-		/**
161
-		 * Check if in module list can have this controller
162
-		 * @see Module::findClassInModuleFullFilePath
163
-		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
164
-		 */
165
-		public static function findControllerFullPath($class, $module = null){
166
-			return self::findClassInModuleFullFilePath($class, $module, 'controllers');
167
-		}
160
+        /**
161
+         * Check if in module list can have this controller
162
+         * @see Module::findClassInModuleFullFilePath
163
+         * @return boolean|string  false or null if no module have this controller, path the full path of the controller
164
+         */
165
+        public static function findControllerFullPath($class, $module = null){
166
+            return self::findClassInModuleFullFilePath($class, $module, 'controllers');
167
+        }
168 168
 
169
-		/**
170
-		 * Check if in module list can have this model
171
-		 * @see Module::findClassInModuleFullFilePath
172
-		 * @return boolean|string  false or null if no module have this model, return the full path of this model
173
-		 */
174
-		public static function findModelFullPath($class, $module = null){
175
-			return self::findClassInModuleFullFilePath($class, $module, 'models');
176
-		}
169
+        /**
170
+         * Check if in module list can have this model
171
+         * @see Module::findClassInModuleFullFilePath
172
+         * @return boolean|string  false or null if no module have this model, return the full path of this model
173
+         */
174
+        public static function findModelFullPath($class, $module = null){
175
+            return self::findClassInModuleFullFilePath($class, $module, 'models');
176
+        }
177 177
 
178
-		/**
179
-		 * Check if in module list can have this library
180
-		 * @see Module::findClassInModuleFullFilePath
181
-		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
182
-		 */
183
-		public static function findLibraryFullPath($class, $module = null){
184
-			return self::findClassInModuleFullFilePath($class, $module, 'libraries');
185
-		}
178
+        /**
179
+         * Check if in module list can have this library
180
+         * @see Module::findClassInModuleFullFilePath
181
+         * @return boolean|string  false or null if no module have this library,  return the full path of this library
182
+         */
183
+        public static function findLibraryFullPath($class, $module = null){
184
+            return self::findClassInModuleFullFilePath($class, $module, 'libraries');
185
+        }
186 186
 
187 187
 		
188
-		/**
189
-		 * Check if in module list can have this config
190
-		 * @see  Module::findNonClassInModuleFullFilePath
191
-		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
192
-		 */
193
-		public static function findConfigFullPath($configuration, $module = null){
194
-			return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
195
-		}
188
+        /**
189
+         * Check if in module list can have this config
190
+         * @see  Module::findNonClassInModuleFullFilePath
191
+         * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
192
+         */
193
+        public static function findConfigFullPath($configuration, $module = null){
194
+            return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
195
+        }
196 196
 
197
-		/**
198
-		 * Check if in module list can have this helper
199
-		 * @see  Module::findNonClassInModuleFullFilePath
200
-		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
201
-		 */
202
-		public static function findFunctionFullPath($helper, $module = null){
203
-			return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
204
-		}
197
+        /**
198
+         * Check if in module list can have this helper
199
+         * @see  Module::findNonClassInModuleFullFilePath
200
+         * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
201
+         */
202
+        public static function findFunctionFullPath($helper, $module = null){
203
+            return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
204
+        }
205 205
 
206
-		/**
207
-		 * Check if in module list can have this view
208
-		 * @see  Module::findNonClassInModuleFullFilePath
209
-		 * @return boolean|string  false or null if no module have this view, path the full path of the view
210
-		 */
211
-		public static function findViewFullPath($view, $module = null){
212
-			return self::findNonClassInModuleFullFilePath($view, $module, 'views');
213
-		}
206
+        /**
207
+         * Check if in module list can have this view
208
+         * @see  Module::findNonClassInModuleFullFilePath
209
+         * @return boolean|string  false or null if no module have this view, path the full path of the view
210
+         */
211
+        public static function findViewFullPath($view, $module = null){
212
+            return self::findNonClassInModuleFullFilePath($view, $module, 'views');
213
+        }
214 214
 
215
-		/**
216
-		 * Check if in module list can have this language
217
-		 * @see  Module::findNonClassInModuleFullFilePath
218
-		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
219
-		 */
220
-		public static function findLanguageFullPath($language, $appLang, $module = null){
221
-			return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
222
-		}
215
+        /**
216
+         * Check if in module list can have this language
217
+         * @see  Module::findNonClassInModuleFullFilePath
218
+         * @return boolean|string  false or null if no module have this language,  return the full path of this language
219
+         */
220
+        public static function findLanguageFullPath($language, $appLang, $module = null){
221
+            return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
222
+        }
223 223
 
224
-		/**
225
-		 * Get the list of module loaded
226
-		 * @return array the module list
227
-		 */
228
-		public static function getModuleList(){
229
-			return self::$list;
230
-		}
224
+        /**
225
+         * Get the list of module loaded
226
+         * @return array the module list
227
+         */
228
+        public static function getModuleList(){
229
+            return self::$list;
230
+        }
231 231
 
232
-		/**
233
-		 * Check if the application has an module
234
-		 * @return boolean
235
-		 */
236
-		public static function hasModule(){
237
-			return !empty(self::$list);
238
-		}
232
+        /**
233
+         * Check if the application has an module
234
+         * @return boolean
235
+         */
236
+        public static function hasModule(){
237
+            return !empty(self::$list);
238
+        }
239 239
 
240
-		/**
241
-		 * Check if in module list can have the model, controller, library
242
-		 * @param  string $class the class name of library, model, controller
243
-		 * @param string $module the module name
244
-		 * @param string $type the name of the type "controllers", "libraries", "models"
245
-		 * @return boolean|string  false or null if no module 
246
-		 * have this class, return the full path of the class
247
-		 */
248
-		protected static function findClassInModuleFullFilePath($class, $module, $type){
249
-			$logger = self::getLogger();
250
-		    $class = str_ireplace('.php', '', $class);
251
-		    $class = ucfirst($class);
252
-		    $classFile = $class.'.php';
253
-		    $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
254
-		    $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
255
-		    if (file_exists($filePath)){
256
-		        $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' .$filePath. ']');
257
-		        return $filePath;
258
-		    }
259
-		    $logger->info('Class [' . $class . '] does not exist in the module [' .$module. '] for [' . $type . ']');
260
-		    return false;
261
-		}
240
+        /**
241
+         * Check if in module list can have the model, controller, library
242
+         * @param  string $class the class name of library, model, controller
243
+         * @param string $module the module name
244
+         * @param string $type the name of the type "controllers", "libraries", "models"
245
+         * @return boolean|string  false or null if no module 
246
+         * have this class, return the full path of the class
247
+         */
248
+        protected static function findClassInModuleFullFilePath($class, $module, $type){
249
+            $logger = self::getLogger();
250
+            $class = str_ireplace('.php', '', $class);
251
+            $class = ucfirst($class);
252
+            $classFile = $class.'.php';
253
+            $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
254
+            $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
255
+            if (file_exists($filePath)){
256
+                $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' .$filePath. ']');
257
+                return $filePath;
258
+            }
259
+            $logger->info('Class [' . $class . '] does not exist in the module [' .$module. '] for [' . $type . ']');
260
+            return false;
261
+        }
262 262
 
263
-		/**
264
-		 * Check if in module list can have the config, view, helper, language
265
-		 * @param string $name the name of config, view, helper, language
266
-		 * @param string $module the module name
267
-		 * @param string $type the name of the type "config", "functions", "views", "lang"
268
-		 * @param string|null $appLang the application language. This is use only when $type = "lang"
269
-		 * @return boolean|string  false or null if no module 
270
-		 * have this resource, return the full path of the resource
271
-		 */
272
-		protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null){
273
-		    $logger = self::getLogger();
274
-		    $name = str_ireplace('.php', '', $name);
275
-		    $file = $name.'.php';
276
-		    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
277
-		    switch($type){
278
-		        case 'functions':
279
-		            $name = str_ireplace('function_', '', $name);
280
-		            $file = 'function_'.$name.'.php';
281
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
282
-		        break;
283
-		        case 'views':
284
-		            $name = trim($name, '/\\');
285
-		            $name = str_ireplace('/', DS, $name);
286
-		            $file = $name . '.php';
287
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
288
-		        break;
289
-		        case 'lang':
290
-		            $name = str_ireplace('lang_', '', $name);
291
-		            $file = 'lang_'.$name.'.php';
292
-		            $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
293
-		        break;
294
-		    }
295
-		    $logger->debug('Checking resource [' . $name . '] in module [' .$module. '] for [' . $type . '] ...');
296
-		    if (file_exists($filePath)){
297
-		        $logger->info('Found resource [' . $name . '] in module [' .$module. '] for [' . $type . '] the file path is [' .$filePath. ']');
298
-		        return $filePath;
299
-		    }
300
-		    $logger->info('Resource [' . $name . '] does not exist in the module [' .$module. '] for [' . $type . ']');
301
-		    return false;
302
-		}
263
+        /**
264
+         * Check if in module list can have the config, view, helper, language
265
+         * @param string $name the name of config, view, helper, language
266
+         * @param string $module the module name
267
+         * @param string $type the name of the type "config", "functions", "views", "lang"
268
+         * @param string|null $appLang the application language. This is use only when $type = "lang"
269
+         * @return boolean|string  false or null if no module 
270
+         * have this resource, return the full path of the resource
271
+         */
272
+        protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null){
273
+            $logger = self::getLogger();
274
+            $name = str_ireplace('.php', '', $name);
275
+            $file = $name.'.php';
276
+            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
277
+            switch($type){
278
+                case 'functions':
279
+                    $name = str_ireplace('function_', '', $name);
280
+                    $file = 'function_'.$name.'.php';
281
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
282
+                break;
283
+                case 'views':
284
+                    $name = trim($name, '/\\');
285
+                    $name = str_ireplace('/', DS, $name);
286
+                    $file = $name . '.php';
287
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
288
+                break;
289
+                case 'lang':
290
+                    $name = str_ireplace('lang_', '', $name);
291
+                    $file = 'lang_'.$name.'.php';
292
+                    $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
293
+                break;
294
+            }
295
+            $logger->debug('Checking resource [' . $name . '] in module [' .$module. '] for [' . $type . '] ...');
296
+            if (file_exists($filePath)){
297
+                $logger->info('Found resource [' . $name . '] in module [' .$module. '] for [' . $type . '] the file path is [' .$filePath. ']');
298
+                return $filePath;
299
+            }
300
+            $logger->info('Resource [' . $name . '] does not exist in the module [' .$module. '] for [' . $type . ']');
301
+            return false;
302
+        }
303 303
 
304
-	}
304
+    }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
     */
26 26
    
27
-	class Module{
27
+	class Module {
28 28
 		
29 29
 		/**
30 30
 		 * list of loaded module
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
 		/**
42 42
 		 * Initialise the module list by scanning the directory MODULE_PATH
43 43
 		 */
44
-		public function init(){
44
+		public function init() {
45 45
 			$logger = self::getLogger();
46 46
 			$logger->debug('Check if the application contains the modules ...');
47 47
 			$moduleDir = opendir(MODULE_PATH);
48
-			if (is_resource($moduleDir)){
49
-				while(($module = readdir($moduleDir)) !== false){
50
-					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
48
+			if (is_resource($moduleDir)) {
49
+				while (($module = readdir($moduleDir)) !== false) {
50
+					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) {
51 51
 						self::$list[] = $module;
52 52
 					}
53
-					else{
54
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
53
+					else {
54
+						$logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name');
55 55
 					}
56 56
 				}
57 57
 				closedir($moduleDir);
58 58
 			}
59 59
 			ksort(self::$list);
60 60
 			
61
-			if (! empty(self::$list)){
61
+			if (!empty(self::$list)) {
62 62
 				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
63 63
 			}
64 64
 		}
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 		 * The signleton of the logger
68 68
 		 * @return Object the Log instance
69 69
 		 */
70
-		public static function getLogger(){
71
-			if (self::$logger == null){
70
+		public static function getLogger() {
71
+			if (self::$logger == null) {
72 72
 				$logger = array();
73
-				$logger[0] =& class_loader('Log', 'classes');
73
+				$logger[0] = & class_loader('Log', 'classes');
74 74
 				$logger[0]->setLogger('Library::Module');
75 75
 				self::$logger = $logger[0];
76 76
 			}
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		 * @param object $logger the log object
83 83
 		 * @return object the log instance
84 84
 		 */
85
-		public static function setLogger($logger){
85
+		public static function setLogger($logger) {
86 86
 			self::$logger = $logger;
87 87
 			return self::$logger;
88 88
 		}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 *
96 96
 		 * @return object the current instance
97 97
 		 */
98
-		public function add($name){
98
+		public function add($name) {
99 99
 			self::$list[] = $name;
100 100
 			return $this;
101 101
 		}
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
 		 * Get the list of the custom autoload configuration from module if exists
105 105
 		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
106 106
 		 */
107
-		public static function getModulesAutoloadConfig(){
107
+		public static function getModulesAutoloadConfig() {
108 108
 			$logger = self::getLogger();
109
-			if (empty(self::$list)){
109
+			if (empty(self::$list)) {
110 110
 				$logger->info('No module was loaded skipping.');
111 111
 				return false;
112 112
 			}
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 			
120 120
 			foreach (self::$list as $module) {
121 121
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
122
-				if (file_exists($file)){
122
+				if (file_exists($file)) {
123 123
 					$autoload = array();
124 124
 					require_once $file;
125
-					if (! empty($autoload) && is_array($autoload)){
125
+					if (!empty($autoload) && is_array($autoload)) {
126 126
 						$autoloads = array_merge_recursive($autoloads, $autoload);
127 127
 						unset($autoload);
128 128
 					}
@@ -135,19 +135,19 @@  discard block
 block discarded – undo
135 135
 		 * Get the list of the custom routes configuration from module if exists
136 136
 		 * @return array|boolean the routes list or false if no module contains the routes configuration
137 137
 		 */
138
-		public static function getModulesRoutesConfig(){
138
+		public static function getModulesRoutesConfig() {
139 139
 			$logger = self::getLogger();
140
-			if (empty(self::$list)){
140
+			if (empty(self::$list)) {
141 141
 				$logger->info('No module was loaded skipping.');
142 142
 				return false;
143 143
 			}
144 144
 			$routes = array();
145 145
 			foreach (self::$list as $module) {
146 146
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
147
-				if (file_exists($file)){
147
+				if (file_exists($file)) {
148 148
 					$route = array();
149 149
 					require_once $file;
150
-					if (! empty($route) && is_array($route)){
150
+					if (!empty($route) && is_array($route)) {
151 151
 						$routes = array_merge($routes, $route);
152 152
 						unset($route);
153 153
 					}
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		 * @see Module::findClassInModuleFullFilePath
163 163
 		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
164 164
 		 */
165
-		public static function findControllerFullPath($class, $module = null){
165
+		public static function findControllerFullPath($class, $module = null) {
166 166
 			return self::findClassInModuleFullFilePath($class, $module, 'controllers');
167 167
 		}
168 168
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		 * @see Module::findClassInModuleFullFilePath
172 172
 		 * @return boolean|string  false or null if no module have this model, return the full path of this model
173 173
 		 */
174
-		public static function findModelFullPath($class, $module = null){
174
+		public static function findModelFullPath($class, $module = null) {
175 175
 			return self::findClassInModuleFullFilePath($class, $module, 'models');
176 176
 		}
177 177
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		 * @see Module::findClassInModuleFullFilePath
181 181
 		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
182 182
 		 */
183
-		public static function findLibraryFullPath($class, $module = null){
183
+		public static function findLibraryFullPath($class, $module = null) {
184 184
 			return self::findClassInModuleFullFilePath($class, $module, 'libraries');
185 185
 		}
186 186
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		 * @see  Module::findNonClassInModuleFullFilePath
191 191
 		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
192 192
 		 */
193
-		public static function findConfigFullPath($configuration, $module = null){
193
+		public static function findConfigFullPath($configuration, $module = null) {
194 194
 			return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
195 195
 		}
196 196
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		 * @see  Module::findNonClassInModuleFullFilePath
200 200
 		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
201 201
 		 */
202
-		public static function findFunctionFullPath($helper, $module = null){
202
+		public static function findFunctionFullPath($helper, $module = null) {
203 203
 			return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
204 204
 		}
205 205
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 		 * @see  Module::findNonClassInModuleFullFilePath
209 209
 		 * @return boolean|string  false or null if no module have this view, path the full path of the view
210 210
 		 */
211
-		public static function findViewFullPath($view, $module = null){
211
+		public static function findViewFullPath($view, $module = null) {
212 212
 			return self::findNonClassInModuleFullFilePath($view, $module, 'views');
213 213
 		}
214 214
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 		 * @see  Module::findNonClassInModuleFullFilePath
218 218
 		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
219 219
 		 */
220
-		public static function findLanguageFullPath($language, $appLang, $module = null){
220
+		public static function findLanguageFullPath($language, $appLang, $module = null) {
221 221
 			return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
222 222
 		}
223 223
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		 * Get the list of module loaded
226 226
 		 * @return array the module list
227 227
 		 */
228
-		public static function getModuleList(){
228
+		public static function getModuleList() {
229 229
 			return self::$list;
230 230
 		}
231 231
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 		 * Check if the application has an module
234 234
 		 * @return boolean
235 235
 		 */
236
-		public static function hasModule(){
236
+		public static function hasModule() {
237 237
 			return !empty(self::$list);
238 238
 		}
239 239
 
@@ -245,18 +245,18 @@  discard block
 block discarded – undo
245 245
 		 * @return boolean|string  false or null if no module 
246 246
 		 * have this class, return the full path of the class
247 247
 		 */
248
-		protected static function findClassInModuleFullFilePath($class, $module, $type){
248
+		protected static function findClassInModuleFullFilePath($class, $module, $type) {
249 249
 			$logger = self::getLogger();
250 250
 		    $class = str_ireplace('.php', '', $class);
251 251
 		    $class = ucfirst($class);
252
-		    $classFile = $class.'.php';
252
+		    $classFile = $class . '.php';
253 253
 		    $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
254 254
 		    $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
255
-		    if (file_exists($filePath)){
256
-		        $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' .$filePath. ']');
255
+		    if (file_exists($filePath)) {
256
+		        $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
257 257
 		        return $filePath;
258 258
 		    }
259
-		    $logger->info('Class [' . $class . '] does not exist in the module [' .$module. '] for [' . $type . ']');
259
+		    $logger->info('Class [' . $class . '] does not exist in the module [' . $module . '] for [' . $type . ']');
260 260
 		    return false;
261 261
 		}
262 262
 
@@ -269,15 +269,15 @@  discard block
 block discarded – undo
269 269
 		 * @return boolean|string  false or null if no module 
270 270
 		 * have this resource, return the full path of the resource
271 271
 		 */
272
-		protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null){
272
+		protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null) {
273 273
 		    $logger = self::getLogger();
274 274
 		    $name = str_ireplace('.php', '', $name);
275
-		    $file = $name.'.php';
275
+		    $file = $name . '.php';
276 276
 		    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
277
-		    switch($type){
277
+		    switch ($type) {
278 278
 		        case 'functions':
279 279
 		            $name = str_ireplace('function_', '', $name);
280
-		            $file = 'function_'.$name.'.php';
280
+		            $file = 'function_' . $name . '.php';
281 281
 		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
282 282
 		        break;
283 283
 		        case 'views':
@@ -288,16 +288,16 @@  discard block
 block discarded – undo
288 288
 		        break;
289 289
 		        case 'lang':
290 290
 		            $name = str_ireplace('lang_', '', $name);
291
-		            $file = 'lang_'.$name.'.php';
291
+		            $file = 'lang_' . $name . '.php';
292 292
 		            $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
293 293
 		        break;
294 294
 		    }
295
-		    $logger->debug('Checking resource [' . $name . '] in module [' .$module. '] for [' . $type . '] ...');
296
-		    if (file_exists($filePath)){
297
-		        $logger->info('Found resource [' . $name . '] in module [' .$module. '] for [' . $type . '] the file path is [' .$filePath. ']');
295
+		    $logger->debug('Checking resource [' . $name . '] in module [' . $module . '] for [' . $type . '] ...');
296
+		    if (file_exists($filePath)) {
297
+		        $logger->info('Found resource [' . $name . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
298 298
 		        return $filePath;
299 299
 		    }
300
-		    $logger->info('Resource [' . $name . '] does not exist in the module [' .$module. '] for [' . $type . ']');
300
+		    $logger->info('Resource [' . $name . '] does not exist in the module [' . $module . '] for [' . $type . ']');
301 301
 		    return false;
302 302
 		}
303 303
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,8 +49,7 @@
 block discarded – undo
49 49
 				while(($module = readdir($moduleDir)) !== false){
50 50
 					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
51 51
 						self::$list[] = $module;
52
-					}
53
-					else{
52
+					} else{
54 53
 						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
55 54
 					}
56 55
 				}
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 2 patches
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -1,81 +1,81 @@  discard block
 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
-	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29
-	 */
30
-	if ( !interface_exists('SessionHandlerInterface')){
31
-		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32
-	}
33
-
34
-	class DBSessionHandler implements SessionHandlerInterface{
27
+    /**
28
+     * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29
+     */
30
+    if ( !interface_exists('SessionHandlerInterface')){
31
+        show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32
+    }
33
+
34
+    class DBSessionHandler implements SessionHandlerInterface{
35 35
 		
36
-		/**
37
-		 * The encryption method to use to encrypt session data in database
38
-		 * @const string
39
-		 */
40
-		const DB_SESSION_HASH_METHOD = 'AES-256-CBC';
36
+        /**
37
+         * The encryption method to use to encrypt session data in database
38
+         * @const string
39
+         */
40
+        const DB_SESSION_HASH_METHOD = 'AES-256-CBC';
41 41
 		
42
-		/**
43
-		 * Super global instance
44
-		 * @var object
45
-		 */
46
-		protected $OBJ = null;
47
-
48
-		/**
49
-		 * Session secret to use 
50
-		 * @var string
51
-		 */
52
-		private $sessionSecret = null;
53
-
54
-		/**
55
-		 * The initialisation vector to use for openssl
56
-		 * @var string
57
-		 */
58
-		private $iv = null;
59
-
60
-		/**
61
-		 * The model instance to use
62
-		 * @var object
63
-		 */
64
-		private $modelInstance = null;
65
-
66
-		/**
67
-		 * The columns of the table to use to store session data
68
-		 * @var array
69
-		 */
70
-		private $sessionTableColumns = array();
71
-
72
-		/**
73
-		 * The instance of the Log 
74
-		 * @var Log
75
-		 */
76
-		private $logger;
77
-
78
-		/**
42
+        /**
43
+         * Super global instance
44
+         * @var object
45
+         */
46
+        protected $OBJ = null;
47
+
48
+        /**
49
+         * Session secret to use 
50
+         * @var string
51
+         */
52
+        private $sessionSecret = null;
53
+
54
+        /**
55
+         * The initialisation vector to use for openssl
56
+         * @var string
57
+         */
58
+        private $iv = null;
59
+
60
+        /**
61
+         * The model instance to use
62
+         * @var object
63
+         */
64
+        private $modelInstance = null;
65
+
66
+        /**
67
+         * The columns of the table to use to store session data
68
+         * @var array
69
+         */
70
+        private $sessionTableColumns = array();
71
+
72
+        /**
73
+         * The instance of the Log 
74
+         * @var Log
75
+         */
76
+        private $logger;
77
+
78
+        /**
79 79
          * Instance of the Loader class
80 80
          * @var Loader
81 81
          */
@@ -85,227 +85,227 @@  discard block
 block discarded – undo
85 85
          * Create new instance of Database session handler
86 86
          * @param object $modelInstance the model instance
87 87
          */
88
-		public function __construct(DBSessionHandlerModel $modelInstance = null){
89
-			//Set Log instance to use
90
-	        $this->setLoggerFromParamOrCreate(null);
88
+        public function __construct(DBSessionHandlerModel $modelInstance = null){
89
+            //Set Log instance to use
90
+            $this->setLoggerFromParamOrCreate(null);
91 91
 			
92
-	    	//Set Loader instance to use
93
-	        $this->setDependencyInstanceFromParamOrCreate('loader', null, 'Loader', 'classes');
92
+            //Set Loader instance to use
93
+            $this->setDependencyInstanceFromParamOrCreate('loader', null, 'Loader', 'classes');
94 94
 	       
95
-		    $this->OBJ = & get_instance();
95
+            $this->OBJ = & get_instance();
96 96
 		    
97
-			if (is_object($modelInstance)){
98
-				$this->setModelInstance($modelInstance);
99
-			}
100
-		}
101
-
102
-		/**
103
-		 * Set the session secret used to encrypt the data in database 
104
-		 * @param string $secret the base64 string secret
105
-		 */
106
-		public function setSessionSecret($secret){
107
-			$this->sessionSecret = $secret;
108
-			return $this;
109
-		}
110
-
111
-		/**
112
-		 * Return the session secret
113
-		 * @return string 
114
-		 */
115
-		public function getSessionSecret(){
116
-			return $this->sessionSecret;
117
-		}
118
-
119
-
120
-		/**
121
-		 * Set the initializer vector for openssl 
122
-		 * @param string $key the session secret used in base64 format
123
-		 */
124
-		public function setInitializerVector($key){
125
-			$ivLength = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
126
-			$key = base64_decode($key);
127
-			$this->iv = substr(hash('sha256', $key), 0, $ivLength);
128
-			return $this;
129
-		}
130
-
131
-		/**
132
-		 * Return the initializer vector
133
-		 * @return string 
134
-		 */
135
-		public function getInitializerVector(){
136
-			return $this->iv;
137
-		}
138
-
139
-		/**
140
-		 * Open the database session handler, here nothing to do just return true
141
-		 * @param  string $savePath    the session save path
142
-		 * @param  string $sessionName the session name
143
-		 * @return boolean 
144
-		 */
145
-		public function open($savePath, $sessionName){
146
-			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
147
-			//try to check if session secret is set before
148
-			$secret = $this->getSessionSecret();
149
-			if (empty($secret)){
150
-				$secret = get_config('session_secret', null);
151
-				$this->setSessionSecret($secret);
152
-			}
153
-			$this->logger->info('Session secret: ' . $secret);
154
-
155
-			if (! is_object($this->modelInstance)){
156
-				$this->setModelInstanceFromConfig();
157
-			}
158
-			$this->setInitializerVector($secret);
159
-
160
-			//set session tables columns
161
-			$this->sessionTableColumns = $this->modelInstance->getSessionTableColumns();
162
-
163
-			if (empty($this->sessionTableColumns)){
164
-				show_error('The session handler is "database" but the table columns not set');
165
-			}
166
-			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
97
+            if (is_object($modelInstance)){
98
+                $this->setModelInstance($modelInstance);
99
+            }
100
+        }
101
+
102
+        /**
103
+         * Set the session secret used to encrypt the data in database 
104
+         * @param string $secret the base64 string secret
105
+         */
106
+        public function setSessionSecret($secret){
107
+            $this->sessionSecret = $secret;
108
+            return $this;
109
+        }
110
+
111
+        /**
112
+         * Return the session secret
113
+         * @return string 
114
+         */
115
+        public function getSessionSecret(){
116
+            return $this->sessionSecret;
117
+        }
118
+
119
+
120
+        /**
121
+         * Set the initializer vector for openssl 
122
+         * @param string $key the session secret used in base64 format
123
+         */
124
+        public function setInitializerVector($key){
125
+            $ivLength = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
126
+            $key = base64_decode($key);
127
+            $this->iv = substr(hash('sha256', $key), 0, $ivLength);
128
+            return $this;
129
+        }
130
+
131
+        /**
132
+         * Return the initializer vector
133
+         * @return string 
134
+         */
135
+        public function getInitializerVector(){
136
+            return $this->iv;
137
+        }
138
+
139
+        /**
140
+         * Open the database session handler, here nothing to do just return true
141
+         * @param  string $savePath    the session save path
142
+         * @param  string $sessionName the session name
143
+         * @return boolean 
144
+         */
145
+        public function open($savePath, $sessionName){
146
+            $this->logger->debug('Opening database session handler for [' . $sessionName . ']');
147
+            //try to check if session secret is set before
148
+            $secret = $this->getSessionSecret();
149
+            if (empty($secret)){
150
+                $secret = get_config('session_secret', null);
151
+                $this->setSessionSecret($secret);
152
+            }
153
+            $this->logger->info('Session secret: ' . $secret);
154
+
155
+            if (! is_object($this->modelInstance)){
156
+                $this->setModelInstanceFromConfig();
157
+            }
158
+            $this->setInitializerVector($secret);
159
+
160
+            //set session tables columns
161
+            $this->sessionTableColumns = $this->modelInstance->getSessionTableColumns();
162
+
163
+            if (empty($this->sessionTableColumns)){
164
+                show_error('The session handler is "database" but the table columns not set');
165
+            }
166
+            $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
167 167
 			
168
-			//delete the expired session
169
-			$timeActivity = get_config('session_inactivity_time', 100);
170
-			$this->gc($timeActivity);
168
+            //delete the expired session
169
+            $timeActivity = get_config('session_inactivity_time', 100);
170
+            $this->gc($timeActivity);
171 171
 			
172
-			return true;
173
-		}
174
-
175
-		/**
176
-		 * Close the session
177
-		 * @return boolean
178
-		 */
179
-		public function close(){
180
-			$this->logger->debug('Closing database session handler');
181
-			return true;
182
-		}
183
-
184
-		/**
185
-		 * Get the session value for the given session id
186
-		 * @param  string $sid the session id to use
187
-		 * @return string      the session data in serialiaze format
188
-		 */
189
-		public function read($sid){
190
-			$this->logger->debug('Reading database session data for SID: ' . $sid);
191
-			$instance = $this->getModelInstance();
192
-			$columns = $this->sessionTableColumns;
193
-			$this->loader->functions('user_agent'); 
194
-			$this->loader->library('Browser'); 
172
+            return true;
173
+        }
174
+
175
+        /**
176
+         * Close the session
177
+         * @return boolean
178
+         */
179
+        public function close(){
180
+            $this->logger->debug('Closing database session handler');
181
+            return true;
182
+        }
183
+
184
+        /**
185
+         * Get the session value for the given session id
186
+         * @param  string $sid the session id to use
187
+         * @return string      the session data in serialiaze format
188
+         */
189
+        public function read($sid){
190
+            $this->logger->debug('Reading database session data for SID: ' . $sid);
191
+            $instance = $this->getModelInstance();
192
+            $columns = $this->sessionTableColumns;
193
+            $this->loader->functions('user_agent'); 
194
+            $this->loader->library('Browser'); 
195 195
 			
196
-			$ip = get_ip();
197
-			$host = @gethostbyaddr($ip) or null;
198
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
196
+            $ip = get_ip();
197
+            $host = @gethostbyaddr($ip) or null;
198
+            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
199 199
 			
200
-			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
201
-			if ($data && isset($data->{$columns['sdata']})){
202
-				//checking inactivity 
203
-				$timeInactivity = time() - get_config('session_inactivity_time', 100);
204
-				if ($data->{$columns['stime']} < $timeInactivity){
205
-					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
206
-					$this->destroy($sid);
207
-					return null;
208
-				}
209
-				return $this->decode($data->{$columns['sdata']});
210
-			}
211
-			$this->logger->info('Database session data for SID: ' . $sid . ' is not valid return false, may be the session ID is wrong');
212
-			return null;
213
-		}
214
-
215
-		/**
216
-		 * Save the session data
217
-		 * @param  string $sid  the session ID
218
-		 * @param  mixed $data the session data to save in serialize format
219
-		 * @return boolean 
220
-		 */
221
-		public function write($sid, $data){
222
-			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
223
-			$instance = $this->getModelInstance();
224
-			$columns = $this->sessionTableColumns;
225
-
226
-			$this->loader->functions('user_agent'); 
227
-			$this->loader->library('Browser'); 
228
-
229
-			$ip = get_ip();
230
-			$keyValue = $instance->getKeyValue();
231
-			$host = @gethostbyaddr($ip) or null;
232
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
233
-			$data = $this->encode($data);
234
-			$params = array(
235
-							$columns['sid'] => $sid,
236
-							$columns['sdata'] => $data,
237
-							$columns['stime'] => time(),
238
-							$columns['shost'] => $host,
239
-							$columns['sbrowser'] => $browser,
240
-							$columns['sip'] => $ip,
241
-							$columns['skey'] => $keyValue
242
-						);
243
-			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
244
-			$exists = $instance->get($sid);
245
-			if ($exists){
246
-				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
247
-				//update
248
-				unset($params[$columns['sid']]);
249
-				return $instance->update($sid, $params);
250
-			}
251
-			$this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
252
-			return $instance->insert($params);
253
-			return true;
254
-		}
255
-
256
-
257
-		/**
258
-		 * Destroy the session data for the given session id
259
-		 * @param  string $sid the session id value
260
-		 * @return boolean
261
-		 */
262
-		public function destroy($sid){
263
-			$this->logger->debug('Destroy of session data for SID: ' . $sid);
264
-			$instance = $this->modelInstance;
265
-			$instance->delete($sid);
266
-			return true;
267
-		}
268
-
269
-		/**
270
-		 * Clean the expire session data to save espace
271
-		 * @param  integer $maxLifetime the max lifetime
272
-		 * @return boolean
273
-		 */
274
-		public function gc($maxLifetime){
275
-			$instance = $this->modelInstance;
276
-			$time = time() - $maxLifetime;
277
-			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
278
-			$instance->deleteByTime($time);
279
-			return true;
280
-		}
281
-
282
-		/**
283
-		 * Encode the session data using the openssl
284
-		 * @param  mixed $data the session data to encode
285
-		 * @return mixed the encoded session data
286
-		 */
287
-		public function encode($data){
288
-			$key = base64_decode($this->sessionSecret);
289
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
290
-			$output = base64_encode($dataEncrypted);
291
-			return $output;
292
-		}
293
-
294
-
295
-		/**
296
-		 * Decode the session data using the openssl
297
-		 * @param  mixed $data the data to decode
298
-		 * @return mixed       the decoded data
299
-		 */
300
-		public function decode($data){
301
-			$key = base64_decode($this->sessionSecret);
302
-			$data = base64_decode($data);
303
-			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
304
-			return $data;
305
-		}
200
+            $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
201
+            if ($data && isset($data->{$columns['sdata']})){
202
+                //checking inactivity 
203
+                $timeInactivity = time() - get_config('session_inactivity_time', 100);
204
+                if ($data->{$columns['stime']} < $timeInactivity){
205
+                    $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
206
+                    $this->destroy($sid);
207
+                    return null;
208
+                }
209
+                return $this->decode($data->{$columns['sdata']});
210
+            }
211
+            $this->logger->info('Database session data for SID: ' . $sid . ' is not valid return false, may be the session ID is wrong');
212
+            return null;
213
+        }
214
+
215
+        /**
216
+         * Save the session data
217
+         * @param  string $sid  the session ID
218
+         * @param  mixed $data the session data to save in serialize format
219
+         * @return boolean 
220
+         */
221
+        public function write($sid, $data){
222
+            $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
223
+            $instance = $this->getModelInstance();
224
+            $columns = $this->sessionTableColumns;
225
+
226
+            $this->loader->functions('user_agent'); 
227
+            $this->loader->library('Browser'); 
228
+
229
+            $ip = get_ip();
230
+            $keyValue = $instance->getKeyValue();
231
+            $host = @gethostbyaddr($ip) or null;
232
+            $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
233
+            $data = $this->encode($data);
234
+            $params = array(
235
+                            $columns['sid'] => $sid,
236
+                            $columns['sdata'] => $data,
237
+                            $columns['stime'] => time(),
238
+                            $columns['shost'] => $host,
239
+                            $columns['sbrowser'] => $browser,
240
+                            $columns['sip'] => $ip,
241
+                            $columns['skey'] => $keyValue
242
+                        );
243
+            $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
244
+            $exists = $instance->get($sid);
245
+            if ($exists){
246
+                $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
247
+                //update
248
+                unset($params[$columns['sid']]);
249
+                return $instance->update($sid, $params);
250
+            }
251
+            $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now');
252
+            return $instance->insert($params);
253
+            return true;
254
+        }
255
+
256
+
257
+        /**
258
+         * Destroy the session data for the given session id
259
+         * @param  string $sid the session id value
260
+         * @return boolean
261
+         */
262
+        public function destroy($sid){
263
+            $this->logger->debug('Destroy of session data for SID: ' . $sid);
264
+            $instance = $this->modelInstance;
265
+            $instance->delete($sid);
266
+            return true;
267
+        }
268
+
269
+        /**
270
+         * Clean the expire session data to save espace
271
+         * @param  integer $maxLifetime the max lifetime
272
+         * @return boolean
273
+         */
274
+        public function gc($maxLifetime){
275
+            $instance = $this->modelInstance;
276
+            $time = time() - $maxLifetime;
277
+            $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
278
+            $instance->deleteByTime($time);
279
+            return true;
280
+        }
281
+
282
+        /**
283
+         * Encode the session data using the openssl
284
+         * @param  mixed $data the session data to encode
285
+         * @return mixed the encoded session data
286
+         */
287
+        public function encode($data){
288
+            $key = base64_decode($this->sessionSecret);
289
+            $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
290
+            $output = base64_encode($dataEncrypted);
291
+            return $output;
292
+        }
293
+
294
+
295
+        /**
296
+         * Decode the session data using the openssl
297
+         * @param  mixed $data the data to decode
298
+         * @return mixed       the decoded data
299
+         */
300
+        public function decode($data){
301
+            $key = base64_decode($this->sessionSecret);
302
+            $data = base64_decode($data);
303
+            $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
304
+            return $data;
305
+        }
306 306
 
307 307
 		
308
-		/**
308
+        /**
309 309
          * Return the loader instance
310 310
          * @return object Loader the loader instance
311 311
          */
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
          * set the loader instance for future use
318 318
          * @param object Loader $loader the loader object
319 319
          */
320
-         public function setLoader($loader){
320
+            public function setLoader($loader){
321 321
             $this->loader = $loader;
322 322
             return $this;
323 323
         }
@@ -334,77 +334,77 @@  discard block
 block discarded – undo
334 334
          * set the model instance for future use
335 335
          * @param DBSessionHandlerModel $modelInstance the model object
336 336
          */
337
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
337
+            public function setModelInstance(DBSessionHandlerModel $modelInstance){
338 338
             $this->modelInstance = $modelInstance;
339 339
             return $this;
340 340
         }
341 341
 
342 342
         /**
343
-	     * Return the Log instance
344
-	     * @return Log
345
-	     */
346
-	    public function getLogger(){
347
-	      return $this->logger;
348
-	    }
349
-
350
-	    /**
351
-	     * Set the log instance
352
-	     * @param Log $logger the log object
353
-	     */
354
-	    public function setLogger(Log $logger){
355
-	      $this->logger = $logger;
356
-	      return $this;
357
-	    }
358
-
359
-	    /**
360
-	     * Set the dependencies instance using argument or create new instance if is null
361
-	     * @param string $name this class property name.
362
-	     * @param object $instance the instance. If is not null will use it
363
-	     * otherwise will create new instance.
364
-	     * @param string $loadClassName the name of class to load using class_loader function.
365
-	     * @param string $loadClassPath the path of class to load using class_loader function.
366
-	     *
367
-	     * @return object this current instance
368
-	     */
369
-	    protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
370
-	      if ($instance !== null){
371
-	        $this->{$name} = $instance;
372
-	        return $this;
373
-	      }
374
-	      $this->{$name} =& class_loader($loadClassName, $loadClassePath);
375
-	      return $this;
376
-	    }
343
+         * Return the Log instance
344
+         * @return Log
345
+         */
346
+        public function getLogger(){
347
+            return $this->logger;
348
+        }
349
+
350
+        /**
351
+         * Set the log instance
352
+         * @param Log $logger the log object
353
+         */
354
+        public function setLogger(Log $logger){
355
+            $this->logger = $logger;
356
+            return $this;
357
+        }
358
+
359
+        /**
360
+         * Set the dependencies instance using argument or create new instance if is null
361
+         * @param string $name this class property name.
362
+         * @param object $instance the instance. If is not null will use it
363
+         * otherwise will create new instance.
364
+         * @param string $loadClassName the name of class to load using class_loader function.
365
+         * @param string $loadClassPath the path of class to load using class_loader function.
366
+         *
367
+         * @return object this current instance
368
+         */
369
+        protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
370
+            if ($instance !== null){
371
+            $this->{$name} = $instance;
372
+            return $this;
373
+            }
374
+            $this->{$name} =& class_loader($loadClassName, $loadClassePath);
375
+            return $this;
376
+        }
377 377
 	    
378
-		   /**
379
-	     * Set the Log instance using argument or create new instance
380
-	     * @param object $logger the Log instance if not null
381
-	     *
382
-	     * @return object this current instance
383
-	     */
384
-	    protected function setLoggerFromParamOrCreate(Log $logger = null){
385
-	      $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
386
-	      if ($logger === null){
387
-	        $this->logger->setLogger('Library::DBSessionHandler');
388
-	      }
389
-	      return $this;
390
-	    }
391
-
392
-	    /**
393
-	     * Set the model instance using the configuration for session
394
-	     */
395
-	    protected function setModelInstanceFromConfig(){
396
-	    	$modelName = get_config('session_save_path');
397
-			$this->logger->info('The database session model: ' . $modelName);
398
-			$this->loader->model($modelName, 'dbsessionhandlerinstance'); 
399
-			//@codeCoverageIgnoreStart
378
+            /**
379
+             * Set the Log instance using argument or create new instance
380
+             * @param object $logger the Log instance if not null
381
+             *
382
+             * @return object this current instance
383
+             */
384
+        protected function setLoggerFromParamOrCreate(Log $logger = null){
385
+            $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
386
+            if ($logger === null){
387
+            $this->logger->setLogger('Library::DBSessionHandler');
388
+            }
389
+            return $this;
390
+        }
391
+
392
+        /**
393
+         * Set the model instance using the configuration for session
394
+         */
395
+        protected function setModelInstanceFromConfig(){
396
+            $modelName = get_config('session_save_path');
397
+            $this->logger->info('The database session model: ' . $modelName);
398
+            $this->loader->model($modelName, 'dbsessionhandlerinstance'); 
399
+            //@codeCoverageIgnoreStart
400 400
             if (isset($this->OBJ->dbsessionhandlerinstance) 
401
-            	&& ! ($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
401
+                && ! ($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
402 402
             ) {
403
-				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
404
-			}  
405
-			//@codeCoverageIgnoreEnd
403
+                show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
404
+            }  
405
+            //@codeCoverageIgnoreEnd
406 406
 			
407
-			//set model instance
408
-			$this->modelInstance = $this->OBJ->dbsessionhandlerinstance;
409
-	    }
410
-	}
407
+            //set model instance
408
+            $this->modelInstance = $this->OBJ->dbsessionhandlerinstance;
409
+        }
410
+    }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists)
29 29
 	 */
30
-	if ( !interface_exists('SessionHandlerInterface')){
30
+	if (!interface_exists('SessionHandlerInterface')) {
31 31
 		show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.');
32 32
 	}
33 33
 
34
-	class DBSessionHandler implements SessionHandlerInterface{
34
+	class DBSessionHandler implements SessionHandlerInterface {
35 35
 		
36 36
 		/**
37 37
 		 * The encryption method to use to encrypt session data in database
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
          * Create new instance of Database session handler
86 86
          * @param object $modelInstance the model instance
87 87
          */
88
-		public function __construct(DBSessionHandlerModel $modelInstance = null){
88
+		public function __construct(DBSessionHandlerModel $modelInstance = null) {
89 89
 			//Set Log instance to use
90 90
 	        $this->setLoggerFromParamOrCreate(null);
91 91
 			
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	       
95 95
 		    $this->OBJ = & get_instance();
96 96
 		    
97
-			if (is_object($modelInstance)){
97
+			if (is_object($modelInstance)) {
98 98
 				$this->setModelInstance($modelInstance);
99 99
 			}
100 100
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		 * Set the session secret used to encrypt the data in database 
104 104
 		 * @param string $secret the base64 string secret
105 105
 		 */
106
-		public function setSessionSecret($secret){
106
+		public function setSessionSecret($secret) {
107 107
 			$this->sessionSecret = $secret;
108 108
 			return $this;
109 109
 		}
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 		 * Return the session secret
113 113
 		 * @return string 
114 114
 		 */
115
-		public function getSessionSecret(){
115
+		public function getSessionSecret() {
116 116
 			return $this->sessionSecret;
117 117
 		}
118 118
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		 * Set the initializer vector for openssl 
122 122
 		 * @param string $key the session secret used in base64 format
123 123
 		 */
124
-		public function setInitializerVector($key){
124
+		public function setInitializerVector($key) {
125 125
 			$ivLength = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
126 126
 			$key = base64_decode($key);
127 127
 			$this->iv = substr(hash('sha256', $key), 0, $ivLength);
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		 * Return the initializer vector
133 133
 		 * @return string 
134 134
 		 */
135
-		public function getInitializerVector(){
135
+		public function getInitializerVector() {
136 136
 			return $this->iv;
137 137
 		}
138 138
 
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
 		 * @param  string $sessionName the session name
143 143
 		 * @return boolean 
144 144
 		 */
145
-		public function open($savePath, $sessionName){
145
+		public function open($savePath, $sessionName) {
146 146
 			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
147 147
 			//try to check if session secret is set before
148 148
 			$secret = $this->getSessionSecret();
149
-			if (empty($secret)){
149
+			if (empty($secret)) {
150 150
 				$secret = get_config('session_secret', null);
151 151
 				$this->setSessionSecret($secret);
152 152
 			}
153 153
 			$this->logger->info('Session secret: ' . $secret);
154 154
 
155
-			if (! is_object($this->modelInstance)){
155
+			if (!is_object($this->modelInstance)) {
156 156
 				$this->setModelInstanceFromConfig();
157 157
 			}
158 158
 			$this->setInitializerVector($secret);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 			//set session tables columns
161 161
 			$this->sessionTableColumns = $this->modelInstance->getSessionTableColumns();
162 162
 
163
-			if (empty($this->sessionTableColumns)){
163
+			if (empty($this->sessionTableColumns)) {
164 164
 				show_error('The session handler is "database" but the table columns not set');
165 165
 			}
166 166
 			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 		 * Close the session
177 177
 		 * @return boolean
178 178
 		 */
179
-		public function close(){
179
+		public function close() {
180 180
 			$this->logger->debug('Closing database session handler');
181 181
 			return true;
182 182
 		}
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		 * @param  string $sid the session id to use
187 187
 		 * @return string      the session data in serialiaze format
188 188
 		 */
189
-		public function read($sid){
189
+		public function read($sid) {
190 190
 			$this->logger->debug('Reading database session data for SID: ' . $sid);
191 191
 			$instance = $this->getModelInstance();
192 192
 			$columns = $this->sessionTableColumns;
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 			
196 196
 			$ip = get_ip();
197 197
 			$host = @gethostbyaddr($ip) or null;
198
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
198
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
199 199
 			
200 200
 			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
201
-			if ($data && isset($data->{$columns['sdata']})){
201
+			if ($data && isset($data->{$columns['sdata']})) {
202 202
 				//checking inactivity 
203 203
 				$timeInactivity = time() - get_config('session_inactivity_time', 100);
204
-				if ($data->{$columns['stime']} < $timeInactivity){
204
+				if ($data->{$columns['stime']} < $timeInactivity) {
205 205
 					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
206 206
 					$this->destroy($sid);
207 207
 					return null;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 		 * @param  mixed $data the session data to save in serialize format
219 219
 		 * @return boolean 
220 220
 		 */
221
-		public function write($sid, $data){
221
+		public function write($sid, $data) {
222 222
 			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
223 223
 			$instance = $this->getModelInstance();
224 224
 			$columns = $this->sessionTableColumns;
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 			$ip = get_ip();
230 230
 			$keyValue = $instance->getKeyValue();
231 231
 			$host = @gethostbyaddr($ip) or null;
232
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
232
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
233 233
 			$data = $this->encode($data);
234 234
 			$params = array(
235 235
 							$columns['sid'] => $sid,
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 						);
243 243
 			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
244 244
 			$exists = $instance->get($sid);
245
-			if ($exists){
245
+			if ($exists) {
246 246
 				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
247 247
 				//update
248 248
 				unset($params[$columns['sid']]);
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		 * @param  string $sid the session id value
260 260
 		 * @return boolean
261 261
 		 */
262
-		public function destroy($sid){
262
+		public function destroy($sid) {
263 263
 			$this->logger->debug('Destroy of session data for SID: ' . $sid);
264 264
 			$instance = $this->modelInstance;
265 265
 			$instance->delete($sid);
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		 * @param  integer $maxLifetime the max lifetime
272 272
 		 * @return boolean
273 273
 		 */
274
-		public function gc($maxLifetime){
274
+		public function gc($maxLifetime) {
275 275
 			$instance = $this->modelInstance;
276 276
 			$time = time() - $maxLifetime;
277 277
 			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -284,9 +284,9 @@  discard block
 block discarded – undo
284 284
 		 * @param  mixed $data the session data to encode
285 285
 		 * @return mixed the encoded session data
286 286
 		 */
287
-		public function encode($data){
287
+		public function encode($data) {
288 288
 			$key = base64_decode($this->sessionSecret);
289
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
289
+			$dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
290 290
 			$output = base64_encode($dataEncrypted);
291 291
 			return $output;
292 292
 		}
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 		 * @param  mixed $data the data to decode
298 298
 		 * @return mixed       the decoded data
299 299
 		 */
300
-		public function decode($data){
300
+		public function decode($data) {
301 301
 			$key = base64_decode($this->sessionSecret);
302 302
 			$data = base64_decode($data);
303 303
 			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
          * Return the loader instance
310 310
          * @return object Loader the loader instance
311 311
          */
312
-        public function getLoader(){
312
+        public function getLoader() {
313 313
             return $this->loader;
314 314
         }
315 315
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
          * set the loader instance for future use
318 318
          * @param object Loader $loader the loader object
319 319
          */
320
-         public function setLoader($loader){
320
+         public function setLoader($loader) {
321 321
             $this->loader = $loader;
322 322
             return $this;
323 323
         }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
          * Return the model instance
327 327
          * @return object DBSessionHandlerModel the model instance
328 328
          */
329
-        public function getModelInstance(){
329
+        public function getModelInstance() {
330 330
             return $this->modelInstance;
331 331
         }
332 332
 
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
          * set the model instance for future use
335 335
          * @param DBSessionHandlerModel $modelInstance the model object
336 336
          */
337
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
337
+         public function setModelInstance(DBSessionHandlerModel $modelInstance) {
338 338
             $this->modelInstance = $modelInstance;
339 339
             return $this;
340 340
         }
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 	     * Return the Log instance
344 344
 	     * @return Log
345 345
 	     */
346
-	    public function getLogger(){
346
+	    public function getLogger() {
347 347
 	      return $this->logger;
348 348
 	    }
349 349
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	     * Set the log instance
352 352
 	     * @param Log $logger the log object
353 353
 	     */
354
-	    public function setLogger(Log $logger){
354
+	    public function setLogger(Log $logger) {
355 355
 	      $this->logger = $logger;
356 356
 	      return $this;
357 357
 	    }
@@ -366,12 +366,12 @@  discard block
 block discarded – undo
366 366
 	     *
367 367
 	     * @return object this current instance
368 368
 	     */
369
-	    protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes'){
370
-	      if ($instance !== null){
369
+	    protected function setDependencyInstanceFromParamOrCreate($name, $instance = null, $loadClassName = null, $loadClassePath = 'classes') {
370
+	      if ($instance !== null) {
371 371
 	        $this->{$name} = $instance;
372 372
 	        return $this;
373 373
 	      }
374
-	      $this->{$name} =& class_loader($loadClassName, $loadClassePath);
374
+	      $this->{$name} = & class_loader($loadClassName, $loadClassePath);
375 375
 	      return $this;
376 376
 	    }
377 377
 	    
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
 	     *
382 382
 	     * @return object this current instance
383 383
 	     */
384
-	    protected function setLoggerFromParamOrCreate(Log $logger = null){
384
+	    protected function setLoggerFromParamOrCreate(Log $logger = null) {
385 385
 	      $this->setDependencyInstanceFromParamOrCreate('logger', $logger, 'Log', 'classes');
386
-	      if ($logger === null){
386
+	      if ($logger === null) {
387 387
 	        $this->logger->setLogger('Library::DBSessionHandler');
388 388
 	      }
389 389
 	      return $this;
@@ -392,13 +392,13 @@  discard block
 block discarded – undo
392 392
 	    /**
393 393
 	     * Set the model instance using the configuration for session
394 394
 	     */
395
-	    protected function setModelInstanceFromConfig(){
395
+	    protected function setModelInstanceFromConfig() {
396 396
 	    	$modelName = get_config('session_save_path');
397 397
 			$this->logger->info('The database session model: ' . $modelName);
398 398
 			$this->loader->model($modelName, 'dbsessionhandlerinstance'); 
399 399
 			//@codeCoverageIgnoreStart
400 400
             if (isset($this->OBJ->dbsessionhandlerinstance) 
401
-            	&& ! ($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
401
+            	&& !($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
402 402
             ) {
403 403
 				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
404 404
 			}  
Please login to merge, or discard this patch.
core/libraries/Form.php 2 patches
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -1,322 +1,322 @@
 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 27
 
28
-	class Form{
28
+    class Form{
29 29
 
30
-		/**
31
-		 * Generate the form opened tag
32
-		 * @param  string $path       the form action path
33
-		 * @param  array  $attributes the additional form attributes
34
-		 * @param  string $method     the form method like 'GET', 'POST'
35
-		 * @param  string $enctype    the form enctype like "multipart/form-data"
36
-		 * @return string             the generated form html
37
-		 */
38
-		public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){
39
-			if($path){
40
-				$path = Url::site_url($path);
41
-			}
42
-			$method = strtoupper($method);
43
-			$str = null;
44
-			$str .= '<form action = "'.$path.'" method = "'.$method.'"';
45
-			if(! empty($enctype)){
46
-				$str .= ' enctype = "'.$enctype.'" ';
47
-			}
48
-			if(! isset($attributes['accept-charset'])){
49
-				$attributes['accept-charset'] = get_config('charset', 'utf-8');
50
-			}
51
-			$str .= attributes_to_string($attributes);
52
-			$str .= '>';
53
-			//if CSRF is enabled in the configuration
54
-			if(get_config('csrf_enable', false) && $method == 'POST'){
55
-				$csrfValue = Security::generateCSRF();
56
-				$csrfName = get_config('csrf_key', 'csrf_key');
57
-				$str .= static::hidden($csrfName, $csrfValue);
58
-			}
59
-			return $str;
60
-		}
30
+        /**
31
+         * Generate the form opened tag
32
+         * @param  string $path       the form action path
33
+         * @param  array  $attributes the additional form attributes
34
+         * @param  string $method     the form method like 'GET', 'POST'
35
+         * @param  string $enctype    the form enctype like "multipart/form-data"
36
+         * @return string             the generated form html
37
+         */
38
+        public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){
39
+            if($path){
40
+                $path = Url::site_url($path);
41
+            }
42
+            $method = strtoupper($method);
43
+            $str = null;
44
+            $str .= '<form action = "'.$path.'" method = "'.$method.'"';
45
+            if(! empty($enctype)){
46
+                $str .= ' enctype = "'.$enctype.'" ';
47
+            }
48
+            if(! isset($attributes['accept-charset'])){
49
+                $attributes['accept-charset'] = get_config('charset', 'utf-8');
50
+            }
51
+            $str .= attributes_to_string($attributes);
52
+            $str .= '>';
53
+            //if CSRF is enabled in the configuration
54
+            if(get_config('csrf_enable', false) && $method == 'POST'){
55
+                $csrfValue = Security::generateCSRF();
56
+                $csrfName = get_config('csrf_key', 'csrf_key');
57
+                $str .= static::hidden($csrfName, $csrfValue);
58
+            }
59
+            return $str;
60
+        }
61 61
 
62
-		/**
63
-		 * Generate the form opened tag for multipart like to send a file
64
-		 * @see Form::open() for more details
65
-		 * @return string the generated multipart form html
66
-		 */
67
-		public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){
68
-			return self::open($path, $attributes, $method, 'multipart/form-data');
69
-		}
62
+        /**
63
+         * Generate the form opened tag for multipart like to send a file
64
+         * @see Form::open() for more details
65
+         * @return string the generated multipart form html
66
+         */
67
+        public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){
68
+            return self::open($path, $attributes, $method, 'multipart/form-data');
69
+        }
70 70
 
71
-		/**
72
-		 * Generate the form close
73
-		 * @return string the form close html
74
-		 */
75
-		public static function close(){
76
-			return '</form>';
77
-		}
71
+        /**
72
+         * Generate the form close
73
+         * @return string the form close html
74
+         */
75
+        public static function close(){
76
+            return '</form>';
77
+        }
78 78
 
79
-		/**
80
-		 * Generate the form fieldset & legend
81
-		 * @param  string $legend the legend tag value
82
-		 * @param  array  $fieldsetAttributes the fieldset additional HTML attributes
83
-		 * @param  array  $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty
84
-		 * @return string         the generated fieldset value
85
-		 */
86
-		public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){
87
-			$str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>';
88
-			if($legend){
89
-				$str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>';
90
-			}
91
-			return $str;
92
-		}
79
+        /**
80
+         * Generate the form fieldset & legend
81
+         * @param  string $legend the legend tag value
82
+         * @param  array  $fieldsetAttributes the fieldset additional HTML attributes
83
+         * @param  array  $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty
84
+         * @return string         the generated fieldset value
85
+         */
86
+        public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){
87
+            $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>';
88
+            if($legend){
89
+                $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>';
90
+            }
91
+            return $str;
92
+        }
93 93
 
94
-		/**
95
-		 * Generate the fieldset close tag
96
-		 * @return string the generated html for fieldset close
97
-		 */
98
-		public static function fieldsetClose(){
99
-			return '</fieldset>';
100
-		}
94
+        /**
95
+         * Generate the fieldset close tag
96
+         * @return string the generated html for fieldset close
97
+         */
98
+        public static function fieldsetClose(){
99
+            return '</fieldset>';
100
+        }
101 101
 
102
-		/**
103
-		 * Get the error message for the given form field name.
104
-		 * This use the form validation information to get the error information.
105
-		 * @param  string $name the form field name
106
-		 * @return string       the error message if exists and null if not
107
-		 */
108
-		public static function error($name){
109
-			$return = null;
110
-			$obj = & get_instance();
111
-			if(isset($obj->formvalidation)){
112
-				$errors = $obj->formvalidation->returnErrors();
113
-				if(isset($errors[$name])){
114
-					list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter();
115
-					$return = $errorStart . $errors[$name] . $errorEnd;
116
-				}
117
-			}
118
-			return $return;
119
-		}
102
+        /**
103
+         * Get the error message for the given form field name.
104
+         * This use the form validation information to get the error information.
105
+         * @param  string $name the form field name
106
+         * @return string       the error message if exists and null if not
107
+         */
108
+        public static function error($name){
109
+            $return = null;
110
+            $obj = & get_instance();
111
+            if(isset($obj->formvalidation)){
112
+                $errors = $obj->formvalidation->returnErrors();
113
+                if(isset($errors[$name])){
114
+                    list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter();
115
+                    $return = $errorStart . $errors[$name] . $errorEnd;
116
+                }
117
+            }
118
+            return $return;
119
+        }
120 120
 
121
-		/**
122
-		 * Get the form field value
123
-		 * @param  string $name    the form field name
124
-		 * @param  mixed $default the default value if can not found the given form field name
125
-		 * @return mixed the form field value if is set, otherwise return the default value.
126
-		 */
127
-		public static function value($name, $default = null){
128
-			$value = get_instance()->request->query($name);
129
-			if(strlen($value) > 0){
130
-				return $value;
131
-			}
132
-			return $default;
133
-		}
121
+        /**
122
+         * Get the form field value
123
+         * @param  string $name    the form field name
124
+         * @param  mixed $default the default value if can not found the given form field name
125
+         * @return mixed the form field value if is set, otherwise return the default value.
126
+         */
127
+        public static function value($name, $default = null){
128
+            $value = get_instance()->request->query($name);
129
+            if(strlen($value) > 0){
130
+                return $value;
131
+            }
132
+            return $default;
133
+        }
134 134
 
135
-		/**
136
-		 * Generate the form label html content
137
-		 * @param  string $label      the title of the label
138
-		 * @param  string $for        the value of the label "for" attribute
139
-		 * @param  array  $attributes the additional attributes to be added
140
-		 * @return string the generated label html content
141
-		 */
142
-		public static function label($label, $for = '', array $attributes = array()){
143
-			$str = '<label';
144
-			if($for){
145
-				$str .= ' for = "'.$for.'"';
146
-			}
147
-			$str .= attributes_to_string($attributes);
148
-			$str .= '>';
149
-			$str .= $label.'</label>';
150
-			return $str;
151
-		}
135
+        /**
136
+         * Generate the form label html content
137
+         * @param  string $label      the title of the label
138
+         * @param  string $for        the value of the label "for" attribute
139
+         * @param  array  $attributes the additional attributes to be added
140
+         * @return string the generated label html content
141
+         */
142
+        public static function label($label, $for = '', array $attributes = array()){
143
+            $str = '<label';
144
+            if($for){
145
+                $str .= ' for = "'.$for.'"';
146
+            }
147
+            $str .= attributes_to_string($attributes);
148
+            $str .= '>';
149
+            $str .= $label.'</label>';
150
+            return $str;
151
+        }
152 152
 
153
-		/**
154
-		 * Generate the form field for input like "text", "email", "password", etc.
155
-		 * @param  string $name       the form field name
156
-		 * @param  mixed $value      the form field value to be set
157
-		 * @param  array  $attributes the additional attributes to be added in the form input
158
-		 * @param  string $type       the type of the form field (password, text, submit, button, etc.)
159
-		 * @return string             the generated form field html content for the input
160
-		 */
161
-		public static function input($name, $value = null, array $attributes = array(), $type = 'text'){
162
-			$str = null;
163
-			$str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"';
164
-			$str .= attributes_to_string($attributes);
165
-			$str .= '/>';
166
-			return $str;
167
-		}
153
+        /**
154
+         * Generate the form field for input like "text", "email", "password", etc.
155
+         * @param  string $name       the form field name
156
+         * @param  mixed $value      the form field value to be set
157
+         * @param  array  $attributes the additional attributes to be added in the form input
158
+         * @param  string $type       the type of the form field (password, text, submit, button, etc.)
159
+         * @return string             the generated form field html content for the input
160
+         */
161
+        public static function input($name, $value = null, array $attributes = array(), $type = 'text'){
162
+            $str = null;
163
+            $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"';
164
+            $str .= attributes_to_string($attributes);
165
+            $str .= '/>';
166
+            return $str;
167
+        }
168 168
 		
169
-		/**
170
-		 * Generate the form field for "text"
171
-		 * @see Form::input() for more details
172
-		 */
173
-		public static function text($name, $value = null, array $attributes = array()){
174
-			return self::input($name, $value, $attributes, 'text');
175
-		}
169
+        /**
170
+         * Generate the form field for "text"
171
+         * @see Form::input() for more details
172
+         */
173
+        public static function text($name, $value = null, array $attributes = array()){
174
+            return self::input($name, $value, $attributes, 'text');
175
+        }
176 176
 
177
-		/**
178
-		 * Generate the form field for "password"
179
-		 * @see Form::input() for more details
180
-		 */
181
-		public static function password($name, $value = null, array $attributes = array()){
182
-			return self::input($name, $value, $attributes, 'password');
183
-		}
177
+        /**
178
+         * Generate the form field for "password"
179
+         * @see Form::input() for more details
180
+         */
181
+        public static function password($name, $value = null, array $attributes = array()){
182
+            return self::input($name, $value, $attributes, 'password');
183
+        }
184 184
 
185
-		/**
186
-		 * Generate the form field for "radio"
187
-		 * @see Form::input() for more details
188
-		 */
189
-		public static function radio($name, $value = null,  $checked = false, array $attributes = array()){
190
-			if($checked){
191
-				$attributes['checked'] = true;
192
-			}
193
-			return self::input($name, $value, $attributes, 'radio');
194
-		}
185
+        /**
186
+         * Generate the form field for "radio"
187
+         * @see Form::input() for more details
188
+         */
189
+        public static function radio($name, $value = null,  $checked = false, array $attributes = array()){
190
+            if($checked){
191
+                $attributes['checked'] = true;
192
+            }
193
+            return self::input($name, $value, $attributes, 'radio');
194
+        }
195 195
 
196
-		/**
197
-		 * Generate the form field for "checkbox"
198
-		 * @see Form::input() for more details
199
-		 */
200
-		public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){
201
-			if($checked){
202
-				$attributes['checked'] = true;
203
-			}
204
-			return self::input($name, $value, $attributes, 'checkbox');
205
-		}
196
+        /**
197
+         * Generate the form field for "checkbox"
198
+         * @see Form::input() for more details
199
+         */
200
+        public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){
201
+            if($checked){
202
+                $attributes['checked'] = true;
203
+            }
204
+            return self::input($name, $value, $attributes, 'checkbox');
205
+        }
206 206
 
207
-		/**
208
-		 * Generate the form field for "number"
209
-		 * @see Form::input() for more details
210
-		 */
211
-		public static function number($name, $value = null, array $attributes = array()){
212
-			return self::input($name, $value, $attributes, 'number');
213
-		}
207
+        /**
208
+         * Generate the form field for "number"
209
+         * @see Form::input() for more details
210
+         */
211
+        public static function number($name, $value = null, array $attributes = array()){
212
+            return self::input($name, $value, $attributes, 'number');
213
+        }
214 214
 
215
-		/**
216
-		 * Generate the form field for "phone"
217
-		 * @see Form::input() for more details
218
-		 */
219
-		public static function phone($name, $value = null, array $attributes = array()){
220
-			return self::input($name, $value, $attributes, 'phone');
221
-		}
215
+        /**
216
+         * Generate the form field for "phone"
217
+         * @see Form::input() for more details
218
+         */
219
+        public static function phone($name, $value = null, array $attributes = array()){
220
+            return self::input($name, $value, $attributes, 'phone');
221
+        }
222 222
 
223
-		/**
224
-		 * Generate the form field for "email"
225
-		 * @see Form::input() for more details
226
-		 */
227
-		public static function email($name, $value = null, array $attributes = array()){
228
-			return self::input($name, $value, $attributes, 'email');
229
-		}
223
+        /**
224
+         * Generate the form field for "email"
225
+         * @see Form::input() for more details
226
+         */
227
+        public static function email($name, $value = null, array $attributes = array()){
228
+            return self::input($name, $value, $attributes, 'email');
229
+        }
230 230
 		
231
-		/**
232
-		 * Generate the form field for "search"
233
-		 * @see Form::input() for more details
234
-		 */
235
-		public static function search($name, $value = null, array $attributes = array()){
236
-			return self::input($name, $value, $attributes, 'search');
237
-		}
231
+        /**
232
+         * Generate the form field for "search"
233
+         * @see Form::input() for more details
234
+         */
235
+        public static function search($name, $value = null, array $attributes = array()){
236
+            return self::input($name, $value, $attributes, 'search');
237
+        }
238 238
 		
239
-		/**
240
-		 * Generate the form field for "hidden"
241
-		 * @see Form::input() for more details
242
-		 */
243
-		public static function hidden($name, $value = null, array $attributes = array()){
244
-			return self::input($name, $value, $attributes, 'hidden');
245
-		}
239
+        /**
240
+         * Generate the form field for "hidden"
241
+         * @see Form::input() for more details
242
+         */
243
+        public static function hidden($name, $value = null, array $attributes = array()){
244
+            return self::input($name, $value, $attributes, 'hidden');
245
+        }
246 246
 		
247
-		/**
248
-		 * Generate the form field for "file"
249
-		 * @see Form::input() for more details
250
-		 */
251
-		public static function file($name, array $attributes = array()){
252
-			return self::input($name, null, $attributes, 'file');
253
-		}
247
+        /**
248
+         * Generate the form field for "file"
249
+         * @see Form::input() for more details
250
+         */
251
+        public static function file($name, array $attributes = array()){
252
+            return self::input($name, null, $attributes, 'file');
253
+        }
254 254
 		
255
-		/**
256
-		 * Generate the form field for "button"
257
-		 * @see Form::input() for more details
258
-		 */
259
-		public static function button($name, $value = null, array $attributes = array()){
260
-			return self::input($name, $value, $attributes, 'button');
261
-		}
255
+        /**
256
+         * Generate the form field for "button"
257
+         * @see Form::input() for more details
258
+         */
259
+        public static function button($name, $value = null, array $attributes = array()){
260
+            return self::input($name, $value, $attributes, 'button');
261
+        }
262 262
 		
263
-		/**
264
-		 * Generate the form field for "reset"
265
-		 * @see Form::input() for more details
266
-		 */
267
-		public static function reset($name, $value = null, array $attributes = array()){
268
-			return self::input($name, $value, $attributes, 'reset');
269
-		}
263
+        /**
264
+         * Generate the form field for "reset"
265
+         * @see Form::input() for more details
266
+         */
267
+        public static function reset($name, $value = null, array $attributes = array()){
268
+            return self::input($name, $value, $attributes, 'reset');
269
+        }
270 270
 		
271
-		/**
272
-		 * Generate the form field for "submit"
273
-		 * @see Form::input() for more details
274
-		 */
275
-		public static function submit($name, $value = null, array $attributes = array()){
276
-			return self::input($name, $value, $attributes, 'submit');
277
-		}
271
+        /**
272
+         * Generate the form field for "submit"
273
+         * @see Form::input() for more details
274
+         */
275
+        public static function submit($name, $value = null, array $attributes = array()){
276
+            return self::input($name, $value, $attributes, 'submit');
277
+        }
278 278
 
279
-		/**
280
-		 * Generate the form field for textarea
281
-		 * @param  string $name       the name of the textarea field
282
-		 * @param  string $value      the textarea field value
283
-		 * @param  array  $attributes the additional attributes to be added
284
-		 * @return string             the generated textarea form html content
285
-		 */
286
-		public static function textarea($name, $value = '', array $attributes = array()){
287
-			$str = null;
288
-			$str .= '<textarea name = "'.$name.'"';
289
-			$str .= attributes_to_string($attributes);
290
-			$str .= '>';
291
-			$str .= $value.'</textarea>';
292
-			return $str;
293
-		}
279
+        /**
280
+         * Generate the form field for textarea
281
+         * @param  string $name       the name of the textarea field
282
+         * @param  string $value      the textarea field value
283
+         * @param  array  $attributes the additional attributes to be added
284
+         * @return string             the generated textarea form html content
285
+         */
286
+        public static function textarea($name, $value = '', array $attributes = array()){
287
+            $str = null;
288
+            $str .= '<textarea name = "'.$name.'"';
289
+            $str .= attributes_to_string($attributes);
290
+            $str .= '>';
291
+            $str .= $value.'</textarea>';
292
+            return $str;
293
+        }
294 294
 		
295
-		/**
296
-		 * Generate the form field for select
297
-		 * @param  string $name       the name of the form field
298
-		 * @param  mixed|array $values      the values used to populate the "option" tags
299
-		 * @param  mixed $selected   the selected value in the option list
300
-		 * @param  array  $attributes the additional attribute to be added
301
-		 * @return string             the generated form field html content for select
302
-		 */
303
-		public static function select($name, $values = null, $selected = null, array $attributes = array()){
304
-			if(! is_array($values)){
305
-				$values = array('' => $values);
306
-			}
307
-			$str = null;
308
-			$str .= '<select name = "'.$name.'"';
309
-			$str .= attributes_to_string($attributes);
310
-			$str .= '>';
311
-			foreach($values as $key => $val){
312
-				$select = '';
313
-				if($key == $selected){
314
-					$select = 'selected';
315
-				}
316
-				$str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>';
317
-			}
318
-			$str .= '</select>';
319
-			return $str;
320
-		}
295
+        /**
296
+         * Generate the form field for select
297
+         * @param  string $name       the name of the form field
298
+         * @param  mixed|array $values      the values used to populate the "option" tags
299
+         * @param  mixed $selected   the selected value in the option list
300
+         * @param  array  $attributes the additional attribute to be added
301
+         * @return string             the generated form field html content for select
302
+         */
303
+        public static function select($name, $values = null, $selected = null, array $attributes = array()){
304
+            if(! is_array($values)){
305
+                $values = array('' => $values);
306
+            }
307
+            $str = null;
308
+            $str .= '<select name = "'.$name.'"';
309
+            $str .= attributes_to_string($attributes);
310
+            $str .= '>';
311
+            foreach($values as $key => $val){
312
+                $select = '';
313
+                if($key == $selected){
314
+                    $select = 'selected';
315
+                }
316
+                $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>';
317
+            }
318
+            $str .= '</select>';
319
+            return $str;
320
+        }
321 321
 
322
-	}
322
+    }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Form{
28
+	class Form {
29 29
 
30 30
 		/**
31 31
 		 * Generate the form opened tag
@@ -35,23 +35,23 @@  discard block
 block discarded – undo
35 35
 		 * @param  string $enctype    the form enctype like "multipart/form-data"
36 36
 		 * @return string             the generated form html
37 37
 		 */
38
-		public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){
39
-			if($path){
38
+		public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null) {
39
+			if ($path) {
40 40
 				$path = Url::site_url($path);
41 41
 			}
42 42
 			$method = strtoupper($method);
43 43
 			$str = null;
44
-			$str .= '<form action = "'.$path.'" method = "'.$method.'"';
45
-			if(! empty($enctype)){
46
-				$str .= ' enctype = "'.$enctype.'" ';
44
+			$str .= '<form action = "' . $path . '" method = "' . $method . '"';
45
+			if (!empty($enctype)) {
46
+				$str .= ' enctype = "' . $enctype . '" ';
47 47
 			}
48
-			if(! isset($attributes['accept-charset'])){
48
+			if (!isset($attributes['accept-charset'])) {
49 49
 				$attributes['accept-charset'] = get_config('charset', 'utf-8');
50 50
 			}
51 51
 			$str .= attributes_to_string($attributes);
52 52
 			$str .= '>';
53 53
 			//if CSRF is enabled in the configuration
54
-			if(get_config('csrf_enable', false) && $method == 'POST'){
54
+			if (get_config('csrf_enable', false) && $method == 'POST') {
55 55
 				$csrfValue = Security::generateCSRF();
56 56
 				$csrfName = get_config('csrf_key', 'csrf_key');
57 57
 				$str .= static::hidden($csrfName, $csrfValue);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		 * @see Form::open() for more details
65 65
 		 * @return string the generated multipart form html
66 66
 		 */
67
-		public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){
67
+		public static function openMultipart($path = null, array $attributes = array(), $method = 'POST') {
68 68
 			return self::open($path, $attributes, $method, 'multipart/form-data');
69 69
 		}
70 70
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		 * Generate the form close
73 73
 		 * @return string the form close html
74 74
 		 */
75
-		public static function close(){
75
+		public static function close() {
76 76
 			return '</form>';
77 77
 		}
78 78
 
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 		 * @param  array  $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty
84 84
 		 * @return string         the generated fieldset value
85 85
 		 */
86
-		public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){
86
+		public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()) {
87 87
 			$str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>';
88
-			if($legend){
89
-				$str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>';
88
+			if ($legend) {
89
+				$str .= '<legend' . attributes_to_string($legendAttributes) . '>' . $legend . '</legend>';
90 90
 			}
91 91
 			return $str;
92 92
 		}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * Generate the fieldset close tag
96 96
 		 * @return string the generated html for fieldset close
97 97
 		 */
98
-		public static function fieldsetClose(){
98
+		public static function fieldsetClose() {
99 99
 			return '</fieldset>';
100 100
 		}
101 101
 
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
 		 * @param  string $name the form field name
106 106
 		 * @return string       the error message if exists and null if not
107 107
 		 */
108
-		public static function error($name){
108
+		public static function error($name) {
109 109
 			$return = null;
110 110
 			$obj = & get_instance();
111
-			if(isset($obj->formvalidation)){
111
+			if (isset($obj->formvalidation)) {
112 112
 				$errors = $obj->formvalidation->returnErrors();
113
-				if(isset($errors[$name])){
113
+				if (isset($errors[$name])) {
114 114
 					list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter();
115 115
 					$return = $errorStart . $errors[$name] . $errorEnd;
116 116
 				}
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 		 * @param  mixed $default the default value if can not found the given form field name
125 125
 		 * @return mixed the form field value if is set, otherwise return the default value.
126 126
 		 */
127
-		public static function value($name, $default = null){
127
+		public static function value($name, $default = null) {
128 128
 			$value = get_instance()->request->query($name);
129
-			if(strlen($value) > 0){
129
+			if (strlen($value) > 0) {
130 130
 				return $value;
131 131
 			}
132 132
 			return $default;
@@ -139,14 +139,14 @@  discard block
 block discarded – undo
139 139
 		 * @param  array  $attributes the additional attributes to be added
140 140
 		 * @return string the generated label html content
141 141
 		 */
142
-		public static function label($label, $for = '', array $attributes = array()){
142
+		public static function label($label, $for = '', array $attributes = array()) {
143 143
 			$str = '<label';
144
-			if($for){
145
-				$str .= ' for = "'.$for.'"';
144
+			if ($for) {
145
+				$str .= ' for = "' . $for . '"';
146 146
 			}
147 147
 			$str .= attributes_to_string($attributes);
148 148
 			$str .= '>';
149
-			$str .= $label.'</label>';
149
+			$str .= $label . '</label>';
150 150
 			return $str;
151 151
 		}
152 152
 
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
 		 * @param  string $type       the type of the form field (password, text, submit, button, etc.)
159 159
 		 * @return string             the generated form field html content for the input
160 160
 		 */
161
-		public static function input($name, $value = null, array $attributes = array(), $type = 'text'){
161
+		public static function input($name, $value = null, array $attributes = array(), $type = 'text') {
162 162
 			$str = null;
163
-			$str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"';
163
+			$str .= '<input name = "' . $name . '" value = "' . $value . '" type = "' . $type . '"';
164 164
 			$str .= attributes_to_string($attributes);
165 165
 			$str .= '/>';
166 166
 			return $str;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		 * Generate the form field for "text"
171 171
 		 * @see Form::input() for more details
172 172
 		 */
173
-		public static function text($name, $value = null, array $attributes = array()){
173
+		public static function text($name, $value = null, array $attributes = array()) {
174 174
 			return self::input($name, $value, $attributes, 'text');
175 175
 		}
176 176
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 		 * Generate the form field for "password"
179 179
 		 * @see Form::input() for more details
180 180
 		 */
181
-		public static function password($name, $value = null, array $attributes = array()){
181
+		public static function password($name, $value = null, array $attributes = array()) {
182 182
 			return self::input($name, $value, $attributes, 'password');
183 183
 		}
184 184
 
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 		 * Generate the form field for "radio"
187 187
 		 * @see Form::input() for more details
188 188
 		 */
189
-		public static function radio($name, $value = null,  $checked = false, array $attributes = array()){
190
-			if($checked){
189
+		public static function radio($name, $value = null, $checked = false, array $attributes = array()) {
190
+			if ($checked) {
191 191
 				$attributes['checked'] = true;
192 192
 			}
193 193
 			return self::input($name, $value, $attributes, 'radio');
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 		 * Generate the form field for "checkbox"
198 198
 		 * @see Form::input() for more details
199 199
 		 */
200
-		public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){
201
-			if($checked){
200
+		public static function checkbox($name, $value = null, $checked = false, array $attributes = array()) {
201
+			if ($checked) {
202 202
 				$attributes['checked'] = true;
203 203
 			}
204 204
 			return self::input($name, $value, $attributes, 'checkbox');
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 		 * Generate the form field for "number"
209 209
 		 * @see Form::input() for more details
210 210
 		 */
211
-		public static function number($name, $value = null, array $attributes = array()){
211
+		public static function number($name, $value = null, array $attributes = array()) {
212 212
 			return self::input($name, $value, $attributes, 'number');
213 213
 		}
214 214
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 		 * Generate the form field for "phone"
217 217
 		 * @see Form::input() for more details
218 218
 		 */
219
-		public static function phone($name, $value = null, array $attributes = array()){
219
+		public static function phone($name, $value = null, array $attributes = array()) {
220 220
 			return self::input($name, $value, $attributes, 'phone');
221 221
 		}
222 222
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		 * Generate the form field for "email"
225 225
 		 * @see Form::input() for more details
226 226
 		 */
227
-		public static function email($name, $value = null, array $attributes = array()){
227
+		public static function email($name, $value = null, array $attributes = array()) {
228 228
 			return self::input($name, $value, $attributes, 'email');
229 229
 		}
230 230
 		
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		 * Generate the form field for "search"
233 233
 		 * @see Form::input() for more details
234 234
 		 */
235
-		public static function search($name, $value = null, array $attributes = array()){
235
+		public static function search($name, $value = null, array $attributes = array()) {
236 236
 			return self::input($name, $value, $attributes, 'search');
237 237
 		}
238 238
 		
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 		 * Generate the form field for "hidden"
241 241
 		 * @see Form::input() for more details
242 242
 		 */
243
-		public static function hidden($name, $value = null, array $attributes = array()){
243
+		public static function hidden($name, $value = null, array $attributes = array()) {
244 244
 			return self::input($name, $value, $attributes, 'hidden');
245 245
 		}
246 246
 		
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 		 * Generate the form field for "file"
249 249
 		 * @see Form::input() for more details
250 250
 		 */
251
-		public static function file($name, array $attributes = array()){
251
+		public static function file($name, array $attributes = array()) {
252 252
 			return self::input($name, null, $attributes, 'file');
253 253
 		}
254 254
 		
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 		 * Generate the form field for "button"
257 257
 		 * @see Form::input() for more details
258 258
 		 */
259
-		public static function button($name, $value = null, array $attributes = array()){
259
+		public static function button($name, $value = null, array $attributes = array()) {
260 260
 			return self::input($name, $value, $attributes, 'button');
261 261
 		}
262 262
 		
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 		 * Generate the form field for "reset"
265 265
 		 * @see Form::input() for more details
266 266
 		 */
267
-		public static function reset($name, $value = null, array $attributes = array()){
267
+		public static function reset($name, $value = null, array $attributes = array()) {
268 268
 			return self::input($name, $value, $attributes, 'reset');
269 269
 		}
270 270
 		
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 		 * Generate the form field for "submit"
273 273
 		 * @see Form::input() for more details
274 274
 		 */
275
-		public static function submit($name, $value = null, array $attributes = array()){
275
+		public static function submit($name, $value = null, array $attributes = array()) {
276 276
 			return self::input($name, $value, $attributes, 'submit');
277 277
 		}
278 278
 
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
 		 * @param  array  $attributes the additional attributes to be added
284 284
 		 * @return string             the generated textarea form html content
285 285
 		 */
286
-		public static function textarea($name, $value = '', array $attributes = array()){
286
+		public static function textarea($name, $value = '', array $attributes = array()) {
287 287
 			$str = null;
288
-			$str .= '<textarea name = "'.$name.'"';
288
+			$str .= '<textarea name = "' . $name . '"';
289 289
 			$str .= attributes_to_string($attributes);
290 290
 			$str .= '>';
291
-			$str .= $value.'</textarea>';
291
+			$str .= $value . '</textarea>';
292 292
 			return $str;
293 293
 		}
294 294
 		
@@ -300,20 +300,20 @@  discard block
 block discarded – undo
300 300
 		 * @param  array  $attributes the additional attribute to be added
301 301
 		 * @return string             the generated form field html content for select
302 302
 		 */
303
-		public static function select($name, $values = null, $selected = null, array $attributes = array()){
304
-			if(! is_array($values)){
303
+		public static function select($name, $values = null, $selected = null, array $attributes = array()) {
304
+			if (!is_array($values)) {
305 305
 				$values = array('' => $values);
306 306
 			}
307 307
 			$str = null;
308
-			$str .= '<select name = "'.$name.'"';
308
+			$str .= '<select name = "' . $name . '"';
309 309
 			$str .= attributes_to_string($attributes);
310 310
 			$str .= '>';
311
-			foreach($values as $key => $val){
311
+			foreach ($values as $key => $val) {
312 312
 				$select = '';
313
-				if($key == $selected){
313
+				if ($key == $selected) {
314 314
 					$select = 'selected';
315 315
 				}
316
-				$str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>';
316
+				$str .= '<option value = "' . $key . '" ' . $select . '>' . $val . '</option>';
317 317
 			}
318 318
 			$str .= '</select>';
319 319
 			return $str;
Please login to merge, or discard this patch.