Passed
Branch 1.0.0-dev (c78053)
by nguereza
04:10 queued 15s
created
core/classes/EventInfo.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * This class represent the event detail to dispatch to correspond listener
29 29
 	 */
30
-	class EventInfo{
30
+	class EventInfo {
31 31
 		
32 32
 		/**
33 33
 		 * The event name
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		 */
55 55
 		public $stop;
56 56
 		
57
-		public function __construct($name, $payload = array(), $returnBack = false, $stop = false){
57
+		public function __construct($name, $payload = array(), $returnBack = false, $stop = false) {
58 58
 			$this->name = $name;
59 59
 			$this->payload = $payload;
60 60
 			$this->returnBack = $returnBack;
Please login to merge, or discard this patch.
core/classes/EventDispatcher.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * also to dispatch the event
30 30
 	 */
31 31
 	
32
-	class EventDispatcher{
32
+	class EventDispatcher {
33 33
 		
34 34
 		/**
35 35
 		 * The list of the registered listeners
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 		 */
45 45
 		private $logger;
46 46
 
47
-		public function __construct(){
48
-			$this->logger =& class_loader('Log', 'classes');
47
+		public function __construct() {
48
+			$this->logger = & class_loader('Log', 'classes');
49 49
 			$this->logger->setLogger('Library::EventDispatcher');
50 50
 		}
51 51
 
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 		 * @param string   $eventName the name of the event to register for
55 55
 		 * @param callable $listener  the function or class method to receive the event information after dispatch
56 56
 		 */
57
-		public function addListener($eventName, callable $listener){
58
-			$this->logger->debug('Adding new event listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
59
-			if(! isset($this->listeners[$eventName])){
57
+		public function addListener($eventName, callable $listener) {
58
+			$this->logger->debug('Adding new event listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
59
+			if (!isset($this->listeners[$eventName])) {
60 60
 				$this->logger->info('This event does not have the registered event listener before, adding new one');
61 61
 				$this->listeners[$eventName] = array();
62 62
 			}
63
-			else{
63
+			else {
64 64
 				$this->logger->info('This event already have the registered listener, add this listener to the list');
65 65
 			}
66 66
 			$this->listeners[$eventName][] = $listener;
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
 		 * @param  string   $eventName the event name
72 72
 		 * @param  callable $listener  the listener callback
73 73
 		 */
74
-		public function removeListener($eventName, callable $listener){
75
-			$this->logger->debug('Removing of the event listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']');
76
-			if(isset($this->listeners[$eventName])){
74
+		public function removeListener($eventName, callable $listener) {
75
+			$this->logger->debug('Removing of the event listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']');
76
+			if (isset($this->listeners[$eventName])) {
77 77
 				$this->logger->info('This event have the listeners, check if this listener exists');
78
-				if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){
79
-					$this->logger->info('Found the listener at index [' .$index. '] remove it');
78
+				if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) {
79
+					$this->logger->info('Found the listener at index [' . $index . '] remove it');
80 80
 					unset($this->listeners[$eventName][$index]);
81 81
 				}
82
-				else{
82
+				else {
83 83
 					$this->logger->info('Cannot found this listener in the event listener list');
84 84
 				}
85 85
 			}
86
-			else{
86
+			else {
87 87
 				$this->logger->info('This event does not have this listener ignore remove');
88 88
 			}
89 89
 		}
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 		 * remove all listeners for this event
94 94
 		 * @param  string $eventName the event name
95 95
 		 */
96
-		public function removeAllListener($eventName = null){
97
-			$this->logger->debug('Removing of all event listener, the event name [' .$eventName. ']');
98
-			if($eventName !== null && isset($this->listeners[$eventName])){
96
+		public function removeAllListener($eventName = null) {
97
+			$this->logger->debug('Removing of all event listener, the event name [' . $eventName . ']');
98
+			if ($eventName !== null && isset($this->listeners[$eventName])) {
99 99
 				$this->logger->info('The event name is set of exist in the listener just remove all event listener for this event');
100 100
 				unset($this->listeners[$eventName]);
101 101
 			}
102
-			else{
102
+			else {
103 103
 				$this->logger->info('The event name is not set or does not exist in the listener, so remove all event listener');
104 104
 				$this->listeners = array();
105 105
 			}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		 * @param string $eventName the event name
111 111
 		 * @return array the listeners for this event or empty array if this event does not contain any listener
112 112
 		 */
113
-		public function getListeners($eventName){
113
+		public function getListeners($eventName) {
114 114
 			return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array();
115 115
 		}
116 116
 		
@@ -119,21 +119,21 @@  discard block
 block discarded – undo
119 119
 		 * @param  mixed|object $event the event information
120 120
 		 * @return void|object if event need return, will return the final EventInfo object.
121 121
 		 */	
122
-		public function dispatch($event){
123
-			if(! $event || !$event instanceof EventInfo){
122
+		public function dispatch($event) {
123
+			if (!$event || !$event instanceof EventInfo) {
124 124
 				$this->logger->info('The event is not set or is not an instance of "EventInfo" create the default "EventInfo" object to use instead of.');
125 125
 				$event = new EventInfo((string) $event);
126 126
 			}			
127
-			$this->logger->debug('Dispatch to the event listener, the event [' .stringfy_vars($event). ']');
128
-			if(isset($event->stop) && $event->stop){
127
+			$this->logger->debug('Dispatch to the event listener, the event [' . stringfy_vars($event) . ']');
128
+			if (isset($event->stop) && $event->stop) {
129 129
 				$this->logger->info('This event need stopped, no need call any listener');
130 130
 				return;
131 131
 			}
132
-			if($event->returnBack){
132
+			if ($event->returnBack) {
133 133
 				$this->logger->info('This event need return back, return the result for future use');
134 134
 				return $this->dispatchToListerners($event);
135 135
 			}
136
-			else{
136
+			else {
137 137
 				$this->logger->info('This event no need return back the result, just dispatch it');
138 138
 				$this->dispatchToListerners($event);
139 139
 			}
@@ -144,38 +144,38 @@  discard block
 block discarded – undo
144 144
 		 * @param  object EventInfo $event  the event information
145 145
 		 * @return void|object if event need return, will return the final EventInfo instance.
146 146
 		 */	
147
-		private function dispatchToListerners(EventInfo $event){
147
+		private function dispatchToListerners(EventInfo $event) {
148 148
 			$eBackup = $event;
149 149
 			$list = $this->getListeners($event->name);
150
-			if(empty($list)){
151
-				$this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.');
152
-				if($event->returnBack){
150
+			if (empty($list)) {
151
+				$this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.');
152
+				if ($event->returnBack) {
153 153
 					return $event;
154 154
 				}
155 155
 				return;
156 156
 			}
157
-			else{
158
-				$this->logger->info('Found the registered event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list));
157
+			else {
158
+				$this->logger->info('Found the registered event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list));
159 159
 			}
160
-			foreach($list as $listener){
161
-				if($eBackup->returnBack){
160
+			foreach ($list as $listener) {
161
+				if ($eBackup->returnBack) {
162 162
 					$returnedEvent = call_user_func_array($listener, array($event));
163
-					if($returnedEvent instanceof EventInfo){
163
+					if ($returnedEvent instanceof EventInfo) {
164 164
 						$event = $returnedEvent;
165 165
 					}
166
-					else{
167
-						show_error('This event [' .$event->name. '] need you return the event object after processing');
166
+					else {
167
+						show_error('This event [' . $event->name . '] need you return the event object after processing');
168 168
 					}
169 169
 				}
170
-				else{
170
+				else {
171 171
 					call_user_func_array($listener, array($event));
172 172
 				}
173
-				if($event->stop){
173
+				if ($event->stop) {
174 174
 					break;
175 175
 				}
176 176
 			}
177 177
 			//only test for original event may be during the flow some listeners change this parameter
178
-			if($eBackup->returnBack){
178
+			if ($eBackup->returnBack) {
179 179
 				return $event;
180 180
 			}
181 181
 		}
Please login to merge, or discard this patch.
core/classes/Response.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Response{
27
+	class Response {
28 28
 
29 29
 		/**
30 30
 		 * The list of request header to send with response
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Construct new response instance
67 67
 		 */
68
-		public function __construct(){
69
-			$this->_currentUrl =  (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' )
70
-					. (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' );
68
+		public function __construct() {
69
+			$this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')
70
+					. (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '');
71 71
 					
72 72
 			$this->_currentUrlCacheKey = md5($this->_currentUrl);
73 73
 			
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 		 * Get the logger singleton instance
83 83
 		 * @return Log the logger instance
84 84
 		 */
85
-		private static function getLogger(){
86
-			if(self::$logger == null){
87
-				self::$logger[0] =& class_loader('Log', 'classes');
85
+		private static function getLogger() {
86
+			if (self::$logger == null) {
87
+				self::$logger[0] = & class_loader('Log', 'classes');
88 88
 				self::$logger[0]->setLogger('Library::Response');
89 89
 			}
90 90
 			return self::$logger[0];
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 		 * @param  integer $httpCode the HTTP status code
96 96
 		 * @param  array   $headers   the additional headers to add to the existing headers list
97 97
 		 */
98
-		public static function sendHeaders($httpCode = 200, array $headers = array()){
98
+		public static function sendHeaders($httpCode = 200, array $headers = array()) {
99 99
 			set_http_status_header($httpCode);
100 100
 			self::setHeaders($headers);
101
-			if(! headers_sent()){
102
-				foreach(self::getHeaders() as $key => $value){
103
-					header($key .': '.$value);
101
+			if (!headers_sent()) {
102
+				foreach (self::getHeaders() as $key => $value) {
103
+					header($key . ': ' . $value);
104 104
 				}
105 105
 			}
106 106
 		}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		 * Get the list of the headers
110 110
 		 * @return array the headers list
111 111
 		 */
112
-		public static function getHeaders(){
112
+		public static function getHeaders() {
113 113
 			return self::$headers;
114 114
 		}
115 115
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		 * @param  string $name the header name
119 119
 		 * @return string       the header value
120 120
 		 */
121
-		public static function getHeader($name){
121
+		public static function getHeader($name) {
122 122
 			return array_key_exists($name, self::$headers) ? self::$headers[$name] : null;
123 123
 		}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		 * @param string $name  the header name
129 129
 		 * @param string $value the header value to be set
130 130
 		 */
131
-		public static function setHeader($name, $value){
131
+		public static function setHeader($name, $value) {
132 132
 			self::$headers[$name] = $value;
133 133
 		}
134 134
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 		 * @param array $headers the list of the headers to set. 
138 138
 		 * Note: this will merge with the existing headers
139 139
 		 */
140
-		public static function setHeaders(array $headers){
140
+		public static function setHeaders(array $headers) {
141 141
 			self::$headers = array_merge(self::getHeaders(), $headers);
142 142
 		}
143 143
 		
@@ -145,17 +145,17 @@  discard block
 block discarded – undo
145 145
 		 * Redirect user in the specified page
146 146
 		 * @param  string $path the URL or URI to be redirect to
147 147
 		 */
148
-		public static function redirect($path = ''){
148
+		public static function redirect($path = '') {
149 149
 			$logger = self::getLogger();
150 150
 			$url = Url::site_url($path);
151
-			$logger->info('Redirect to URL [' .$url. ']');
152
-			if(! headers_sent()){
153
-				header('Location: '.$url);
151
+			$logger->info('Redirect to URL [' . $url . ']');
152
+			if (!headers_sent()) {
153
+				header('Location: ' . $url);
154 154
 				exit;
155 155
 			}
156
-			else{
156
+			else {
157 157
 				echo '<script>
158
-						location.href = "'.$url.'";
158
+						location.href = "'.$url . '";
159 159
 					</script>';
160 160
 			}
161 161
 		}
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
 		 * @return void|string          if $return is true will return the view content otherwise
169 169
 		 * will display the view content.
170 170
 		 */
171
-		public function render($view, $data = null, $return = false){
171
+		public function render($view, $data = null, $return = false) {
172 172
 			$logger = self::getLogger();
173 173
 			//convert data to an array
174
-			$data = ! is_array($data) ? (array) $data : $data;
174
+			$data = !is_array($data) ? (array) $data : $data;
175 175
 			$view = str_ireplace('.php', '', $view);
176 176
 			$view = trim($view, '/\\');
177 177
 			$viewFile = $view . '.php';
@@ -180,42 +180,42 @@  discard block
 block discarded – undo
180 180
 			//super instance
181 181
 			$obj = & get_instance();
182 182
 			
183
-			if(Module::hasModule()){
183
+			if (Module::hasModule()) {
184 184
 				//check in module first
185 185
 				$logger->debug('Checking the view [' . $view . '] from module list ...');
186 186
 				$mod = null;
187 187
 				//check if the request class contains module name
188
-				if(strpos($view, '/') !== false){
188
+				if (strpos($view, '/') !== false) {
189 189
 					$viewPath = explode('/', $view);
190
-					if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){
190
+					if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) {
191 191
 						$mod = $viewPath[0];
192 192
 						array_shift($viewPath);
193 193
 						$view = implode('/', $viewPath);
194 194
 						$viewFile = $view . '.php';
195 195
 					}
196 196
 				}
197
-				if(! $mod && !empty($obj->moduleName)){
197
+				if (!$mod && !empty($obj->moduleName)) {
198 198
 					$mod = $obj->moduleName;
199 199
 				}
200
-				if($mod){
200
+				if ($mod) {
201 201
 					$moduleViewPath = Module::findViewFullPath($view, $mod);
202
-					if($moduleViewPath){
202
+					if ($moduleViewPath) {
203 203
 						$path = $moduleViewPath;
204
-						$logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it');
204
+						$logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it');
205 205
 					}
206
-					else{
207
-						$logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location');
206
+					else {
207
+						$logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location');
208 208
 					}
209 209
 				}
210
-				else{
210
+				else {
211 211
 					$logger->info('The current request does not use module using the default location.');
212 212
 				}
213 213
 			}
214 214
 			$logger->info('The view file path to be loaded is [' . $path . ']');
215 215
 			$found = false;
216
-			if(file_exists($path)){
217
-				foreach(get_object_vars($obj) as $key => $value){
218
-					if(! isset($this->{$key})){
216
+			if (file_exists($path)) {
217
+				foreach (get_object_vars($obj) as $key => $value) {
218
+					if (!isset($this->{$key})) {
219 219
 						$this->{$key} = & $obj->{$key};
220 220
 					}
221 221
 				}
@@ -224,39 +224,39 @@  discard block
 block discarded – undo
224 224
 				//need use require() instead of require_once because can load this view many time
225 225
 				require $path;
226 226
 				$content = ob_get_clean();
227
-				if($return){
227
+				if ($return) {
228 228
 					return $content;
229 229
 				}
230 230
 				$this->_pageRender .= $content;
231 231
 				$found = true;
232 232
 			}
233
-			if(! $found){
234
-				show_error('Unable to find view [' .$view . ']');
233
+			if (!$found) {
234
+				show_error('Unable to find view [' . $view . ']');
235 235
 			}
236 236
 		}
237 237
 		
238 238
 		/**
239 239
 		* Send the final page output to user
240 240
 		*/
241
-		public function renderFinalPage(){
241
+		public function renderFinalPage() {
242 242
 			$logger = self::getLogger();
243 243
 			$obj = & get_instance();
244 244
 			$cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable);
245 245
 			$dispatcher = $obj->eventdispatcher;
246 246
 			$content = $this->_pageRender;
247
-			if(! $content){
247
+			if (!$content) {
248 248
 				$logger->warning('The final view content is empty.');
249 249
 				return;
250 250
 			}
251 251
 			//dispatch
252 252
 			$event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true));
253
-			$content = ! empty($event->payload) ? $event->payload : null;
254
-			if(empty($content)){
253
+			$content = !empty($event->payload) ? $event->payload : null;
254
+			if (empty($content)) {
255 255
 				$logger->warning('The view content is empty after dispatch to event listeners.');
256 256
 			}
257 257
 			
258 258
 			//check whether need save the page into cache.
259
-			if($cachePageStatus){
259
+			if ($cachePageStatus) {
260 260
 				//current page URL
261 261
 				$url = $this->_currentUrl;
262 262
 				//Cache view Time to live in second
@@ -271,14 +271,14 @@  discard block
 block discarded – undo
271 271
 				
272 272
 				//get the cache information to prepare header to send to browser
273 273
 				$cacheInfo = $cacheInstance->getInfo($cacheKey);
274
-				if($cacheInfo){
274
+				if ($cacheInfo) {
275 275
 					$lastModified = $cacheInfo['mtime'];
276 276
 					$expire = $cacheInfo['expire'];
277 277
 					$maxAge = $expire - time();
278 278
 					self::setHeader('Pragma', 'public');
279 279
 					self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
280
-					self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
281
-					self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');	
280
+					self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
281
+					self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');	
282 282
 				}
283 283
 			}
284 284
 			
@@ -289,10 +289,10 @@  discard block
 block discarded – undo
289 289
 			$content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content);
290 290
 			
291 291
 			//compress the output if is available
292
-			if (self::$_canCompressOutput){
292
+			if (self::$_canCompressOutput) {
293 293
 				ob_start('ob_gzhandler');
294 294
 			}
295
-			else{
295
+			else {
296 296
 				ob_start();
297 297
 			}
298 298
 			self::sendHeaders(200);
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 		/**
304 304
 		* Send the final page output to user if is cached
305 305
 		*/
306
-		public function renderFinalPageFromCache(&$cache){
306
+		public function renderFinalPageFromCache(&$cache) {
307 307
 			$logger = self::getLogger();
308 308
 			$url = $this->_currentUrl;					
309 309
 			//the current page cache key for identification
@@ -312,25 +312,25 @@  discard block
 block discarded – undo
312 312
 			$logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...');
313 313
 			//get the cache information to prepare header to send to browser
314 314
 			$cacheInfo = $cache->getInfo($pageCacheKey);
315
-			if($cacheInfo){
315
+			if ($cacheInfo) {
316 316
 				$lastModified = $cacheInfo['mtime'];
317 317
 				$expire = $cacheInfo['expire'];
318 318
 				$maxAge = $expire - $_SERVER['REQUEST_TIME'];
319 319
 				self::setHeader('Pragma', 'public');
320 320
 				self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public');
321
-				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT');
322
-				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT');
323
-				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
321
+				self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT');
322
+				self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT');
323
+				if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
324 324
 					$logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser');
325 325
 					self::sendHeaders(304);
326 326
 					return;
327 327
 				}
328
-				else{
328
+				else {
329 329
 					$logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser');
330 330
 					self::sendHeaders(200);
331 331
 					//get the cache content
332 332
 					$content = $cache->get($pageCacheKey);
333
-					if($content){
333
+					if ($content) {
334 334
 						$logger->info('The page content for the URL [' . $url . '] already cached just display it');
335 335
 						//load benchmark class
336 336
 						$benchmark = & class_loader('Benchmark');
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
 						
344 344
 						///display the final output
345 345
 						//compress the output if is available
346
-						if (self::$_canCompressOutput){
346
+						if (self::$_canCompressOutput) {
347 347
 							ob_start('ob_gzhandler');
348 348
 						}
349
-						else{
349
+						else {
350 350
 							ob_start();
351 351
 						}
352 352
 						echo $content;
353 353
 						ob_end_flush();
354 354
 						return;
355 355
 					}
356
-					else{
356
+					else {
357 357
 						$logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired');
358 358
 						$cache->delete($pageCacheKey);
359 359
 					}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 		* Get the final page to be rendered
366 366
 		* @return string
367 367
 		*/
368
-		public function getFinalPageRendered(){
368
+		public function getFinalPageRendered() {
369 369
 			return $this->_pageRender;
370 370
 		}
371 371
 
@@ -373,14 +373,14 @@  discard block
 block discarded – undo
373 373
 		 * Send the HTTP 404 error if can not found the 
374 374
 		 * routing information for the current request
375 375
 		 */
376
-		public static function send404(){
376
+		public static function send404() {
377 377
 			/********* for logs **************/
378 378
 			//can't use $obj = & get_instance()  here because the global super object will be available until
379 379
 			//the main controller is loaded even for Loader::library('xxxx');
380 380
 			$logger = self::getLogger();
381
-			$request =& class_loader('Request', 'classes');
382
-			$userAgent =& class_loader('Browser');
383
-			$browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion();
381
+			$request = & class_loader('Request', 'classes');
382
+			$userAgent = & class_loader('Browser');
383
+			$browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion();
384 384
 			
385 385
 			//here can't use Loader::functions just include the helper manually
386 386
 			require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
@@ -390,12 +390,12 @@  discard block
 block discarded – undo
390 390
 			$logger->error($str);
391 391
 			/***********************************/
392 392
 			$path = CORE_VIEWS_PATH . '404.php';
393
-			if(file_exists($path)){
393
+			if (file_exists($path)) {
394 394
 				//compress the output if is available
395
-				if (self::$_canCompressOutput){
395
+				if (self::$_canCompressOutput) {
396 396
 					ob_start('ob_gzhandler');
397 397
 				}
398
-				else{
398
+				else {
399 399
 					ob_start();
400 400
 				}
401 401
 				require_once $path;
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 				self::sendHeaders(404);
404 404
 				echo $output;
405 405
 			}
406
-			else{
407
-				show_error('The 404 view [' .$path. '] does not exist');
406
+			else {
407
+				show_error('The 404 view [' . $path . '] does not exist');
408 408
 			}
409 409
 		}
410 410
 
@@ -412,14 +412,14 @@  discard block
 block discarded – undo
412 412
 		 * Display the error to user
413 413
 		 * @param  array  $data the error information
414 414
 		 */
415
-		public static function sendError(array $data = array()){
415
+		public static function sendError(array $data = array()) {
416 416
 			$path = CORE_VIEWS_PATH . 'errors.php';
417
-			if(file_exists($path)){
417
+			if (file_exists($path)) {
418 418
 				//compress the output if exists
419
-				if (self::$_canCompressOutput){
419
+				if (self::$_canCompressOutput) {
420 420
 					ob_start('ob_gzhandler');
421 421
 				}
422
-				else{
422
+				else {
423 423
 					ob_start();
424 424
 				}
425 425
 				extract($data);
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 				self::sendHeaders(503);
429 429
 				echo $output;
430 430
 			}
431
-			else{
431
+			else {
432 432
 				//can't use show_error() at this time because some dependencies not yet loaded and to prevent loop
433 433
 				set_http_status_header(503);
434 434
 				echo 'The error view [' . $path . '] does not exist';
Please login to merge, or discard this patch.
tests/tnhfw/classes/EventInfoTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
 		
27 27
 		
28
-		public function testDefaultValue(){
28
+		public function testDefaultValue() {
29 29
 			$e = new EventInfo('foo');
30 30
 			$this->assertSame($e->name, 'foo');
31 31
 			$this->assertSame($e->payload, array());
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 			$this->assertFalse($e->stop);
34 34
 		}
35 35
 		
36
-		public function testPayloadValueIsSet(){
36
+		public function testPayloadValueIsSet() {
37 37
 			$e = new EventInfo('foo', array('bar'));
38 38
 			$this->assertSame($e->name, 'foo');
39 39
 			$this->assertSame($e->payload, array('bar'));
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 			$this->assertFalse($e->stop);
42 42
 		}
43 43
 		
44
-		public function testReturnBackValueIsSetToTrue(){
44
+		public function testReturnBackValueIsSetToTrue() {
45 45
 			$e = new EventInfo('foo', array('bar'), true);
46 46
 			$this->assertSame($e->name, 'foo');
47 47
 			$this->assertSame($e->payload, array('bar'));
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 			$this->assertFalse($e->stop);
50 50
 		}
51 51
 		
52
-		public function testStopValueIsSetToTue(){
52
+		public function testStopValueIsSetToTue() {
53 53
 			$e = new EventInfo('foo', array('bar'), true, true);
54 54
 			$this->assertSame($e->name, 'foo');
55 55
 			$this->assertSame($e->payload, array('bar'));
Please login to merge, or discard this patch.
core/classes/Config.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-	class Config{
27
+	class Config {
28 28
 		
29 29
 		/**
30 30
 		 * The list of loaded configuration
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 		 * The signleton of the logger
43 43
 		 * @return Object the Log instance
44 44
 		 */
45
-		private static function getLogger(){
46
-			if(self::$logger == null){
45
+		private static function getLogger() {
46
+			if (self::$logger == null) {
47 47
 				$logger = array();
48
-				$logger[0] =& class_loader('Log', 'classes');
48
+				$logger[0] = & class_loader('Log', 'classes');
49 49
 				$logger[0]->setLogger('Library::Config');
50 50
 				self::$logger = $logger[0];
51 51
 			}
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		 * @param Log $logger the log object
58 58
 		 * @return Log the log instance
59 59
 		 */
60
-		public static function setLogger($logger){
60
+		public static function setLogger($logger) {
61 61
 			self::$logger = $logger;
62 62
 			return self::$logger;
63 63
 		}
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 		/**
66 66
 		 * Initialize the configuration by loading all the configuration from config file
67 67
 		 */
68
-		public static function init(){
68
+		public static function init() {
69 69
 			$logger = static::getLogger();
70 70
 			$logger->debug('Initialization of the configuration');
71 71
 			self::$config = & load_configurations();
72 72
 			self::setBaseUrlUsingServerVar();
73
-			if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){
73
+			if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) {
74 74
 				$logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance');
75 75
 			}
76 76
 			$logger->info('Configuration initialized successfully');
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 		 * @param  mixed $default the default value to use if can not find the config item in the list
84 84
 		 * @return mixed          the config value if exist or the default value
85 85
 		 */
86
-		public static function get($item, $default = null){
86
+		public static function get($item, $default = null) {
87 87
 			$logger = static::getLogger();
88
-			if(array_key_exists($item, self::$config)){
88
+			if (array_key_exists($item, self::$config)) {
89 89
 				return self::$config[$item];
90 90
 			}
91
-			$logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']');
91
+			$logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']');
92 92
 			return $default;
93 93
 		}
94 94
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		 * @param string $item  the config item name to set
98 98
 		 * @param mixed $value the config item value
99 99
 		 */
100
-		public static function set($item, $value){
100
+		public static function set($item, $value) {
101 101
 			self::$config[$item] = $value;
102 102
 		}
103 103
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		 * Get all the configuration values
106 106
 		 * @return array the config values
107 107
 		 */
108
-		public static function getAll(){
108
+		public static function getAll() {
109 109
 			return self::$config;
110 110
 		}
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		 * Set the configuration values bu merged with the existing configuration
114 114
 		 * @param array $config the config values to add in the configuration list
115 115
 		 */
116
-		public static function setAll(array $config = array()){
116
+		public static function setAll(array $config = array()) {
117 117
 			self::$config = array_merge(self::$config, $config);
118 118
 		}
119 119
 
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 		 * @param  string $item the config item name to be deleted
123 123
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
124 124
 		 */
125
-		public static function delete($item){
125
+		public static function delete($item) {
126 126
 			$logger = static::getLogger();
127
-			if(array_key_exists($item, self::$config)){
128
-				$logger->info('Delete config item ['.$item.']');
127
+			if (array_key_exists($item, self::$config)) {
128
+				$logger->info('Delete config item [' . $item . ']');
129 129
 				unset(self::$config[$item]);
130 130
 				return true;
131 131
 			}
132
-			else{
133
-				$logger->warning('Config item ['.$item.'] to be deleted does not exists');
132
+			else {
133
+				$logger->warning('Config item [' . $item . '] to be deleted does not exists');
134 134
 				return false;
135 135
 			}
136 136
 		}
@@ -139,38 +139,38 @@  discard block
 block discarded – undo
139 139
 		 * Load the configuration file. This an alias to Loader::config()
140 140
 		 * @param  string $config the config name to be loaded
141 141
 		 */
142
-		public static function load($config){
142
+		public static function load($config) {
143 143
 			Loader::config($config);
144 144
 		}
145 145
 
146 146
 		/**
147 147
 		 * Set the configuration for "base_url" if is not set in the configuration
148 148
 		 */
149
-		private static function setBaseUrlUsingServerVar(){
149
+		private static function setBaseUrlUsingServerVar() {
150 150
 			$logger = static::getLogger();
151
-			if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){
152
-				if(ENVIRONMENT == 'production'){
151
+			if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) {
152
+				if (ENVIRONMENT == 'production') {
153 153
 					$logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time');
154 154
 				}
155 155
 				$baseUrl = null;
156
-				if (isset($_SERVER['SERVER_ADDR'])){
156
+				if (isset($_SERVER['SERVER_ADDR'])) {
157 157
 					//check if the server is running under IPv6
158
-					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){
159
-						$baseUrl = '['.$_SERVER['SERVER_ADDR'].']';
158
+					if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) {
159
+						$baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']';
160 160
 					}
161
-					else{
161
+					else {
162 162
 						$baseUrl = $_SERVER['SERVER_ADDR'];
163 163
 					}
164
-					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
-					$baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port
164
+					$port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : '');
165
+					$baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port
166 166
 						. substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
167 167
 				}
168
-				else{
168
+				else {
169 169
 					$logger->warning('Can not determine the application base URL automatically, use http://localhost as default');
170 170
 					$baseUrl = 'http://localhost/';
171 171
 				}
172 172
 				self::set('base_url', $baseUrl);
173 173
 			}
174
-			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/';
174
+			self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/';
175 175
 		}
176 176
 	}
Please login to merge, or discard this patch.
core/classes/Loader.php 1 patch
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * along with this program; if not, write to the Free Software
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26
-	class Loader{
26
+	class Loader {
27 27
 		
28 28
 		/**
29 29
 		 * List of loaded resources
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		private static $logger;
39 39
 
40 40
 
41
-		public function __construct(){
41
+		public function __construct() {
42 42
 			//add the resources already loaded during application bootstrap
43 43
 			//in the list to prevent duplicate or loading the resources again.
44 44
 			static::$loaded = class_loaded();
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		 * Get the logger singleton instance
52 52
 		 * @return Log the logger instance
53 53
 		 */
54
-		private static function getLogger(){
55
-			if(self::$logger == null){
56
-				self::$logger[0] =& class_loader('Log', 'classes');
54
+		private static function getLogger() {
55
+			if (self::$logger == null) {
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Loader');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -67,25 +67,25 @@  discard block
 block discarded – undo
67 67
 		 *
68 68
 		 * @return void
69 69
 		 */
70
-		public static function model($class, $instance = null){
70
+		public static function model($class, $instance = null) {
71 71
 			$logger = static::getLogger();
72 72
 			$class = str_ireplace('.php', '', $class);
73 73
 			$class = trim($class, '/\\');
74
-			$file = ucfirst($class).'.php';
74
+			$file = ucfirst($class) . '.php';
75 75
 			$logger->debug('Loading model [' . $class . '] ...');
76
-			if(! $instance){
76
+			if (!$instance) {
77 77
 				//for module
78
-				if(strpos($class, '/') !== false){
78
+				if (strpos($class, '/') !== false) {
79 79
 					$path = explode('/', $class);
80
-					if(isset($path[1])){
80
+					if (isset($path[1])) {
81 81
 						$instance = strtolower($path[1]);
82 82
 					}
83 83
 				}
84
-				else{
84
+				else {
85 85
 					$instance = strtolower($class);
86 86
 				}
87 87
 			}
88
-			if(isset(static::$loaded[$instance])){
88
+			if (isset(static::$loaded[$instance])) {
89 89
 				$logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance');
90 90
 				return;
91 91
 			}
@@ -95,43 +95,43 @@  discard block
 block discarded – undo
95 95
 			$searchModuleName = null;
96 96
 			$obj = & get_instance();
97 97
 			//check if the request class contains module name
98
-			if(strpos($class, '/') !== false){
98
+			if (strpos($class, '/') !== false) {
99 99
 				$path = explode('/', $class);
100
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
100
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
101 101
 					$searchModuleName = $path[0];
102 102
 					$class = ucfirst($path[1]);
103 103
 				}
104 104
 			}
105
-			else{
105
+			else {
106 106
 				$class = ucfirst($class);
107 107
 			}
108 108
 
109
-			if(! $searchModuleName && !empty($obj->moduleName)){
109
+			if (!$searchModuleName && !empty($obj->moduleName)) {
110 110
 				$searchModuleName = $obj->moduleName;
111 111
 			}
112 112
 			$moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName);
113
-			if($moduleModelFilePath){
114
-				$logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it');
113
+			if ($moduleModelFilePath) {
114
+				$logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it');
115 115
 				$classFilePath = $moduleModelFilePath;
116 116
 			}
117
-			else{
117
+			else {
118 118
 				$logger->info('Cannot find model [' . $class . '] from modules using the default location');
119 119
 			}
120 120
 			$logger->info('The model file path to be loaded is [' . $classFilePath . ']');
121
-			if(file_exists($classFilePath)){
121
+			if (file_exists($classFilePath)) {
122 122
 				require_once $classFilePath;
123
-				if(class_exists($class)){
123
+				if (class_exists($class)) {
124 124
 					$c = new $class();
125 125
 					$obj = & get_instance();
126 126
 					$obj->{$instance} = $c;
127 127
 					static::$loaded[$instance] = $class;
128 128
 					$logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.');
129 129
 				}
130
-				else{
131
-					show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']');
130
+				else {
131
+					show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']');
132 132
 				}
133 133
 			}
134
-			else{
134
+			else {
135 135
 				show_error('Unable to find the model [' . $class . ']');
136 136
 			}
137 137
 		}
@@ -146,31 +146,31 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return void
148 148
 		 */
149
-		public static function library($class, $instance = null, array $params = array()){
149
+		public static function library($class, $instance = null, array $params = array()) {
150 150
 			$logger = static::getLogger();
151 151
 			$class = str_ireplace('.php', '', $class);
152 152
 			$class = trim($class, '/\\');
153
-			$file = ucfirst($class) .'.php';
153
+			$file = ucfirst($class) . '.php';
154 154
 			$logger->debug('Loading library [' . $class . '] ...');
155
-			if(! $instance){
155
+			if (!$instance) {
156 156
 				//for module
157
-				if(strpos($class, '/') !== false){
157
+				if (strpos($class, '/') !== false) {
158 158
 					$path = explode('/', $class);
159
-					if(isset($path[1])){
159
+					if (isset($path[1])) {
160 160
 						$instance = strtolower($path[1]);
161 161
 					}
162 162
 				}
163
-				else{
163
+				else {
164 164
 					$instance = strtolower($class);
165 165
 				}
166 166
 			}
167
-			if(isset(static::$loaded[$instance])){
167
+			if (isset(static::$loaded[$instance])) {
168 168
 				$logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance');
169 169
 				return;
170 170
 			}
171 171
 			$obj = & get_instance();
172 172
 			//TODO for Database library
173
-			if(strtolower($class) == 'database'){
173
+			if (strtolower($class) == 'database') {
174 174
 				$logger->info('This is the Database library ...');
175 175
 				$dbInstance = & class_loader('Database', 'classes', $params);
176 176
 				$obj->{$instance} = $dbInstance;
@@ -180,44 +180,44 @@  discard block
 block discarded – undo
180 180
 			}
181 181
 			$libraryFilePath = null;
182 182
 			$logger->debug('Check if this is a system library ...');
183
-			if(file_exists(CORE_LIBRARY_PATH . $file)){
183
+			if (file_exists(CORE_LIBRARY_PATH . $file)) {
184 184
 				$libraryFilePath = CORE_LIBRARY_PATH . $file;
185 185
 				$class = ucfirst($class);
186 186
 				$logger->info('This library is a system library');
187 187
 			}
188
-			else{
188
+			else {
189 189
 				$logger->info('This library is not a system library');	
190 190
 				//first check if this library is in the module
191 191
 				$logger->debug('Checking library [' . $class . '] from module list ...');
192 192
 				$searchModuleName = null;
193 193
 				//check if the request class contains module name
194
-				if(strpos($class, '/') !== false){
194
+				if (strpos($class, '/') !== false) {
195 195
 					$path = explode('/', $class);
196
-					if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
196
+					if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
197 197
 						$searchModuleName = $path[0];
198 198
 						$class = ucfirst($path[1]);
199 199
 					}
200 200
 				}
201
-				else{
201
+				else {
202 202
 					$class = ucfirst($class);
203 203
 				}
204
-				if(! $searchModuleName && !empty($obj->moduleName)){
204
+				if (!$searchModuleName && !empty($obj->moduleName)) {
205 205
 					$searchModuleName = $obj->moduleName;
206 206
 				}
207 207
 				$moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName);
208
-				if($moduleLibraryPath){
209
-					$logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it');
208
+				if ($moduleLibraryPath) {
209
+					$logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it');
210 210
 					$libraryFilePath = $moduleLibraryPath;
211 211
 				}
212
-				else{
212
+				else {
213 213
 					$logger->info('Cannot find library [' . $class . '] from modules using the default location');
214 214
 				}
215 215
 			}
216
-			if(! $libraryFilePath){
216
+			if (!$libraryFilePath) {
217 217
 				$searchDir = array(LIBRARY_PATH);
218
-				foreach($searchDir as $dir){
218
+				foreach ($searchDir as $dir) {
219 219
 					$filePath = $dir . $file;
220
-					if(file_exists($filePath)){
220
+					if (file_exists($filePath)) {
221 221
 						$libraryFilePath = $filePath;
222 222
 						//is already found not to continue
223 223
 						break;
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
 				}
226 226
 			}
227 227
 			$logger->info('The library file path to be loaded is [' . $libraryFilePath . ']');
228
-			if($libraryFilePath){
228
+			if ($libraryFilePath) {
229 229
 				require_once $libraryFilePath;
230
-				if(class_exists($class)){
230
+				if (class_exists($class)) {
231 231
 					$c = $params ? new $class($params) : new $class();
232 232
 					$obj = & get_instance();
233 233
 					$obj->{$instance} = $c;
234 234
 					static::$loaded[$instance] = $class;
235 235
 					$logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.');
236 236
 				}
237
-				else{
238
-					show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class);
237
+				else {
238
+					show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class);
239 239
 				}
240 240
 			}
241
-			else{
241
+			else {
242 242
 				show_error('Unable to find library class [' . $class . ']');
243 243
 			}
244 244
 		}
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 		 *
251 251
 		 * @return void
252 252
 		 */
253
-		public static function functions($function){
253
+		public static function functions($function) {
254 254
 			$logger = static::getLogger();
255 255
 			$function = str_ireplace('.php', '', $function);
256 256
 			$function = trim($function, '/\\');
257 257
 			$function = str_ireplace('function_', '', $function);
258
-			$file = 'function_'.$function.'.php';
258
+			$file = 'function_' . $function . '.php';
259 259
 			$logger->debug('Loading helper [' . $function . '] ...');
260
-			if(isset(static::$loaded['function_' . $function])){
260
+			if (isset(static::$loaded['function_' . $function])) {
261 261
 				$logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance');
262 262
 				return;
263 263
 			}
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
 			$searchModuleName = null;
268 268
 			$obj = & get_instance();
269 269
 			//check if the request class contains module name
270
-			if(strpos($function, '/') !== false){
270
+			if (strpos($function, '/') !== false) {
271 271
 				$path = explode('/', $function);
272
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
272
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
273 273
 					$searchModuleName = $path[0];
274 274
 					$function = 'function_' . $path[1] . '.php';
275
-					$file = $path[0] . DS . 'function_'.$function.'.php';
275
+					$file = $path[0] . DS . 'function_' . $function . '.php';
276 276
 				}
277 277
 			}
278
-			if(! $searchModuleName && !empty($obj->moduleName)){
278
+			if (!$searchModuleName && !empty($obj->moduleName)) {
279 279
 				$searchModuleName = $obj->moduleName;
280 280
 			}
281 281
 			$moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName);
282
-			if($moduleFunctionPath){
283
-				$logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it');
282
+			if ($moduleFunctionPath) {
283
+				$logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it');
284 284
 				$functionFilePath = $moduleFunctionPath;
285 285
 			}
286
-			else{
286
+			else {
287 287
 				$logger->info('Cannot find helper [' . $function . '] from modules using the default location');
288 288
 			}
289
-			if(! $functionFilePath){
289
+			if (!$functionFilePath) {
290 290
 				$searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH);
291
-				foreach($searchDir as $dir){
291
+				foreach ($searchDir as $dir) {
292 292
 					$filePath = $dir . $file;
293
-					if(file_exists($filePath)){
293
+					if (file_exists($filePath)) {
294 294
 						$functionFilePath = $filePath;
295 295
 						//is already found not to continue
296 296
 						break;
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 				}
299 299
 			}
300 300
 			$logger->info('The helper file path to be loaded is [' . $functionFilePath . ']');
301
-			if($functionFilePath){
301
+			if ($functionFilePath) {
302 302
 				require_once $functionFilePath;
303 303
 				static::$loaded['function_' . $function] = $functionFilePath;
304 304
 				$logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.');
305 305
 			}
306
-			else{
306
+			else {
307 307
 				show_error('Unable to find helper file [' . $file . ']');
308 308
 			}
309 309
 		}
@@ -315,14 +315,14 @@  discard block
 block discarded – undo
315 315
 		 *
316 316
 		 * @return void
317 317
 		 */
318
-		public static function config($filename){
318
+		public static function config($filename) {
319 319
 			$logger = static::getLogger();
320 320
 			$filename = str_ireplace('.php', '', $filename);
321 321
 			$filename = trim($filename, '/\\');
322 322
 			$filename = str_ireplace('config_', '', $filename);
323
-			$file = 'config_'.$filename.'.php';
323
+			$file = 'config_' . $filename . '.php';
324 324
 			$logger->debug('Loading configuration [' . $filename . '] ...');
325
-			if(isset(static::$loaded['config_' . $filename])){
325
+			if (isset(static::$loaded['config_' . $filename])) {
326 326
 				$logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance');
327 327
 				return;
328 328
 			}
@@ -332,33 +332,33 @@  discard block
 block discarded – undo
332 332
 			$searchModuleName = null;
333 333
 			$obj = & get_instance();
334 334
 			//check if the request class contains module name
335
-			if(strpos($filename, '/') !== false){
335
+			if (strpos($filename, '/') !== false) {
336 336
 				$path = explode('/', $filename);
337
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
337
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
338 338
 					$searchModuleName = $path[0];
339 339
 					$filename = $path[1] . '.php';
340 340
 				}
341 341
 			}
342
-			if(! $searchModuleName && !empty($obj->moduleName)){
342
+			if (!$searchModuleName && !empty($obj->moduleName)) {
343 343
 				$searchModuleName = $obj->moduleName;
344 344
 			}
345 345
 			$moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName);
346
-			if($moduleConfigPath){
347
-				$logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it');
346
+			if ($moduleConfigPath) {
347
+				$logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it');
348 348
 				$configFilePath = $moduleConfigPath;
349 349
 			}
350
-			else{
350
+			else {
351 351
 				$logger->info('Cannot find config [' . $filename . '] from modules using the default location');
352 352
 			}
353 353
 			$logger->info('The config file path to be loaded is [' . $configFilePath . ']');
354
-			if(file_exists($configFilePath)){
354
+			if (file_exists($configFilePath)) {
355 355
 				require_once $configFilePath;
356
-				if(! empty($config) && is_array($config)){
356
+				if (!empty($config) && is_array($config)) {
357 357
 					Config::setAll($config);
358 358
 				}
359 359
 			}
360
-			else{
361
-				show_error('Unable to find config file ['. $configFilePath . ']');
360
+			else {
361
+				show_error('Unable to find config file [' . $configFilePath . ']');
362 362
 			}
363 363
 			static::$loaded['config_' . $filename] = $configFilePath;
364 364
 			$logger->info('Configuration [' . $configFilePath . '] loaded successfully.');
@@ -374,14 +374,14 @@  discard block
 block discarded – undo
374 374
 		 *
375 375
 		 * @return void
376 376
 		 */
377
-		public static function lang($language){
377
+		public static function lang($language) {
378 378
 			$logger = static::getLogger();
379 379
 			$language = str_ireplace('.php', '', $language);
380 380
 			$language = trim($language, '/\\');
381 381
 			$language = str_ireplace('lang_', '', $language);
382
-			$file = 'lang_'.$language.'.php';
382
+			$file = 'lang_' . $language . '.php';
383 383
 			$logger->debug('Loading language [' . $language . '] ...');
384
-			if(isset(static::$loaded['lang_' . $language])){
384
+			if (isset(static::$loaded['lang_' . $language])) {
385 385
 				$logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance');
386 386
 				return;
387 387
 			}
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			$cfgKey = get_config('language_cookie_name');
392 392
 			$objCookie = & class_loader('Cookie');
393 393
 			$cookieLang = $objCookie->get($cfgKey);
394
-			if($cookieLang){
394
+			if ($cookieLang) {
395 395
 				$appLang = $cookieLang;
396 396
 			}
397 397
 			$languageFilePath = null;
@@ -400,30 +400,30 @@  discard block
 block discarded – undo
400 400
 			$searchModuleName = null;
401 401
 			$obj = & get_instance();
402 402
 			//check if the request class contains module name
403
-			if(strpos($language, '/') !== false){
403
+			if (strpos($language, '/') !== false) {
404 404
 				$path = explode('/', $language);
405
-				if(isset($path[0]) && in_array($path[0], Module::getModuleList())){
405
+				if (isset($path[0]) && in_array($path[0], Module::getModuleList())) {
406 406
 					$searchModuleName = $path[0];
407 407
 					$language = 'lang_' . $path[1] . '.php';
408
-					$file = $path[0] . DS .$language;
408
+					$file = $path[0] . DS . $language;
409 409
 				}
410 410
 			}
411
-			if(! $searchModuleName && !empty($obj->moduleName)){
411
+			if (!$searchModuleName && !empty($obj->moduleName)) {
412 412
 				$searchModuleName = $obj->moduleName;
413 413
 			}
414 414
 			$moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang);
415
-			if($moduleLanguagePath){
416
-				$logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it');
415
+			if ($moduleLanguagePath) {
416
+				$logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it');
417 417
 				$languageFilePath = $moduleLanguagePath;
418 418
 			}
419
-			else{
419
+			else {
420 420
 				$logger->info('Cannot find language [' . $language . '] from modules using the default location');
421 421
 			}
422
-			if(! $languageFilePath){
422
+			if (!$languageFilePath) {
423 423
 				$searchDir = array(APP_LANG_PATH, CORE_LANG_PATH);
424
-				foreach($searchDir as $dir){
424
+				foreach ($searchDir as $dir) {
425 425
 					$filePath = $dir . $appLang . DS . $file;
426
-					if(file_exists($filePath)){
426
+					if (file_exists($filePath)) {
427 427
 						$languageFilePath = $filePath;
428 428
 						//is already found not to continue
429 429
 						break;
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
 				}
432 432
 			}
433 433
 			$logger->info('The language file path to be loaded is [' . $languageFilePath . ']');
434
-			if($languageFilePath){
434
+			if ($languageFilePath) {
435 435
 				require_once $languageFilePath;
436
-				if(! empty($lang) && is_array($lang)){
437
-					$logger->info('Language file  [' .$languageFilePath. '] contains the valid languages keys add them to language list');
436
+				if (!empty($lang) && is_array($lang)) {
437
+					$logger->info('Language file  [' . $languageFilePath . '] contains the valid languages keys add them to language list');
438 438
 					//Note: may be here the class 'Lang' not yet loaded
439
-					$langObj =& class_loader('Lang', 'classes');
439
+					$langObj = & class_loader('Lang', 'classes');
440 440
 					$langObj->addLangMessages($lang);
441 441
 					//free the memory
442 442
 					unset($lang);
@@ -444,13 +444,13 @@  discard block
 block discarded – undo
444 444
 				static::$loaded['lang_' . $language] = $languageFilePath;
445 445
 				$logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.');
446 446
 			}
447
-			else{
447
+			else {
448 448
 				show_error('Unable to find language file [' . $file . ']');
449 449
 			}
450 450
 		}
451 451
 
452 452
 
453
-		private function getResourcesFromAutoloadConfig(){
453
+		private function getResourcesFromAutoloadConfig() {
454 454
 			$autoloads = array();
455 455
 			$autoloads['config']    = array();
456 456
 			$autoloads['languages'] = array();
@@ -458,22 +458,22 @@  discard block
 block discarded – undo
458 458
 			$autoloads['models']    = array();
459 459
 			$autoloads['functions'] = array();
460 460
 			//loading of the resources in autoload.php configuration file
461
-			if(file_exists(CONFIG_PATH . 'autoload.php')){
461
+			if (file_exists(CONFIG_PATH . 'autoload.php')) {
462 462
 				require_once CONFIG_PATH . 'autoload.php';
463
-				if(! empty($autoload) && is_array($autoload)){
463
+				if (!empty($autoload) && is_array($autoload)) {
464 464
 					$autoloads = array_merge($autoloads, $autoload);
465 465
 					unset($autoload);
466 466
 				}
467 467
 			}
468 468
 			//loading autoload configuration for modules
469 469
 			$modulesAutoloads = Module::getModulesAutoloadConfig();
470
-			if(! empty($modulesAutoloads) && is_array($modulesAutoloads)){
470
+			if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) {
471 471
 				$autoloads = array_merge_recursive($autoloads, $modulesAutoloads);
472 472
 			}
473 473
 			return $autoloads;
474 474
 		}
475 475
 
476
-		private function loadResourcesFromAutoloadConfig(){
476
+		private function loadResourcesFromAutoloadConfig() {
477 477
 			$autoloads = array();
478 478
 			$autoloads['config']    = array();
479 479
 			$autoloads['languages'] = array();
@@ -485,29 +485,29 @@  discard block
 block discarded – undo
485 485
 
486 486
 			$autoloads = array_merge($autoloads, $list);
487 487
 			//config autoload
488
-			foreach($autoloads['config'] as $c){
488
+			foreach ($autoloads['config'] as $c) {
489 489
 				$this->config($c);
490 490
 			}
491 491
 			
492 492
 			//languages autoload
493
-			foreach($autoloads['languages'] as $language){
493
+			foreach ($autoloads['languages'] as $language) {
494 494
 				$this->lang($language);
495 495
 			}
496 496
 			
497 497
 			//libraries autoload
498
-			foreach($autoloads['libraries'] as $library){
498
+			foreach ($autoloads['libraries'] as $library) {
499 499
 				$this->library($library);
500 500
 			}
501 501
 
502 502
 			//models autoload
503
-			if(! empty($autoloads['models']) && is_array($autoloads['models'])){
503
+			if (!empty($autoloads['models']) && is_array($autoloads['models'])) {
504 504
 				require_once CORE_CLASSES_MODEL_PATH . 'Model.php';
505
-				foreach($autoloads['models'] as $model){
505
+				foreach ($autoloads['models'] as $model) {
506 506
 					$this->model($model);
507 507
 				}
508 508
 			}
509 509
 			
510
-			foreach($autoloads['functions'] as $function){
510
+			foreach ($autoloads['functions'] as $function) {
511 511
 				$this->functions($function);
512 512
 			}
513 513
 		}
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
     */
26 26
 
27 27
 
28
-     class FormValidation{
28
+     class FormValidation {
29 29
 		 
30 30
         /**
31 31
          * The form validation status
32 32
          * @var boolean
33 33
          */
34
-        protected $_success  = false;
34
+        protected $_success = false;
35 35
 
36 36
         /**
37 37
          * The list of errors messages
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
         protected $_errorsMessages = array();
41 41
         
42 42
         // Array of rule sets, fieldName => PIPE seperated ruleString
43
-        protected $_rules             = array();
43
+        protected $_rules = array();
44 44
         
45 45
         // Array of errors, niceName => Error Message
46
-        protected $_errors             = array();
46
+        protected $_errors = array();
47 47
         
48 48
         // Array of post Key => Nice name labels
49
-        protected $_labels          = array();
49
+        protected $_labels = array();
50 50
         
51 51
         /**
52 52
          * The errors delimiters
53 53
          * @var array
54 54
          */
55
-        protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
55
+        protected $_allErrorsDelimiter = array('<div class="error">', '</div>');
56 56
 
57 57
         /**
58 58
          * The each error delimiter
59 59
          * @var array
60 60
          */
61
-        protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
61
+        protected $_eachErrorDelimiter = array('<p class="error">', '</p>');
62 62
         
63 63
 		/**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
67
-        protected $_forceFail            = false;
67
+        protected $_forceFail = false;
68 68
 
69 69
         /**
70 70
          * The list of the error messages overrides by the original
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
          * @return void
99 99
          */
100 100
         public function __construct() {
101
-            $this->logger =& class_loader('Log', 'classes');
101
+            $this->logger = & class_loader('Log', 'classes');
102 102
             $this->logger->setLogger('Library::FormValidation');
103 103
            
104 104
 		   //Load form validation language message
105 105
             Loader::lang('form_validation');
106 106
             $obj = & get_instance();
107
-            $this->_errorsMessages  = array(
107
+            $this->_errorsMessages = array(
108 108
                         'required'         => $obj->lang->get('fv_required'),
109 109
                         'min_length'       => $obj->lang->get('fv_min_length'),
110 110
                         'max_length'       => $obj->lang->get('fv_max_length'),
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
             $this->_success              = false;
142 142
             $this->_forceFail            = false;
143 143
             $this->data                  = array();
144
-			$this->enableCsrfCheck       = false;
144
+			$this->enableCsrfCheck = false;
145 145
         }
146 146
 
147 147
         /**
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		 *
151 151
          * @return FormValidation Current instance of object.
152 152
          */
153
-        public function setData(array $data){
153
+        public function setData(array $data) {
154 154
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
155 155
             $this->data = $data;
156 156
 			return $this;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
          * Get the form validation data
161 161
          * @return array the form validation data to be validated
162 162
          */
163
-        public function getData(){
163
+        public function getData() {
164 164
             return $this->data;
165 165
         }
166 166
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		*
170 170
 		* @return string the function name
171 171
 		*/
172
-        protected function _toCallCase($funcName, $prefix='_validate') {
172
+        protected function _toCallCase($funcName, $prefix = '_validate') {
173 173
             $funcName = strtolower($funcName);
174 174
             $finalFuncName = $prefix;
175 175
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
          * @return boolean Whether or not the form has been submitted or the data is available for validation.
194 194
          */
195 195
         public function canDoValidation() {
196
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
196
+            return get_instance()->request->method() === 'POST' || !empty($this->data);
197 197
         }
198 198
 
199 199
         /**
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
          * afterwards.
216 216
          */
217 217
         protected function _run() {
218
-            if(get_instance()->request->method() == 'POST' || $this->enableCsrfCheck){
218
+            if (get_instance()->request->method() == 'POST' || $this->enableCsrfCheck) {
219 219
                 $this->logger->debug('Check if CSRF is enabled in configuration');
220 220
                 //first check for CSRF
221
-                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && ! Security::validateCSRF()){
221
+                if ((get_config('csrf_enable', false) || $this->enableCsrfCheck) && !Security::validateCSRF()) {
222 222
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
223 223
                 }
224
-                else{
224
+                else {
225 225
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
226 226
                 }
227 227
             }
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
             $this->_forceFail = false;
230 230
 
231 231
             foreach ($this->getData() as $inputName => $inputVal) {
232
-    			if(is_array($this->data[$inputName])){
232
+    			if (is_array($this->data[$inputName])) {
233 233
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
234 234
     			}
235
-    			else{
235
+    			else {
236 236
     				$this->data[$inputName] = trim($this->data[$inputName]);
237 237
     			}
238 238
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         public function setRule($inputField, $inputLabel, $ruleSets) {
260 260
             $this->_rules[$inputField] = $ruleSets;
261 261
             $this->_labels[$inputField] = $inputLabel;
262
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
262
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
263 263
             return $this;
264 264
         }
265 265
 
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
             }
424 424
             $errorOutput .= $errorsEnd;
425 425
             echo ($echo) ? $errorOutput : '';
426
-            return (! $echo) ? $errorOutput : null;
426
+            return (!$echo) ? $errorOutput : null;
427 427
         }
428 428
 
429 429
         /**
@@ -448,25 +448,25 @@  discard block
 block discarded – undo
448 448
             /*
449 449
             //////////////// hack for regex rule that can contain "|"
450 450
             */
451
-            if(strpos($ruleString, 'regex') !== false){
451
+            if (strpos($ruleString, 'regex') !== false) {
452 452
                 $regexRule = array();
453 453
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
454 454
                 preg_match($rule, $ruleString, $regexRule);
455 455
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
456
-                 if(!empty($regexRule[0])){
456
+                 if (!empty($regexRule[0])) {
457 457
                      $ruleSets[] = $regexRule[0];
458 458
                  }
459 459
                  $ruleStringRegex = explode('|', $ruleStringTemp);
460 460
                 foreach ($ruleStringRegex as $rule) {
461 461
                     $rule = trim($rule);
462
-                    if($rule){
462
+                    if ($rule) {
463 463
                         $ruleSets[] = $rule;
464 464
                     }
465 465
                 }
466 466
                  
467 467
             }
468 468
             /***********************************/
469
-            else{
469
+            else {
470 470
                 if (strpos($ruleString, '|') !== FALSE) {
471 471
                     $ruleSets = explode('|', $ruleString);
472 472
                 } else {
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
          * @return void
499 499
          */
500 500
         protected function _validateRule($inputName, $inputVal, $ruleName) {
501
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
501
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
502 502
             // Array to store args
503 503
             $ruleArgs = array();
504 504
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
                 $key = $i - 1;
544 544
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
545 545
             }
546
-            if (! array_key_exists($inputName, $this->_errors)) {
546
+            if (!array_key_exists($inputName, $this->_errors)) {
547 547
                 $this->_errors[$inputName] = $rulePhrase;
548 548
             }
549 549
         }
@@ -595,13 +595,13 @@  discard block
 block discarded – undo
595 595
          */
596 596
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
597 597
             $inputVal = $this->post($inputName);
598
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
598
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
599 599
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
600 600
                 if ($inputVal == '' && $callbackReturn == true) {
601 601
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
602 602
                 }
603 603
             } 
604
-			else if($inputVal == '') {
604
+			else if ($inputVal == '') {
605 605
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
606 606
             }
607 607
         }
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
628 628
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
629 629
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
630
-				if(! $result){
630
+				if (!$result) {
631 631
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
632 632
 				}
633 633
             }
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
                         continue;
662 662
                     }
663 663
                 } 
664
-				else{
664
+				else {
665 665
                     if ($inputVal == $doNotEqual) {
666 666
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
667 667
                         continue;
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
          */
692 692
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
693 693
             $inputVal = $this->post($inputName);
694
-            if (! preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
695
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
694
+            if (!preg_match("/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i", $inputVal)) {
695
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
696 696
                     return;
697 697
                 }
698 698
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
709 709
             $inputVal = $this->post($inputName);
710 710
             if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
711
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
711
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
712 712
                     return;
713 713
                 }
714 714
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
         protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
725 725
             $inputVal = $this->post($inputName);
726 726
             if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
727
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
727
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
728 728
                     return;
729 729
                 }
730 730
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
         protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
741 741
             $inputVal = $this->post($inputName);
742 742
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
743
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
743
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
744 744
                     return;
745 745
                 }
746 746
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
757 757
             $inputVal = $this->post($inputName);
758 758
             if ($inputVal >= $ruleArgs[1]) { 
759
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
759
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
760 760
                     return;
761 761
                 }
762 762
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
773 773
             $inputVal = $this->post($inputName);
774 774
             if ($inputVal <= $ruleArgs[1]) {
775
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
775
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
776 776
                     return;
777 777
                 }
778 778
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
          */
788 788
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
789 789
             $inputVal = $this->post($inputName);
790
-            if (! is_numeric($inputVal)) {
791
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
790
+            if (!is_numeric($inputVal)) {
791
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
792 792
                     return;
793 793
                 }
794 794
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
805 805
             $inputVal = $this->post($inputName);
806 806
     		$obj = & get_instance();
807
-    		if(! isset($obj->database)){
807
+    		if (!isset($obj->database)) {
808 808
     			return;
809 809
     		}
810 810
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
     			          ->get();
814 814
     		$nb = $obj->database->numRows();
815 815
             if ($nb == 0) {
816
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
816
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
817 817
                     return;
818 818
                 }
819 819
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
830 830
             $inputVal = $this->post($inputName);
831 831
     		$obj = & get_instance();
832
-    		if(! isset($obj->database)){
832
+    		if (!isset($obj->database)) {
833 833
     			return;
834 834
     		}
835 835
     		list($table, $column) = explode('.', $ruleArgs[1]);
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
     			          ->get();
839 839
     		$nb = $obj->database->numRows();
840 840
             if ($nb != 0) {
841
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
841
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
842 842
                     return;
843 843
                 }
844 844
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -854,11 +854,11 @@  discard block
 block discarded – undo
854 854
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
855 855
             $inputVal = $this->post($inputName);
856 856
     		$obj = & get_instance();
857
-    		if(! isset($obj->database)){
857
+    		if (!isset($obj->database)) {
858 858
     			return;
859 859
     		}
860 860
     		$data = explode(',', $ruleArgs[1]);
861
-    		if(count($data) < 2){
861
+    		if (count($data) < 2) {
862 862
     			return;
863 863
     		}
864 864
     		list($table, $column) = explode('.', $data[0]);
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
                 		  ->get();
870 870
     		$nb = $obj->database->numRows();
871 871
             if ($nb != 0) {
872
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
872
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
873 873
                     return;
874 874
                 }
875 875
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -886,8 +886,8 @@  discard block
 block discarded – undo
886 886
             $inputVal = $this->post($inputName);
887 887
     		$list = explode(',', $ruleArgs[1]);
888 888
             $list = array_map('trim', $list);
889
-            if (! in_array($inputVal, $list)) {
890
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
889
+            if (!in_array($inputVal, $list)) {
890
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
891 891
                     return;
892 892
                 }
893 893
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -903,8 +903,8 @@  discard block
 block discarded – undo
903 903
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
904 904
             $inputVal = $this->post($inputName);
905 905
     		$regex = $ruleArgs[1];
906
-            if (! preg_match($regex, $inputVal)) {
907
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
906
+            if (!preg_match($regex, $inputVal)) {
907
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
908 908
                     return;
909 909
                 }
910 910
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.
tests/include/common.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
29 29
 		//put the first letter of class to upper case 
30 30
 		$class = ucfirst($class);
31 31
 		static $classes = array();
32
-		if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){
32
+		if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') {
33 33
 			return $classes[$class];
34 34
 		}
35 35
 		$found = false;
36 36
 		foreach (array(ROOT_PATH, CORE_PATH) as $path) {
37 37
 			$file = $path . $dir . '/' . $class . '.php';
38
-			if(file_exists($file)){
39
-				if(class_exists($class, false) === false){
38
+			if (file_exists($file)) {
39
+				if (class_exists($class, false) === false) {
40 40
 					require_once $file;
41 41
 				}
42 42
 				//already found
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 				break;
45 45
 			}
46 46
 		}
47
-		if(! $found){
47
+		if (!$found) {
48 48
 			//can't use show_error() at this time because some dependencies not yet loaded
49 49
 			set_http_status_header(503);
50 50
 			echo 'Cannot find the class [' . $class . ']';
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		/*
55 55
 		   TODO use the best method to get the Log instance
56 56
 		 */
57
-		if($class == 'Log'){
57
+		if ($class == 'Log') {
58 58
 			//can't use the instruction like "return new Log()" 
59 59
 			//because we need return the reference instance of the loaded class.
60 60
 			$log = new Log();
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
 	function & class_loaded($class = null){
74 74
 		static $list = array();
75
-		if($class != null){
75
+		if ($class != null) {
76 76
 			$list[strtolower($class)] = $class;
77 77
 		}
78 78
 		return $list;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
 	function & load_configurations(array $overwrite_values = array()){
82 82
 		static $config;
83
-		if(empty($config)){
83
+		if (empty($config)) {
84 84
 			$file = CONFIG_PATH . 'config.php';
85 85
 			require_once $file;
86 86
 		
@@ -94,53 +94,53 @@  discard block
 block discarded – undo
94 94
 	/**
95 95
 	*  @test
96 96
 	*/
97
-	function get_config($key, $default = null){
97
+	function get_config($key, $default = null) {
98 98
 		static $cfg;
99
-		if(empty($cfg)){
99
+		if (empty($cfg)) {
100 100
 			$cfg[0] = & load_configurations();
101 101
 		}
102 102
 		return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default;
103 103
 	}
104 104
 
105
-	function save_to_log($level, $message, $logger = null){
106
-		echo 'save_to_log('.$level . ',' . $message . ',' . $logger . ")\n";
105
+	function save_to_log($level, $message, $logger = null) {
106
+		echo 'save_to_log(' . $level . ',' . $message . ',' . $logger . ")\n";
107 107
 	}
108 108
 
109 109
 	
110
-	function set_http_status_header($code = 200, $text = null){
110
+	function set_http_status_header($code = 200, $text = null) {
111 111
 		echo 'header(' . $code . ', ' . $text . ')';
112 112
 		return true;
113 113
 	}
114 114
 
115 115
 	
116
-	function show_error($msg, $title = 'error', $logging = true){
116
+	function show_error($msg, $title = 'error', $logging = true) {
117 117
 		//show only and continue to help track of some error occured
118 118
 		echo 'show_error(' . $msg . ', ' . $title . ', ' . ($logging ? 'Y' : 'N') . ")\n";
119 119
 	}
120 120
 
121
-	function is_https(){
121
+	function is_https() {
122 122
 		return false;
123 123
 	}
124 124
 	
125 125
 	/**
126 126
 	*  @test
127 127
 	*/
128
-	function is_url($url){
128
+	function is_url($url) {
129 129
 		return preg_match('/^(http|https|ftp):\/\/(.*)/', $url);
130 130
 	}
131 131
 		
132
-	function php_exception_handler($ex){
132
+	function php_exception_handler($ex) {
133 133
 		//show only and continue to help track of some error occured
134
-		echo 'php_exception_handler('.$ex->getMessage().', '.$ex->getFile().', '.$ex->getLine() . ")\n";
134
+		echo 'php_exception_handler(' . $ex->getMessage() . ', ' . $ex->getFile() . ', ' . $ex->getLine() . ")\n";
135 135
 	}
136 136
 	
137 137
 	
138
-	function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){
138
+	function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) {
139 139
 		//show only and continue to help track of some error occured
140
-		echo 'php_error_handler('.$errno .', ' . $errstr.', ' . $errfile.', '.$errline . ")\n";
140
+		echo 'php_error_handler(' . $errno . ', ' . $errstr . ', ' . $errfile . ', ' . $errline . ")\n";
141 141
 	}
142 142
 
143
-	function php_shudown_handler(){
143
+	function php_shudown_handler() {
144 144
 		return true;
145 145
 	}
146 146
 
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
 	/**
149 149
 	*  @test
150 150
 	*/
151
-	function attributes_to_string(array $attributes){
151
+	function attributes_to_string(array $attributes) {
152 152
 		$str = ' ';
153 153
 		//we check that the array passed as an argument is not empty.
154
-		if(! empty($attributes)){
155
-			foreach($attributes as $key => $value){
154
+		if (!empty($attributes)) {
155
+			foreach ($attributes as $key => $value) {
156 156
 				$key = trim(htmlspecialchars($key));
157 157
 				$value = trim(htmlspecialchars($value));
158 158
 				/*
@@ -162,35 +162,35 @@  discard block
 block discarded – undo
162 162
 				* 	$attr = array('placeholder' => 'I am a "puple"')
163 163
 				* 	$str = attributes_to_string($attr); => placeholder = "I am a \"puple\""
164 164
 				 */
165
-				if($value && strpos('"', $value) !== false){
165
+				if ($value && strpos('"', $value) !== false) {
166 166
 					$value = addslashes($value);
167 167
 				}
168
-				$str .= $key.' = "'.$value.'" ';
168
+				$str .= $key . ' = "' . $value . '" ';
169 169
 			}
170 170
 		}
171 171
 		//remove the space after using rtrim()
172 172
 		return rtrim($str);
173 173
 	}
174 174
 
175
-	function stringfy_vars($var){
175
+	function stringfy_vars($var) {
176 176
 		return print_r($var, true);
177 177
 	}
178 178
 
179 179
 	/**
180 180
 	*  @test
181 181
 	*/
182
-	function clean_input($str){
183
-		if(is_array($str)){
182
+	function clean_input($str) {
183
+		if (is_array($str)) {
184 184
 			$str = array_map('clean_input', $str);
185 185
 		}
186
-		else if(is_object($str)){
186
+		else if (is_object($str)) {
187 187
 			$obj = $str;
188 188
 			foreach ($str as $var => $value) {
189 189
 				$obj->$var = clean_input($value);
190 190
 			}
191 191
 			$str = $obj;
192 192
 		}
193
-		else{
193
+		else {
194 194
 			$str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8');
195 195
 		}
196 196
 		return $str;
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	/**
200 200
 	*  @test
201 201
 	*/
202
-	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){
202
+	function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') {
203 203
 		//get the string length
204 204
 		$len = strlen($str);
205 205
 		//if str is empty
206
-		if($len <= 0){
206
+		if ($len <= 0) {
207 207
 			return str_repeat($hiddenChar, 6);
208 208
 		}
209 209
 		//if the length is less than startCount and endCount
@@ -211,14 +211,14 @@  discard block
 block discarded – undo
211 211
 		//or startCount is negative or endCount is negative
212 212
 		//return the full string hidden
213 213
 		
214
-		if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){
214
+		if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) {
215 215
 			return str_repeat($hiddenChar, $len);
216 216
 		}
217 217
 		//the start non hidden string
218 218
 		$startNonHiddenStr = substr($str, 0, $startCount);
219 219
 		//the end non hidden string
220 220
 		$endNonHiddenStr = null;
221
-		if($endCount > 0){
221
+		if ($endCount > 0) {
222 222
 			$endNonHiddenStr = substr($str, - $endCount);
223 223
 		}
224 224
 		//the hidden string
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 		return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr;
228 228
 	}
229 229
 	
230
-	function set_session_config(){
230
+	function set_session_config() {
231 231
 		return true;
232 232
 	}
233 233
 	
234 234
 	function & get_instance(){
235
-		if(! Controller::get_instance()){
235
+		if (!Controller::get_instance()) {
236 236
 			$c = new Controller();
237 237
 			return $c;
238 238
 		}
Please login to merge, or discard this patch.
core/libraries/Upload.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     *    @package FileUpload
38 38
     *    @version 1.5
39 39
     */
40
-    class Upload{
40
+    class Upload {
41 41
 
42 42
         /**
43 43
         *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         *    @version    1.0
70 70
         *    @var        array
71 71
         */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
         *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         *    @version    1.0
120 120
         *    @var        float
121 121
         */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
         *    List of allowed mime types
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
         *    @return    object
218 218
         *    @method    object    __construct
219 219
         */
220
-        public function __construct(){
221
-            $this->logger =& class_loader('Log', 'classes');
220
+        public function __construct() {
221
+            $this->logger = & class_loader('Log', 'classes');
222 222
             $this->logger->setLogger('Library::Upload');
223 223
 
224 224
             Loader::lang('file_upload');
225
-            $obj =& get_instance();
225
+            $obj = & get_instance();
226 226
 
227 227
             $this->error_messages = array(
228 228
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
             );
240 240
 
241 241
             $this->file = array(
242
-                'status'                =>    false,    // True: success upload
243
-                'mime'                  =>    '',       // Empty string
244
-                'filename'              =>    '',       // Empty string
245
-                'original'              =>    '',       // Empty string
246
-                'size'                  =>    0,        // 0 Bytes
247
-                'sizeFormated'          =>    '0B',     // 0 Bytes
248
-                'destination'           =>    './',     // Default: ./
249
-                'allowed_mime_types'    =>    array(),  // Allowed mime types
250
-                'error'                 =>    null,        // File error
242
+                'status'                =>    false, // True: success upload
243
+                'mime'                  =>    '', // Empty string
244
+                'filename'              =>    '', // Empty string
245
+                'original'              =>    '', // Empty string
246
+                'size'                  =>    0, // 0 Bytes
247
+                'sizeFormated'          =>    '0B', // 0 Bytes
248
+                'destination'           =>    './', // Default: ./
249
+                'allowed_mime_types'    =>    array(), // Allowed mime types
250
+                'error'                 =>    null, // File error
251 251
             );
252 252
 
253 253
             // Change dir to current dir
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
             } elseif (isset($HTTP_POST_FILES) && is_array($HTTP_POST_FILES)) {
260 260
                 $this->file_array = $HTTP_POST_FILES;
261 261
             }
262
-            $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array));
262
+            $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array));
263 263
         }
264 264
         /**
265 265
         *    Set input.
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
         */
276 276
         public function setInput($input)
277 277
         {
278
-            if (!empty($input) && (is_string($input) || is_numeric($input) )) {
278
+            if (!empty($input) && (is_string($input) || is_numeric($input))) {
279 279
                 $this->input = $input;
280 280
             }
281 281
             return $this;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         */
312 312
         public function setAutoFilename()
313 313
         {
314
-            $this->filename = sha1(mt_rand(1, 9999).uniqid());
314
+            $this->filename = sha1(mt_rand(1, 9999) . uniqid());
315 315
             $this->filename .= time();
316 316
             return $this;
317 317
         }
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
                 $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize'));
333 333
                 // Calculate difference
334 334
                 if ($php_size < $file_size) {
335
-                    $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']');
335
+                    $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']');
336 336
                 }
337 337
                 $this->max_file_size = $file_size;
338 338
             }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         public function setAllowedMimeTypes(array $mimes)
351 351
         {
352 352
             if (count($mimes) > 0) {
353
-                array_map(array($this , 'setAllowMimeType'), $mimes);
353
+                array_map(array($this, 'setAllowMimeType'), $mimes);
354 354
             }
355 355
             return $this;
356 356
         }
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
         {
416 416
             if (!empty($name) && is_string($name)) {
417 417
                 if (array_key_exists($name, $this->mime_helping)) {
418
-                    return $this->setAllowedMimeTypes($this->mime_helping[ $name ]);
418
+                    return $this->setAllowedMimeTypes($this->mime_helping[$name]);
419 419
                 }
420 420
             }
421 421
             return $this;
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
         */
435 435
         public function setUploadFunction($function)
436 436
         {
437
-            if (!empty($function) && (is_array($function) || is_string($function) )) {
438
-                if (is_callable( $function)) {
437
+            if (!empty($function) && (is_array($function) || is_string($function))) {
438
+                if (is_callable($function)) {
439 439
                     $this->upload_function = $function;
440 440
                 }
441 441
             }
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
                         $this->destination_directory = $destination_directory;
481 481
                         chdir($destination_directory);
482 482
                     }
483
-                    else{
484
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
483
+                    else {
484
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
485 485
                     }
486 486
                 }
487 487
             }
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         public function isFilename($filename)
532 532
         {
533 533
             $filename = basename($filename);
534
-            return (!empty($filename) && (is_string( $filename) || is_numeric($filename)));
534
+            return (!empty($filename) && (is_string($filename) || is_numeric($filename)));
535 535
         }
536 536
         /**
537 537
         *    Validate mime type with allowed mime types,
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
         */
574 574
         public function isDirpath($path)
575 575
         {
576
-            if (!empty( $path) && (is_string( $path) || is_numeric($path) )) {
576
+            if (!empty($path) && (is_string($path) || is_numeric($path))) {
577 577
                 if (DIRECTORY_SEPARATOR == '/') {
578
-                    return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 );
578
+                    return (preg_match('/^[^*?"<>|:]*$/', $path) == 1);
579 579
                 } else {
580
-                    return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1);
580
+                    return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1);
581 581
                 }
582 582
             }
583 583
             return false;
@@ -605,10 +605,10 @@  discard block
 block discarded – undo
605 605
         */
606 606
         public function getInfo()
607 607
         {
608
-            return (object)$this->file;
608
+            return (object) $this->file;
609 609
         }
610 610
 
611
-        public function isUploaded(){
611
+        public function isUploaded() {
612 612
             return isset($this->file_array[$this->input])
613 613
             &&
614 614
             is_uploaded_file($this->file_array[$this->input]['tmp_name']);
@@ -621,9 +621,9 @@  discard block
 block discarded – undo
621 621
         *    @return    boolean
622 622
         *    @method    boolean    save
623 623
         */
624
-        public function save(){
624
+        public function save() {
625 625
             //check if file upload is  allowed in the configuration
626
-            if(! ini_get('file_uploads')){
626
+            if (!ini_get('file_uploads')) {
627 627
                 $this->setError($this->error_messages['file_uploads']);
628 628
                 return false;
629 629
             }
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
                     if (empty($this->filename)) {
634 634
                         $this->filename = $this->file_array[$this->input]['name'];
635 635
                     }
636
-                    else{
636
+                    else {
637 637
                         // Replace %s for extension in filename
638 638
                         // Before: /[\w\d]*(.[\d\w]+)$/i
639 639
                         // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -657,10 +657,10 @@  discard block
 block discarded – undo
657 657
                     $this->file['filename']     = $this->filename;
658 658
                     $this->file['error']        = $this->file_array[$this->input]['error'];
659 659
 
660
-                    $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file));
660
+                    $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file));
661 661
 
662 662
                     //check for php upload error
663
-                    if(is_numeric($this->file['error']) && $this->file['error'] > 0){
663
+                    if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
664 664
                         $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
665 665
                         return false;
666 666
                     }
@@ -686,8 +686,8 @@  discard block
 block discarded – undo
686 686
                     }
687 687
 
688 688
                     // Execute input callback
689
-                    if (!empty( $this->callbacks['input'])) {
690
-                        call_user_func($this->callbacks['input'], (object)$this->file);
689
+                    if (!empty($this->callbacks['input'])) {
690
+                        call_user_func($this->callbacks['input'], (object) $this->file);
691 691
                     }
692 692
                    
693 693
 
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
                     );
700 700
 
701 701
                     // Execute output callback
702
-                    if (!empty( $this->callbacks['output'])) {
703
-                        call_user_func($this->callbacks['output'], (object)$this->file);
702
+                    if (!empty($this->callbacks['output'])) {
703
+                        call_user_func($this->callbacks['output'], (object) $this->file);
704 704
                     }
705 705
                     return $this->file['status'];
706 706
                 }
@@ -719,10 +719,10 @@  discard block
 block discarded – undo
719 719
         */
720 720
         public function sizeFormat($size, $precision = 2)
721 721
         {
722
-            if($size > 0){
722
+            if ($size > 0) {
723 723
                 $base       = log($size) / log(1024);
724 724
                 $suffixes   = array('B', 'K', 'M', 'G', 'T');
725
-                return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
725
+                return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : '');
726 726
             }
727 727
             return null;
728 728
         }
@@ -746,14 +746,14 @@  discard block
 block discarded – undo
746 746
             if (array_key_exists('unit', $matches)) {
747 747
                 $unit = strtoupper($matches['unit']);
748 748
             }
749
-            return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ;
749
+            return (floatval($matches['size']) * pow(1024, $units[$unit]));
750 750
         }
751 751
 
752 752
         /**
753 753
          * Get the upload error message
754 754
          * @return string
755 755
          */
756
-        public function getError(){
756
+        public function getError() {
757 757
             return $this->error;
758 758
         }
759 759
 
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
          * Set the upload error message
762 762
          * @param string $message the upload error message to set
763 763
          */
764
-        public function setError($message){
764
+        public function setError($message) {
765 765
             $this->logger->info('The upload got error : ' . $message);
766 766
             $this->error = $message;
767 767
         }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
          * @param  int $code the error code
772 772
          * @return string the error message
773 773
          */
774
-        private function getPhpUploadErrorMessageByCode($code){
774
+        private function getPhpUploadErrorMessageByCode($code) {
775 775
             $codeMessageMaps = array(
776 776
                 1 => $this->error_messages['upload_err_ini_size'],
777 777
                 2 => $this->error_messages['upload_err_form_size'],
Please login to merge, or discard this patch.