Passed
Push — 1.0.0-dev ( 8edc19...2b6704 )
by nguereza
03:32
created
core/functions/function_user_agent.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	
43 43
 	 
44
-	if(! function_exists('get_ip')){
44
+	if (!function_exists('get_ip')) {
45 45
 		/**
46 46
 		 *  Retrieves the user's IP address
47 47
 		 *  
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		 *  
51 51
 		 *  @return string the IP address.
52 52
 		 */
53
-		function get_ip(){
53
+		function get_ip() {
54 54
 			$ip = '127.0.0.1';
55 55
 			$ipServerVars = array(
56 56
 								'REMOTE_ADDR',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 								'HTTP_FORWARDED'
62 62
 							);
63 63
 			foreach ($ipServerVars as $var) {
64
-				if(isset($_SERVER[$var])){
64
+				if (isset($_SERVER[$var])) {
65 65
 					$ip = $_SERVER[$var];
66 66
 					break;
67 67
 				}
Please login to merge, or discard this patch.
core/libraries/Assets.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *  @since 1.0.0
39 39
 	 *  @filesource
40 40
 	 */
41
-	class Assets{
41
+	class Assets {
42 42
 		
43 43
 		/**
44 44
 		 * The logger instance
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 		 * The signleton of the logger
51 51
 		 * @return Object the Log instance
52 52
 		 */
53
-		private static function getLogger(){
54
-			if(self::$logger == null){
53
+		private static function getLogger() {
54
+			if (self::$logger == null) {
55 55
 				//can't assign reference to static variable
56
-				self::$logger[0] =& class_loader('Log', 'classes');
56
+				self::$logger[0] = & class_loader('Log', 'classes');
57 57
 				self::$logger[0]->setLogger('Library::Assets');
58 58
 			}
59 59
 			return self::$logger[0];
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 		 *  @param string $asset the name of the assets file path with the extension.
73 73
 		 *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
74 74
 		 */
75
-		public static function path($asset){
75
+		public static function path($asset) {
76 76
 			$logger = self::getLogger();	
77 77
 			$path = ASSETS_PATH . $asset;
78 78
 			
79 79
 			$logger->debug('Including the Assets file [' . $path . ']');
80 80
 			//Check if the file exists
81
-			if(file_exists($path)){
81
+			if (file_exists($path)) {
82 82
 				$logger->info('Assets file [' . $path . '] included successfully');
83 83
 				return Url::base_url($path);
84 84
 			}
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 *  @param string $path the name of the css file without the extension.
99 99
 		 *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
100 100
 		 */
101
-		public static function css($path){
101
+		public static function css($path) {
102 102
 			$logger = self::getLogger();
103 103
 			/*
104 104
 			* if the file name contains the ".css" extension, replace it with 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			
110 110
 			$logger->debug('Including the Assets file [' . $path . '] for CSS');
111 111
 			//Check if the file exists
112
-			if(file_exists($path)){
112
+			if (file_exists($path)) {
113 113
 				$logger->info('Assets file [' . $path . '] for CSS included successfully');
114 114
 				return Url::base_url($path);
115 115
 			}
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 		 *  @param string $path the name of the javascript file without the extension.
130 130
 		 *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
131 131
 		 */
132
-		public static function js($path){
132
+		public static function js($path) {
133 133
 			$logger = self::getLogger();
134 134
 			$path = str_ireplace('.js', '', $path);
135 135
 			$path = ASSETS_PATH . 'js/' . $path . '.js';
136 136
 			$logger->debug('Including the Assets file [' . $path . '] for javascript');
137
-			if(file_exists($path)){
137
+			if (file_exists($path)) {
138 138
 				$logger->info('Assets file [' . $path . '] for Javascript included successfully');
139 139
 				return Url::base_url($path);
140 140
 			}
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		 *  @param string $path the name of the image file with the extension.
155 155
 		 *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
156 156
 		 */
157
-		public static function img($path){
157
+		public static function img($path) {
158 158
 			$logger = self::getLogger();
159 159
 			$path = ASSETS_PATH . 'images/' . $path;
160 160
 			$logger->debug('Including the Assets file [' . $path . '] for image');
161
-			if(file_exists($path)){
161
+			if (file_exists($path)) {
162 162
 				$logger->info('Assets file [' . $path . '] for image included successfully');
163 163
 				return Url::base_url($path);
164 164
 			}
Please login to merge, or discard this patch.
core/classes/Url.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Url{
28
+	class Url {
29 29
 
30 30
 		/**
31 31
 		 * Return the link using base_url config without front controller "index.php"
32 32
 		 * @param  string $path the link path or full URL
33 33
 		 * @return string the full link URL
34 34
 		 */
35
-		public static function base_url($path = ''){
36
-			if(is_url($path)){
35
+		public static function base_url($path = '') {
36
+			if (is_url($path)) {
37 37
 				return $path;
38 38
 			}
39 39
 			return get_config('base_url') . $path;
@@ -44,26 +44,26 @@  discard block
 block discarded – undo
44 44
 		 * @param  string $path the link path or full URL
45 45
 		 * @return string the full link URL
46 46
 		 */
47
-		public static function site_url($path = ''){
48
-			if(is_url($path)){
47
+		public static function site_url($path = '') {
48
+			if (is_url($path)) {
49 49
 				return $path;
50 50
 			}
51 51
 			$path = rtrim($path, '/');
52 52
 			$baseUrl = get_config('base_url');
53 53
 			$frontController = get_config('front_controller');
54 54
 			$url = $baseUrl;
55
-			if($frontController){
55
+			if ($frontController) {
56 56
 				$url .= $frontController . '/';
57 57
 			}
58
-			if(($suffix = get_config('url_suffix')) && $path){
59
-				if(strpos($path, '?') !== false){
58
+			if (($suffix = get_config('url_suffix')) && $path) {
59
+				if (strpos($path, '?') !== false) {
60 60
 					$query = explode('?', $path);
61 61
 					$query[0] = str_ireplace($suffix, '', $query[0]);
62 62
 					$query[0] = rtrim($query[0], '/');
63 63
 					$query[0] .= $suffix;
64 64
 					$path = implode('?', $query);
65 65
 				}
66
-				else{
66
+				else {
67 67
 					$path .= $suffix;
68 68
 				}
69 69
 			}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 		 * Return the current site URL
75 75
 		 * @return string
76 76
 		 */
77
-		public static function current(){
77
+		public static function current() {
78 78
 			$current = '/';
79 79
 			$requestUri = get_instance()->request->requestUri();
80
-			if($requestUri){
80
+			if ($requestUri) {
81 81
 				$current = $requestUri;
82 82
 			}
83 83
 			return static::domain() . $current;
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
 		 * @param  boolean $lowercase whether to set the final text to lowe case or not
91 91
 		 * @return string the friendly generated text
92 92
 		 */
93
-		public static function title($str = null, $separator = '-', $lowercase = true){
93
+		public static function title($str = null, $separator = '-', $lowercase = true) {
94 94
 			$str = trim($str);
95
-			$from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ');
96
-			$to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n');
95
+			$from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ');
96
+			$to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n');
97 97
 			$str = str_replace($from, $to, $str);
98 98
 			$str = preg_replace('#([^a-z0-9]+)#i', $separator, $str);
99 99
 			$str = str_replace('--', $separator, $str);
100 100
 			//if after process we get something like one-two-three-, need truncate the last separator "-"
101
-			if(substr($str, -1) == $separator){
101
+			if (substr($str, -1) == $separator) {
102 102
 				$str = substr($str, 0, -1);
103 103
 			}
104
-			if($lowercase){
104
+			if ($lowercase) {
105 105
 				$str = strtolower($str);
106 106
 			}
107 107
 			return $str;
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 		 * Get the current application domain with protocol
112 112
 		 * @return string the domain name
113 113
 		 */
114
-		public static function domain(){
114
+		public static function domain() {
115 115
 			$domain = 'localhost';
116 116
 			$port = get_instance()->request->server('SERVER_PORT');
117 117
 			$protocol = 'http';
118
-			if(is_https()){
118
+			if (is_https()) {
119 119
 				$protocol = 'https';
120 120
 			}
121 121
 
@@ -127,23 +127,23 @@  discard block
 block discarded – undo
127 127
 
128 128
 			foreach ($domainserverVars as $var) {
129 129
 				$value = get_instance()->request->server($var);
130
-				if($value){
130
+				if ($value) {
131 131
 					$domain = $value;
132 132
 					break;
133 133
 				}
134 134
 			}
135 135
 			
136
-			if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){
137
-				$domain .= ':'.$port;
136
+			if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) {
137
+				$domain .= ':' . $port;
138 138
 			}
139
-			return $protocol.'://'.$domain;
139
+			return $protocol . '://' . $domain;
140 140
 		}
141 141
 
142 142
 		/**
143 143
 		 * Get the current request query string
144 144
 		 * @return string
145 145
 		 */
146
-		public static function queryString(){
146
+		public static function queryString() {
147 147
 			return get_instance()->request->server('QUERY_STRING');
148 148
 		}
149 149
 	}
Please login to merge, or discard this patch.
core/libraries/Form.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	*/
26 26
 
27 27
 
28
-	class Form{
28
+	class Form {
29 29
 
30 30
 		/**
31 31
 		 * Generate the form opened tag
@@ -35,23 +35,23 @@  discard block
 block discarded – undo
35 35
 		 * @param  string $enctype    the form enctype like "multipart/form-data"
36 36
 		 * @return string             the generated form html
37 37
 		 */
38
-		public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){
39
-			if($path){
38
+		public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null) {
39
+			if ($path) {
40 40
 				$path = Url::site_url($path);
41 41
 			}
42 42
 			$method = strtoupper($method);
43 43
 			$str = null;
44
-			$str .= '<form action = "'.$path.'" method = "'.$method.'"';
45
-			if(! empty($enctype)){
46
-				$str .= ' enctype = "'.$enctype.'" ';
44
+			$str .= '<form action = "' . $path . '" method = "' . $method . '"';
45
+			if (!empty($enctype)) {
46
+				$str .= ' enctype = "' . $enctype . '" ';
47 47
 			}
48
-			if(! isset($attributes['accept-charset'])){
48
+			if (!isset($attributes['accept-charset'])) {
49 49
 				$attributes['accept-charset'] = get_config('charset', 'utf-8');
50 50
 			}
51 51
 			$str .= attributes_to_string($attributes);
52 52
 			$str .= '>';
53 53
 			//if CSRF is enabled in the configuration
54
-			if(get_config('csrf_enable', false) && $method == 'POST'){
54
+			if (get_config('csrf_enable', false) && $method == 'POST') {
55 55
 				$csrfValue = Security::generateCSRF();
56 56
 				$csrfName = get_config('csrf_key', 'csrf_key');
57 57
 				$str .= static::hidden($csrfName, $csrfValue);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		 * @see Form::open() for more details
65 65
 		 * @return string the generated multipart form html
66 66
 		 */
67
-		public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){
67
+		public static function openMultipart($path = null, array $attributes = array(), $method = 'POST') {
68 68
 			return self::open($path, $attributes, $method, 'multipart/form-data');
69 69
 		}
70 70
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		 * Generate the form close
73 73
 		 * @return string the form close html
74 74
 		 */
75
-		public static function close(){
75
+		public static function close() {
76 76
 			return '</form>';
77 77
 		}
78 78
 
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
 		 * @param  array  $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty
84 84
 		 * @return string         the generated fieldset value
85 85
 		 */
86
-		public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){
86
+		public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()) {
87 87
 			$str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>';
88
-			if($legend){
89
-				$str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>';
88
+			if ($legend) {
89
+				$str .= '<legend' . attributes_to_string($legendAttributes) . '>' . $legend . '</legend>';
90 90
 			}
91 91
 			return $str;
92 92
 		}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		 * Generate the fieldset close tag
96 96
 		 * @return string the generated html for fieldset close
97 97
 		 */
98
-		public static function fieldsetClose(){
98
+		public static function fieldsetClose() {
99 99
 			return '</fieldset>';
100 100
 		}
101 101
 
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 		 * @param  string $name the form field name
106 106
 		 * @return string       the error message if exists and null if not
107 107
 		 */
108
-		public static function error($name){
108
+		public static function error($name) {
109 109
 			$return = null;
110 110
 			$obj = & get_instance();
111
-			if(isset($obj->formvalidation)){
111
+			if (isset($obj->formvalidation)) {
112 112
 				$errors = $obj->formvalidation->returnErrors();
113
-				$error =  isset($errors[$name]) ? $errors[$name] : null;
114
-				if($error){
113
+				$error = isset($errors[$name]) ? $errors[$name] : null;
114
+				if ($error) {
115 115
 					list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter();
116 116
 					$return = $errorStart . $error . $errorEnd;
117 117
 				}
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		 * @param  mixed $default the default value if can not found the given form field name
126 126
 		 * @return mixed the form field value if is set, otherwise return the default value.
127 127
 		 */
128
-		public static function value($name, $default = null){
128
+		public static function value($name, $default = null) {
129 129
 			$value = get_instance()->request->query($name);
130 130
 			return $value ? $value : $default;
131 131
 		}
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 		 * @param  array  $attributes the additional attributes to be added
138 138
 		 * @return string the generated label html content
139 139
 		 */
140
-		public static function label($label, $for = '', array $attributes = array()){
140
+		public static function label($label, $for = '', array $attributes = array()) {
141 141
 			$str = '<label';
142
-			if($for){
143
-				$str .= ' for = "'.$for.'"';
142
+			if ($for) {
143
+				$str .= ' for = "' . $for . '"';
144 144
 			}
145 145
 			$str .= attributes_to_string($attributes);
146 146
 			$str .= '>';
147
-			$str .= $label.'</label>';
147
+			$str .= $label . '</label>';
148 148
 			return $str;
149 149
 		}
150 150
 
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 		 * @param  string $type       the type of the form field (password, text, submit, button, etc.)
157 157
 		 * @return string             the generated form field html content for the input
158 158
 		 */
159
-		public static function input($name, $value = null, array $attributes = array(), $type = 'text'){
159
+		public static function input($name, $value = null, array $attributes = array(), $type = 'text') {
160 160
 			$str = null;
161
-			$str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"';
161
+			$str .= '<input name = "' . $name . '" value = "' . $value . '" type = "' . $type . '"';
162 162
 			$str .= attributes_to_string($attributes);
163 163
 			$str .= '/>';
164 164
 			return $str;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		 * Generate the form field for "text"
169 169
 		 * @see Form::input() for more details
170 170
 		 */
171
-		public static function text($name, $value = null, array $attributes = array()){
171
+		public static function text($name, $value = null, array $attributes = array()) {
172 172
 			return self::input($name, $value, $attributes, 'text');
173 173
 		}
174 174
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 		 * Generate the form field for "password"
177 177
 		 * @see Form::input() for more details
178 178
 		 */
179
-		public static function password($name, $value = null, array $attributes = array()){
179
+		public static function password($name, $value = null, array $attributes = array()) {
180 180
 			return self::input($name, $value, $attributes, 'password');
181 181
 		}
182 182
 
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 		 * Generate the form field for "radio"
185 185
 		 * @see Form::input() for more details
186 186
 		 */
187
-		public static function radio($name, $value = null,  $checked = false, array $attributes = array()){
188
-			if($checked){
187
+		public static function radio($name, $value = null, $checked = false, array $attributes = array()) {
188
+			if ($checked) {
189 189
 				$attributes['checked'] = true;
190 190
 			}
191 191
 			return self::input($name, $value, $attributes, 'radio');
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 		 * Generate the form field for "checkbox"
196 196
 		 * @see Form::input() for more details
197 197
 		 */
198
-		public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){
199
-			if($checked){
198
+		public static function checkbox($name, $value = null, $checked = false, array $attributes = array()) {
199
+			if ($checked) {
200 200
 				$attributes['checked'] = true;
201 201
 			}
202 202
 			return self::input($name, $value, $attributes, 'checkbox');
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		 * Generate the form field for "number"
207 207
 		 * @see Form::input() for more details
208 208
 		 */
209
-		public static function number($name, $value = null, array $attributes = array()){
209
+		public static function number($name, $value = null, array $attributes = array()) {
210 210
 			return self::input($name, $value, $attributes, 'number');
211 211
 		}
212 212
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		 * Generate the form field for "phone"
215 215
 		 * @see Form::input() for more details
216 216
 		 */
217
-		public static function phone($name, $value = null, array $attributes = array()){
217
+		public static function phone($name, $value = null, array $attributes = array()) {
218 218
 			return self::input($name, $value, $attributes, 'phone');
219 219
 		}
220 220
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		 * Generate the form field for "email"
223 223
 		 * @see Form::input() for more details
224 224
 		 */
225
-		public static function email($name, $value = null, array $attributes = array()){
225
+		public static function email($name, $value = null, array $attributes = array()) {
226 226
 			return self::input($name, $value, $attributes, 'email');
227 227
 		}
228 228
 		
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		 * Generate the form field for "search"
231 231
 		 * @see Form::input() for more details
232 232
 		 */
233
-		public static function search($name, $value = null, array $attributes = array()){
233
+		public static function search($name, $value = null, array $attributes = array()) {
234 234
 			return self::input($name, $value, $attributes, 'search');
235 235
 		}
236 236
 		
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		 * Generate the form field for "hidden"
239 239
 		 * @see Form::input() for more details
240 240
 		 */
241
-		public static function hidden($name, $value = null, array $attributes = array()){
241
+		public static function hidden($name, $value = null, array $attributes = array()) {
242 242
 			return self::input($name, $value, $attributes, 'hidden');
243 243
 		}
244 244
 		
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 		 * Generate the form field for "file"
247 247
 		 * @see Form::input() for more details
248 248
 		 */
249
-		public static function file($name, array $attributes = array()){
249
+		public static function file($name, array $attributes = array()) {
250 250
 			return self::input($name, null, $attributes, 'file');
251 251
 		}
252 252
 		
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		 * Generate the form field for "button"
255 255
 		 * @see Form::input() for more details
256 256
 		 */
257
-		public static function button($name, $value = null, array $attributes = array()){
257
+		public static function button($name, $value = null, array $attributes = array()) {
258 258
 			return self::input($name, $value, $attributes, 'button');
259 259
 		}
260 260
 		
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 		 * Generate the form field for "reset"
263 263
 		 * @see Form::input() for more details
264 264
 		 */
265
-		public static function reset($name, $value = null, array $attributes = array()){
265
+		public static function reset($name, $value = null, array $attributes = array()) {
266 266
 			return self::input($name, $value, $attributes, 'reset');
267 267
 		}
268 268
 		
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 		 * Generate the form field for "submit"
271 271
 		 * @see Form::input() for more details
272 272
 		 */
273
-		public static function submit($name, $value = null, array $attributes = array()){
273
+		public static function submit($name, $value = null, array $attributes = array()) {
274 274
 			return self::input($name, $value, $attributes, 'submit');
275 275
 		}
276 276
 
@@ -281,12 +281,12 @@  discard block
 block discarded – undo
281 281
 		 * @param  array  $attributes the additional attributes to be added
282 282
 		 * @return string             the generated textarea form html content
283 283
 		 */
284
-		public static function textarea($name, $value = '', array $attributes = array()){
284
+		public static function textarea($name, $value = '', array $attributes = array()) {
285 285
 			$str = null;
286
-			$str .= '<textarea name = "'.$name.'"';
286
+			$str .= '<textarea name = "' . $name . '"';
287 287
 			$str .= attributes_to_string($attributes);
288 288
 			$str .= '>';
289
-			$str .= $value.'</textarea>';
289
+			$str .= $value . '</textarea>';
290 290
 			return $str;
291 291
 		}
292 292
 		
@@ -298,20 +298,20 @@  discard block
 block discarded – undo
298 298
 		 * @param  array  $attributes the additional attribute to be added
299 299
 		 * @return string             the generated form field html content for select
300 300
 		 */
301
-		public static function select($name, $values = null, $selected = null, array $attributes = array()){
302
-			if(! is_array($values)){
301
+		public static function select($name, $values = null, $selected = null, array $attributes = array()) {
302
+			if (!is_array($values)) {
303 303
 				$values = array('' => $values);
304 304
 			}
305 305
 			$str = null;
306
-			$str .= '<select name = "'.$name.'"';
306
+			$str .= '<select name = "' . $name . '"';
307 307
 			$str .= attributes_to_string($attributes);
308 308
 			$str .= '>';
309
-			foreach($values as $key => $val){
309
+			foreach ($values as $key => $val) {
310 310
 				$select = '';
311
-				if($key == $selected){
311
+				if ($key == $selected) {
312 312
 					$select = 'selected';
313 313
 				}
314
-				$str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>';
314
+				$str .= '<option value = "' . $key . '" ' . $select . '>' . $val . '</option>';
315 315
 			}
316 316
 			$str .= '</select>';
317 317
 			return $str;
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	/**
60 60
 	* Custom application path for tests 
61 61
 	*/
62
-	define('APPS_PATH', TESTS_PATH .'hmvc' . DS);
62
+	define('APPS_PATH', TESTS_PATH . 'hmvc' . DS);
63 63
 
64 64
 	/**
65 65
 	* The path to the controller directory of your application.
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	* It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, 
203 203
 	* in HMVC architecture (hierichical, controllers, models, views).
204 204
 	*/
205
-	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS);
205
+	define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS);
206 206
 
207 207
 	/**
208 208
 	* The path to the directory of sources external to your application.
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	$_SESSION = array();
243 243
 	
244 244
 	//check for composer autoload file if exists include it
245
-	if (file_exists(VENDOR_PATH . 'autoload.php')){
245
+	if (file_exists(VENDOR_PATH . 'autoload.php')) {
246 246
 		require_once VENDOR_PATH . 'autoload.php';
247 247
 		
248 248
 		//define the class alias for vstream
Please login to merge, or discard this patch.
core/classes/cache/FileCache.php 1 patch
Spacing   +59 added lines, -59 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 FileCache implements CacheInterface{
27
+	class FileCache implements CacheInterface {
28 28
 		
29 29
 		/**
30 30
 		 * Whether to enable compression of the cache data file.
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
 		private $logger;
40 40
 		
41 41
 		
42
-		public function __construct(Log $logger = null){
43
-			if(! $this->isSupported()){
42
+		public function __construct(Log $logger = null) {
43
+			if (!$this->isSupported()) {
44 44
 				show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.');
45 45
 			}
46 46
 			/**
47 47
 	         * instance of the Log class
48 48
 	         */
49
-	        if(is_object($logger)){
49
+	        if (is_object($logger)) {
50 50
 	          $this->logger = $logger;
51 51
 	        }
52
-	        else{
53
-	            $this->logger =& class_loader('Log', 'classes');
52
+	        else {
53
+	            $this->logger = & class_loader('Log', 'classes');
54 54
 	            $this->logger->setLogger('Library::FileCache');
55 55
 	        }
56 56
 			
57 57
 			//if Zlib extension is not loaded set compressCacheData to false
58
-			if(! extension_loaded('zlib')){
58
+			if (!extension_loaded('zlib')) {
59 59
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
60 60
 				$this->compressCacheData = false;
61 61
 			}
@@ -66,17 +66,17 @@  discard block
 block discarded – undo
66 66
 		 * @param  string $key the key to identify the cache data
67 67
 		 * @return mixed      the cache data if exists else return false
68 68
 		 */
69
-		public function get($key){
70
-			$this->logger->debug('Getting cache data for key ['. $key .']');
69
+		public function get($key) {
70
+			$this->logger->debug('Getting cache data for key [' . $key . ']');
71 71
 			$filePath = $this->getFilePath($key);
72
-			if(! file_exists($filePath)){
73
-				$this->logger->info('No cache file found for the key ['. $key .'], return false');
72
+			if (!file_exists($filePath)) {
73
+				$this->logger->info('No cache file found for the key [' . $key . '], return false');
74 74
 				return false;
75 75
 			}
76
-			$this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid');
77
-			$handle = fopen($filePath,'r');
78
-			if(! is_resource($handle)){
79
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
76
+			$this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid');
77
+			$handle = fopen($filePath, 'r');
78
+			if (!is_resource($handle)) {
79
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
80 80
 				return false;
81 81
 			}
82 82
 			// Getting a shared lock 
@@ -84,20 +84,20 @@  discard block
 block discarded – undo
84 84
 		    $data = file_get_contents($filePath);
85 85
       		fclose($handle);
86 86
       		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
87
-      		if (! $data) {
88
-      			$this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false');
87
+      		if (!$data) {
88
+      			$this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false');
89 89
 		         // If unserializing somehow didn't work out, we'll delete the file
90 90
 		         unlink($filePath);
91 91
 		         return false;
92 92
 	      	}
93 93
 	      	if (time() > $data['expire']) {
94
-	      		$this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']');
94
+	      		$this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']');
95 95
 		        // Unlinking when the file was expired
96 96
 		        unlink($filePath);
97 97
 		        return false;
98 98
 		     }
99
-		     else{
100
-		     	$this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
99
+		     else {
100
+		     	$this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']');
101 101
 		     	return $data['data'];
102 102
 		     }
103 103
 		}
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 		 * @param integer $ttl  the cache life time
111 111
 		 * @return boolean true if success otherwise will return false
112 112
 		 */
113
-		public function set($key, $data, $ttl = 0){
113
+		public function set($key, $data, $ttl = 0) {
114 114
 			$expire = time() + $ttl;
115
-			$this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
115
+			$this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']');
116 116
 			$filePath = $this->getFilePath($key);
117
-			$handle = fopen($filePath,'w');
118
-			if(! is_resource($handle)){
119
-				$this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false');
117
+			$handle = fopen($filePath, 'w');
118
+			if (!is_resource($handle)) {
119
+				$this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false');
120 120
 				return false;
121 121
 			}
122 122
 			flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 									)
130 130
 								);		   
131 131
 		    $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData);
132
-		    if(! $result){
133
-		    	$this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false');
132
+		    if (!$result) {
133
+		    	$this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false');
134 134
 		    	fclose($handle);
135 135
 		    	return false;
136 136
 		    }
137
-		    else{
138
-		    	$this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']');
137
+		    else {
138
+		    	$this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']');
139 139
 		    	fclose($handle);
140 140
 				chmod($filePath, 0640);
141 141
 				return true;
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
 		 * @return boolean      true if the cache is delete, false if can't delete 
150 150
 		 * the cache or the cache with the given key not exist
151 151
 		 */
152
-		public function delete($key){
153
-			$this->logger->debug('Deleting of cache data for key [' .$key. ']');
152
+		public function delete($key) {
153
+			$this->logger->debug('Deleting of cache data for key [' . $key . ']');
154 154
 			$filePath = $this->getFilePath($key);
155
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
156
-			if(! file_exists($filePath)){
155
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
156
+			if (!file_exists($filePath)) {
157 157
 				$this->logger->info('This cache file does not exists skipping');
158 158
 				return false;
159 159
 			}
160
-			else{
161
-				$this->logger->info('Found cache file [' .$filePath. '] remove it');
160
+			else {
161
+				$this->logger->info('Found cache file [' . $filePath . '] remove it');
162 162
 	      		unlink($filePath);
163 163
 				return true;
164 164
 			}
@@ -172,23 +172,23 @@  discard block
 block discarded – undo
172 172
 		 * 'expire' => expiration time of the cache (Unix timestamp),
173 173
 		 * 'ttl' => the time to live of the cache in second
174 174
 		 */
175
-		public function getInfo($key){
176
-			$this->logger->debug('Getting of cache info for key [' .$key. ']');
175
+		public function getInfo($key) {
176
+			$this->logger->debug('Getting of cache info for key [' . $key . ']');
177 177
 			$filePath = $this->getFilePath($key);
178
-			$this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']');
179
-			if(! file_exists($filePath)){
178
+			$this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']');
179
+			if (!file_exists($filePath)) {
180 180
 				$this->logger->info('This cache file does not exists skipping');
181 181
 				return false;
182 182
 			}
183
-			$this->logger->info('Found cache file [' .$filePath. '] check the validity');
183
+			$this->logger->info('Found cache file [' . $filePath . '] check the validity');
184 184
       		$data = file_get_contents($filePath);
185 185
 			$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
186
-			if(! $data){
186
+			if (!$data) {
187 187
 				$this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']');
188 188
 				return false;
189 189
 			}
190 190
 			$this->logger->info('This cache data is OK check for expire');
191
-			if(isset($data['expire']) && $data['expire'] > time()){
191
+			if (isset($data['expire']) && $data['expire'] > time()) {
192 192
 				$this->logger->info('This cache not yet expired return cache informations');
193 193
 				$info = array(
194 194
 					'mtime' => $data['mtime'],
@@ -205,26 +205,26 @@  discard block
 block discarded – undo
205 205
 		/**
206 206
 		 * Used to delete expired cache data
207 207
 		 */
208
-		public function deleteExpiredCache(){
208
+		public function deleteExpiredCache() {
209 209
 			$this->logger->debug('Deleting of expired cache files');
210 210
 			$list = glob(CACHE_PATH . '*.cache');
211
-			if(! $list){
211
+			if (!$list) {
212 212
 				$this->logger->info('No cache files were found skipping');
213 213
 			}
214
-			else{
214
+			else {
215 215
 				$this->logger->info('Found [' . count($list) . '] cache files to remove if expired');
216 216
 				foreach ($list as $file) {
217 217
 					$this->logger->debug('Processing the cache file [' . $file . ']');
218 218
 					$data = file_get_contents($file);
219 219
 		      		$data = @unserialize($this->compressCacheData ? gzinflate($data) : $data);
220
-		      		if(! $data){
220
+		      		if (!$data) {
221 221
 		      			$this->logger->warning('Can not unserialize the cache data for file [' . $file . ']');
222 222
 		      		}
223
-		      		else if(time() > $data['expire']){
223
+		      		else if (time() > $data['expire']) {
224 224
 		      			$this->logger->info('The cache data for file [' . $file . '] already expired remove it');
225 225
 		      			unlink($file);
226 226
 		      		}
227
-		      		else{
227
+		      		else {
228 228
 		      			$this->logger->info('The cache data for file [' . $file . '] not yet expired skip it');
229 229
 		      		}
230 230
 				}
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 		/**
235 235
 		 * Remove all file from cache folder
236 236
 		 */
237
-		public function clean(){
237
+		public function clean() {
238 238
 			$this->logger->debug('Deleting of all cache files');
239 239
 			$list = glob(CACHE_PATH . '*.cache');
240
-			if(! $list){
240
+			if (!$list) {
241 241
 				$this->logger->info('No cache files were found skipping');
242 242
 			}
243
-			else{
243
+			else {
244 244
 				$this->logger->info('Found [' . count($list) . '] cache files to remove');
245 245
 				foreach ($list as $file) {
246 246
 					$this->logger->debug('Processing the cache file [' . $file . ']');
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	    /**
253 253
 	     * @return boolean
254 254
 	     */
255
-	    public function isCompressCacheData(){
255
+	    public function isCompressCacheData() {
256 256
 	        return $this->compressCacheData;
257 257
 	    }
258 258
 
@@ -261,14 +261,14 @@  discard block
 block discarded – undo
261 261
 	     *
262 262
 	     * @return object
263 263
 	     */
264
-	    public function setCompressCacheData($status = true){
264
+	    public function setCompressCacheData($status = true) {
265 265
 			//if Zlib extension is not loaded set compressCacheData to false
266
-			if($status === true && ! extension_loaded('zlib')){
266
+			if ($status === true && !extension_loaded('zlib')) {
267 267
 				
268 268
 				$this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE');
269 269
 				$this->compressCacheData = false;
270 270
 			}
271
-			else{
271
+			else {
272 272
 				$this->compressCacheData = $status;
273 273
 			}
274 274
 			return $this;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		 *
280 280
 		 * @return bool
281 281
 		 */
282
-		public function isSupported(){
282
+		public function isSupported() {
283 283
 			return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH);
284 284
 		}
285 285
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	     * Return the Log instance
288 288
 	     * @return object
289 289
 	     */
290
-	    public function getLogger(){
290
+	    public function getLogger() {
291 291
 	      return $this->logger;
292 292
 	    }
293 293
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	     * Set the log instance
296 296
 	     * @param Log $logger the log object
297 297
 	     */
298
-	    public function setLogger(Log $logger){
298
+	    public function setLogger(Log $logger) {
299 299
 	      $this->logger = $logger;
300 300
 	      return $this;
301 301
 	    }
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		* @param string $key the cache item key
307 307
 		* @return string the full cache file path for this key
308 308
 		*/
309
-		private function getFilePath($key){
309
+		private function getFilePath($key) {
310 310
 			return CACHE_PATH . md5($key) . '.cache';
311 311
 		}
312 312
 	}
Please login to merge, or discard this patch.
core/classes/Router.php 1 patch
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
 		/**
97 97
 		 * Construct the new Router instance
98 98
 		 */
99
-		public function __construct(){
99
+		public function __construct() {
100 100
 			$this->setLoggerFromParamOrCreateNewInstance(null);
101 101
 			
102 102
 			//loading routes for module
103 103
 			$moduleRouteList = array();
104 104
 			$modulesRoutes = Module::getModulesRoutes();
105
-			if($modulesRoutes && is_array($modulesRoutes)){
105
+			if ($modulesRoutes && is_array($modulesRoutes)) {
106 106
 				$moduleRouteList = $modulesRoutes;
107 107
 				unset($modulesRoutes);
108 108
 			}
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		 * Get the route patterns
118 118
 		 * @return array
119 119
 		 */
120
-		public function getPattern(){
120
+		public function getPattern() {
121 121
 			return $this->pattern;
122 122
 		}
123 123
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		 * Get the route callbacks
126 126
 		 * @return array
127 127
 		 */
128
-		public function getCallback(){
128
+		public function getCallback() {
129 129
 			return $this->callback;
130 130
 		}
131 131
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		 * Get the module name
134 134
 		 * @return string
135 135
 		 */
136
-		public function getModule(){
136
+		public function getModule() {
137 137
 			return $this->module;
138 138
 		}
139 139
 		
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 		 * Get the controller name
142 142
 		 * @return string
143 143
 		 */
144
-		public function getController(){
144
+		public function getController() {
145 145
 			return $this->controller;
146 146
 		}
147 147
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		 * Get the controller file path
150 150
 		 * @return string
151 151
 		 */
152
-		public function getControllerPath(){
152
+		public function getControllerPath() {
153 153
 			return $this->controllerPath;
154 154
 		}
155 155
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		 * Get the controller method
158 158
 		 * @return string
159 159
 		 */
160
-		public function getMethod(){
160
+		public function getMethod() {
161 161
 			return $this->method;
162 162
 		}
163 163
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		 * Get the request arguments
166 166
 		 * @return array
167 167
 		 */
168
-		public function getArgs(){
168
+		public function getArgs() {
169 169
 			return $this->args;
170 170
 		}
171 171
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		 * Get the URL segments array
174 174
 		 * @return array
175 175
 		 */
176
-		public function getSegments(){
176
+		public function getSegments() {
177 177
 			return $this->segments;
178 178
 		}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	     * Return the Log instance
182 182
 	     * @return Log
183 183
 	     */
184
-	    public function getLogger(){
184
+	    public function getLogger() {
185 185
 	      return $this->logger;
186 186
 	    }
187 187
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	     * @param Log $logger the log object
191 191
 		 * @return object
192 192
 	     */
193
-	    public function setLogger($logger){
193
+	    public function setLogger($logger) {
194 194
 	      $this->logger = $logger;
195 195
 	      return $this;
196 196
 	    }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		 * Get the route URI
200 200
 		 * @return string
201 201
 		 */
202
-		public function getRouteUri(){
202
+		public function getRouteUri() {
203 203
 			return $this->uri;
204 204
 		}
205 205
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		*/
214 214
 		public function add($uri, $callback) {
215 215
 			$uri = trim($uri, $this->uriTrim);
216
-			if(in_array($uri, $this->pattern)){
216
+			if (in_array($uri, $this->pattern)) {
217 217
 				$this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict');
218 218
 			}
219 219
 			$this->pattern[] = $uri;
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 		* @return object the current instance
230 230
 		*/
231 231
 		public function removeRoute($uri) {
232
-			$index  = array_search($uri, $this->pattern, true);
233
-			if($index !== false){
232
+			$index = array_search($uri, $this->pattern, true);
233
+			if ($index !== false) {
234 234
 				$this->logger->info('Remove route for uri [' . $uri . '] from the configuration');
235 235
 				unset($this->pattern[$index]);
236 236
 				unset($this->callback[$index]);
@@ -258,26 +258,26 @@  discard block
 block discarded – undo
258 258
 	     * @param string $uri the route URI, if is empty will determine automatically
259 259
 	     * @return object
260 260
 	     */
261
-	    public function setRouteUri($uri = ''){
261
+	    public function setRouteUri($uri = '') {
262 262
 	    	$routeUri = '';
263
-	    	if(! empty($uri)){
263
+	    	if (!empty($uri)) {
264 264
 	    		$routeUri = $uri;
265 265
 	    	}
266 266
 	    	//if the application is running in CLI mode use the first argument
267
-			else if(IS_CLI && isset($_SERVER['argv'][1])){
267
+			else if (IS_CLI && isset($_SERVER['argv'][1])) {
268 268
 				$routeUri = $_SERVER['argv'][1];
269 269
 			}
270
-			else if(isset($_SERVER['REQUEST_URI'])){
270
+			else if (isset($_SERVER['REQUEST_URI'])) {
271 271
 				$routeUri = $_SERVER['REQUEST_URI'];
272 272
 			}
273 273
 			$this->logger->debug('Check if URL suffix is enabled in the configuration');
274 274
 			//remove url suffix from the request URI
275 275
 			$suffix = get_config('url_suffix');
276 276
 			if ($suffix) {
277
-				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' );
277
+				$this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']');
278 278
 				$routeUri = str_ireplace($suffix, '', $routeUri);
279 279
 			} 
280
-			if (strpos($routeUri, '?') !== false){
280
+			if (strpos($routeUri, '?') !== false) {
281 281
 				$routeUri = substr($routeUri, 0, strpos($routeUri, '?'));
282 282
 			}
283 283
 			$this->uri = trim($routeUri, $this->uriTrim);
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 		 * 
291 291
 		 * @return object
292 292
 		 */
293
-		public function setRouteSegments(array $segments = array()){
294
-			if(! empty($segments)){
293
+		public function setRouteSegments(array $segments = array()) {
294
+			if (!empty($segments)) {
295 295
 				$this->segments = $segments;
296 296
 			} else if (!empty($this->uri)) {
297 297
 				$this->segments = explode('/', $this->uri);
@@ -299,12 +299,12 @@  discard block
 block discarded – undo
299 299
 			$segment = $this->segments;
300 300
 			$baseUrl = get_config('base_url');
301 301
 			//check if the app is not in DOCUMENT_ROOT
302
-			if(isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false){
302
+			if (isset($segment[0]) && stripos($baseUrl, $segment[0]) !== false) {
303 303
 				array_shift($segment);
304 304
 				$this->segments = $segment;
305 305
 			}
306 306
 			$this->logger->debug('Check if the request URI contains the front controller');
307
-			if(isset($segment[0]) && $segment[0] == SELF){
307
+			if (isset($segment[0]) && $segment[0] == SELF) {
308 308
 				$this->logger->info('The request URI contains the front controller');
309 309
 				array_shift($segment);
310 310
 				$this->segments = $segment;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 			
325 325
 			//if can not determine the module/controller/method via the defined routes configuration we will use
326 326
 			//the URL like http://domain.com/module/controller/method/arg1/arg2
327
-			if(! $this->controller){
327
+			if (!$this->controller) {
328 328
 				$this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters');
329 329
 				//determine route parameters using the REQUEST_URI param
330 330
 				$this->determineRouteParamsFromRequestUri();
@@ -340,14 +340,14 @@  discard block
 block discarded – undo
340 340
 		 * Routing the request to the correspondant module/controller/method if exists
341 341
 		 * otherwise send 404 error.
342 342
 		 */
343
-	    public function processRequest(){
343
+	    public function processRequest() {
344 344
 	    	//Setting the route URI
345 345
 			$this->setRouteUri();
346 346
 
347 347
 			//setting route segments
348 348
 			$this->setRouteSegments();
349 349
 
350
-			$this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']' );
350
+			$this->logger->info('The final Request URI is [' . implode('/', $this->segments) . ']');
351 351
 
352 352
 	    	//determine the route parameters information
353 353
 	    	$this->determineRouteParamsInformation();
@@ -358,20 +358,20 @@  discard block
 block discarded – undo
358 358
 	    	$this->logger->info('The routing information are: module [' . $this->module . '], controller [' . $controller . '], method [' . $this->method . '], args [' . stringfy_vars($this->args) . ']');
359 359
 	    	$this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...');
360 360
 	    	
361
-			if(file_exists($classFilePath)){
361
+			if (file_exists($classFilePath)) {
362 362
 				require_once $classFilePath;
363
-				if(! class_exists($controller, false)){
363
+				if (!class_exists($controller, false)) {
364 364
 					$e404 = true;
365
-					$this->logger->warning('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']');
365
+					$this->logger->warning('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']');
366 366
 				}
367
-				else{
367
+				else {
368 368
 					$controllerInstance = new $controller();
369 369
 					$controllerMethod = $this->getMethod();
370
-					if(! method_exists($controllerInstance, $controllerMethod)){
370
+					if (!method_exists($controllerInstance, $controllerMethod)) {
371 371
 						$e404 = true;
372 372
 						$this->logger->warning('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']');
373 373
 					}
374
-					else{
374
+					else {
375 375
 						$this->logger->info('Routing data is set correctly now GO!');
376 376
 						call_user_func_array(array($controllerInstance, $controllerMethod), $this->args);
377 377
 						//render the final page to user
@@ -380,16 +380,16 @@  discard block
 block discarded – undo
380 380
 					}
381 381
 				}
382 382
 			}
383
-			else{
383
+			else {
384 384
 				$this->logger->info('The controller file path [' . $classFilePath . '] does not exist');
385 385
 				$e404 = true;
386 386
 			}
387
-			if($e404){
388
-				if(IS_CLI){
387
+			if ($e404) {
388
+				if (IS_CLI) {
389 389
 					set_http_status_header(404);
390 390
 					echo 'Error 404: page not found.';
391 391
 				} else {
392
-					$response =& class_loader('Response', 'classes');
392
+					$response = & class_loader('Response', 'classes');
393 393
 					$response->send404();
394 394
 				}
395 395
 			}
@@ -402,15 +402,15 @@  discard block
 block discarded – undo
402 402
 	    * @param boolean $useConfigFile whether to use route configuration file
403 403
 		* @return object
404 404
 	    */
405
-	    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true){
405
+	    public function setRouteConfiguration(array $overwriteConfig = array(), $useConfigFile = true) {
406 406
 	        $route = array();
407
-	        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')){
407
+	        if ($useConfigFile && file_exists(CONFIG_PATH . 'routes.php')) {
408 408
 	            require_once CONFIG_PATH . 'routes.php';
409 409
 	        }
410 410
 	        $route = array_merge($route, $overwriteConfig);
411 411
 	        $this->routes = $route;
412 412
 	        //if route is empty remove all configuration
413
-	        if(empty($route)){
413
+	        if (empty($route)) {
414 414
 	        	$this->removeAllRoute();
415 415
 	        }
416 416
 			return $this;
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 		 * Get the route configuration
421 421
 		 * @return array
422 422
 		 */
423
-		public function getRouteConfiguration(){
423
+		public function getRouteConfiguration() {
424 424
 			return $this->routes;
425 425
 		}
426 426
 
@@ -432,19 +432,19 @@  discard block
 block discarded – undo
432 432
 	     *
433 433
 	     * @return object the current instance
434 434
 	     */
435
-	    public function setControllerFilePath($path = null){
436
-	    	if($path !== null){
435
+	    public function setControllerFilePath($path = null) {
436
+	    	if ($path !== null) {
437 437
 	    		$this->controllerPath = $path;
438 438
 	    		return $this;
439 439
 	    	}
440 440
 	    	//did we set the controller, so set the controller path
441
-			if($this->controller && ! $this->controllerPath){
441
+			if ($this->controller && !$this->controllerPath) {
442 442
 				$this->logger->debug('Setting the file path for the controller [' . $this->controller . ']');
443 443
 				$controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->controller) . '.php';
444 444
 				//if the controller is in module
445
-				if($this->module){
445
+				if ($this->module) {
446 446
 					$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
447
-					if($path !== false){
447
+					if ($path !== false) {
448 448
 						$controllerPath = $path;
449 449
 					}
450 450
 				}
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	     * Determine the route parameters from route configuration
458 458
 	     * @return void
459 459
 	     */
460
-	    protected function determineRouteParamsFromConfig(){
460
+	    protected function determineRouteParamsFromConfig() {
461 461
 	    	$uri = implode('/', $this->segments);
462 462
 	    	/*
463 463
 	   		* Generics routes patterns
@@ -482,20 +482,20 @@  discard block
 block discarded – undo
482 482
 					array_shift($args);
483 483
 					//check if this contains an module
484 484
 					$moduleControllerMethod = explode('#', $this->callback[$index]);
485
-					if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){
485
+					if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) {
486 486
 						$this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']');
487 487
 						$this->module = $moduleControllerMethod[0];
488 488
 						$moduleControllerMethod = explode('@', $moduleControllerMethod[1]);
489 489
 					}
490
-					else{
490
+					else {
491 491
 						$this->logger->info('The current request does not use the module');
492 492
 						$moduleControllerMethod = explode('@', $this->callback[$index]);
493 493
 					}
494
-					if(is_array($moduleControllerMethod)){
495
-						if(isset($moduleControllerMethod[0])){
494
+					if (is_array($moduleControllerMethod)) {
495
+						if (isset($moduleControllerMethod[0])) {
496 496
 							$this->controller = $moduleControllerMethod[0];	
497 497
 						}
498
-						if(isset($moduleControllerMethod[1])){
498
+						if (isset($moduleControllerMethod[1])) {
499 499
 							$this->method = $moduleControllerMethod[1];
500 500
 						}
501 501
 						$this->args = $args;
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 			}
507 507
 
508 508
 			//first if the controller is not set and the module is set use the module name as the controller
509
-			if(! $this->controller && $this->module){
509
+			if (!$this->controller && $this->module) {
510 510
 				$this->logger->info(
511 511
 									'After loop in predefined routes configuration, 
512 512
 									the module name is set but the controller is not set, 
@@ -520,67 +520,67 @@  discard block
 block discarded – undo
520 520
 	     * Determine the route parameters using the server variable "REQUEST_URI"
521 521
 	     * @return void
522 522
 	     */
523
-	    protected function determineRouteParamsFromRequestUri(){
523
+	    protected function determineRouteParamsFromRequestUri() {
524 524
 	    	$segment = $this->segments;
525 525
 	    	$nbSegment = count($segment);
526 526
 			//if segment is null so means no need to perform
527
-			if($nbSegment > 0){
527
+			if ($nbSegment > 0) {
528 528
 				//get the module list
529 529
 				$modules = Module::getModuleList();
530 530
 				//first check if no module
531
-				if(empty($modules)){
531
+				if (empty($modules)) {
532 532
 					$this->logger->info('No module was loaded will skip the module checking');
533 533
 					//the application don't use module
534 534
 					//controller
535
-					if(isset($segment[0])){
535
+					if (isset($segment[0])) {
536 536
 						$this->controller = $segment[0];
537 537
 						array_shift($segment);
538 538
 					}
539 539
 					//method
540
-					if(isset($segment[0])){
540
+					if (isset($segment[0])) {
541 541
 						$this->method = $segment[0];
542 542
 						array_shift($segment);
543 543
 					}
544 544
 					//args
545 545
 					$this->args = $segment;
546 546
 				}
547
-				else{
547
+				else {
548 548
 					$this->logger->info('The application contains a loaded module will check if the current request is found in the module list');
549
-					if(in_array($segment[0], $modules)){
549
+					if (in_array($segment[0], $modules)) {
550 550
 						$this->logger->info('Found, the current request use the module [' . $segment[0] . ']');
551 551
 						$this->module = $segment[0];
552 552
 						array_shift($segment);
553 553
 						//check if the second arg is the controller from module
554
-						if(isset($segment[0])){
554
+						if (isset($segment[0])) {
555 555
 							$this->controller = $segment[0];
556 556
 							//check if the request use the same module name and controller
557 557
 							$path = Module::findControllerFullPath(ucfirst($this->controller), $this->module);
558
-							if(! $path){
558
+							if (!$path) {
559 559
 								$this->logger->info('The controller [' . $this->controller . '] not found in the module, may be will use the module [' . $this->module . '] as controller');
560 560
 								$this->controller = $this->module;
561 561
 							}
562
-							else{
562
+							else {
563 563
 								$this->controllerPath = $path;
564 564
 								array_shift($segment);
565 565
 							}
566 566
 						}
567 567
 						//check for method
568
-						if(isset($segment[0])){
568
+						if (isset($segment[0])) {
569 569
 							$this->method = $segment[0];
570 570
 							array_shift($segment);
571 571
 						}
572 572
 						//the remaining is for args
573 573
 						$this->args = $segment;
574 574
 					}
575
-					else{
575
+					else {
576 576
 						$this->logger->info('The current request information is not found in the module list');
577 577
 						//controller
578
-						if(isset($segment[0])){
578
+						if (isset($segment[0])) {
579 579
 							$this->controller = $segment[0];
580 580
 							array_shift($segment);
581 581
 						}
582 582
 						//method
583
-						if(isset($segment[0])){
583
+						if (isset($segment[0])) {
584 584
 							$this->method = $segment[0];
585 585
 							array_shift($segment);
586 586
 						}
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 						$this->args = $segment;
589 589
 					}
590 590
 				}
591
-				if(! $this->controller && $this->module){
591
+				if (!$this->controller && $this->module) {
592 592
 					$this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller');
593 593
 					$this->controller = $this->module;
594 594
 				}
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
 	     *
601 601
 	     * @return object the current instance
602 602
 	     */
603
-	    protected function setRouteConfigurationInfos(){
603
+	    protected function setRouteConfigurationInfos() {
604 604
 	    	//adding route
605
-			foreach($this->routes as $pattern => $callback){
605
+			foreach ($this->routes as $pattern => $callback) {
606 606
 				$this->add($pattern, $callback);
607 607
 			}
608 608
 			return $this;
@@ -612,12 +612,12 @@  discard block
 block discarded – undo
612 612
 	     * Set the Log instance using argument or create new instance
613 613
 	     * @param object $logger the Log instance if not null
614 614
 	     */
615
-	    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){
616
-	      if ($logger !== null){
615
+	    protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) {
616
+	      if ($logger !== null) {
617 617
 	        $this->logger = $logger;
618 618
 	      }
619
-	      else{
620
-	          $this->logger =& class_loader('Log', 'classes');
619
+	      else {
620
+	          $this->logger = & class_loader('Log', 'classes');
621 621
 	          $this->logger->setLogger('Library::Router');
622 622
 	      }
623 623
 	    }
Please login to merge, or discard this patch.
core/classes/Security.php 1 patch
Spacing   +20 added lines, -20 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 Security{
27
+	class Security {
28 28
 		
29 29
 		/**
30 30
 		 * The logger instance
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 		 * Get the logger singleton instance
37 37
 		 * @return Log the logger instance
38 38
 		 */
39
-		private static function getLogger(){
40
-			if(self::$logger == null){
41
-				self::$logger[0] =& class_loader('Log', 'classes');
39
+		private static function getLogger() {
40
+			if (self::$logger == null) {
41
+				self::$logger[0] = & class_loader('Log', 'classes');
42 42
 				self::$logger[0]->setLogger('Library::Security');
43 43
 			}
44 44
 			return self::$logger[0];
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		 * This method is used to generate the CSRF token
50 50
 		 * @return string the generated CSRF token
51 51
 		 */
52
-		public static function generateCSRF(){
52
+		public static function generateCSRF() {
53 53
 			$logger = self::getLogger();
54 54
 			$logger->debug('Generation of CSRF ...');
55 55
 			
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 			$expire = get_config('csrf_expire', 60);
58 58
 			$keyExpire = 'csrf_expire';
59 59
 			$currentTime = time();
60
-			if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){
60
+			if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) {
61 61
 				$logger->info('The CSRF token not yet expire just return it');
62 62
 				return Session::get($key);
63 63
 			}
64
-			else{
64
+			else {
65 65
 				$newTime = $currentTime + $expire;
66 66
 				$token = sha1(uniqid()) . sha1(uniqid());
67
-				$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']');
67
+				$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']');
68 68
 				Session::set($keyExpire, $newTime);
69 69
 				Session::set($key, $token);
70 70
 				return Session::get($key);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		 * This method is used to check the CSRF if is valid, not yet expire, etc.
76 76
 		 * @return boolean true if valid, false if not valid
77 77
 		 */
78
-		public static function validateCSRF(){
78
+		public static function validateCSRF() {
79 79
 			$logger = self::getLogger();
80 80
 			$logger->debug('Validation of CSRF ...');
81 81
 				
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 			$expire = get_config('csrf_expire', 60);
84 84
 			$keyExpire = 'csrf_expire';
85 85
 			$currentTime = time();
86
-			$logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']');
87
-			if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){
86
+			$logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']');
87
+			if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) {
88 88
 				$logger->warning('The CSRF session data is not valide');
89 89
 				return false;
90 90
 			}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 			//super instance
94 94
 			$obj = & get_instance();
95 95
 			$token = $obj->request->query($key);
96
-			if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){
97
-				$logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job');
96
+			if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) {
97
+				$logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job');
98 98
 				return false;
99 99
 			}
100
-			$logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue');
100
+			$logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue');
101 101
 			//remove the token from session
102 102
 			Session::clear($key);
103 103
 			Session::clear($keyExpire);
@@ -107,24 +107,24 @@  discard block
 block discarded – undo
107 107
 		/**
108 108
 		 * This method is used to check the whitelist IP address access
109 109
 		 */
110
-		 public static function checkWhiteListIpAccess(){
110
+		 public static function checkWhiteListIpAccess() {
111 111
 			$logger = self::getLogger();
112 112
 			$logger->debug('Validation of the IP address access ...');
113 113
 			$logger->debug('Check if whitelist IP access is enabled in the configuration ...');
114 114
 			$isEnable = get_config('white_list_ip_enable', false);
115
-			if($isEnable){
115
+			if ($isEnable) {
116 116
 				$logger->info('Whitelist IP access is enabled in the configuration');
117 117
 				$list = get_config('white_list_ip_addresses', array());
118
-				if(! empty($list)){
118
+				if (!empty($list)) {
119 119
 					//Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing
120 120
 					require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php';
121 121
 					$ip = get_ip();
122
-					if((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)){
122
+					if ((count($list) == 1 && $list[0] == '*') || in_array($ip, $list)) {
123 123
 						$logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP');
124 124
 						//wildcard to access all ip address
125 125
 						return;
126 126
 					}
127
-					else{
127
+					else {
128 128
 						// go through all whitelisted ips
129 129
 						foreach ($list as $ipaddr) {
130 130
 							// find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*")
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 					}
151 151
 				}
152 152
 			}
153
-			else{
153
+			else {
154 154
 				$logger->info('Whitelist IP access is not enabled in the configuration, ignore checking');
155 155
 			}
156 156
 		 }
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 1 patch
Spacing   +58 added lines, -58 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
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
          * @return void
98 98
          */
99 99
         public function __construct() {
100
-            $this->logger =& class_loader('Log', 'classes');
100
+            $this->logger = & class_loader('Log', 'classes');
101 101
             $this->logger->setLogger('Library::FormValidation');
102 102
            
103 103
 		   //Load form validation language message
104 104
             Loader::lang('form_validation');
105 105
             $obj = & get_instance();
106
-            $this->_errorsMessages  = array(
106
+            $this->_errorsMessages = array(
107 107
                         'required'         => $obj->lang->get('fv_required'),
108 108
                         'min_length'       => $obj->lang->get('fv_min_length'),
109 109
                         'max_length'       => $obj->lang->get('fv_max_length'),
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
          * Set the database instance
134 134
          * @param object $database the database instance
135 135
          */
136
-        public function setDatabase(Database $database){
136
+        public function setDatabase(Database $database) {
137 137
             $this->databaseInstance = $database;
138 138
             return $this;
139 139
         }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
          * Get the database instance
143 143
          * @return object the database instance
144 144
          */
145
-        public function getDatabase(){
145
+        public function getDatabase() {
146 146
             return $this->databaseInstance;
147 147
         }
148 148
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		 *
166 166
          * @return FormValidation Current instance of object.
167 167
          */
168
-        public function setData(array $data){
168
+        public function setData(array $data) {
169 169
             $this->logger->debug('Setting the form validation data, the values are: ' . stringfy_vars($data));
170 170
             $this->data = $data;
171 171
 			return $this;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
          * Get the form validation data
176 176
          * @return array the form validation data to be validated
177 177
          */
178
-        public function getData(){
178
+        public function getData() {
179 179
             return $this->data;
180 180
         }
181 181
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		*
185 185
 		* @return string the function name
186 186
 		*/
187
-        protected function _toCallCase($funcName, $prefix='_validate') {
187
+        protected function _toCallCase($funcName, $prefix = '_validate') {
188 188
             $funcName = strtolower($funcName);
189 189
             $finalFuncName = $prefix;
190 190
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
          * @return boolean Whether or not the form has been submitted or the data is available for validation.
209 209
          */
210 210
         public function canDoValidation() {
211
-            return get_instance()->request->method() === 'POST' || ! empty($this->data);
211
+            return get_instance()->request->method() === 'POST' || !empty($this->data);
212 212
         }
213 213
 
214 214
         /**
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
          * Validate the CSRF 
229 229
          * @return void 
230 230
          */
231
-        protected function validateCSRF(){
232
-            if(get_instance()->request->method() == 'POST'){
231
+        protected function validateCSRF() {
232
+            if (get_instance()->request->method() == 'POST') {
233 233
                 $this->logger->debug('Check if CSRF is enabled in configuration');
234 234
                 //first check for CSRF
235
-                if (get_config('csrf_enable', false) && ! Security::validateCSRF()){
235
+                if (get_config('csrf_enable', false) && !Security::validateCSRF()) {
236 236
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
237 237
                 }
238
-                else{
238
+                else {
239 239
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
240 240
                 }
241 241
             }
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
             $this->_forceFail = false;
254 254
 
255 255
             foreach ($this->getData() as $inputName => $inputVal) {
256
-    			if(is_array($this->data[$inputName])){
256
+    			if (is_array($this->data[$inputName])) {
257 257
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
258 258
     			}
259
-    			else{
259
+    			else {
260 260
     				$this->data[$inputName] = trim($this->data[$inputName]);
261 261
     			}
262 262
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
                     }
267 267
                 }
268 268
             }
269
-            $this->_success =  empty($this->_errors) && $this->_forceFail === false;
269
+            $this->_success = empty($this->_errors) && $this->_forceFail === false;
270 270
         }
271 271
 
272 272
         /**
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         public function setRule($inputField, $inputLabel, $ruleSets) {
281 281
             $this->_rules[$inputField] = $ruleSets;
282 282
             $this->_labels[$inputField] = $inputLabel;
283
-            $this->logger->info('Set the field rule: name [' .$inputField. '], label [' .$inputLabel. '], rules [' .$ruleSets. ']');
283
+            $this->logger->info('Set the field rule: name [' . $inputField . '], label [' . $inputLabel . '], rules [' . $ruleSets . ']');
284 284
             return $this;
285 285
         }
286 286
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
             }
445 445
             $errorOutput .= $errorsEnd;
446 446
             echo ($echo) ? $errorOutput : '';
447
-            return (! $echo) ? $errorOutput : null;
447
+            return (!$echo) ? $errorOutput : null;
448 448
         }
449 449
 
450 450
         /**
@@ -469,25 +469,25 @@  discard block
 block discarded – undo
469 469
             /*
470 470
             //////////////// hack for regex rule that can contain "|"
471 471
             */
472
-            if(strpos($ruleString, 'regex') !== false){
472
+            if (strpos($ruleString, 'regex') !== false) {
473 473
                 $regexRule = array();
474 474
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
475 475
                 preg_match($rule, $ruleString, $regexRule);
476 476
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
477
-                 if(!empty($regexRule[0])){
477
+                 if (!empty($regexRule[0])) {
478 478
                      $ruleSets[] = $regexRule[0];
479 479
                  }
480 480
                  $ruleStringRegex = explode('|', $ruleStringTemp);
481 481
                 foreach ($ruleStringRegex as $rule) {
482 482
                     $rule = trim($rule);
483
-                    if($rule){
483
+                    if ($rule) {
484 484
                         $ruleSets[] = $rule;
485 485
                     }
486 486
                 }
487 487
                  
488 488
             }
489 489
             /***********************************/
490
-            else{
490
+            else {
491 491
                 if (strpos($ruleString, '|') !== FALSE) {
492 492
                     $ruleSets = explode('|', $ruleString);
493 493
                 } else {
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
          * @return void
520 520
          */
521 521
         protected function _validateRule($inputName, $inputVal, $ruleName) {
522
-            $this->logger->debug('Rule validation of field [' .$inputName. '], value [' .$inputVal. '], rule [' .$ruleName. ']');
522
+            $this->logger->debug('Rule validation of field [' . $inputName . '], value [' . $inputVal . '], rule [' . $ruleName . ']');
523 523
             // Array to store args
524 524
             $ruleArgs = array();
525 525
 
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
                 $key = $i - 1;
565 565
                 $rulePhrase = str_replace('%' . $i, $replacements[$key], $rulePhrase);
566 566
             }
567
-            if (! array_key_exists($inputName, $this->_errors)) {
567
+            if (!array_key_exists($inputName, $this->_errors)) {
568 568
                 $this->_errors[$inputName] = $rulePhrase;
569 569
             }
570 570
         }
@@ -616,13 +616,13 @@  discard block
 block discarded – undo
616 616
          */
617 617
 		protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
618 618
             $inputVal = $this->post($inputName);
619
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
619
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
620 620
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
621 621
                 if ($inputVal == '' && $callbackReturn == true) {
622 622
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
623 623
                 }
624 624
             } 
625
-			else if($inputVal == '') {
625
+			else if ($inputVal == '') {
626 626
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
627 627
             }
628 628
         }
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
649 649
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
650 650
 				$result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
651
-				if(! $result){
651
+				if (!$result) {
652 652
 					$this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
653 653
 				}
654 654
             }
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
                         continue;
683 683
                     }
684 684
                 } 
685
-				else{
685
+				else {
686 686
                     if ($inputVal == $doNotEqual) {
687 687
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
688 688
                         continue;
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
          */
713 713
         protected function _validateValidEmail($inputName, $ruleName, array $ruleArgs) {
714 714
             $inputVal = $this->post($inputName);
715
-            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)) {
716
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
715
+            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)) {
716
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
717 717
                     return;
718 718
                 }
719 719
                 $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
         protected function _validateExactLength($inputName, $ruleName, array $ruleArgs) {
730 730
             $inputVal = $this->post($inputName);
731 731
             if (strlen($inputVal) != $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
732
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
732
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
733 733
                     return;
734 734
                 }
735 735
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
         protected function _validateMaxLength($inputName, $ruleName, array $ruleArgs) {
746 746
             $inputVal = $this->post($inputName);
747 747
             if (strlen($inputVal) > $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
748
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
748
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
749 749
                     return;
750 750
                 }
751 751
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
         protected function _validateMinLength($inputName, $ruleName, array $ruleArgs) {
762 762
             $inputVal = $this->post($inputName);
763 763
             if (strlen($inputVal) < $ruleArgs[1]) { // $ruleArgs[0] is [length] $rulesArgs[1] is just length
764
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
764
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
765 765
                     return;
766 766
                 }
767 767
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
     	protected function _validateLessThan($inputName, $ruleName, array $ruleArgs) {
778 778
             $inputVal = $this->post($inputName);
779 779
             if ($inputVal >= $ruleArgs[1]) { 
780
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
780
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
781 781
                     return;
782 782
                 }
783 783
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
     	protected function _validateGreaterThan($inputName, $ruleName, array $ruleArgs) {
794 794
             $inputVal = $this->post($inputName);
795 795
             if ($inputVal <= $ruleArgs[1]) {
796
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
796
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
797 797
                     return;
798 798
                 }
799 799
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
          */
809 809
     	protected function _validateNumeric($inputName, $ruleName, array $ruleArgs) {
810 810
             $inputVal = $this->post($inputName);
811
-            if (! is_numeric($inputVal)) {
812
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
811
+            if (!is_numeric($inputVal)) {
812
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
813 813
                     return;
814 814
                 }
815 815
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -824,9 +824,9 @@  discard block
 block discarded – undo
824 824
          */
825 825
 		protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
826 826
             $inputVal = $this->post($inputName);
827
-    		if (! is_object($this->databaseInstance)){
827
+    		if (!is_object($this->databaseInstance)) {
828 828
                 $obj = & get_instance();
829
-                if(isset($obj->database)){
829
+                if (isset($obj->database)) {
830 830
                     $this->databaseInstance = $obj->database;
831 831
                 } 
832 832
             }
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
     			                                       ->where($column, $inputVal);
836 836
     		$this->databaseInstance->get();
837 837
             if ($this->databaseInstance->numRows() <= 0) {
838
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
838
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
839 839
                     return;
840 840
                 }
841 841
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -850,9 +850,9 @@  discard block
 block discarded – undo
850 850
          */
851 851
     	protected function _validateIsUnique($inputName, $ruleName, array $ruleArgs) {
852 852
             $inputVal = $this->post($inputName);
853
-            if (! is_object($this->databaseInstance)){
853
+            if (!is_object($this->databaseInstance)) {
854 854
                 $obj = & get_instance();
855
-                if(isset($obj->database)){
855
+                if (isset($obj->database)) {
856 856
                     $this->databaseInstance = $obj->database;
857 857
                 } 
858 858
             }
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
     			                                      ->where($column, $inputVal);
862 862
     		$this->databaseInstance->get();
863 863
     		if ($this->databaseInstance->numRows() > 0) {
864
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
864
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
865 865
                     return;
866 866
                 }
867 867
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -876,14 +876,14 @@  discard block
 block discarded – undo
876 876
          */
877 877
     	protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
878 878
             $inputVal = $this->post($inputName);
879
-    		if (! is_object($this->databaseInstance)){
879
+    		if (!is_object($this->databaseInstance)) {
880 880
                 $obj = & get_instance();
881
-                if(isset($obj->database)){
881
+                if (isset($obj->database)) {
882 882
                     $this->databaseInstance = $obj->database;
883 883
                 } 
884 884
             }
885 885
     		$data = explode(',', $ruleArgs[1]);
886
-    		if(count($data) < 2){
886
+    		if (count($data) < 2) {
887 887
     			return;
888 888
     		}
889 889
     		list($table, $column) = explode('.', $data[0]);
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
                                             		  ->where($field, '!=', trim($val));
894 894
             $this->databaseInstance->get();
895 895
     		if ($this->databaseInstance->numRows() > 0) {
896
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
896
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
897 897
                     return;
898 898
                 }
899 899
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
             $inputVal = $this->post($inputName);
911 911
     		$list = explode(',', $ruleArgs[1]);
912 912
             $list = array_map('trim', $list);
913
-            if (! in_array($inputVal, $list)) {
914
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
913
+            if (!in_array($inputVal, $list)) {
914
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
915 915
                     return;
916 916
                 }
917 917
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName), $this->_getLabel($ruleArgs[1])));
@@ -927,8 +927,8 @@  discard block
 block discarded – undo
927 927
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
928 928
             $inputVal = $this->post($inputName);
929 929
     		$regex = $ruleArgs[1];
930
-            if (! preg_match($regex, $inputVal)) {
931
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
930
+            if (!preg_match($regex, $inputVal)) {
931
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
932 932
                     return;
933 933
                 }
934 934
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.