Passed
Push — 1.0.0-dev ( 93958a...e1c8ef )
by nguereza
02:26
created
core/classes/Module.php 1 patch
Spacing   +40 added lines, -40 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 extends BaseStaticClass{
27
+	class Module extends BaseStaticClass {
28 28
 		
29 29
 		/**
30 30
 		 * list of loaded module
@@ -35,24 +35,24 @@  discard block
 block discarded – undo
35 35
 		/**
36 36
 		 * Initialise the module list by scanning the directory MODULE_PATH
37 37
 		 */
38
-		public function init(){
38
+		public function init() {
39 39
 			$logger = self::getLogger();
40 40
 			$logger->debug('Check if the application contains the modules ...');
41 41
 			$moduleDir = opendir(MODULE_PATH);
42
-			if (is_resource($moduleDir)){
43
-				while(($module = readdir($moduleDir)) !== false){
44
-					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){
42
+			if (is_resource($moduleDir)) {
43
+				while (($module = readdir($moduleDir)) !== false) {
44
+					if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) {
45 45
 						self::$list[] = $module;
46 46
 					}
47
-					else{
48
-						$logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name');
47
+					else {
48
+						$logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name');
49 49
 					}
50 50
 				}
51 51
 				closedir($moduleDir);
52 52
 			}
53 53
 			ksort(self::$list);
54 54
 			
55
-			if (! empty(self::$list)){
55
+			if (!empty(self::$list)) {
56 56
 				$logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']');
57 57
 			}
58 58
 		}
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		 *
65 65
 		 * @return object the current instance
66 66
 		 */
67
-		public function add($name){
67
+		public function add($name) {
68 68
 			self::$list[] = $name;
69 69
 			return $this;
70 70
 		}
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 		 * Get the list of the custom autoload configuration from module if exists
74 74
 		 * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values
75 75
 		 */
76
-		public static function getModulesAutoloadConfig(){
76
+		public static function getModulesAutoloadConfig() {
77 77
 			$logger = self::getLogger();
78
-			if (empty(self::$list)){
78
+			if (empty(self::$list)) {
79 79
 				$logger->info('No module was loaded skipping.');
80 80
 				return false;
81 81
 			}
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
 			
89 89
 			foreach (self::$list as $module) {
90 90
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php';
91
-				if (file_exists($file)){
91
+				if (file_exists($file)) {
92 92
 					$autoload = array();
93 93
 					require_once $file;
94
-					if (! empty($autoload) && is_array($autoload)){
94
+					if (!empty($autoload) && is_array($autoload)) {
95 95
 						$autoloads = array_merge_recursive($autoloads, $autoload);
96 96
 						unset($autoload);
97 97
 					}
@@ -104,19 +104,19 @@  discard block
 block discarded – undo
104 104
 		 * Get the list of the custom routes configuration from module if exists
105 105
 		 * @return array|boolean the routes list or false if no module contains the routes configuration
106 106
 		 */
107
-		public static function getModulesRoutesConfig(){
107
+		public static function getModulesRoutesConfig() {
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
 			}
113 113
 			$routes = array();
114 114
 			foreach (self::$list as $module) {
115 115
 				$file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php';
116
-				if (file_exists($file)){
116
+				if (file_exists($file)) {
117 117
 					$route = array();
118 118
 					require_once $file;
119
-					if (! empty($route) && is_array($route)){
119
+					if (!empty($route) && is_array($route)) {
120 120
 						$routes = array_merge($routes, $route);
121 121
 						unset($route);
122 122
 					}
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		 * @see Module::findClassInModuleFullFilePath
132 132
 		 * @return boolean|string  false or null if no module have this controller, path the full path of the controller
133 133
 		 */
134
-		public static function findControllerFullPath($class, $module = null){
134
+		public static function findControllerFullPath($class, $module = null) {
135 135
 			return self::findClassInModuleFullFilePath($class, $module, 'controllers');
136 136
 		}
137 137
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		 * @see Module::findClassInModuleFullFilePath
141 141
 		 * @return boolean|string  false or null if no module have this model, return the full path of this model
142 142
 		 */
143
-		public static function findModelFullPath($class, $module = null){
143
+		public static function findModelFullPath($class, $module = null) {
144 144
 			return self::findClassInModuleFullFilePath($class, $module, 'models');
145 145
 		}
146 146
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		 * @see Module::findClassInModuleFullFilePath
150 150
 		 * @return boolean|string  false or null if no module have this library,  return the full path of this library
151 151
 		 */
152
-		public static function findLibraryFullPath($class, $module = null){
152
+		public static function findLibraryFullPath($class, $module = null) {
153 153
 			return self::findClassInModuleFullFilePath($class, $module, 'libraries');
154 154
 		}
155 155
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 		 * @see  Module::findNonClassInModuleFullFilePath
160 160
 		 * @return boolean|string  false or null if no module have this configuration,  return the full path of this configuration
161 161
 		 */
162
-		public static function findConfigFullPath($configuration, $module = null){
162
+		public static function findConfigFullPath($configuration, $module = null) {
163 163
 			return self::findNonClassInModuleFullFilePath($configuration, $module, 'config');
164 164
 		}
165 165
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		 * @see  Module::findNonClassInModuleFullFilePath
169 169
 		 * @return boolean|string  false or null if no module have this helper,  return the full path of this helper
170 170
 		 */
171
-		public static function findFunctionFullPath($helper, $module = null){
171
+		public static function findFunctionFullPath($helper, $module = null) {
172 172
 			return self::findNonClassInModuleFullFilePath($helper, $module, 'functions');
173 173
 		}
174 174
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 		 * @see  Module::findNonClassInModuleFullFilePath
178 178
 		 * @return boolean|string  false or null if no module have this view, path the full path of the view
179 179
 		 */
180
-		public static function findViewFullPath($view, $module = null){
180
+		public static function findViewFullPath($view, $module = null) {
181 181
 			return self::findNonClassInModuleFullFilePath($view, $module, 'views');
182 182
 		}
183 183
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 		 * @see  Module::findNonClassInModuleFullFilePath
187 187
 		 * @return boolean|string  false or null if no module have this language,  return the full path of this language
188 188
 		 */
189
-		public static function findLanguageFullPath($language, $appLang, $module = null){
189
+		public static function findLanguageFullPath($language, $appLang, $module = null) {
190 190
 			return self::findNonClassInModuleFullFilePath($language, $module, 'lang', $appLang);
191 191
 		}
192 192
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 		 * Get the list of module loaded
195 195
 		 * @return array the module list
196 196
 		 */
197
-		public static function getModuleList(){
197
+		public static function getModuleList() {
198 198
 			return self::$list;
199 199
 		}
200 200
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		 * Check if the application has an module
203 203
 		 * @return boolean
204 204
 		 */
205
-		public static function hasModule(){
205
+		public static function hasModule() {
206 206
 			return !empty(self::$list);
207 207
 		}
208 208
 
@@ -214,18 +214,18 @@  discard block
 block discarded – undo
214 214
 		 * @return boolean|string  false or null if no module 
215 215
 		 * have this class, return the full path of the class
216 216
 		 */
217
-		protected static function findClassInModuleFullFilePath($class, $module, $type){
217
+		protected static function findClassInModuleFullFilePath($class, $module, $type) {
218 218
 			$logger = self::getLogger();
219 219
 		    $class = str_ireplace('.php', '', $class);
220 220
 		    $class = ucfirst($class);
221
-		    $classFile = $class.'.php';
221
+		    $classFile = $class . '.php';
222 222
 		    $logger->debug('Checking the class [' . $class . '] in module [' . $module . '] for [' . $type . '] ...');
223 223
 		    $filePath = MODULE_PATH . $module . DS . $type . DS . $classFile;
224
-		    if (file_exists($filePath)){
225
-		        $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' .$filePath. ']');
224
+		    if (file_exists($filePath)) {
225
+		        $logger->info('Found class [' . $class . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
226 226
 		        return $filePath;
227 227
 		    }
228
-		    $logger->info('Class [' . $class . '] does not exist in the module [' .$module. '] for [' . $type . ']');
228
+		    $logger->info('Class [' . $class . '] does not exist in the module [' . $module . '] for [' . $type . ']');
229 229
 		    return false;
230 230
 		}
231 231
 
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
 		 * @return boolean|string  false or null if no module 
239 239
 		 * have this resource, return the full path of the resource
240 240
 		 */
241
-		protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null){
241
+		protected static function findNonClassInModuleFullFilePath($name, $module, $type, $appLang = null) {
242 242
 		    $logger = self::getLogger();
243 243
 		    $name = str_ireplace('.php', '', $name);
244
-		    $file = $name.'.php';
244
+		    $file = $name . '.php';
245 245
 		    $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
246
-		    switch($type){
246
+		    switch ($type) {
247 247
 		        case 'functions':
248 248
 		            $name = str_ireplace('function_', '', $name);
249
-		            $file = 'function_'.$name.'.php';
249
+		            $file = 'function_' . $name . '.php';
250 250
 		            $filePath = MODULE_PATH . $module . DS . $type . DS . $file;
251 251
 		        break;
252 252
 		        case 'views':
@@ -257,16 +257,16 @@  discard block
 block discarded – undo
257 257
 		        break;
258 258
 		        case 'lang':
259 259
 		            $name = str_ireplace('lang_', '', $name);
260
-		            $file = 'lang_'.$name.'.php';
260
+		            $file = 'lang_' . $name . '.php';
261 261
 		            $filePath = MODULE_PATH . $module . DS . $type . DS . $appLang . DS . $file;
262 262
 		        break;
263 263
 		    }
264
-		    $logger->debug('Checking resource [' . $name . '] in module [' .$module. '] for [' . $type . '] ...');
265
-		    if (file_exists($filePath)){
266
-		        $logger->info('Found resource [' . $name . '] in module [' .$module. '] for [' . $type . '] the file path is [' .$filePath. ']');
264
+		    $logger->debug('Checking resource [' . $name . '] in module [' . $module . '] for [' . $type . '] ...');
265
+		    if (file_exists($filePath)) {
266
+		        $logger->info('Found resource [' . $name . '] in module [' . $module . '] for [' . $type . '] the file path is [' . $filePath . ']');
267 267
 		        return $filePath;
268 268
 		    }
269
-		    $logger->info('Resource [' . $name . '] does not exist in the module [' .$module. '] for [' . $type . ']');
269
+		    $logger->info('Resource [' . $name . '] does not exist in the module [' . $module . '] for [' . $type . ']');
270 270
 		    return false;
271 271
 		}
272 272
 
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Config extends BaseStaticClass{
27
+	class Config extends BaseStaticClass {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
 		/**
36 36
 		 * Initialize the configuration by loading all the configuration from config file
37 37
 		 */
38
-		public static function init(){
38
+		public static function init() {
39 39
 			$logger = self::getLogger();
40 40
 			$logger->debug('Initialization of the configuration');
41 41
 			self::$config = & load_configurations();
42 42
 			self::setBaseUrlUsingServerVar();
43
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
43
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
44 44
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
45 45
 			}
46 46
 			$logger->info('Configuration initialized successfully');
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 		 * @param  mixed $default the default value to use if can not find the config item in the list
54 54
 		 * @return mixed          the config value if exist or the default value
55 55
 		 */
56
-		public static function get($item, $default = null){
56
+		public static function get($item, $default = null) {
57 57
 			$logger = self::getLogger();
58
-			if(array_key_exists($item, self::$config)){
58
+			if (array_key_exists($item, self::$config)) {
59 59
 				return self::$config[$item];
60 60
 			}
61
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
61
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
62 62
 			return $default;
63 63
 		}
64 64
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		 * @param string $item  the config item name to set
68 68
 		 * @param mixed $value the config item value
69 69
 		 */
70
-		public static function set($item, $value){
70
+		public static function set($item, $value) {
71 71
 			self::$config[$item] = $value;
72 72
 		}
73 73
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * Get all the configuration values
76 76
 		 * @return array the config values
77 77
 		 */
78
-		public static function getAll(){
78
+		public static function getAll() {
79 79
 			return self::$config;
80 80
 		}
81 81
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		 * Set the configuration values bu merged with the existing configuration
84 84
 		 * @param array $config the config values to add in the configuration list
85 85
 		 */
86
-		public static function setAll(array $config = array()){
86
+		public static function setAll(array $config = array()) {
87 87
 			self::$config = array_merge(self::$config, $config);
88 88
 		}
89 89
 
@@ -92,15 +92,15 @@  discard block
 block discarded – undo
92 92
 		 * @param  string $item the config item name to be deleted
93 93
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
94 94
 		 */
95
-		public static function delete($item){
95
+		public static function delete($item) {
96 96
 			$logger = self::getLogger();
97
-			if(array_key_exists($item, self::$config)){
98
-				$logger->info('Delete config item ['.$item.']');
97
+			if (array_key_exists($item, self::$config)) {
98
+				$logger->info('Delete config item [' . $item . ']');
99 99
 				unset(self::$config[$item]);
100 100
 				return true;
101 101
 			}
102
-			else{
103
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
102
+			else {
103
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
104 104
 				return false;
105 105
 			}
106 106
 		}
@@ -109,39 +109,39 @@  discard block
 block discarded – undo
109 109
 		 * Load the configuration file. This an alias to Loader::config()
110 110
 		 * @param  string $config the config name to be loaded
111 111
 		 */
112
-		public static function load($config){
112
+		public static function load($config) {
113 113
 			Loader::config($config);
114 114
 		}
115 115
 
116 116
 		/**
117 117
 		 * Set the configuration for "base_url" if is not set in the configuration
118 118
 		 */
119
-		private static function setBaseUrlUsingServerVar(){
119
+		private static function setBaseUrlUsingServerVar() {
120 120
 			$logger = self::getLogger();
121
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
122
-				if(ENVIRONMENT == 'production'){
121
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
122
+				if (ENVIRONMENT == 'production') {
123 123
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
124 124
 				}
125 125
 				$baseUrl = null;
126 126
 				$protocol = 'http';
127
-				if(is_https()){
127
+				if (is_https()) {
128 128
 					$protocol = 'https';
129 129
 				}
130
-				$protocol .='://';
130
+				$protocol .= '://';
131 131
 
132
-				if (isset($_SERVER['SERVER_ADDR'])){
132
+				if (isset($_SERVER['SERVER_ADDR'])) {
133 133
 					$baseUrl = $_SERVER['SERVER_ADDR'];
134 134
 					//check if the server is running under IPv6
135
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
136
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
135
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
136
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
137 137
 					}
138 138
 					$serverPort = 80;
139 139
 					if (isset($_SERVER['SERVER_PORT'])) {
140 140
 						$serverPort = $_SERVER['SERVER_PORT'];
141 141
 					}
142 142
 					$port = '';
143
-					if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){
144
-						$port = ':'.$serverPort;
143
+					if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) {
144
+						$port = ':' . $serverPort;
145 145
 					}
146 146
 					$baseUrl = $protocol . $baseUrl . $port . substr(
147 147
 																		$_SERVER['SCRIPT_NAME'], 
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 																		strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))
150 150
 																	);
151 151
 				}
152
-				else{
152
+				else {
153 153
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
154 154
 					$baseUrl = 'http://localhost/';
155 155
 				}
156 156
 				self::set('base_url', $baseUrl);
157 157
 			}
158
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
158
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
159 159
 		}
160 160
 	}
Please login to merge, or discard this patch.
core/classes/database/DatabaseQueryRunner.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class DatabaseQueryRunner extends BaseClass{
26
+  class DatabaseQueryRunner extends BaseClass {
27 27
       
28 28
    
29 29
   	/**
30 30
   	 * The last query result
31 31
   	 * @var object
32 32
   	*/
33
-  	private $queryResult       = null;
33
+  	private $queryResult = null;
34 34
   	
35 35
   	/**
36 36
     * The benchmark instance
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
 	 * The SQL query statment to execute
43 43
 	 * @var string
44 44
 	*/
45
-    private $query             = null;
45
+    private $query = null;
46 46
     
47 47
     /**
48 48
 	 * Indicate if we need return result as list (boolean) 
49 49
      * or the data used to replace the placeholder (array)
50 50
 	 * @var array|boolean
51 51
 	 */
52
-     private $returnAsList     = true;
52
+     private $returnAsList = true;
53 53
      
54 54
      
55 55
      /**
56 56
 	   * Indicate if we need return result as array or not
57 57
      * @var boolean
58 58
 	   */
59
-     private $returnAsArray     = true;
59
+     private $returnAsArray = true;
60 60
      
61 61
      /**
62 62
      * The last PDOStatment instance
63 63
      * @var object
64 64
      */
65
-     private $pdoStatment       = null;
65
+     private $pdoStatment = null;
66 66
      
67 67
      /**
68 68
   	 * The error returned for the last query
69 69
   	 * @var string
70 70
   	 */
71
-     private $error             = null;
71
+     private $error = null;
72 72
 	
73 73
     /**
74 74
      * The PDO instance
75 75
      * @var object
76 76
     */
77
-    private $pdo                = null;
77
+    private $pdo = null;
78 78
   
79 79
     /**
80 80
      * The database driver name used
81 81
      * @var string
82 82
     */
83
-    private $driver             = null;
83
+    private $driver = null;
84 84
 
85 85
 
86 86
 	
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      * @param boolean $returnAsList if need return as list or just one row
92 92
      * @param boolean $returnAsArray whether to return the result as array or not
93 93
      */
94
-    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false){
94
+    public function __construct(PDO $pdo = null, $query = null, $returnAsList = true, $returnAsArray = false) {
95 95
         parent::__construct();
96
-        if (is_object($pdo)){
96
+        if (is_object($pdo)) {
97 97
           $this->pdo = $pdo;
98 98
         }
99 99
         $this->query         = $query;
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
      * 
109 109
      * @return object|void
110 110
      */
111
-    public function execute(){
111
+    public function execute() {
112 112
         //reset instance
113 113
         $this->reset();
114 114
        
115 115
        //for database query execution time
116 116
         $benchmarkMarkerKey = $this->getBenchmarkKey();
117
-        if (! is_object($this->benchmarkInstance)){
117
+        if (!is_object($this->benchmarkInstance)) {
118 118
           $this->benchmarkInstance = & class_loader('Benchmark');
119 119
         }
120 120
         
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
                                                                 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'
131 131
                                                               );
132 132
 		    //TODO use the configuration value for the high response time currently is 1 second
133
-        if ($responseTime >= 1 ){
133
+        if ($responseTime >= 1) {
134 134
             $this->logger->warning(
135 135
                                     'High response time while processing database query [' . $this->query . ']. 
136
-                                     The response time is [' .$responseTime. '] sec.'
136
+                                     The response time is [' .$responseTime . '] sec.'
137 137
                                   );
138 138
         }
139 139
 		
140
-        if ($this->pdoStatment !== false){
140
+        if ($this->pdoStatment !== false) {
141 141
           $isSqlSELECTQuery = stristr($this->query, 'SELECT') !== false;
142
-          if($isSqlSELECTQuery){
142
+          if ($isSqlSELECTQuery) {
143 143
               $this->setResultForSelect();              
144 144
           }
145
-          else{
145
+          else {
146 146
               $this->setResultForNonSelect();
147 147
           }
148 148
           return $this->queryResult;
@@ -154,28 +154,28 @@  discard block
 block discarded – undo
154 154
    * Return the result for SELECT query
155 155
    * @see DatabaseQueryRunner::execute
156 156
    */
157
-    protected function setResultForSelect(){
157
+    protected function setResultForSelect() {
158 158
       //if need return all result like list of record
159 159
       $result = null;
160 160
       $numRows = 0;
161 161
       $fetchMode = PDO::FETCH_OBJ;
162
-      if($this->returnAsArray){
162
+      if ($this->returnAsArray) {
163 163
         $fetchMode = PDO::FETCH_ASSOC;
164 164
       }
165
-      if ($this->returnAsList){
165
+      if ($this->returnAsList) {
166 166
           $result = $this->pdoStatment->fetchAll($fetchMode);
167 167
       }
168
-      else{
168
+      else {
169 169
           $result = $this->pdoStatment->fetch($fetchMode);
170 170
       }
171 171
       //Sqlite and pgsql always return 0 when using rowCount()
172
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
172
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
173 173
         $numRows = count($result);  
174 174
       }
175
-      else{
175
+      else {
176 176
         $numRows = $this->pdoStatment->rowCount(); 
177 177
       }
178
-      if(! is_object($this->queryResult)){
178
+      if (!is_object($this->queryResult)) {
179 179
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
180 180
       }
181 181
       $this->queryResult->setResult($result);
@@ -186,20 +186,20 @@  discard block
 block discarded – undo
186 186
    * Return the result for non SELECT query
187 187
    * @see DatabaseQueryRunner::execute
188 188
    */
189
-    protected function setResultForNonSelect(){
189
+    protected function setResultForNonSelect() {
190 190
       //Sqlite and pgsql always return 0 when using rowCount()
191 191
       $result = false;
192 192
       $numRows = 0;
193
-      if (in_array($this->driver, array('sqlite', 'pgsql'))){
193
+      if (in_array($this->driver, array('sqlite', 'pgsql'))) {
194 194
         $result = true; //to test the result for the query like UPDATE, INSERT, DELETE
195 195
         $numRows = 1; //TODO use the correct method to get the exact affected row
196 196
       }
197
-      else{
197
+      else {
198 198
           //to test the result for the query like UPDATE, INSERT, DELETE
199 199
           $result  = $this->pdoStatment->rowCount() >= 0; 
200 200
           $numRows = $this->pdoStatment->rowCount(); 
201 201
       }
202
-      if(! is_object($this->queryResult)){
202
+      if (!is_object($this->queryResult)) {
203 203
           $this->queryResult = & class_loader('DatabaseQueryResult', 'classes/database');
204 204
       }
205 205
       $this->queryResult->setResult($result);
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      * Return the benchmark instance
212 212
      * @return Benchmark
213 213
      */
214
-    public function getBenchmark(){
214
+    public function getBenchmark() {
215 215
       return $this->benchmarkInstance;
216 216
     }
217 217
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      * @param Benchmark $benchmark the benchmark object
221 221
 	 * @return object DatabaseQueryRunner
222 222
      */
223
-    public function setBenchmark($benchmark){
223
+    public function setBenchmark($benchmark) {
224 224
       $this->benchmarkInstance = $benchmark;
225 225
       return $this;
226 226
     }
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @return object DatabaseQueryResult
232 232
      */
233
-    public function getQueryResult(){
233
+    public function getQueryResult() {
234 234
       return $this->queryResult;
235 235
     }
236 236
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      *
241 241
 	 * @return object DatabaseQueryRunner
242 242
      */
243
-    public function setQueryResult(DatabaseQueryResult $queryResult){
243
+    public function setQueryResult(DatabaseQueryResult $queryResult) {
244 244
       $this->queryResult = $queryResult;
245 245
       return $this;
246 246
     }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      * Return the current query SQL string
250 250
      * @return string
251 251
      */
252
-    public function getQuery(){
252
+    public function getQuery() {
253 253
       return $this->query;
254 254
     }
255 255
     
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      * @param string $query the SQL query to set
259 259
      * @return object DatabaseQueryRunner
260 260
      */
261
-    public function setQuery($query){
261
+    public function setQuery($query) {
262 262
        $this->query = $query;
263 263
        return $this;
264 264
     }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @param boolean $returnType
269 269
      * @return object DatabaseQueryRunner
270 270
      */
271
-    public function setReturnType($returnType){
271
+    public function setReturnType($returnType) {
272 272
        $this->returnAsList = $returnType;
273 273
        return $this;
274 274
     }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * @param boolean $status the status if true will return as array
279 279
      * @return object DatabaseQueryRunner
280 280
      */
281
-    public function setReturnAsArray($status = true){
281
+    public function setReturnAsArray($status = true) {
282 282
        $this->returnAsArray = $status;
283 283
        return $this;
284 284
     }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      * Return the error for last query execution
288 288
      * @return string
289 289
      */
290
-    public function getQueryError(){
290
+    public function getQueryError() {
291 291
       return $this->error;
292 292
     }
293 293
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
      * Return the PDO instance
296 296
      * @return object
297 297
      */
298
-    public function getPdo(){
298
+    public function getPdo() {
299 299
       return $this->pdo;
300 300
     }
301 301
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
      * @param PDO $pdo the pdo object
305 305
      * @return object DatabaseQueryRunner
306 306
      */
307
-    public function setPdo(PDO $pdo = null){
307
+    public function setPdo(PDO $pdo = null) {
308 308
       $this->pdo = $pdo;
309 309
       return $this;
310 310
     }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      * Return the database driver
314 314
      * @return string
315 315
      */
316
-    public function getDriver(){
316
+    public function getDriver() {
317 317
       return $this->driver;
318 318
     }
319 319
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      * @param string $driver the new driver
323 323
      * @return object DatabaseQueryRunner
324 324
      */
325
-    public function setDriver($driver){
325
+    public function setDriver($driver) {
326 326
       $this->driver = $driver;
327 327
       return $this;
328 328
     }
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
      * 
333 333
      *  @return string
334 334
      */
335
-    protected function getBenchmarkKey(){
335
+    protected function getBenchmarkKey() {
336 336
       return md5($this->query . $this->returnAsList . $this->returnAsArray);
337 337
     }
338 338
     
339 339
     /**
340 340
      * Set error for database query execution
341 341
      */
342
-    protected function setQueryRunnerError(){
342
+    protected function setQueryRunnerError() {
343 343
       $error = $this->pdo->errorInfo();
344 344
       $this->error = isset($error[2]) ? $error[2] : '';
345 345
       $this->logger->error('The database query execution got an error: ' . stringfy_vars($error));
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
      * Set the Log instance using argument or create new instance
352 352
      * @param object $logger the Log instance if not null
353 353
      */
354
-    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
355
-      if ($logger !== null){
354
+    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
355
+      if ($logger !== null) {
356 356
         $this->logger = $logger;
357 357
       }
358
-      else{
359
-          $this->logger =& class_loader('Log', 'classes');
358
+      else {
359
+          $this->logger = & class_loader('Log', 'classes');
360 360
           $this->logger->setLogger('Library::DatabaseQueryRunner');
361 361
       }
362 362
     }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     /**
366 366
     * Reset the instance before run each query
367 367
     */
368
-    private function reset(){
368
+    private function reset() {
369 369
         $this->error = null;
370 370
         $this->pdoStatment = null;
371 371
     }
Please login to merge, or discard this patch.
core/classes/database/Database.php 1 patch
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -23,92 +23,92 @@  discard block
 block discarded – undo
23 23
    * along with this program; if not, write to the Free Software
24 24
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
   */
26
-  class Database extends BaseClass{
26
+  class Database extends BaseClass {
27 27
 	
28 28
   	/**
29 29
   	 * The PDO instance
30 30
   	 * @var object
31 31
   	*/
32
-    private $pdo                 = null;
32
+    private $pdo = null;
33 33
     
34 34
   	/**
35 35
   	 * The database name used for the application
36 36
   	 * @var string
37 37
   	*/
38
-	  private $databaseName        = null;
38
+	  private $databaseName = null;
39 39
 	
40 40
   	/**
41 41
   	 * The number of rows returned by the last query
42 42
   	 * @var int
43 43
   	*/
44
-    private $numRows             = 0;
44
+    private $numRows = 0;
45 45
 	
46 46
   	/**
47 47
   	 * The last insert id for the primary key column that have auto increment or sequence
48 48
   	 * @var mixed
49 49
   	*/
50
-    private $insertId            = null;
50
+    private $insertId = null;
51 51
 	
52 52
   	/**
53 53
   	 * The full SQL query statment after build for each command
54 54
   	 * @var string
55 55
   	*/
56
-    private $query               = null;
56
+    private $query = null;
57 57
 	
58 58
   	/**
59 59
   	 * The result returned for the last query
60 60
   	 * @var mixed
61 61
   	*/
62
-    private $result              = array();
62
+    private $result = array();
63 63
 	
64 64
   	/**
65 65
   	 * The cache default time to live in second. 0 means no need to use the cache feature
66 66
   	 * @var int
67 67
   	*/
68
-  	private $cacheTtl             = 0;
68
+  	private $cacheTtl = 0;
69 69
 	
70 70
   	/**
71 71
   	 * The cache current time to live. 0 means no need to use the cache feature
72 72
   	 * @var int
73 73
   	*/
74
-    private $temporaryCacheTtl   = 0;
74
+    private $temporaryCacheTtl = 0;
75 75
 	
76 76
   	/**
77 77
   	 * The number of executed query for the current request
78 78
   	 * @var int
79 79
   	*/
80
-    private $queryCount          = 0;
80
+    private $queryCount = 0;
81 81
 	
82 82
   	/**
83 83
   	 * The default data to be used in the statments query INSERT, UPDATE
84 84
   	 * @var array
85 85
   	*/
86
-    private $data                = array();
86
+    private $data = array();
87 87
 	
88 88
   	/**
89 89
   	 * The database configuration
90 90
   	 * @var array
91 91
   	*/
92
-    private $config              = array();
92
+    private $config = array();
93 93
 	
94 94
     /**
95 95
     * The cache instance
96 96
     * @var object
97 97
     */
98
-    private $cacheInstance       = null;
98
+    private $cacheInstance = null;
99 99
 
100 100
     
101 101
   	/**
102 102
     * The DatabaseQueryBuilder instance
103 103
     * @var object
104 104
     */
105
-    protected $queryBuilder        = null;
105
+    protected $queryBuilder = null;
106 106
     
107 107
     /**
108 108
     * The DatabaseQueryRunner instance
109 109
     * @var object
110 110
     */
111
-    protected $queryRunner         = null;
111
+    protected $queryRunner = null;
112 112
 
113 113
 
114 114
     /**
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      * @param array $overwriteConfig the config to overwrite with the config set in database.php
117 117
      * @param boolean $autoConnect whether to connect to database automatically
118 118
      */
119
-    public function __construct($overwriteConfig = array(), $autoConnect = true){
119
+    public function __construct($overwriteConfig = array(), $autoConnect = true) {
120 120
         parent::__construct();
121 121
 		
122 122
     		//Set DatabaseQueryBuilder instance to use
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
      * This is used to connect to database
137 137
      * @return bool 
138 138
      */
139
-    public function connect(){
139
+    public function connect() {
140 140
       $config = $this->getDatabaseConfiguration();
141
-      if (! empty($config)){
142
-        try{
141
+      if (!empty($config)) {
142
+        try {
143 143
             $this->pdo = new PDO($this->getDsnValueFromConfig(), $config['username'], $config['password']);
144 144
             $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'");
145 145
             $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'");
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
             return is_object($this->pdo);
152 152
           }
153
-          catch (PDOException $e){
153
+          catch (PDOException $e) {
154 154
             $this->logger->fatal($e->getMessage());
155 155
             show_error('Cannot connect to Database.');
156 156
             return false;
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      * Return the number of rows returned by the current query
165 165
      * @return int
166 166
      */
167
-    public function numRows(){
167
+    public function numRows() {
168 168
       return $this->numRows;
169 169
     }
170 170
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * Return the last insert id value
173 173
      * @return mixed
174 174
      */
175
-    public function insertId(){
175
+    public function insertId() {
176 176
       return $this->insertId;
177 177
     }
178 178
 
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
      * If is string will determine the result type "array" or "object"
184 184
      * @return mixed       the query SQL string or the record result
185 185
      */
186
-    public function get($returnSQLQueryOrResultType = false){
186
+    public function get($returnSQLQueryOrResultType = false) {
187 187
       $this->queryBuilder->limit(1);
188 188
       $query = $this->getAll(true);
189
-      if ($returnSQLQueryOrResultType === true){
189
+      if ($returnSQLQueryOrResultType === true) {
190 190
         return $query;
191 191
       } else {
192 192
         return $this->query($query, false, $returnSQLQueryOrResultType == 'array');
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
      * If is string will determine the result type "array" or "object"
200 200
      * @return mixed       the query SQL string or the record result
201 201
      */
202
-    public function getAll($returnSQLQueryOrResultType = false){
202
+    public function getAll($returnSQLQueryOrResultType = false) {
203 203
 	   $query = $this->queryBuilder->getQuery();
204
-	   if ($returnSQLQueryOrResultType === true){
204
+	   if ($returnSQLQueryOrResultType === true) {
205 205
       	return $query;
206 206
       }
207 207
       return $this->query($query, true, $returnSQLQueryOrResultType == 'array');
@@ -213,18 +213,18 @@  discard block
 block discarded – undo
213 213
      * @param  boolean $escape  whether to escape or not the values
214 214
      * @return mixed          the insert id of the new record or null
215 215
      */
216
-    public function insert($data = array(), $escape = true){
217
-      if (empty($data) && ! empty($this->data)){
216
+    public function insert($data = array(), $escape = true) {
217
+      if (empty($data) && !empty($this->data)) {
218 218
         //as when using $this->setData() may be the data already escaped
219 219
         $escape = false;
220 220
         $data = $this->data;
221 221
       }
222 222
       $query = $this->queryBuilder->insert($data, $escape)->getQuery();
223 223
       $result = $this->query($query);
224
-      if ($result){
224
+      if ($result) {
225 225
         $this->insertId = $this->pdo->lastInsertId();
226 226
 		    //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned 
227
-        return ! ($this->insertId) ? true : $this->insertId;
227
+        return !($this->insertId) ? true : $this->insertId;
228 228
       }
229 229
       return false;
230 230
     }
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
      * @param  boolean $escape  whether to escape or not the values
236 236
      * @return mixed          the update status
237 237
      */
238
-    public function update($data = array(), $escape = true){
239
-      if (empty($data) && ! empty($this->data)){
238
+    public function update($data = array(), $escape = true) {
239
+      if (empty($data) && !empty($this->data)) {
240 240
         //as when using $this->setData() may be the data already escaped
241 241
         $escape = false;
242 242
         $data = $this->data;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      * Delete the record in database
250 250
      * @return mixed the delete status
251 251
      */
252
-    public function delete(){
252
+    public function delete() {
253 253
 		  $query = $this->queryBuilder->delete()->getQuery();
254 254
     	return $this->query($query);
255 255
     }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
      * @param integer $ttl the cache time to live in second
260 260
      * @return object        the current Database instance
261 261
      */
262
-    public function setCache($ttl = 0){
262
+    public function setCache($ttl = 0) {
263 263
       $this->cacheTtl = $ttl;
264 264
       $this->temporaryCacheTtl = $ttl;
265 265
       return $this;
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @param  integer $ttl the cache time to live in second
271 271
 	 * @return object        the current Database instance
272 272
 	 */
273
-  	public function cached($ttl = 0){
273
+  	public function cached($ttl = 0) {
274 274
         $this->temporaryCacheTtl = $ttl;
275 275
         return $this;
276 276
     }
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
      * @return mixed       the data after escaped or the same data if no
283 283
      * need escaped
284 284
      */
285
-    public function escape($data, $escaped = true){
285
+    public function escape($data, $escaped = true) {
286 286
       $data = trim($data);
287
-      if($escaped){
287
+      if ($escaped) {
288 288
         return $this->pdo->quote($data);
289 289
       }
290 290
       return $data; 
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      * Return the number query executed count for the current request
295 295
      * @return int
296 296
      */
297
-    public function queryCount(){
297
+    public function queryCount() {
298 298
       return $this->queryCount;
299 299
     }
300 300
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      * Return the current query SQL string
303 303
      * @return string
304 304
      */
305
-    public function getQuery(){
305
+    public function getQuery() {
306 306
       return $this->query;
307 307
     }
308 308
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      * Return the application database name
311 311
      * @return string
312 312
      */
313
-    public function getDatabaseName(){
313
+    public function getDatabaseName() {
314 314
       return $this->databaseName;
315 315
     }
316 316
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      * Return the PDO instance
319 319
      * @return object
320 320
      */
321
-    public function getPdo(){
321
+    public function getPdo() {
322 322
       return $this->pdo;
323 323
     }
324 324
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      * @param object $pdo the pdo object
328 328
 	 * @return object Database
329 329
      */
330
-    public function setPdo(PDO $pdo){
330
+    public function setPdo(PDO $pdo) {
331 331
       $this->pdo = $pdo;
332 332
       return $this;
333 333
     }
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
      * Return the cache instance
337 337
      * @return CacheInterface
338 338
      */
339
-    public function getCacheInstance(){
339
+    public function getCacheInstance() {
340 340
       return $this->cacheInstance;
341 341
     }
342 342
 
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
      * @param CacheInterface $cache the cache object
346 346
 	 * @return object Database
347 347
      */
348
-    public function setCacheInstance($cache){
348
+    public function setCacheInstance($cache) {
349 349
       $this->cacheInstance = $cache;
350 350
       return $this;
351 351
     }
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
      * Return the DatabaseQueryBuilder instance
356 356
      * @return object DatabaseQueryBuilder
357 357
      */
358
-    public function getQueryBuilder(){
358
+    public function getQueryBuilder() {
359 359
       return $this->queryBuilder;
360 360
     }
361 361
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * Set the DatabaseQueryBuilder instance
364 364
      * @param object DatabaseQueryBuilder $queryBuilder the DatabaseQueryBuilder object
365 365
      */
366
-    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder){
366
+    public function setQueryBuilder(DatabaseQueryBuilder $queryBuilder) {
367 367
       $this->queryBuilder = $queryBuilder;
368 368
       return $this;
369 369
     }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
      * Return the DatabaseQueryRunner instance
373 373
      * @return object DatabaseQueryRunner
374 374
      */
375
-    public function getQueryRunner(){
375
+    public function getQueryRunner() {
376 376
       return $this->queryRunner;
377 377
     }
378 378
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
      * Set the DatabaseQueryRunner instance
381 381
      * @param object DatabaseQueryRunner $queryRunner the DatabaseQueryRunner object
382 382
      */
383
-    public function setQueryRunner(DatabaseQueryRunner $queryRunner){
383
+    public function setQueryRunner(DatabaseQueryRunner $queryRunner) {
384 384
       $this->queryRunner = $queryRunner;
385 385
       return $this;
386 386
     }
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
      * Return the data to be used for insert, update, etc.
390 390
      * @return array
391 391
      */
392
-    public function getData(){
392
+    public function getData() {
393 393
       return $this->data;
394 394
     }
395 395
 
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
      * @param boolean $escape whether to escape or not the $value
401 401
      * @return object        the current Database instance
402 402
      */
403
-    public function setData($key, $value = null, $escape = true){
404
-  	  if (is_array($key)){
405
-    		foreach($key as $k => $v){
403
+    public function setData($key, $value = null, $escape = true) {
404
+  	  if (is_array($key)) {
405
+    		foreach ($key as $k => $v) {
406 406
     			$this->setData($k, $v, $escape);
407 407
     		}	
408 408
   	  } else {
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
      * @param  boolean $returnAsArray return the result as array or not
419 419
      * @return mixed         the query result
420 420
      */
421
-    public function query($query, $returnAsList = true, $returnAsArray = false){
421
+    public function query($query, $returnAsList = true, $returnAsArray = false) {
422 422
       $this->reset();
423 423
       $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query));
424 424
       //If is the SELECT query
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
       //if can use cache feature for this query
440 440
       $dbCacheStatus = $cacheEnable && $cacheExpire > 0;
441 441
     
442
-      if ($dbCacheStatus && $isSqlSELECTQuery){
442
+      if ($dbCacheStatus && $isSqlSELECTQuery) {
443 443
           $this->logger->info('The cache is enabled for this query, try to get result from cache'); 
444 444
           $cacheContent = $this->getCacheContentForQuery($query, $returnAsList, $returnAsArray);  
445 445
       }
446 446
       
447
-      if (!$cacheContent){
447
+      if (!$cacheContent) {
448 448
   	   	//count the number of query execution to server
449 449
         $this->queryCount++;
450 450
         
@@ -453,19 +453,19 @@  discard block
 block discarded – undo
453 453
                                           ->setReturnAsArray($returnAsArray)
454 454
                                           ->execute();
455 455
 
456
-        if (!is_object($queryResult)){
456
+        if (!is_object($queryResult)) {
457 457
           $this->result = false;
458 458
           $this->numRows = 0;
459 459
           return $this->result;
460 460
         }
461 461
         $this->result  = $queryResult->getResult();
462 462
         $this->numRows = $queryResult->getNumRows();
463
-        if ($isSqlSELECTQuery && $dbCacheStatus){
463
+        if ($isSqlSELECTQuery && $dbCacheStatus) {
464 464
             $key = $this->getCacheKeyForQuery($this->query, $returnAsList, $returnAsArray);
465 465
             $this->setCacheContentForQuery($this->query, $key, $this->result, $cacheExpire);
466 466
         }
467
-      } else if ($isSqlSELECTQuery){
468
-          $this->logger->info('The result for query [' .$this->query. '] already cached use it');
467
+      } else if ($isSqlSELECTQuery) {
468
+          $this->logger->info('The result for query [' . $this->query . '] already cached use it');
469 469
           $this->result = $cacheContent;
470 470
           $this->numRows = count($this->result);
471 471
       }
@@ -479,9 +479,9 @@  discard block
 block discarded – undo
479 479
     * @param boolean $autoConnect whether to connect to database after set the configuration
480 480
 	  * @return object Database
481 481
     */
482
-    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false){
482
+    public function setDatabaseConfiguration(array $overwriteConfig = array(), $useConfigFile = true, $autoConnect = false) {
483 483
       $db = array();
484
-      if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')){
484
+      if ($useConfigFile && file_exists(CONFIG_PATH . 'database.php')) {
485 485
           //here don't use require_once because somewhere user can create database instance directly
486 486
           require CONFIG_PATH . 'database.php';
487 487
       }
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
     	//determine the port using the hostname like localhost:3307
497 497
       //hostname will be "localhost", and port "3307"
498 498
       $p = explode(':', $config['hostname']);
499
-  	  if (count($p) >= 2){
499
+  	  if (count($p) >= 2) {
500 500
   		  $config['hostname'] = $p[0];
501 501
   		  $config['port'] = $p[1];
502 502
   		}
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 															array('password' => string_hidden($this->config['password']))
511 511
 												))
512 512
 							);
513
-  	  if($autoConnect){
513
+  	  if ($autoConnect) {
514 514
     		 //Now connect to the database
515 515
     		 $this->connect();
516 516
   		}
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
    * Return the database configuration
522 522
    * @return array
523 523
    */
524
-    public  function getDatabaseConfiguration(){
524
+    public  function getDatabaseConfiguration() {
525 525
       return $this->config;
526 526
     }
527 527
 
528 528
     /**
529 529
      * Close the connexion
530 530
      */
531
-    public function close(){
531
+    public function close() {
532 532
       $this->pdo = null;
533 533
     }
534 534
 
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
      * Return the database default configuration
537 537
      * @return array
538 538
      */
539
-    protected function getDatabaseDefaultConfiguration(){
539
+    protected function getDatabaseDefaultConfiguration() {
540 540
       return array(
541 541
               'driver' => '',
542 542
               'username' => '',
@@ -554,16 +554,16 @@  discard block
 block discarded – undo
554 554
      * Update the DatabaseQueryBuilder and DatabaseQueryRunner properties
555 555
      * @return void
556 556
      */
557
-    protected function updateQueryBuilderAndRunnerProperties(){
557
+    protected function updateQueryBuilderAndRunnerProperties() {
558 558
        //update queryBuilder with some properties needed
559
-     if (is_object($this->queryBuilder)){
559
+     if (is_object($this->queryBuilder)) {
560 560
         $this->queryBuilder->setDriver($this->config['driver'])
561 561
                            ->setPrefix($this->config['prefix'])
562 562
                            ->setPdo($this->pdo);
563 563
      }
564 564
 
565 565
       //update queryRunner with some properties needed
566
-     if (is_object($this->queryRunner)){
566
+     if (is_object($this->queryRunner)) {
567 567
         $this->queryRunner->setDriver($this->config['driver'])
568 568
                           ->setPdo($this->pdo);
569 569
      }
@@ -574,10 +574,10 @@  discard block
 block discarded – undo
574 574
      * This method is used to get the PDO DSN string using the configured driver
575 575
      * @return string|null the DSN string or null if can not find it
576 576
      */
577
-    protected function getDsnValueFromConfig(){
577
+    protected function getDsnValueFromConfig() {
578 578
       $dsn = null;
579 579
       $config = $this->getDatabaseConfiguration();
580
-      if (! empty($config)){
580
+      if (!empty($config)) {
581 581
         $driver = $config['driver'];
582 582
         $driverDsnMap = array(
583 583
                               'mysql'  => $this->getDsnValueForDriver('mysql'),
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
                               'sqlite' => $this->getDsnValueForDriver('sqlite'),
586 586
                               'oracle' => $this->getDsnValueForDriver('oracle')
587 587
                               );
588
-        if (isset($driverDsnMap[$driver])){
588
+        if (isset($driverDsnMap[$driver])) {
589 589
           $dsn = $driverDsnMap[$driver];
590 590
         }
591 591
       }    
@@ -597,17 +597,17 @@  discard block
 block discarded – undo
597 597
      * @param  string $driver the driver name
598 598
      * @return string|null         the dsn name
599 599
      */
600
-    protected function getDsnValueForDriver($driver){
600
+    protected function getDsnValueForDriver($driver) {
601 601
       $dsn = '';
602 602
       $config = $this->getDatabaseConfiguration();
603
-      if (empty($config)){
603
+      if (empty($config)) {
604 604
         return null;
605 605
       }
606 606
       switch ($driver) {
607 607
         case 'mysql':
608 608
         case 'pgsql':
609 609
           $port = '';
610
-          if (! empty($config['port'])) {
610
+          if (!empty($config['port'])) {
611 611
             $port = 'port=' . $config['port'] . ';';
612 612
           }
613 613
           $dsn = $driver . ':host=' . $config['hostname'] . ';' . $port . 'dbname=' . $config['database'];
@@ -617,10 +617,10 @@  discard block
 block discarded – undo
617 617
           break;
618 618
           case 'oracle':
619 619
           $port = '';
620
-          if (! empty($config['port'])) {
620
+          if (!empty($config['port'])) {
621 621
             $port = ':' . $config['port'];
622 622
           }
623
-          $dsn =  'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
623
+          $dsn = 'oci:dbname=' . $config['hostname'] . $port . '/' . $config['database'];
624 624
           break;
625 625
       }
626 626
       return $dsn;
@@ -632,9 +632,9 @@  discard block
 block discarded – undo
632 632
      *      
633 633
      * @return mixed
634 634
      */
635
-    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray){
635
+    protected function getCacheContentForQuery($query, $returnAsList, $returnAsArray) {
636 636
         $cacheKey = $this->getCacheKeyForQuery($query, $returnAsList, $returnAsArray);
637
-        if (! is_object($this->cacheInstance)){
637
+        if (!is_object($this->cacheInstance)) {
638 638
     			//can not call method with reference in argument
639 639
     			//like $this->setCacheInstance(& get_instance()->cache);
640 640
     			//use temporary variable
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
      * @param mixed $result the query result to save
652 652
      * @param int $expire the cache TTL
653 653
      */
654
-     protected function setCacheContentForQuery($query, $key, $result, $expire){
655
-        $this->logger->info('Save the result for query [' .$query. '] into cache for future use');
656
-        if (! is_object($this->cacheInstance)){
654
+     protected function setCacheContentForQuery($query, $key, $result, $expire) {
655
+        $this->logger->info('Save the result for query [' . $query . '] into cache for future use');
656
+        if (!is_object($this->cacheInstance)) {
657 657
   				//can not call method with reference in argument
658 658
   				//like $this->setCacheInstance(& get_instance()->cache);
659 659
   				//use temporary variable
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
      * 
671 671
      *  @return string
672 672
      */
673
-    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray){
673
+    protected function getCacheKeyForQuery($query, $returnAsList, $returnAsArray) {
674 674
       return md5($query . $returnAsList . $returnAsArray);
675 675
     }
676 676
 
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
     /**
679 679
      * Reset the database class attributs to the initail values before each query.
680 680
      */
681
-    private function reset(){
681
+    private function reset() {
682 682
 	   //query builder reset
683 683
       $this->queryBuilder->reset();
684 684
       $this->numRows  = 0;
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
     /**
692 692
      * The class destructor
693 693
      */
694
-    public function __destruct(){
694
+    public function __destruct() {
695 695
       $this->pdo = null;
696 696
     }
697 697
 
Please login to merge, or discard this patch.
core/classes/DBSessionHandler.php 1 patch
Spacing   +31 added lines, -31 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 extends BaseClass implements SessionHandlerInterface{
34
+	class DBSessionHandler extends BaseClass implements SessionHandlerInterface {
35 35
 		
36 36
 		/**
37 37
 		 * The encryption method to use to encrypt session data in database
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
          * Create new instance of Database session handler
80 80
          * @param object $modelInstance the model instance
81 81
          */
82
-		public function __construct(DBSessionHandlerModel $modelInstance = null){
82
+		public function __construct(DBSessionHandlerModel $modelInstance = null) {
83 83
 			parent::__construct();
84 84
 			
85 85
 	    	//Set Loader instance to use
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	       
88 88
 		    $this->OBJ = & get_instance();
89 89
 		    
90
-			if (is_object($modelInstance)){
90
+			if (is_object($modelInstance)) {
91 91
 				$this->setModelInstance($modelInstance);
92 92
 			}
93 93
 		}
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		 * Set the session secret used to encrypt the data in database 
97 97
 		 * @param string $secret the base64 string secret
98 98
 		 */
99
-		public function setSessionSecret($secret){
99
+		public function setSessionSecret($secret) {
100 100
 			$this->sessionSecret = $secret;
101 101
 			return $this;
102 102
 		}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Return the session secret
106 106
 		 * @return string 
107 107
 		 */
108
-		public function getSessionSecret(){
108
+		public function getSessionSecret() {
109 109
 			return $this->sessionSecret;
110 110
 		}
111 111
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 		 * Set the initializer vector for openssl 
115 115
 		 * @param string $key the session secret used in base64 format
116 116
 		 */
117
-		public function setInitializerVector($key){
117
+		public function setInitializerVector($key) {
118 118
 			$ivLength = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD);
119 119
 			$key = base64_decode($key);
120 120
 			$this->iv = substr(hash('sha256', $key), 0, $ivLength);
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		 * Return the initializer vector
126 126
 		 * @return string 
127 127
 		 */
128
-		public function getInitializerVector(){
128
+		public function getInitializerVector() {
129 129
 			return $this->iv;
130 130
 		}
131 131
 
@@ -135,17 +135,17 @@  discard block
 block discarded – undo
135 135
 		 * @param  string $sessionName the session name
136 136
 		 * @return boolean 
137 137
 		 */
138
-		public function open($savePath, $sessionName){
138
+		public function open($savePath, $sessionName) {
139 139
 			$this->logger->debug('Opening database session handler for [' . $sessionName . ']');
140 140
 			//try to check if session secret is set before
141 141
 			$secret = $this->getSessionSecret();
142
-			if (empty($secret)){
142
+			if (empty($secret)) {
143 143
 				$secret = get_config('session_secret', null);
144 144
 				$this->setSessionSecret($secret);
145 145
 			}
146 146
 			$this->logger->info('Session secret: ' . $secret);
147 147
 
148
-			if (! is_object($this->modelInstance)){
148
+			if (!is_object($this->modelInstance)) {
149 149
 				$this->setModelInstanceFromSessionConfig();
150 150
 			}
151 151
 			$this->setInitializerVector($secret);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			//set session tables columns
154 154
 			$this->sessionTableColumns = $this->modelInstance->getSessionTableColumns();
155 155
 
156
-			if (empty($this->sessionTableColumns)){
156
+			if (empty($this->sessionTableColumns)) {
157 157
 				show_error('The session handler is "database" but the table columns not set');
158 158
 			}
159 159
 			$this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns));
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		 * Close the session
170 170
 		 * @return boolean
171 171
 		 */
172
-		public function close(){
172
+		public function close() {
173 173
 			$this->logger->debug('Closing database session handler');
174 174
 			return true;
175 175
 		}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 		 * @param  string $sid the session id to use
180 180
 		 * @return string      the session data in serialiaze format
181 181
 		 */
182
-		public function read($sid){
182
+		public function read($sid) {
183 183
 			$this->logger->debug('Reading database session data for SID: ' . $sid);
184 184
 			$instance = $this->getModelInstance();
185 185
 			$columns = $this->sessionTableColumns;
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
 			
189 189
 			$ip = get_ip();
190 190
 			$host = @gethostbyaddr($ip) or null;
191
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
191
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
192 192
 			
193 193
 			$data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser));
194
-			if ($data && isset($data->{$columns['sdata']})){
194
+			if ($data && isset($data->{$columns['sdata']})) {
195 195
 				//checking inactivity 
196 196
 				$timeInactivity = time() - get_config('session_inactivity_time', 100);
197
-				if ($data->{$columns['stime']} < $timeInactivity){
197
+				if ($data->{$columns['stime']} < $timeInactivity) {
198 198
 					$this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it');
199 199
 					$this->destroy($sid);
200 200
 					return null;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 		 * @param  mixed $data the session data to save in serialize format
212 212
 		 * @return boolean 
213 213
 		 */
214
-		public function write($sid, $data){
214
+		public function write($sid, $data) {
215 215
 			$this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data));
216 216
 			$instance = $this->getModelInstance();
217 217
 			$columns = $this->sessionTableColumns;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 			$ip = get_ip();
223 223
 			$keyValue = $instance->getKeyValue();
224 224
 			$host = @gethostbyaddr($ip) or null;
225
-			$browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion();
225
+			$browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion();
226 226
 			$data = $this->encode($data);
227 227
 			$params = array(
228 228
 							$columns['sid'] => $sid,
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 						);
236 236
 			$this->logger->info('Database session data to save are listed below :' . stringfy_vars($params));
237 237
 			$exists = $instance->get($sid);
238
-			if ($exists){
238
+			if ($exists) {
239 239
 				$this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it');
240 240
 				//update
241 241
 				unset($params[$columns['sid']]);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		 * @param  string $sid the session id value
252 252
 		 * @return boolean
253 253
 		 */
254
-		public function destroy($sid){
254
+		public function destroy($sid) {
255 255
 			$this->logger->debug('Destroy of session data for SID: ' . $sid);
256 256
 			$instance = $this->modelInstance;
257 257
 			$instance->delete($sid);
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 		 * @param  integer $maxLifetime the max lifetime
264 264
 		 * @return boolean
265 265
 		 */
266
-		public function gc($maxLifetime){
266
+		public function gc($maxLifetime) {
267 267
 			$instance = $this->modelInstance;
268 268
 			$time = time() - $maxLifetime;
269 269
 			$this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']');
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
 		 * @param  mixed $data the session data to encode
277 277
 		 * @return mixed the encoded session data
278 278
 		 */
279
-		public function encode($data){
279
+		public function encode($data) {
280 280
 			$key = base64_decode($this->sessionSecret);
281
-			$dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
281
+			$dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
282 282
 			$output = base64_encode($dataEncrypted);
283 283
 			return $output;
284 284
 		}
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		 * @param  mixed $data the data to decode
290 290
 		 * @return mixed       the decoded data
291 291
 		 */
292
-		public function decode($data){
292
+		public function decode($data) {
293 293
 			$key = base64_decode($this->sessionSecret);
294 294
 			$data = base64_decode($data);
295 295
 			$data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector());
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
          * Return the loader instance
302 302
          * @return object Loader the loader instance
303 303
          */
304
-        public function getLoader(){
304
+        public function getLoader() {
305 305
             return $this->loader;
306 306
         }
307 307
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
          * set the loader instance for future use
310 310
          * @param object Loader $loader the loader object
311 311
          */
312
-         public function setLoader($loader){
312
+         public function setLoader($loader) {
313 313
             $this->loader = $loader;
314 314
             return $this;
315 315
         }
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
          * Return the model instance
319 319
          * @return object DBSessionHandlerModel the model instance
320 320
          */
321
-        public function getModelInstance(){
321
+        public function getModelInstance() {
322 322
             return $this->modelInstance;
323 323
         }
324 324
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
          * set the model instance for future use
327 327
          * @param DBSessionHandlerModel $modelInstance the model object
328 328
          */
329
-         public function setModelInstance(DBSessionHandlerModel $modelInstance){
329
+         public function setModelInstance(DBSessionHandlerModel $modelInstance) {
330 330
             $this->modelInstance = $modelInstance;
331 331
             return $this;
332 332
         }
@@ -334,13 +334,13 @@  discard block
 block discarded – undo
334 334
 	    /**
335 335
 	     * Set the model instance using the configuration for session
336 336
 	     */
337
-	    protected function setModelInstanceFromSessionConfig(){
337
+	    protected function setModelInstanceFromSessionConfig() {
338 338
 	    	$modelName = get_config('session_save_path');
339 339
 			$this->logger->info('The database session model: ' . $modelName);
340 340
 			$this->loader->model($modelName, 'dbsessionhandlerinstance'); 
341 341
 			//@codeCoverageIgnoreStart
342 342
             if (isset($this->OBJ->dbsessionhandlerinstance) 
343
-            	&& ! ($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
343
+            	&& !($this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel)
344 344
             ) {
345 345
 				show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"');
346 346
 			}  
Please login to merge, or discard this patch.
core/classes/Lang.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * For application languages management
29 29
 	 */
30
-	class Lang extends BaseClass{
30
+	class Lang extends BaseClass {
31 31
 		
32 32
 		/**
33 33
 		 * The supported available language for this application.
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		/**
62 62
 		 * Construct new Lang instance
63 63
 		 */
64
-		public function __construct(){
64
+		public function __construct() {
65 65
 			parent::__construct();
66 66
 
67 67
 			$this->default = get_config('default_language', 'en');
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 			
70 70
 			//add the supported languages ('key', 'display name')
71 71
 			$languages = get_config('languages', null);
72
-			if(! empty($languages)){
73
-				foreach($languages as $key => $displayName){
72
+			if (!empty($languages)) {
73
+				foreach ($languages as $key => $displayName) {
74 74
 					$this->addLang($key, $displayName);
75 75
 				}
76 76
 			}
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
 
79 79
 			//if the language exists in cookie use it
80 80
 			$cfgKey = get_config('language_cookie_name');
81
-			$this->logger->debug('Getting current language from cookie [' .$cfgKey. ']');
81
+			$this->logger->debug('Getting current language from cookie [' . $cfgKey . ']');
82 82
 			$objCookie = & class_loader('Cookie');
83 83
 			$cookieLang = $objCookie->get($cfgKey);
84
-			if($cookieLang && $this->isValid($cookieLang)){
84
+			if ($cookieLang && $this->isValid($cookieLang)) {
85 85
 				$this->current = $cookieLang;
86
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']');
86
+				$this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']');
87 87
 			}
88
-			else{
89
-				$this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']');
88
+			else {
89
+				$this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']');
90 90
 				$this->current = $this->getDefault();
91 91
 			}
92 92
 		}
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		 *
97 97
 		 * @return array the language message list
98 98
 		 */
99
-		public function getAll(){
99
+		public function getAll() {
100 100
 			return $this->languages;
101 101
 		}
102 102
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 		 * @param string $key the language key to identify
107 107
 		 * @param string $value the language message value
108 108
 		 */
109
-		public function set($key, $value){
109
+		public function set($key, $value) {
110 110
 			$this->languages[$key] = $value;
111 111
 		}
112 112
 
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 		 *
119 119
 		 * @return string the language message value
120 120
 		 */
121
-		public function get($key, $default = 'LANGUAGE_ERROR'){
122
-			if(isset($this->languages[$key])){
121
+		public function get($key, $default = 'LANGUAGE_ERROR') {
122
+			if (isset($this->languages[$key])) {
123 123
 				return $this->languages[$key];
124 124
 			}
125
-			$this->logger->warning('Language key  [' .$key. '] does not exist use the default value [' .$default. ']');
125
+			$this->logger->warning('Language key  [' . $key . '] does not exist use the default value [' . $default . ']');
126 126
 			return $default;
127 127
 		}
128 128
 
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 		 *
134 134
 		 * @return boolean true if the language directory exists, false or not
135 135
 		 */
136
-		public function isValid($language){
136
+		public function isValid($language) {
137 137
 			$searchDir = array(CORE_LANG_PATH, APP_LANG_PATH);
138
-			foreach($searchDir as $dir){
139
-				if(file_exists($dir . $language) && is_dir($dir . $language)){
138
+			foreach ($searchDir as $dir) {
139
+				if (file_exists($dir . $language) && is_dir($dir . $language)) {
140 140
 					return true;
141 141
 				}
142 142
 			}
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		 *
149 149
 		 * @return string the default language
150 150
 		 */
151
-		public function getDefault(){
151
+		public function getDefault() {
152 152
 			return $this->default;
153 153
 		}
154 154
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		 *
158 158
 		 * @return string the current language
159 159
 		 */
160
-		public function getCurrent(){
160
+		public function getCurrent() {
161 161
 			return $this->current;
162 162
 		}
163 163
 
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
 		 * @param string $name the short language name like "en", "fr".
168 168
 		 * @param string $description the human readable description of this language
169 169
 		 */
170
-		public function addLang($name, $description){
171
-			if(isset($this->availables[$name])){
170
+		public function addLang($name, $description) {
171
+			if (isset($this->availables[$name])) {
172 172
 				return; //already added cost in performance
173 173
 			}
174
-			if($this->isValid($name)){
174
+			if ($this->isValid($name)) {
175 175
 				$this->availables[$name] = $description;
176 176
 			}
177
-			else{
177
+			else {
178 178
 				show_error('The language [' . $name . '] is not valid or does not exists.');
179 179
 			}
180 180
 		}
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		 *
185 185
 		 * @return array the list of the application language
186 186
 		 */
187
-		public function getSupported(){
187
+		public function getSupported() {
188 188
 			return $this->availables;
189 189
 		}
190 190
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		 *
194 194
 		 * @param array $langs the languages array of the messages to be added
195 195
 		 */
196
-		public function addLangMessages(array $langs){
196
+		public function addLangMessages(array $langs) {
197 197
 			foreach ($langs as $key => $value) {
198 198
 				$this->set($key, $value);
199 199
 			}
Please login to merge, or discard this patch.
core/classes/Router.php 1 patch
Spacing   +71 added lines, -71 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 Router extends BaseClass{
27
+	class Router extends BaseClass {
28 28
 		/**
29 29
 		* @var array $pattern: The list of URIs to validate against
30 30
 		*/
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
 		/**
91 91
 		 * Construct the new Router instance
92 92
 		 */
93
-		public function __construct(){
93
+		public function __construct() {
94 94
 			parent::__construct();
95 95
 			
96 96
 			//loading routes for module
97 97
 			$moduleRouteList = array();
98 98
 			$modulesRoutes = Module::getModulesRoutesConfig();
99
-			if($modulesRoutes && is_array($modulesRoutes)){
99
+			if ($modulesRoutes && is_array($modulesRoutes)) {
100 100
 				$moduleRouteList = $modulesRoutes;
101 101
 				unset($modulesRoutes);
102 102
 			}
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		 * Get the route patterns
112 112
 		 * @return array
113 113
 		 */
114
-		public function getPattern(){
114
+		public function getPattern() {
115 115
 			return $this->pattern;
116 116
 		}
117 117
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 		 * Get the route callbacks
120 120
 		 * @return array
121 121
 		 */
122
-		public function getCallback(){
122
+		public function getCallback() {
123 123
 			return $this->callback;
124 124
 		}
125 125
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		 * Get the module name
128 128
 		 * @return string
129 129
 		 */
130
-		public function getModule(){
130
+		public function getModule() {
131 131
 			return $this->module;
132 132
 		}
133 133
 		
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		 * Get the controller name
136 136
 		 * @return string
137 137
 		 */
138
-		public function getController(){
138
+		public function getController() {
139 139
 			return $this->controller;
140 140
 		}
141 141
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		 * Get the controller file path
144 144
 		 * @return string
145 145
 		 */
146
-		public function getControllerPath(){
146
+		public function getControllerPath() {
147 147
 			return $this->controllerPath;
148 148
 		}
149 149
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		 * Get the controller method
152 152
 		 * @return string
153 153
 		 */
154
-		public function getMethod(){
154
+		public function getMethod() {
155 155
 			return $this->method;
156 156
 		}
157 157
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 		 * Get the request arguments
160 160
 		 * @return array
161 161
 		 */
162
-		public function getArgs(){
162
+		public function getArgs() {
163 163
 			return $this->args;
164 164
 		}
165 165
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		 * Get the URL segments array
168 168
 		 * @return array
169 169
 		 */
170
-		public function getSegments(){
170
+		public function getSegments() {
171 171
 			return $this->segments;
172 172
 		}
173 173
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 		 * Get the route URI
176 176
 		 * @return string
177 177
 		 */
178
-		public function getRouteUri(){
178
+		public function getRouteUri() {
179 179
 			return $this->uri;
180 180
 		}
181 181
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 		*/
190 190
 		public function add($uri, $callback) {
191 191
 			$uri = trim($uri, $this->uriTrim);
192
-			if(in_array($uri, $this->pattern)){
192
+			if (in_array($uri, $this->pattern)) {
193 193
 				$this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
194 194
 			}
195 195
 			$this->pattern[] = $uri;
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 		* @return object the current instance
206 206
 		*/
207 207
 		public function removeRoute($uri) {
208
-			$index  = array_search($uri, $this->pattern, true);
209
-			if($index !== false){
208
+			$index = array_search($uri, $this->pattern, true);
209
+			if ($index !== false) {
210 210
 				$this->logger->info('Remove route for uri [' . $uri . '] from the configuration');
211 211
 				unset($this->pattern[$index]);
212 212
 				unset($this->callback[$index]);
@@ -234,26 +234,26 @@  discard block
 block discarded – undo
234 234
 	     * @param string $uri the route URI, if is empty will determine automatically
235 235
 	     * @return object
236 236
 	     */
237
-	    public function setRouteUri($uri = ''){
237
+	    public function setRouteUri($uri = '') {
238 238
 	    	$routeUri = '';
239
-	    	if(! empty($uri)){
239
+	    	if (!empty($uri)) {
240 240
 	    		$routeUri = $uri;
241 241
 	    	}
242 242
 	    	//if the application is running in CLI mode use the first argument
243
-			else if(IS_CLI && isset($_SERVER['argv'][1])){
243
+			else if (IS_CLI && isset($_SERVER['argv'][1])) {
244 244
 				$routeUri = $_SERVER['argv'][1];
245 245
 			}
246
-			else if(isset($_SERVER['REQUEST_URI'])){
246
+			else if (isset($_SERVER['REQUEST_URI'])) {
247 247
 				$routeUri = $_SERVER['REQUEST_URI'];
248 248
 			}
249 249
 			$this->logger->debug('Check if URL suffix is enabled in the configuration');
250 250
 			//remove url suffix from the request URI
251 251
 			$suffix = get_config('url_suffix');
252 252
 			if ($suffix) {
253
-				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
253
+				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']');
254 254
 				$routeUri = str_ireplace($suffix, '', $routeUri);
255 255
 			} 
256
-			if (strpos($routeUri, '?') !== false){
256
+			if (strpos($routeUri, '?') !== false) {
257 257
 				$routeUri = substr($routeUri, 0, strpos($routeUri, '?'));
258 258
 			}
259 259
 			$this->uri = trim($routeUri, $this->uriTrim);
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 		 * 
267 267
 		 * @return object
268 268
 		 */
269
-		public function setRouteSegments(array $segments = array()){
270
-			if(! empty($segments)){
269
+		public function setRouteSegments(array $segments = array()) {
270
+			if (!empty($segments)) {
271 271
 				$this->segments = $segments;
272 272
 			} else if (!empty($this->uri)) {
273 273
 				$this->segments = explode('/', $this->uri);
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 			$segment = $this->segments;
276 276
 			$baseUrl = get_config('base_url');
277 277
 			//check if the app is not in DOCUMENT_ROOT
278
-			if(isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false){
278
+			if (isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false) {
279 279
 				array_shift($segment);
280 280
 				$this->segments = $segment;
281 281
 			}
282 282
 			$this->logger->debug('Check if the request URI contains the front controller');
283
-			if(isset($segment[0]) && $segment[0] == SELF){
283
+			if (isset($segment[0]) && $segment[0] == SELF) {
284 284
 				$this->logger->info('The request URI contains the front controller');
285 285
 				array_shift($segment);
286 286
 				$this->segments = $segment;
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 			
301 301
 			//if can not determine the module/controller/method via the defined routes configuration we will use
302 302
 			//the URL like http://domain.com/module/controller/method/arg1/arg2
303
-			if(! $this->controller){
303
+			if (!$this->controller) {
304 304
 				$this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
305 305
 				//determine route parameters using the REQUEST_URI param
306 306
 				$this->determineRouteParamsFromRequestUri();
@@ -316,14 +316,14 @@  discard block
 block discarded – undo
316 316
 		 * Routing the request to the correspondant module/controller/method if exists
317 317
 		 * otherwise send 404 error.
318 318
 		 */
319
-	    public function processRequest(){
319
+	    public function processRequest() {
320 320
 	    	//Setting the route URI
321 321
 			$this->setRouteUri();
322 322
 
323 323
 			//setting route segments
324 324
 			$this->setRouteSegments();
325 325
 
326
-			$this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']' );
326
+			$this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']');
327 327
 
328 328
 	    	//determine the route parameters information
329 329
 	    	$this->determineRouteParamsInformation();
@@ -334,20 +334,20 @@  discard block
 block discarded – undo
334 334
 	    	$this->logger->info('The routing information are: module [' . $this->module . '], controller [' . $controller . '], method [' . $this->method . '], args [' . stringfy_vars($this->args) . ']');
335 335
 	    	$this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
336 336
 	    	
337
-			if(file_exists($classFilePath)){
337
+			if (file_exists($classFilePath)) {
338 338
 				require_once $classFilePath;
339
-				if(! class_exists($controller, false)){
339
+				if (!class_exists($controller, false)) {
340 340
 					$e404 = true;
341
-					$this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
341
+					$this->logger->warning('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']');
342 342
 				}
343
-				else{
343
+				else {
344 344
 					$controllerInstance = new $controller();
345 345
 					$controllerMethod = $this->getMethod();
346
-					if(! method_exists($controllerInstance, $controllerMethod)){
346
+					if (!method_exists($controllerInstance, $controllerMethod)) {
347 347
 						$e404 = true;
348 348
 						$this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
349 349
 					}
350
-					else{
350
+					else {
351 351
 						$this->logger->info('Routing data is set correctly now GO!');
352 352
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
353 353
 						//render the final page to user
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
 					}
357 357
 				}
358 358
 			}
359
-			else{
359
+			else {
360 360
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
361 361
 				$e404 = true;
362 362
 			}
363
-			if($e404){
364
-				if(IS_CLI){
363
+			if ($e404) {
364
+				if (IS_CLI) {
365 365
 					set_http_status_header(404);
366 366
 					echo 'Error 404: page not found.';
367 367
 				} else {
368
-					$response =& class_loader('Response', 'classes');
368
+					$response = & class_loader('Response', 'classes');
369 369
 					$response->send404();
370 370
 				}
371 371
 			}
@@ -378,15 +378,15 @@  discard block
 block discarded – undo
378 378
 	    * @param boolean $useConfigFile whether to use route configuration file
379 379
 		* @return object
380 380
 	    */
381
-	    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
381
+	    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true) {
382 382
 	        $route = array();
383
-	        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')){
383
+	        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')) {
384 384
 	            require_once CONFIG_PATH . 'routes.php';
385 385
 	        }
386 386
 	        $route = array_merge($route, $overwriteConfig);
387 387
 	        $this->routes = $route;
388 388
 	        //if route is empty remove all configuration
389
-	        if(empty($route)){
389
+	        if (empty($route)) {
390 390
 	        	$this->removeAllRoute();
391 391
 	        }
392 392
 			return $this;
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 		 * Get the route configuration
397 397
 		 * @return array
398 398
 		 */
399
-		public function getRouteConfiguration(){
399
+		public function getRouteConfiguration() {
400 400
 			return $this->routes;
401 401
 		}
402 402
 
@@ -408,19 +408,19 @@  discard block
 block discarded – undo
408 408
 	     *
409 409
 	     * @return object the current instance
410 410
 	     */
411
-	    public function setControllerFilePath($path = null){
412
-	    	if($path !== null){
411
+	    public function setControllerFilePath($path = null) {
412
+	    	if ($path !== null) {
413 413
 	    		$this->controllerPath = $path;
414 414
 	    		return $this;
415 415
 	    	}
416 416
 	    	//did we set the controller, so set the controller path
417
-			if($this->controller && ! $this->controllerPath){
417
+			if ($this->controller && !$this->controllerPath) {
418 418
 				$this->logger->debug('Setting the file path for the controller [' . $this->controller . ']');
419 419
 				$controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->controller) . '.php';
420 420
 				//if the controller is in module
421
-				if($this->module){
421
+				if ($this->module) {
422 422
 					$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
423
-					if($path !== false){
423
+					if ($path !== false) {
424 424
 						$controllerPath = $path;
425 425
 					}
426 426
 				}
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	     * Determine the route parameters from route configuration
434 434
 	     * @return void
435 435
 	     */
436
-	    protected function determineRouteParamsFromConfig(){
436
+	    protected function determineRouteParamsFromConfig() {
437 437
 	    	$uri = implode('/', $this->segments);
438 438
 	    	/*
439 439
 	   		* Generics routes patterns
@@ -458,20 +458,20 @@  discard block
 block discarded – undo
458 458
 					array_shift($args);
459 459
 					//check if this contains an module
460 460
 					$moduleControllerMethod = explode('#', $this->callback[$index]);
461
-					if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
461
+					if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) {
462 462
 						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
463 463
 						$this->module = $moduleControllerMethod[0];
464 464
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
465 465
 					}
466
-					else{
466
+					else {
467 467
 						$this->logger->info('The current request does not use the module');
468 468
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
469 469
 					}
470
-					if(is_array($moduleControllerMethod)){
471
-						if(isset($moduleControllerMethod[0])){
470
+					if (is_array($moduleControllerMethod)) {
471
+						if (isset($moduleControllerMethod[0])) {
472 472
 							$this->controller = $moduleControllerMethod[0];	
473 473
 						}
474
-						if(isset($moduleControllerMethod[1])){
474
+						if (isset($moduleControllerMethod[1])) {
475 475
 							$this->method = $moduleControllerMethod[1];
476 476
 						}
477 477
 						$this->args = $args;
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 			}
483 483
 
484 484
 			//first if the controller is not set and the module is set use the module name as the controller
485
-			if(! $this->controller && $this->module){
485
+			if (!$this->controller && $this->module) {
486 486
 				$this->logger->info(
487 487
 									'After loop in predefined routes configuration, 
488 488
 									the module name is set but the controller is not set, 
@@ -496,67 +496,67 @@  discard block
 block discarded – undo
496 496
 	     * Determine the route parameters using the server variable "REQUEST_URI"
497 497
 	     * @return void
498 498
 	     */
499
-	    protected function determineRouteParamsFromRequestUri(){
499
+	    protected function determineRouteParamsFromRequestUri() {
500 500
 	    	$segment = $this->segments;
501 501
 	    	$nbSegment = count($segment);
502 502
 			//if segment is null so means no need to perform
503
-			if($nbSegment > 0){
503
+			if ($nbSegment > 0) {
504 504
 				//get the module list
505 505
 				$modules = Module::getModuleList();
506 506
 				//first check if no module
507
-				if(empty($modules)){
507
+				if (empty($modules)) {
508 508
 					$this->logger->info('No module was loaded will skip the module checking');
509 509
 					//the application don't use module
510 510
 					//controller
511
-					if(isset($segment[0])){
511
+					if (isset($segment[0])) {
512 512
 						$this->controller = $segment[0];
513 513
 						array_shift($segment);
514 514
 					}
515 515
 					//method
516
-					if(isset($segment[0])){
516
+					if (isset($segment[0])) {
517 517
 						$this->method = $segment[0];
518 518
 						array_shift($segment);
519 519
 					}
520 520
 					//args
521 521
 					$this->args = $segment;
522 522
 				}
523
-				else{
523
+				else {
524 524
 					$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
525
-					if(in_array($segment[0], $modules)){
525
+					if (in_array($segment[0], $modules)) {
526 526
 						$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
527 527
 						$this->module = $segment[0];
528 528
 						array_shift($segment);
529 529
 						//check if the second arg is the controller from module
530
-						if(isset($segment[0])){
530
+						if (isset($segment[0])) {
531 531
 							$this->controller = $segment[0];
532 532
 							//check if the request use the same module name and controller
533 533
 							$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
534
-							if(! $path){
534
+							if (!$path) {
535 535
 								$this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
536 536
 								$this->controller = $this->module;
537 537
 							}
538
-							else{
538
+							else {
539 539
 								$this->controllerPath = $path;
540 540
 								array_shift($segment);
541 541
 							}
542 542
 						}
543 543
 						//check for method
544
-						if(isset($segment[0])){
544
+						if (isset($segment[0])) {
545 545
 							$this->method = $segment[0];
546 546
 							array_shift($segment);
547 547
 						}
548 548
 						//the remaining is for args
549 549
 						$this->args = $segment;
550 550
 					}
551
-					else{
551
+					else {
552 552
 						$this->logger->info('The current request information is not found in the module list');
553 553
 						//controller
554
-						if(isset($segment[0])){
554
+						if (isset($segment[0])) {
555 555
 							$this->controller = $segment[0];
556 556
 							array_shift($segment);
557 557
 						}
558 558
 						//method
559
-						if(isset($segment[0])){
559
+						if (isset($segment[0])) {
560 560
 							$this->method = $segment[0];
561 561
 							array_shift($segment);
562 562
 						}
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
 						$this->args = $segment;
565 565
 					}
566 566
 				}
567
-				if(! $this->controller && $this->module){
567
+				if (!$this->controller && $this->module) {
568 568
 					$this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
569 569
 					$this->controller = $this->module;
570 570
 				}
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
 	     *
577 577
 	     * @return object the current instance
578 578
 	     */
579
-	    protected function setRouteConfigurationInfos(){
579
+	    protected function setRouteConfigurationInfos() {
580 580
 	    	//adding route
581
-			foreach($this->routes as $pattern => $callback){
581
+			foreach ($this->routes as $pattern => $callback) {
582 582
 				$this->add($pattern, $callback);
583 583
 			}
584 584
 			return $this;
Please login to merge, or discard this patch.
core/classes/Session.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Session extends BaseStaticClass{
26
+	class Session extends BaseStaticClass {
27 27
 		
28 28
 		/**
29 29
 		 * The session flash key to use
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
 		 * @param  mixed $default the default value to use if can not find the session item in the list
38 38
 		 * @return mixed          the session value if exist or the default value
39 39
 		 */
40
-		public static function get($item, $default = null){
40
+		public static function get($item, $default = null) {
41 41
 			$logger = self::getLogger();
42
-			$logger->debug('Getting session data for item [' .$item. '] ...');
43
-			if(array_key_exists($item, $_SESSION)){
42
+			$logger->debug('Getting session data for item [' . $item . '] ...');
43
+			if (array_key_exists($item, $_SESSION)) {
44 44
 				$logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']');
45 45
 				return $_SESSION[$item];
46 46
 			}
47
-			$logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']');
47
+			$logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']');
48 48
 			return $default;
49 49
 		}
50 50
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		 * @param string $item  the session item name to set
54 54
 		 * @param mixed $value the session item value
55 55
 		 */
56
-		public static function set($item, $value){
56
+		public static function set($item, $value) {
57 57
 			$logger = self::getLogger();
58 58
 			$logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']');
59 59
 			$_SESSION[$item] = $value;
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
 		 * @param  mixed $default the default value to use if can not find the session flash item in the list
66 66
 		 * @return mixed          the session flash value if exist or the default value
67 67
 		 */
68
-		public static function getFlash($item, $default = null){
68
+		public static function getFlash($item, $default = null) {
69 69
 			$logger = self::getLogger();
70
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
70
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
71 71
 			$return = array_key_exists($key, $_SESSION) ?
72 72
 			($_SESSION[$key]) : $default;
73
-			if(array_key_exists($key, $_SESSION)){
73
+			if (array_key_exists($key, $_SESSION)) {
74 74
 				unset($_SESSION[$key]);
75 75
 			}
76
-			else{
77
-				$logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']');
76
+			else {
77
+				$logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']');
78 78
 			}
79 79
 			return $return;
80 80
 		}
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 		 * @param  string  $item the session flash item name
85 85
 		 * @return boolean 
86 86
 		 */
87
-		public static function hasFlash($item){
88
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
87
+		public static function hasFlash($item) {
88
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
89 89
 			return array_key_exists($key, $_SESSION);
90 90
 		}
91 91
 
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 		 * @param string $item  the session flash item name to set
95 95
 		 * @param mixed $value the session flash item value
96 96
 		 */
97
-		public static function setFlash($item, $value){
98
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
97
+		public static function setFlash($item, $value) {
98
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
99 99
 			$_SESSION[$key] = $value;
100 100
 		}
101 101
 
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 		 * Clear the session item in the list
104 104
 		 * @param  string $item the session item name to be deleted
105 105
 		 */
106
-		public static function clear($item){
106
+		public static function clear($item) {
107 107
 			$logger = self::getLogger();
108
-			if(array_key_exists($item, $_SESSION)){
109
-				$logger->info('Deleting of session for item ['.$item.' ]');
108
+			if (array_key_exists($item, $_SESSION)) {
109
+				$logger->info('Deleting of session for item [' . $item . ' ]');
110 110
 				unset($_SESSION[$item]);
111 111
 			}
112
-			else{
113
-				$logger->warning('Session item ['.$item.'] to be deleted does not exists');
112
+			else {
113
+				$logger->warning('Session item [' . $item . '] to be deleted does not exists');
114 114
 			}
115 115
 		}
116 116
 		
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
 		 * Clear the session flash item in the list
119 119
 		 * @param  string $item the session flash item name to be deleted
120 120
 		 */
121
-		public static function clearFlash($item){
121
+		public static function clearFlash($item) {
122 122
 			$logger = self::getLogger();
123
-			$key = self::SESSION_FLASH_KEY.'_'.$item;
124
-			if(array_key_exists($key, $_SESSION)){
125
-				$logger->info('Delete session flash for item ['.$item.']');
123
+			$key = self::SESSION_FLASH_KEY . '_' . $item;
124
+			if (array_key_exists($key, $_SESSION)) {
125
+				$logger->info('Delete session flash for item [' . $item . ']');
126 126
 				unset($_SESSION[$item]);
127 127
 			}
128
-			else{
129
-				$logger->warning('Dession flash item ['.$item.'] to be deleted does not exists');
128
+			else {
129
+				$logger->warning('Dession flash item [' . $item . '] to be deleted does not exists');
130 130
 			}
131 131
 		}
132 132
 
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
 		 * @param  string  $item the session item name
136 136
 		 * @return boolean 
137 137
 		 */
138
-		public static function exists($item){
138
+		public static function exists($item) {
139 139
 			return array_key_exists($item, $_SESSION);
140 140
 		}
141 141
 
142 142
 		/**
143 143
 		 * Destroy all session data values
144 144
 		 */
145
-		public static function clearAll(){
145
+		public static function clearAll() {
146 146
 			session_unset();
147 147
 			session_destroy();
148 148
 		}
Please login to merge, or discard this patch.
core/classes/cache/ApcCache.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  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 ApcCache extends BaseClass implements CacheInterface{
27
+	class ApcCache extends BaseClass implements CacheInterface {
28 28
 
29 29
 		
30 30
 		
31
-		public function __construct(){
31
+		public function __construct() {
32 32
 			parent::__construct();
33
-			if(! $this->isSupported()){
33
+			if (!$this->isSupported()) {
34 34
 				show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.');
35 35
 			}
36 36
 		}
@@ -40,21 +40,21 @@  discard block
 block discarded – undo
40 40
 		 * @param  string $key the key to identify the cache data
41 41
 		 * @return mixed      the cache data if exists else return false
42 42
 		 */
43
-		public function get($key){
44
-			$this->logger->debug('Getting cache data for key ['. $key .']');
43
+		public function get($key) {
44
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
45 45
 			$success = false;
46 46
 			$data = apc_fetch($key, $success);
47
-			if($success === false){
48
-				$this->logger->info('No cache found for the key ['. $key .'], return false');
47
+			if ($success === false) {
48
+				$this->logger->info('No cache found for the key [' . $key . '], return false');
49 49
 				return false;
50 50
 			}
51
-			else{
51
+			else {
52 52
 				$cacheInfo = $this->_getCacheInfo($key);
53 53
 				$expire = time();
54
-				if($cacheInfo){
54
+				if ($cacheInfo) {
55 55
 					$expire = $cacheInfo['creation_time'] + $cacheInfo['ttl'];
56 56
 				}
57
-				$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
57
+				$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']');
58 58
 				return $data;
59 59
 			}
60 60
 		}
@@ -67,16 +67,16 @@  discard block
 block discarded – undo
67 67
 		 * @param integer $ttl  the cache life time
68 68
 		 * @return boolean true if success otherwise will return false
69 69
 		 */
70
-		public function set($key, $data, $ttl = 0){
70
+		public function set($key, $data, $ttl = 0) {
71 71
 			$expire = time() + $ttl;
72
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
72
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
73 73
 			$result = apc_store($key, $data, $ttl);
74
-			if($result === false){
75
-		    	$this->logger->error('Can not write cache data for the key ['. $key .'], return false');
74
+			if ($result === false) {
75
+		    	$this->logger->error('Can not write cache data for the key [' . $key . '], return false');
76 76
 		    	return false;
77 77
 		    }
78
-		    else{
79
-		    	$this->logger->info('Cache data saved for the key ['. $key .']');
78
+		    else {
79
+		    	$this->logger->info('Cache data saved for the key [' . $key . ']');
80 80
 		    	return true;
81 81
 		    }
82 82
 		}
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
 		 * @return boolean      true if the cache is deleted, false if can't delete 
89 89
 		 * the cache or the cache with the given key not exist
90 90
 		 */
91
-		public function delete($key){
92
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
91
+		public function delete($key) {
92
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
93 93
 			$cacheInfo = $this->_getCacheInfo($key);
94
-			if($cacheInfo === false){
94
+			if ($cacheInfo === false) {
95 95
 				$this->logger->info('This cache data does not exists skipping');
96 96
 				return false;
97 97
 			}
98
-			else{
99
-				$this->logger->info('Found cache data for the key [' .$key. '] remove it');
98
+			else {
99
+				$this->logger->info('Found cache data for the key [' . $key . '] remove it');
100 100
 	      		return apc_delete($key) === true;
101 101
 			}
102 102
 		}
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 		 * 'expire' => expiration time of the cache (Unix timestamp),
110 110
 		 * 'ttl' => the time to live of the cache in second
111 111
 		 */
112
-		public function getInfo($key){
113
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
112
+		public function getInfo($key) {
113
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
114 114
 			$cacheInfos = $this->_getCacheInfo($key);
115
-			if($cacheInfos){
115
+			if ($cacheInfos) {
116 116
 				$data = array(
117 117
 							'mtime' => $cacheInfos['creation_time'],
118 118
 							'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'],
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 							);
121 121
 				return $data;
122 122
 			}
123
-			else{
123
+			else {
124 124
 				$this->logger->info('This cache does not exists skipping');
125 125
 				return false;
126 126
 			}
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 		/**
131 131
 		 * Used to delete expired cache data
132 132
 		 */
133
-		public function deleteExpiredCache(){
133
+		public function deleteExpiredCache() {
134 134
 			//for APC[u] is done automatically
135 135
 			return true;
136 136
 		}
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
 		/**
139 139
 		 * Remove all cache data
140 140
 		 */
141
-		public function clean(){
141
+		public function clean() {
142 142
 			$this->logger->debug('Deleting of all cache data');
143 143
 			$cacheInfos = apc_cache_info('user');
144
-			if(empty($cacheInfos['cache_list'])){
144
+			if (empty($cacheInfos['cache_list'])) {
145 145
 				$this->logger->info('No cache data were found skipping');
146 146
 				return false;
147 147
 			}
148
-			else{
148
+			else {
149 149
 				$this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove');
150 150
 				return apc_clear_cache('user');
151 151
 			}
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		 *
158 158
 		 * @return bool
159 159
 		 */
160
-		public function isSupported(){
160
+		public function isSupported() {
161 161
 			return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled');
162 162
 		}
163 163
 		
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
 		* @param string $key the cache key to get the cache information 
168 168
 		* @return boolean|array
169 169
 		*/
170
-		private function _getCacheInfo($key){
170
+		private function _getCacheInfo($key) {
171 171
 			$caches = apc_cache_info('user');
172
-			if(! empty($caches['cache_list'])){
172
+			if (!empty($caches['cache_list'])) {
173 173
 				$cacheLists = $caches['cache_list'];
174
-				foreach ($cacheLists as $c){
175
-					if(isset($c['info']) && $c['info'] === $key){
174
+				foreach ($cacheLists as $c) {
175
+					if (isset($c['info']) && $c['info'] === $key) {
176 176
 						return $c;
177 177
 					}
178 178
 				}
Please login to merge, or discard this patch.