@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - public function testDefaultValue(){ |
|
28 | + public function testDefaultValue() { |
|
29 | 29 | $e = new EventInfo('foo'); |
30 | 30 | $this->assertSame($e->name, 'foo'); |
31 | 31 | $this->assertSame($e->payload, array()); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $this->assertFalse($e->stop); |
34 | 34 | } |
35 | 35 | |
36 | - public function testPayloadValueIsSet(){ |
|
36 | + public function testPayloadValueIsSet() { |
|
37 | 37 | $e = new EventInfo('foo', array('bar')); |
38 | 38 | $this->assertSame($e->name, 'foo'); |
39 | 39 | $this->assertSame($e->payload, array('bar')); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $this->assertFalse($e->stop); |
42 | 42 | } |
43 | 43 | |
44 | - public function testReturnBackValueIsSetToTrue(){ |
|
44 | + public function testReturnBackValueIsSetToTrue() { |
|
45 | 45 | $e = new EventInfo('foo', array('bar'), true); |
46 | 46 | $this->assertSame($e->name, 'foo'); |
47 | 47 | $this->assertSame($e->payload, array('bar')); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $this->assertFalse($e->stop); |
50 | 50 | } |
51 | 51 | |
52 | - public function testStopValueIsSetToTue(){ |
|
52 | + public function testStopValueIsSetToTue() { |
|
53 | 53 | $e = new EventInfo('foo', array('bar'), true, true); |
54 | 54 | $this->assertSame($e->name, 'foo'); |
55 | 55 | $this->assertSame($e->payload, array('bar')); |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
29 | 29 | */ |
30 | - if( !interface_exists('SessionHandlerInterface')){ |
|
30 | + if (!interface_exists('SessionHandlerInterface')) { |
|
31 | 31 | show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.'); |
32 | 32 | } |
33 | 33 | |
34 | - class DBSessionHandler implements SessionHandlerInterface{ |
|
34 | + class DBSessionHandler implements SessionHandlerInterface { |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * The encryption method to use to encrypt session data in database |
@@ -81,25 +81,25 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected $loader = null; |
83 | 83 | |
84 | - public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){ |
|
84 | + public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) { |
|
85 | 85 | /** |
86 | 86 | * instance of the Log class |
87 | 87 | */ |
88 | - if(is_object($logger)){ |
|
88 | + if (is_object($logger)) { |
|
89 | 89 | $this->setLogger($logger); |
90 | 90 | } |
91 | - else{ |
|
92 | - $this->logger =& class_loader('Log', 'classes'); |
|
91 | + else { |
|
92 | + $this->logger = & class_loader('Log', 'classes'); |
|
93 | 93 | $this->logger->setLogger('Library::DBSessionHandler'); |
94 | 94 | } |
95 | 95 | |
96 | - if(is_object($loader)){ |
|
96 | + if (is_object($loader)) { |
|
97 | 97 | $this->setLoader($loader); |
98 | 98 | } |
99 | 99 | $this->OBJ = & get_instance(); |
100 | 100 | |
101 | 101 | |
102 | - if(is_object($modelInstance)){ |
|
102 | + if (is_object($modelInstance)) { |
|
103 | 103 | $this->setModelInstance($modelInstance); |
104 | 104 | } |
105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * Set the session secret used to encrypt the data in database |
109 | 109 | * @param string $secret the base64 string secret |
110 | 110 | */ |
111 | - public function setSessionSecret($secret){ |
|
111 | + public function setSessionSecret($secret) { |
|
112 | 112 | $this->sessionSecret = $secret; |
113 | 113 | return $this; |
114 | 114 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * Return the session secret |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - public function getSessionSecret(){ |
|
120 | + public function getSessionSecret() { |
|
121 | 121 | return $this->sessionSecret; |
122 | 122 | } |
123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * Set the initializer vector for openssl |
127 | 127 | * @param string $key the session secret used |
128 | 128 | */ |
129 | - public function setInitializerVector($key){ |
|
129 | + public function setInitializerVector($key) { |
|
130 | 130 | $iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD); |
131 | 131 | $key = base64_decode($key); |
132 | 132 | $this->iv = substr(hash('sha256', $key), 0, $iv_length); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * Return the initializer vector |
138 | 138 | * @return string |
139 | 139 | */ |
140 | - public function getInitializerVector(){ |
|
140 | + public function getInitializerVector() { |
|
141 | 141 | return $this->iv; |
142 | 142 | } |
143 | 143 | |
@@ -147,17 +147,17 @@ discard block |
||
147 | 147 | * @param string $sessionName the session name |
148 | 148 | * @return boolean |
149 | 149 | */ |
150 | - public function open($savePath, $sessionName){ |
|
150 | + public function open($savePath, $sessionName) { |
|
151 | 151 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
152 | 152 | //try to check if session secret is set before |
153 | 153 | $secret = $this->getSessionSecret(); |
154 | - if(empty($secret)){ |
|
154 | + if (empty($secret)) { |
|
155 | 155 | $secret = get_config('session_secret', null); |
156 | 156 | $this->setSessionSecret($secret); |
157 | 157 | } |
158 | 158 | $this->logger->info('Session secret: ' . $secret); |
159 | 159 | |
160 | - if(! $this->getModelInstance()){ |
|
160 | + if (!$this->getModelInstance()) { |
|
161 | 161 | $this->setModelInstanceFromConfig(); |
162 | 162 | } |
163 | 163 | $this->setInitializerVector($secret); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | //set session tables columns |
166 | 166 | $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns(); |
167 | 167 | |
168 | - if(empty($this->sessionTableColumns)){ |
|
168 | + if (empty($this->sessionTableColumns)) { |
|
169 | 169 | show_error('The session handler is "database" but the table columns not set'); |
170 | 170 | } |
171 | 171 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Close the session |
182 | 182 | * @return boolean |
183 | 183 | */ |
184 | - public function close(){ |
|
184 | + public function close() { |
|
185 | 185 | $this->logger->debug('Closing database session handler'); |
186 | 186 | return true; |
187 | 187 | } |
@@ -191,28 +191,28 @@ discard block |
||
191 | 191 | * @param string $sid the session id to use |
192 | 192 | * @return string the session data in serialiaze format |
193 | 193 | */ |
194 | - public function read($sid){ |
|
194 | + public function read($sid) { |
|
195 | 195 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
196 | 196 | $instance = $this->getModelInstance(); |
197 | 197 | $columns = $this->sessionTableColumns; |
198 | - if($this->getLoader()){ |
|
198 | + if ($this->getLoader()) { |
|
199 | 199 | $this->getLoader()->functions('user_agent'); |
200 | 200 | $this->getLoader()->library('Browser'); |
201 | 201 | } |
202 | - else{ |
|
202 | + else { |
|
203 | 203 | Loader::functions('user_agent'); |
204 | 204 | Loader::library('Browser'); |
205 | 205 | } |
206 | 206 | |
207 | 207 | $ip = get_ip(); |
208 | 208 | $host = @gethostbyaddr($ip) or null; |
209 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
209 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
210 | 210 | |
211 | 211 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
212 | - if($data && isset($data->{$columns['sdata']})){ |
|
212 | + if ($data && isset($data->{$columns['sdata']})) { |
|
213 | 213 | //checking inactivity |
214 | 214 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
215 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
215 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
216 | 216 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
217 | 217 | $this->destroy($sid); |
218 | 218 | return null; |
@@ -229,16 +229,16 @@ discard block |
||
229 | 229 | * @param mixed $data the session data to save in serialize format |
230 | 230 | * @return boolean |
231 | 231 | */ |
232 | - public function write($sid, $data){ |
|
232 | + public function write($sid, $data) { |
|
233 | 233 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
234 | 234 | $instance = $this->getModelInstance(); |
235 | 235 | $columns = $this->sessionTableColumns; |
236 | 236 | |
237 | - if($this->getLoader()){ |
|
237 | + if ($this->getLoader()) { |
|
238 | 238 | $this->getLoader()->functions('user_agent'); |
239 | 239 | $this->getLoader()->library('Browser'); |
240 | 240 | } |
241 | - else{ |
|
241 | + else { |
|
242 | 242 | Loader::functions('user_agent'); |
243 | 243 | Loader::library('Browser'); |
244 | 244 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $ip = get_ip(); |
247 | 247 | $keyValue = $instance->getKeyValue(); |
248 | 248 | $host = @gethostbyaddr($ip) or null; |
249 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
249 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
250 | 250 | $data = $this->encode($data); |
251 | 251 | $params = array( |
252 | 252 | $columns['sid'] => $sid, |
@@ -259,13 +259,13 @@ discard block |
||
259 | 259 | ); |
260 | 260 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
261 | 261 | $exists = $instance->get($sid); |
262 | - if($exists){ |
|
262 | + if ($exists) { |
|
263 | 263 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
264 | 264 | //update |
265 | 265 | unset($params[$columns['sid']]); |
266 | 266 | $instance->update($sid, $params); |
267 | 267 | } |
268 | - else{ |
|
268 | + else { |
|
269 | 269 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
270 | 270 | $instance->insert($params); |
271 | 271 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param string $sid the session id value |
279 | 279 | * @return boolean |
280 | 280 | */ |
281 | - public function destroy($sid){ |
|
281 | + public function destroy($sid) { |
|
282 | 282 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
283 | 283 | $instance = $this->modelInstanceName; |
284 | 284 | $instance->delete($sid); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param integer $maxLifetime the max lifetime |
291 | 291 | * @return boolean |
292 | 292 | */ |
293 | - public function gc($maxLifetime){ |
|
293 | + public function gc($maxLifetime) { |
|
294 | 294 | $instance = $this->modelInstanceName; |
295 | 295 | $time = time() - $maxLifetime; |
296 | 296 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * @param mixed $data the session data to encode |
304 | 304 | * @return mixed the encoded session data |
305 | 305 | */ |
306 | - public function encode($data){ |
|
306 | + public function encode($data) { |
|
307 | 307 | $key = base64_decode($this->sessionSecret); |
308 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
308 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
309 | 309 | $output = base64_encode($dataEncrypted); |
310 | 310 | return $output; |
311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param mixed $data the data to decode |
317 | 317 | * @return mixed the decoded data |
318 | 318 | */ |
319 | - public function decode($data){ |
|
319 | + public function decode($data) { |
|
320 | 320 | $key = base64_decode($this->sessionSecret); |
321 | 321 | $data = base64_decode($data); |
322 | 322 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * Return the loader instance |
329 | 329 | * @return object Loader the loader instance |
330 | 330 | */ |
331 | - public function getLoader(){ |
|
331 | + public function getLoader() { |
|
332 | 332 | return $this->loader; |
333 | 333 | } |
334 | 334 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * set the loader instance for future use |
337 | 337 | * @param object Loader $loader the loader object |
338 | 338 | */ |
339 | - public function setLoader($loader){ |
|
339 | + public function setLoader($loader) { |
|
340 | 340 | $this->loader = $loader; |
341 | 341 | return $this; |
342 | 342 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * Return the model instance |
346 | 346 | * @return object DBSessionHandlerModel the model instance |
347 | 347 | */ |
348 | - public function getModelInstance(){ |
|
348 | + public function getModelInstance() { |
|
349 | 349 | return $this->modelInstanceName; |
350 | 350 | } |
351 | 351 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * set the model instance for future use |
354 | 354 | * @param DBSessionHandlerModel $modelInstance the model object |
355 | 355 | */ |
356 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
356 | + public function setModelInstance(DBSessionHandlerModel $modelInstance) { |
|
357 | 357 | $this->modelInstanceName = $modelInstance; |
358 | 358 | return $this; |
359 | 359 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * Return the Log instance |
363 | 363 | * @return Log |
364 | 364 | */ |
365 | - public function getLogger(){ |
|
365 | + public function getLogger() { |
|
366 | 366 | return $this->logger; |
367 | 367 | } |
368 | 368 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * Set the log instance |
371 | 371 | * @param Log $logger the log object |
372 | 372 | */ |
373 | - public function setLogger(Log $logger){ |
|
373 | + public function setLogger(Log $logger) { |
|
374 | 374 | $this->logger = $logger; |
375 | 375 | return $this; |
376 | 376 | } |
@@ -378,18 +378,18 @@ discard block |
||
378 | 378 | /** |
379 | 379 | * Set the model instance using the configuration for session |
380 | 380 | */ |
381 | - private function setModelInstanceFromConfig(){ |
|
381 | + private function setModelInstanceFromConfig() { |
|
382 | 382 | $modelName = get_config('session_save_path'); |
383 | 383 | $this->logger->info('The database session model: ' . $modelName); |
384 | - if($this->getLoader()){ |
|
384 | + if ($this->getLoader()) { |
|
385 | 385 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
386 | 386 | } |
387 | 387 | //@codeCoverageIgnoreStart |
388 | - else{ |
|
388 | + else { |
|
389 | 389 | Loader::model($modelName, 'dbsessionhandlerinstance'); |
390 | 390 | } |
391 | - if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
392 | - show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"'); |
|
391 | + if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) { |
|
392 | + show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"'); |
|
393 | 393 | } |
394 | 394 | //@codeCoverageIgnoreEnd |
395 | 395 |
@@ -29,14 +29,14 @@ discard block |
||
29 | 29 | //put the first letter of class to upper case |
30 | 30 | $class = ucfirst($class); |
31 | 31 | static $classes = array(); |
32 | - if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
32 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
33 | 33 | return $classes[$class]; |
34 | 34 | } |
35 | 35 | $found = false; |
36 | 36 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
37 | 37 | $file = $path . $dir . '/' . $class . '.php'; |
38 | - if(file_exists($file)){ |
|
39 | - if(class_exists($class, false) === false){ |
|
38 | + if (file_exists($file)) { |
|
39 | + if (class_exists($class, false) === false) { |
|
40 | 40 | require_once $file; |
41 | 41 | } |
42 | 42 | //already found |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | break; |
45 | 45 | } |
46 | 46 | } |
47 | - if(! $found){ |
|
47 | + if (!$found) { |
|
48 | 48 | //can't use show_error() at this time because some dependencies not yet loaded |
49 | 49 | set_http_status_header(503); |
50 | 50 | echo 'Cannot find the class [' . $class . ']'; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | /* |
55 | 55 | TODO use the best method to get the Log instance |
56 | 56 | */ |
57 | - if($class == 'Log'){ |
|
57 | + if ($class == 'Log') { |
|
58 | 58 | //can't use the instruction like "return new Log()" |
59 | 59 | //because we need return the reference instance of the loaded class. |
60 | 60 | $log = new Log(); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | function & class_loaded($class = null){ |
74 | 74 | static $list = array(); |
75 | - if($class != null){ |
|
75 | + if ($class != null) { |
|
76 | 76 | $list[strtolower($class)] = $class; |
77 | 77 | } |
78 | 78 | return $list; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | function & load_configurations(array $overwrite_values = array()){ |
82 | 82 | static $config; |
83 | - if(empty($config)){ |
|
83 | + if (empty($config)) { |
|
84 | 84 | $file = CONFIG_PATH . 'config.php'; |
85 | 85 | require_once $file; |
86 | 86 | |
@@ -94,53 +94,53 @@ discard block |
||
94 | 94 | /** |
95 | 95 | * @test |
96 | 96 | */ |
97 | - function get_config($key, $default = null){ |
|
97 | + function get_config($key, $default = null) { |
|
98 | 98 | static $cfg; |
99 | - if(empty($cfg)){ |
|
99 | + if (empty($cfg)) { |
|
100 | 100 | $cfg[0] = & load_configurations(); |
101 | 101 | } |
102 | 102 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
103 | 103 | } |
104 | 104 | |
105 | - function save_to_log($level, $message, $logger = null){ |
|
106 | - echo 'save_to_log('.$level . ',' . $message . ',' . $logger . ")\n"; |
|
105 | + function save_to_log($level, $message, $logger = null) { |
|
106 | + echo 'save_to_log(' . $level . ',' . $message . ',' . $logger . ")\n"; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
110 | - function set_http_status_header($code = 200, $text = null){ |
|
110 | + function set_http_status_header($code = 200, $text = null) { |
|
111 | 111 | echo 'header(' . $code . ', ' . $text . ')'; |
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | - function show_error($msg, $title = 'error', $logging = true){ |
|
116 | + function show_error($msg, $title = 'error', $logging = true) { |
|
117 | 117 | //show only and continue to help track of some error occured |
118 | 118 | echo 'show_error(' . $msg . ', ' . $title . ', ' . ($logging ? 'Y' : 'N') . ")\n"; |
119 | 119 | } |
120 | 120 | |
121 | - function is_https(){ |
|
121 | + function is_https() { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @test |
127 | 127 | */ |
128 | - function is_url($url){ |
|
128 | + function is_url($url) { |
|
129 | 129 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
130 | 130 | } |
131 | 131 | |
132 | - function php_exception_handler($ex){ |
|
132 | + function php_exception_handler($ex) { |
|
133 | 133 | //show only and continue to help track of some error occured |
134 | - echo 'php_exception_handler('.$ex->getMessage().', '.$ex->getFile().', '.$ex->getLine() . ")\n"; |
|
134 | + echo 'php_exception_handler(' . $ex->getMessage() . ', ' . $ex->getFile() . ', ' . $ex->getLine() . ")\n"; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | |
138 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
138 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
139 | 139 | //show only and continue to help track of some error occured |
140 | - echo 'php_error_handler('.$errno .', ' . $errstr.', ' . $errfile.', '.$errline . ")\n"; |
|
140 | + echo 'php_error_handler(' . $errno . ', ' . $errstr . ', ' . $errfile . ', ' . $errline . ")\n"; |
|
141 | 141 | } |
142 | 142 | |
143 | - function php_shudown_handler(){ |
|
143 | + function php_shudown_handler() { |
|
144 | 144 | return true; |
145 | 145 | } |
146 | 146 | |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | /** |
149 | 149 | * @test |
150 | 150 | */ |
151 | - function attributes_to_string(array $attributes){ |
|
151 | + function attributes_to_string(array $attributes) { |
|
152 | 152 | $str = ' '; |
153 | 153 | //we check that the array passed as an argument is not empty. |
154 | - if(! empty($attributes)){ |
|
155 | - foreach($attributes as $key => $value){ |
|
154 | + if (!empty($attributes)) { |
|
155 | + foreach ($attributes as $key => $value) { |
|
156 | 156 | $key = trim(htmlspecialchars($key)); |
157 | 157 | $value = trim(htmlspecialchars($value)); |
158 | 158 | /* |
@@ -162,35 +162,35 @@ discard block |
||
162 | 162 | * $attr = array('placeholder' => 'I am a "puple"') |
163 | 163 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
164 | 164 | */ |
165 | - if($value && strpos('"', $value) !== false){ |
|
165 | + if ($value && strpos('"', $value) !== false) { |
|
166 | 166 | $value = addslashes($value); |
167 | 167 | } |
168 | - $str .= $key.' = "'.$value.'" '; |
|
168 | + $str .= $key . ' = "' . $value . '" '; |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | //remove the space after using rtrim() |
172 | 172 | return rtrim($str); |
173 | 173 | } |
174 | 174 | |
175 | - function stringfy_vars($var){ |
|
175 | + function stringfy_vars($var) { |
|
176 | 176 | return print_r($var, true); |
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @test |
181 | 181 | */ |
182 | - function clean_input($str){ |
|
183 | - if(is_array($str)){ |
|
182 | + function clean_input($str) { |
|
183 | + if (is_array($str)) { |
|
184 | 184 | $str = array_map('clean_input', $str); |
185 | 185 | } |
186 | - else if(is_object($str)){ |
|
186 | + else if (is_object($str)) { |
|
187 | 187 | $obj = $str; |
188 | 188 | foreach ($str as $var => $value) { |
189 | 189 | $obj->$var = clean_input($value); |
190 | 190 | } |
191 | 191 | $str = $obj; |
192 | 192 | } |
193 | - else{ |
|
193 | + else { |
|
194 | 194 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
195 | 195 | } |
196 | 196 | return $str; |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | /** |
200 | 200 | * @test |
201 | 201 | */ |
202 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
202 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
203 | 203 | //get the string length |
204 | 204 | $len = strlen($str); |
205 | 205 | //if str is empty |
206 | - if($len <= 0){ |
|
206 | + if ($len <= 0) { |
|
207 | 207 | return str_repeat($hiddenChar, 6); |
208 | 208 | } |
209 | 209 | //if the length is less than startCount and endCount |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | //or startCount is negative or endCount is negative |
212 | 212 | //return the full string hidden |
213 | 213 | |
214 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
214 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
215 | 215 | return str_repeat($hiddenChar, $len); |
216 | 216 | } |
217 | 217 | //the start non hidden string |
218 | 218 | $startNonHiddenStr = substr($str, 0, $startCount); |
219 | 219 | //the end non hidden string |
220 | 220 | $endNonHiddenStr = null; |
221 | - if($endCount > 0){ |
|
221 | + if ($endCount > 0) { |
|
222 | 222 | $endNonHiddenStr = substr($str, - $endCount); |
223 | 223 | } |
224 | 224 | //the hidden string |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | return $startNonHiddenStr . $hiddenStr . $endNonHiddenStr; |
228 | 228 | } |
229 | 229 | |
230 | - function set_session_config(){ |
|
230 | + function set_session_config() { |
|
231 | 231 | return true; |
232 | 232 | } |
233 | 233 | |
234 | 234 | function & get_instance(){ |
235 | - if(! Controller::get_instance()){ |
|
235 | + if (!Controller::get_instance()) { |
|
236 | 236 | $c = new Controller(); |
237 | 237 | return $c; |
238 | 238 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
2 | + class DBSessionModel extends DBSessionHandlerModel { |
|
3 | 3 | |
4 | 4 | protected $_table = 'ses'; |
5 | 5 | protected $primary_key = 's_id'; |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | 'skey' => 'test_id' //VARCHAR(255) |
15 | 15 | ); |
16 | 16 | |
17 | - public function deleteByTime($time){ |
|
17 | + public function deleteByTime($time) { |
|
18 | 18 | $this->getQueryBuilder()->from($this->_table) |
19 | 19 | ->where('s_time', '<', $time); |
20 | 20 | $this->_database->delete(); |
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | - public function getKeyValue(){ |
|
24 | + public function getKeyValue() { |
|
25 | 25 | $user_id = 0; |
26 | 26 | return $user_id; |
27 | 27 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | //Autoload function |
3 | - function tests_autoload($class){ |
|
3 | + function tests_autoload($class) { |
|
4 | 4 | $classesMap = array( |
5 | 5 | //Caches |
6 | 6 | 'ApcCache' => CORE_CLASSES_CACHE_PATH . 'ApcCache.php', |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | 'StringHash' => CORE_LIBRARY_PATH . 'StringHash.php', |
41 | 41 | 'Upload' => CORE_LIBRARY_PATH . 'Upload.php', |
42 | 42 | ); |
43 | - if(isset($classesMap[$class])){ |
|
44 | - if(file_exists($classesMap[$class])){ |
|
43 | + if (isset($classesMap[$class])) { |
|
44 | + if (file_exists($classesMap[$class])) { |
|
45 | 45 | require_once $classesMap[$class]; |
46 | 46 | } |
47 | - else{ |
|
47 | + else { |
|
48 | 48 | echo 'File for class ' . $class . ' not found'; |
49 | 49 | } |
50 | 50 | } |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | //put the first letter of class to upper case |
54 | 54 | $class = ucfirst($class); |
55 | 55 | static $classes = array(); |
56 | - if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
57 | 57 | return $classes[$class]; |
58 | 58 | } |
59 | 59 | $found = false; |
60 | 60 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
61 | 61 | $file = $path . $dir . '/' . $class . '.php'; |
62 | - if (file_exists($file)){ |
|
63 | - if (class_exists($class, false) === false){ |
|
62 | + if (file_exists($file)) { |
|
63 | + if (class_exists($class, false) === false) { |
|
64 | 64 | require_once $file; |
65 | 65 | } |
66 | 66 | //already found |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | break; |
69 | 69 | } |
70 | 70 | } |
71 | - if (! $found){ |
|
71 | + if (!$found) { |
|
72 | 72 | //can't use show_error() at this time because some dependencies not yet loaded |
73 | 73 | set_http_status_header(503); |
74 | 74 | echo 'Cannot find the class [' . $class . ']'; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | /* |
79 | 79 | TODO use the best method to get the Log instance |
80 | 80 | */ |
81 | - if ($class == 'Log'){ |
|
81 | + if ($class == 'Log') { |
|
82 | 82 | //can't use the instruction like "return new Log()" |
83 | 83 | //because we need return the reference instance of the loaded class. |
84 | 84 | $log = new Log(); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function & class_loaded($class = null){ |
104 | 104 | static $list = array(); |
105 | - if ($class !== null){ |
|
105 | + if ($class !== null) { |
|
106 | 106 | $list[strtolower($class)] = $class; |
107 | 107 | } |
108 | 108 | return $list; |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function & load_configurations(array $overwrite_values = array()){ |
119 | 119 | static $config; |
120 | - if (empty($config)){ |
|
120 | + if (empty($config)) { |
|
121 | 121 | $file = CONFIG_PATH . 'config.php'; |
122 | 122 | $found = false; |
123 | - if (file_exists($file)){ |
|
123 | + if (file_exists($file)) { |
|
124 | 124 | require_once $file; |
125 | 125 | $found = true; |
126 | 126 | } |
127 | - if (! $found){ |
|
127 | + if (!$found) { |
|
128 | 128 | set_http_status_header(503); |
129 | 129 | echo 'Unable to find the configuration file [' . $file . ']'; |
130 | 130 | die(); |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return mixed the config value |
146 | 146 | */ |
147 | - function get_config($key, $default = null){ |
|
147 | + function get_config($key, $default = null) { |
|
148 | 148 | static $cfg; |
149 | - if (empty($cfg)){ |
|
149 | + if (empty($cfg)) { |
|
150 | 150 | $cfg[0] = & load_configurations(); |
151 | 151 | } |
152 | 152 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @codeCoverageIgnore |
162 | 162 | */ |
163 | - function save_to_log($level, $message, $logger = null){ |
|
164 | - $log =& class_loader('Log', 'classes'); |
|
165 | - if ($logger){ |
|
163 | + function save_to_log($level, $message, $logger = null) { |
|
164 | + $log = & class_loader('Log', 'classes'); |
|
165 | + if ($logger) { |
|
166 | 166 | $log->setLogger($logger); |
167 | 167 | } |
168 | 168 | $log->writeLog($message, $level); |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @codeCoverageIgnore |
177 | 177 | */ |
178 | - function set_http_status_header($code = 200, $text = null){ |
|
179 | - if (empty($text)){ |
|
178 | + function set_http_status_header($code = 200, $text = null) { |
|
179 | + if (empty($text)) { |
|
180 | 180 | $http_status = array( |
181 | 181 | 100 => 'Continue', |
182 | 182 | 101 => 'Switching Protocols', |
@@ -224,18 +224,18 @@ discard block |
||
224 | 224 | 504 => 'Gateway Timeout', |
225 | 225 | 505 => 'HTTP Version Not Supported', |
226 | 226 | ); |
227 | - if (isset($http_status[$code])){ |
|
227 | + if (isset($http_status[$code])) { |
|
228 | 228 | $text = $http_status[$code]; |
229 | 229 | } |
230 | - else{ |
|
230 | + else { |
|
231 | 231 | show_error('No HTTP status text found for your code please check it.'); |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
235 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
236 | 236 | header('Status: ' . $code . ' ' . $text, TRUE); |
237 | 237 | } |
238 | - else{ |
|
238 | + else { |
|
239 | 239 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
240 | 240 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
241 | 241 | } |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @codeCoverageIgnore |
252 | 252 | */ |
253 | - function show_error($msg, $title = 'error', $logging = true){ |
|
253 | + function show_error($msg, $title = 'error', $logging = true) { |
|
254 | 254 | $title = strtoupper($title); |
255 | 255 | $data = array(); |
256 | 256 | $data['error'] = $msg; |
257 | 257 | $data['title'] = $title; |
258 | - if ($logging){ |
|
259 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
258 | + if ($logging) { |
|
259 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
260 | 260 | } |
261 | 261 | $response = & class_loader('Response', 'classes'); |
262 | 262 | $response->sendError($data); |
@@ -270,18 +270,18 @@ discard block |
||
270 | 270 | * |
271 | 271 | * @return boolean true if the web server uses the https protocol, false if not. |
272 | 272 | */ |
273 | - function is_https(){ |
|
273 | + function is_https() { |
|
274 | 274 | /* |
275 | 275 | * some servers pass the "HTTPS" parameter in the server variable, |
276 | 276 | * if is the case, check if the value is "on", "true", "1". |
277 | 277 | */ |
278 | - if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
278 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
279 | 279 | return true; |
280 | 280 | } |
281 | - else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
281 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
282 | 282 | return true; |
283 | 283 | } |
284 | - else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
284 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
285 | 285 | return true; |
286 | 286 | } |
287 | 287 | return false; |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return boolean true if is a valid URL address or false. |
298 | 298 | */ |
299 | - function is_url($url){ |
|
299 | + function is_url($url) { |
|
300 | 300 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
301 | 301 | } |
302 | 302 | |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @param string $controllerClass the controller class name to be loaded |
307 | 307 | * @codeCoverageIgnore |
308 | 308 | */ |
309 | - function autoload_controller($controllerClass){ |
|
310 | - if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
309 | + function autoload_controller($controllerClass) { |
|
310 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
311 | 311 | require_once $path; |
312 | 312 | } |
313 | 313 | } |
@@ -321,11 +321,11 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @return boolean |
323 | 323 | */ |
324 | - function php_exception_handler($ex){ |
|
325 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
326 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
324 | + function php_exception_handler($ex) { |
|
325 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
326 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
327 | 327 | } |
328 | - else{ |
|
328 | + else { |
|
329 | 329 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
330 | 330 | } |
331 | 331 | return true; |
@@ -342,16 +342,16 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @return boolean |
344 | 344 | */ |
345 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
345 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
346 | 346 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
347 | - if ($isError){ |
|
347 | + if ($isError) { |
|
348 | 348 | set_http_status_header(500); |
349 | 349 | } |
350 | - if (! (error_reporting() & $errno)) { |
|
350 | + if (!(error_reporting() & $errno)) { |
|
351 | 351 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
352 | 352 | return; |
353 | 353 | } |
354 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
354 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
355 | 355 | $errorType = 'error'; |
356 | 356 | switch ($errno) { |
357 | 357 | case E_USER_ERROR: |
@@ -367,9 +367,9 @@ discard block |
||
367 | 367 | $errorType = 'error'; |
368 | 368 | break; |
369 | 369 | } |
370 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
370 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
371 | 371 | } |
372 | - if ($isError){ |
|
372 | + if ($isError) { |
|
373 | 373 | die(); |
374 | 374 | } |
375 | 375 | return true; |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | * This function is used to run in shutdown situation of the script |
380 | 380 | * @codeCoverageIgnore |
381 | 381 | */ |
382 | - function php_shudown_handler(){ |
|
382 | + function php_shudown_handler() { |
|
383 | 383 | $lastError = error_get_last(); |
384 | 384 | if (isset($lastError) && |
385 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
385 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
386 | 386 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
387 | 387 | } |
388 | 388 | } |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | * |
401 | 401 | * @return string string of the HTML attribute. |
402 | 402 | */ |
403 | - function attributes_to_string(array $attributes){ |
|
403 | + function attributes_to_string(array $attributes) { |
|
404 | 404 | $str = ' '; |
405 | 405 | //we check that the array passed as an argument is not empty. |
406 | - if (! empty($attributes)){ |
|
407 | - foreach($attributes as $key => $value){ |
|
406 | + if (!empty($attributes)) { |
|
407 | + foreach ($attributes as $key => $value) { |
|
408 | 408 | $key = trim(htmlspecialchars($key)); |
409 | 409 | $value = trim(htmlspecialchars($value)); |
410 | 410 | /* |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | * $attr = array('placeholder' => 'I am a "puple"') |
415 | 415 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
416 | 416 | */ |
417 | - if ($value && strpos('"', $value) !== false){ |
|
417 | + if ($value && strpos('"', $value) !== false) { |
|
418 | 418 | $value = addslashes($value); |
419 | 419 | } |
420 | - $str .= $key.' = "'.$value.'" '; |
|
420 | + $str .= $key . ' = "' . $value . '" '; |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | //remove the space after using rtrim() |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * |
434 | 434 | * @return string the stringfy value |
435 | 435 | */ |
436 | - function stringfy_vars($var){ |
|
436 | + function stringfy_vars($var) { |
|
437 | 437 | return print_r($var, true); |
438 | 438 | } |
439 | 439 | |
@@ -444,18 +444,18 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @return mixed the sanitize value |
446 | 446 | */ |
447 | - function clean_input($str){ |
|
448 | - if (is_array($str)){ |
|
447 | + function clean_input($str) { |
|
448 | + if (is_array($str)) { |
|
449 | 449 | $str = array_map('clean_input', $str); |
450 | 450 | } |
451 | - else if (is_object($str)){ |
|
451 | + else if (is_object($str)) { |
|
452 | 452 | $obj = $str; |
453 | 453 | foreach ($str as $var => $value) { |
454 | 454 | $obj->$var = clean_input($value); |
455 | 455 | } |
456 | 456 | $str = $obj; |
457 | 457 | } |
458 | - else{ |
|
458 | + else { |
|
459 | 459 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
460 | 460 | } |
461 | 461 | return $str; |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | * |
474 | 474 | * @return string the string with the hidden part. |
475 | 475 | */ |
476 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
476 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
477 | 477 | //get the string length |
478 | 478 | $len = strlen($str); |
479 | 479 | //if str is empty |
480 | - if ($len <= 0){ |
|
480 | + if ($len <= 0) { |
|
481 | 481 | return str_repeat($hiddenChar, 6); |
482 | 482 | } |
483 | 483 | //if the length is less than startCount and endCount |
@@ -485,14 +485,14 @@ discard block |
||
485 | 485 | //or startCount is negative or endCount is negative |
486 | 486 | //return the full string hidden |
487 | 487 | |
488 | - if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
488 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
489 | 489 | return str_repeat($hiddenChar, $len); |
490 | 490 | } |
491 | 491 | //the start non hidden string |
492 | 492 | $startNonHiddenStr = substr($str, 0, $startCount); |
493 | 493 | //the end non hidden string |
494 | 494 | $endNonHiddenStr = null; |
495 | - if ($endCount > 0){ |
|
495 | + if ($endCount > 0) { |
|
496 | 496 | $endNonHiddenStr = substr($str, - $endCount); |
497 | 497 | } |
498 | 498 | //the hidden string |
@@ -505,40 +505,40 @@ discard block |
||
505 | 505 | * This function is used to set the initial session config regarding the configuration |
506 | 506 | * @codeCoverageIgnore |
507 | 507 | */ |
508 | - function set_session_config(){ |
|
508 | + function set_session_config() { |
|
509 | 509 | //$_SESSION is not available on cli mode |
510 | - if (! IS_CLI){ |
|
511 | - $logger =& class_loader('Log', 'classes'); |
|
510 | + if (!IS_CLI) { |
|
511 | + $logger = & class_loader('Log', 'classes'); |
|
512 | 512 | $logger->setLogger('PHPSession'); |
513 | 513 | //set session params |
514 | 514 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
515 | 515 | $sessionName = get_config('session_name'); |
516 | - if ($sessionName){ |
|
516 | + if ($sessionName) { |
|
517 | 517 | session_name($sessionName); |
518 | 518 | } |
519 | 519 | $logger->info('Session handler: ' . $sessionHandler); |
520 | 520 | $logger->info('Session name: ' . $sessionName); |
521 | 521 | |
522 | - if ($sessionHandler == 'files'){ |
|
522 | + if ($sessionHandler == 'files') { |
|
523 | 523 | $sessionSavePath = get_config('session_save_path'); |
524 | - if ($sessionSavePath){ |
|
525 | - if (! is_dir($sessionSavePath)){ |
|
524 | + if ($sessionSavePath) { |
|
525 | + if (!is_dir($sessionSavePath)) { |
|
526 | 526 | mkdir($sessionSavePath, 1773); |
527 | 527 | } |
528 | 528 | session_save_path($sessionSavePath); |
529 | 529 | $logger->info('Session save path: ' . $sessionSavePath); |
530 | 530 | } |
531 | 531 | } |
532 | - else if ($sessionHandler == 'database'){ |
|
532 | + else if ($sessionHandler == 'database') { |
|
533 | 533 | //load database session handle library |
534 | 534 | //Database Session handler Model |
535 | 535 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
536 | 536 | |
537 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
537 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
538 | 538 | session_set_save_handler($DBS, true); |
539 | 539 | $logger->info('session save path: ' . get_config('session_save_path')); |
540 | 540 | } |
541 | - else{ |
|
541 | + else { |
|
542 | 542 | show_error('Invalid session handler configuration'); |
543 | 543 | } |
544 | 544 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -561,9 +561,9 @@ discard block |
||
561 | 561 | $logger->info('Session lifetime: ' . $lifetime); |
562 | 562 | $logger->info('Session cookie path: ' . $path); |
563 | 563 | $logger->info('Session domain: ' . $domain); |
564 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
564 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
565 | 565 | |
566 | - if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
566 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
567 | 567 | $logger->info('Session not yet start, start it now'); |
568 | 568 | session_start(); |
569 | 569 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net> |
34 | 34 | */ |
35 | 35 | |
36 | - class Model{ |
|
36 | + class Model { |
|
37 | 37 | |
38 | 38 | /* -------------------------------------------------------------- |
39 | 39 | * VARIABLES |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | * Initialise the model, tie into the CodeIgniter superobject and |
141 | 141 | * try our best to guess the table name. |
142 | 142 | */ |
143 | - public function __construct(Database $db = null){ |
|
144 | - if (is_object($db)){ |
|
143 | + public function __construct(Database $db = null) { |
|
144 | + if (is_object($db)) { |
|
145 | 145 | $this->setDatabaseInstance($db); |
146 | 146 | } |
147 | - else{ |
|
147 | + else { |
|
148 | 148 | $obj = & get_instance(); |
149 | - if (isset($obj->database) && is_object($obj->database)){ |
|
149 | + if (isset($obj->database) && is_object($obj->database)) { |
|
150 | 150 | /** |
151 | 151 | * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
152 | 152 | * to prevent duplication |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
184 | 184 | { |
185 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
185 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
186 | 186 | } |
187 | 187 | $this->_set_where($where); |
188 | 188 | |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | $this->trigger('before_get'); |
225 | 225 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
226 | 226 | { |
227 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
227 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
228 | 228 | } |
229 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
229 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
230 | 230 | $this->getQueryBuilder()->from($this->_table); |
231 | 231 | $result = $this->_database->getAll($type); |
232 | 232 | $this->_temporary_return_type = $this->return_type; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $insert_id = $this->_database->insertId(); |
260 | 260 | $this->trigger('after_create', $insert_id); |
261 | 261 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
262 | - return ! $insert_id ? true : $insert_id; |
|
262 | + return !$insert_id ? true : $insert_id; |
|
263 | 263 | } |
264 | 264 | else |
265 | 265 | { |
@@ -336,13 +336,13 @@ discard block |
||
336 | 336 | { |
337 | 337 | $args = func_get_args(); |
338 | 338 | $data = array(); |
339 | - if (count($args) == 2){ |
|
340 | - if (is_array($args[1])){ |
|
339 | + if (count($args) == 2) { |
|
340 | + if (is_array($args[1])) { |
|
341 | 341 | $data = array_pop($args); |
342 | 342 | } |
343 | 343 | } |
344 | - else if (count($args) == 3){ |
|
345 | - if (is_array($args[2])){ |
|
344 | + else if (count($args) == 3) { |
|
345 | + if (is_array($args[2])) { |
|
346 | 346 | $data = array_pop($args); |
347 | 347 | } |
348 | 348 | } |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | if ($this->soft_delete) |
385 | 385 | { |
386 | 386 | $this->getQueryBuilder()->from($this->_table); |
387 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
387 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
388 | 388 | } |
389 | 389 | else |
390 | 390 | { |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | if ($this->soft_delete) |
409 | 409 | { |
410 | 410 | $this->getQueryBuilder()->from($this->_table); |
411 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
411 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
412 | 412 | } |
413 | 413 | else |
414 | 414 | { |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if ($this->soft_delete) |
431 | 431 | { |
432 | 432 | $this->getQueryBuilder()->from($this->_table); |
433 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
433 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
434 | 434 | } |
435 | 435 | else |
436 | 436 | { |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $key = $this->primary_key; |
501 | 501 | $value = $args[0]; |
502 | 502 | } |
503 | - $this->trigger('before_dropdown', array( $key, $value )); |
|
503 | + $this->trigger('before_dropdown', array($key, $value)); |
|
504 | 504 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
505 | 505 | { |
506 | 506 | $this->getQueryBuilder()->where($this->soft_delete_key, FALSE); |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | { |
526 | 526 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
527 | 527 | { |
528 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
528 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
529 | 529 | } |
530 | 530 | $where = func_get_args(); |
531 | 531 | $this->_set_where($where); |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | { |
542 | 542 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
543 | 543 | { |
544 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
544 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
545 | 545 | } |
546 | 546 | $this->getQueryBuilder()->from($this->_table); |
547 | 547 | $this->_database->getAll(); |
@@ -551,8 +551,8 @@ discard block |
||
551 | 551 | /** |
552 | 552 | * Enabled cache temporary |
553 | 553 | */ |
554 | - public function cached($ttl = 0){ |
|
555 | - if ($ttl > 0){ |
|
554 | + public function cached($ttl = 0) { |
|
555 | + if ($ttl > 0) { |
|
556 | 556 | $this->_database = $this->_database->cached($ttl); |
557 | 557 | } |
558 | 558 | return $this; |
@@ -706,13 +706,13 @@ discard block |
||
706 | 706 | { |
707 | 707 | if (is_object($row)) |
708 | 708 | { |
709 | - if (isset($row->$attr)){ |
|
709 | + if (isset($row->$attr)) { |
|
710 | 710 | unset($row->$attr); |
711 | 711 | } |
712 | 712 | } |
713 | 713 | else |
714 | 714 | { |
715 | - if (isset($row[$attr])){ |
|
715 | + if (isset($row[$attr])) { |
|
716 | 716 | unset($row[$attr]); |
717 | 717 | } |
718 | 718 | } |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | * Return the database instance |
725 | 725 | * @return Database the database instance |
726 | 726 | */ |
727 | - public function getDatabaseInstance(){ |
|
727 | + public function getDatabaseInstance() { |
|
728 | 728 | return $this->_database; |
729 | 729 | } |
730 | 730 | |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | * set the Database instance for future use |
733 | 733 | * @param Database $db the database object |
734 | 734 | */ |
735 | - public function setDatabaseInstance($db){ |
|
735 | + public function setDatabaseInstance($db) { |
|
736 | 736 | $this->_database = $db; |
737 | - if ($this->dbCacheTime > 0){ |
|
737 | + if ($this->dbCacheTime > 0) { |
|
738 | 738 | $this->_database->setCache($this->dbCacheTime); |
739 | 739 | } |
740 | 740 | return $this; |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * Return the loader instance |
745 | 745 | * @return Loader the loader instance |
746 | 746 | */ |
747 | - public function getLoader(){ |
|
747 | + public function getLoader() { |
|
748 | 748 | return $this->loaderInstance; |
749 | 749 | } |
750 | 750 | |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | * @param Loader $loader the loader object |
754 | 754 | * @return object |
755 | 755 | */ |
756 | - public function setLoader($loader){ |
|
756 | + public function setLoader($loader) { |
|
757 | 757 | $this->loaderInstance = $loader; |
758 | 758 | return $this; |
759 | 759 | } |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | * Return the queryBuilder instance this is the shortcut to database queryBuilder |
763 | 763 | * @return object the DatabaseQueryBuilder instance |
764 | 764 | */ |
765 | - public function getQueryBuilder(){ |
|
765 | + public function getQueryBuilder() { |
|
766 | 766 | return $this->_database->getQueryBuilder(); |
767 | 767 | } |
768 | 768 | |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | * @param object $queryBuilder the DatabaseQueryBuilder object |
772 | 772 | * @return object |
773 | 773 | */ |
774 | - public function setQueryBuilder($queryBuilder){ |
|
774 | + public function setQueryBuilder($queryBuilder) { |
|
775 | 775 | $this->_database->setQueryBuilder($queryBuilder); |
776 | 776 | return $this; |
777 | 777 | } |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * Return the FormValidation instance |
782 | 782 | * @return FormValidation the form validation instance |
783 | 783 | */ |
784 | - public function getFormValidation(){ |
|
784 | + public function getFormValidation() { |
|
785 | 785 | return $this->formValidationInstance; |
786 | 786 | } |
787 | 787 | |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | * @param FormValidation $fv the form validation object |
791 | 791 | * @return object |
792 | 792 | */ |
793 | - public function setFormValidation($fv){ |
|
793 | + public function setFormValidation($fv) { |
|
794 | 794 | $this->formValidationInstance = $fv; |
795 | 795 | return $this; |
796 | 796 | } |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | */ |
805 | 805 | public function order_by($criteria, $order = 'ASC') |
806 | 806 | { |
807 | - if ( is_array($criteria) ) |
|
807 | + if (is_array($criteria)) |
|
808 | 808 | { |
809 | 809 | foreach ($criteria as $key => $value) |
810 | 810 | { |
@@ -835,13 +835,13 @@ discard block |
||
835 | 835 | * relate for the relation "belongs_to" |
836 | 836 | * @return mixed |
837 | 837 | */ |
838 | - protected function relateBelongsTo($row){ |
|
838 | + protected function relateBelongsTo($row) { |
|
839 | 839 | foreach ($this->belongs_to as $key => $value) |
840 | 840 | { |
841 | 841 | if (is_string($value)) |
842 | 842 | { |
843 | 843 | $relationship = $value; |
844 | - $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
|
844 | + $options = array('primary_key' => $value . '_id', 'model' => $value . '_model'); |
|
845 | 845 | } |
846 | 846 | else |
847 | 847 | { |
@@ -851,10 +851,10 @@ discard block |
||
851 | 851 | |
852 | 852 | if (in_array($relationship, $this->_with)) |
853 | 853 | { |
854 | - if (is_object($this->loaderInstance)){ |
|
854 | + if (is_object($this->loaderInstance)) { |
|
855 | 855 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
856 | 856 | } |
857 | - else{ |
|
857 | + else { |
|
858 | 858 | Loader::model($options['model'], $relationship . '_model'); |
859 | 859 | } |
860 | 860 | if (is_object($row)) |
@@ -874,13 +874,13 @@ discard block |
||
874 | 874 | * relate for the relation "has_many" |
875 | 875 | * @return mixed |
876 | 876 | */ |
877 | - protected function relateHasMany($row){ |
|
877 | + protected function relateHasMany($row) { |
|
878 | 878 | foreach ($this->has_many as $key => $value) |
879 | 879 | { |
880 | 880 | if (is_string($value)) |
881 | 881 | { |
882 | 882 | $relationship = $value; |
883 | - $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
|
883 | + $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model'); |
|
884 | 884 | } |
885 | 885 | else |
886 | 886 | { |
@@ -890,10 +890,10 @@ discard block |
||
890 | 890 | |
891 | 891 | if (in_array($relationship, $this->_with)) |
892 | 892 | { |
893 | - if (is_object($this->loaderInstance)){ |
|
893 | + if (is_object($this->loaderInstance)) { |
|
894 | 894 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
895 | 895 | } |
896 | - else{ |
|
896 | + else { |
|
897 | 897 | Loader::model($options['model'], $relationship . '_model'); |
898 | 898 | } |
899 | 899 | if (is_object($row)) |
@@ -944,10 +944,10 @@ discard block |
||
944 | 944 | if (!empty($this->validate)) |
945 | 945 | { |
946 | 946 | $fv = null; |
947 | - if (is_object($this->formValidationInstance)){ |
|
947 | + if (is_object($this->formValidationInstance)) { |
|
948 | 948 | $fv = $this->formValidationInstance; |
949 | 949 | } |
950 | - else{ |
|
950 | + else { |
|
951 | 951 | Loader::library('FormValidation'); |
952 | 952 | $fv = $this->formvalidation; |
953 | 953 | $this->setFormValidation($fv); |
@@ -976,7 +976,7 @@ discard block |
||
976 | 976 | * Set WHERE parameters, when is array |
977 | 977 | * @param array $params |
978 | 978 | */ |
979 | - protected function _set_where_array(array $params){ |
|
979 | + protected function _set_where_array(array $params) { |
|
980 | 980 | foreach ($params as $field => $filter) |
981 | 981 | { |
982 | 982 | if (is_array($filter)) |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | /** |
1043 | 1043 | Shortcut to controller |
1044 | 1044 | */ |
1045 | - public function __get($key){ |
|
1045 | + public function __get($key) { |
|
1046 | 1046 | return get_instance()->{$key}; |
1047 | 1047 | } |
1048 | 1048 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @package FileUpload |
38 | 38 | * @version 1.5 |
39 | 39 | */ |
40 | - class Upload{ |
|
40 | + class Upload { |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Version |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @version 1.0 |
70 | 70 | * @var array |
71 | 71 | */ |
72 | - private $file_array = array(); |
|
72 | + private $file_array = array(); |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * If the file you are trying to upload already exists it will |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @version 1.0 |
120 | 120 | * @var float |
121 | 121 | */ |
122 | - private $max_file_size= 0.0; |
|
122 | + private $max_file_size = 0.0; |
|
123 | 123 | |
124 | 124 | /** |
125 | 125 | * List of allowed mime types |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | * @return object |
218 | 218 | * @method object __construct |
219 | 219 | */ |
220 | - public function __construct(){ |
|
221 | - $this->logger =& class_loader('Log', 'classes'); |
|
220 | + public function __construct() { |
|
221 | + $this->logger = & class_loader('Log', 'classes'); |
|
222 | 222 | $this->logger->setLogger('Library::Upload'); |
223 | 223 | |
224 | 224 | Loader::lang('file_upload'); |
225 | - $obj =& get_instance(); |
|
225 | + $obj = & get_instance(); |
|
226 | 226 | |
227 | 227 | $this->error_messages = array( |
228 | 228 | 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'), |
@@ -239,15 +239,15 @@ discard block |
||
239 | 239 | ); |
240 | 240 | |
241 | 241 | $this->file = array( |
242 | - 'status' => false, // True: success upload |
|
243 | - 'mime' => '', // Empty string |
|
244 | - 'filename' => '', // Empty string |
|
245 | - 'original' => '', // Empty string |
|
246 | - 'size' => 0, // 0 Bytes |
|
247 | - 'sizeFormated' => '0B', // 0 Bytes |
|
248 | - 'destination' => './', // Default: ./ |
|
249 | - 'allowed_mime_types' => array(), // Allowed mime types |
|
250 | - 'error' => null, // File error |
|
242 | + 'status' => false, // True: success upload |
|
243 | + 'mime' => '', // Empty string |
|
244 | + 'filename' => '', // Empty string |
|
245 | + 'original' => '', // Empty string |
|
246 | + 'size' => 0, // 0 Bytes |
|
247 | + 'sizeFormated' => '0B', // 0 Bytes |
|
248 | + 'destination' => './', // Default: ./ |
|
249 | + 'allowed_mime_types' => array(), // Allowed mime types |
|
250 | + 'error' => null, // File error |
|
251 | 251 | ); |
252 | 252 | |
253 | 253 | // Change dir to current dir |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | if (isset($_FILES) && is_array($_FILES)) { |
258 | 258 | $this->file_array = $_FILES; |
259 | 259 | } |
260 | - $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
|
260 | + $this->logger->info('The upload file information are : ' . stringfy_vars($this->file_array)); |
|
261 | 261 | } |
262 | 262 | /** |
263 | 263 | * Set input. |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | */ |
274 | 274 | public function setInput($input) |
275 | 275 | { |
276 | - if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
|
276 | + if (!empty($input) && (is_string($input) || is_numeric($input))) { |
|
277 | 277 | $this->input = $input; |
278 | 278 | } |
279 | 279 | return $this; |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | */ |
310 | 310 | public function setAutoFilename() |
311 | 311 | { |
312 | - $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
|
312 | + $this->filename = sha1(mt_rand(1, 9999) . uniqid()); |
|
313 | 313 | $this->filename .= time(); |
314 | 314 | return $this; |
315 | 315 | } |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $php_size = $this->sizeInBytes((int) ini_get('upload_max_filesize')); |
331 | 331 | // Calculate difference |
332 | 332 | if ($php_size < $file_size) { |
333 | - $this->logger->warning('The upload max file size you set [' .$file_size. '] is greather than the PHP configuration for upload max file size [' .$php_size. ']'); |
|
333 | + $this->logger->warning('The upload max file size you set [' . $file_size . '] is greather than the PHP configuration for upload max file size [' . $php_size . ']'); |
|
334 | 334 | } |
335 | 335 | $this->max_file_size = $file_size; |
336 | 336 | } |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | public function setAllowedMimeTypes(array $mimes) |
349 | 349 | { |
350 | 350 | if (count($mimes) > 0) { |
351 | - array_map(array($this , 'setAllowMimeType'), $mimes); |
|
351 | + array_map(array($this, 'setAllowMimeType'), $mimes); |
|
352 | 352 | } |
353 | 353 | return $this; |
354 | 354 | } |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | { |
414 | 414 | if (!empty($name) && is_string($name)) { |
415 | 415 | if (array_key_exists($name, $this->mime_helping)) { |
416 | - return $this->setAllowedMimeTypes($this->mime_helping[ $name ]); |
|
416 | + return $this->setAllowedMimeTypes($this->mime_helping[$name]); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | return $this; |
@@ -432,8 +432,8 @@ discard block |
||
432 | 432 | */ |
433 | 433 | public function setUploadFunction($function) |
434 | 434 | { |
435 | - if (!empty($function) && (is_array($function) || is_string($function) )) { |
|
436 | - if (is_callable( $function)) { |
|
435 | + if (!empty($function) && (is_array($function) || is_string($function))) { |
|
436 | + if (is_callable($function)) { |
|
437 | 437 | $this->upload_function = $function; |
438 | 438 | } |
439 | 439 | } |
@@ -478,8 +478,8 @@ discard block |
||
478 | 478 | $this->destination_directory = $destination_directory; |
479 | 479 | chdir($destination_directory); |
480 | 480 | } |
481 | - else{ |
|
482 | - $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']'); |
|
481 | + else { |
|
482 | + $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']'); |
|
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | public function isFilename($filename) |
530 | 530 | { |
531 | 531 | $filename = basename($filename); |
532 | - return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
|
532 | + return (!empty($filename) && (is_string($filename) || is_numeric($filename))); |
|
533 | 533 | } |
534 | 534 | /** |
535 | 535 | * Validate mime type with allowed mime types, |
@@ -571,11 +571,11 @@ discard block |
||
571 | 571 | */ |
572 | 572 | public function isDirpath($path) |
573 | 573 | { |
574 | - if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
|
574 | + if (!empty($path) && (is_string($path) || is_numeric($path))) { |
|
575 | 575 | if (DIRECTORY_SEPARATOR == '/') { |
576 | - return (preg_match( '/^[^*?"<>|:]*$/' , $path) == 1 ); |
|
576 | + return (preg_match('/^[^*?"<>|:]*$/', $path) == 1); |
|
577 | 577 | } else { |
578 | - return (preg_match( "/^[^*?\"<>|:]*$/" , substr($path,2) ) == 1); |
|
578 | + return (preg_match("/^[^*?\"<>|:]*$/", substr($path, 2)) == 1); |
|
579 | 579 | } |
580 | 580 | } |
581 | 581 | return false; |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | */ |
604 | 604 | public function getInfo() |
605 | 605 | { |
606 | - return (object)$this->file; |
|
606 | + return (object) $this->file; |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | * Check if the file is uploaded |
612 | 612 | * @return boolean |
613 | 613 | */ |
614 | - public function isUploaded(){ |
|
614 | + public function isUploaded() { |
|
615 | 615 | return isset($this->file_array[$this->input]) |
616 | 616 | && is_uploaded_file($this->file_array[$this->input]['tmp_name']); |
617 | 617 | } |
@@ -625,13 +625,13 @@ discard block |
||
625 | 625 | * @return boolean |
626 | 626 | * @method boolean save |
627 | 627 | */ |
628 | - public function save(){ |
|
628 | + public function save() { |
|
629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
630 | 630 | // set original filename if not have a new name |
631 | 631 | if (empty($this->filename)) { |
632 | 632 | $this->filename = $this->file_array[$this->input]['name']; |
633 | 633 | } |
634 | - else{ |
|
634 | + else { |
|
635 | 635 | // Replace %s for extension in filename |
636 | 636 | // Before: /[\w\d]*(.[\d\w]+)$/i |
637 | 637 | // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu |
@@ -655,10 +655,10 @@ discard block |
||
655 | 655 | $this->file['filename'] = $this->filename; |
656 | 656 | $this->file['error'] = $this->file_array[$this->input]['error']; |
657 | 657 | |
658 | - $this->logger->info('The upload file information to process is : ' .stringfy_vars($this->file)); |
|
658 | + $this->logger->info('The upload file information to process is : ' . stringfy_vars($this->file)); |
|
659 | 659 | |
660 | 660 | $error = $this->uploadHasError(); |
661 | - if($error){ |
|
661 | + if ($error) { |
|
662 | 662 | return false; |
663 | 663 | } |
664 | 664 | // Execute input callback |
@@ -692,10 +692,10 @@ discard block |
||
692 | 692 | */ |
693 | 693 | public function sizeFormat($size, $precision = 2) |
694 | 694 | { |
695 | - if($size > 0){ |
|
695 | + if ($size > 0) { |
|
696 | 696 | $base = log($size) / log(1024); |
697 | 697 | $suffixes = array('B', 'K', 'M', 'G', 'T'); |
698 | - return round(pow(1024, $base - floor($base)), $precision) . ( isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
698 | + return round(pow(1024, $base - floor($base)), $precision) . (isset($suffixes[floor($base)]) ? $suffixes[floor($base)] : ''); |
|
699 | 699 | } |
700 | 700 | return null; |
701 | 701 | } |
@@ -719,14 +719,14 @@ discard block |
||
719 | 719 | if (array_key_exists('unit', $matches)) { |
720 | 720 | $unit = strtoupper($matches['unit']); |
721 | 721 | } |
722 | - return (floatval($matches['size']) * pow(1024, $units[$unit]) ) ; |
|
722 | + return (floatval($matches['size']) * pow(1024, $units[$unit])); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
726 | 726 | * Get the upload error message |
727 | 727 | * @return string |
728 | 728 | */ |
729 | - public function getError(){ |
|
729 | + public function getError() { |
|
730 | 730 | return $this->error; |
731 | 731 | } |
732 | 732 | |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | * Set the upload error message |
735 | 735 | * @param string $message the upload error message to set |
736 | 736 | */ |
737 | - public function setError($message){ |
|
737 | + public function setError($message) { |
|
738 | 738 | $this->logger->info('The file upload got error : ' . $message); |
739 | 739 | $this->error = $message; |
740 | 740 | } |
@@ -744,9 +744,9 @@ discard block |
||
744 | 744 | * @param string $type the type of callback "input" or "output" |
745 | 745 | * @return void |
746 | 746 | */ |
747 | - protected function runCallback($type){ |
|
748 | - if (!empty( $this->callbacks[$type])) { |
|
749 | - call_user_func($this->callbacks[$type], (object)$this->file); |
|
747 | + protected function runCallback($type) { |
|
748 | + if (!empty($this->callbacks[$type])) { |
|
749 | + call_user_func($this->callbacks[$type], (object) $this->file); |
|
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
@@ -754,21 +754,21 @@ discard block |
||
754 | 754 | * Check if file upload has error |
755 | 755 | * @return boolean |
756 | 756 | */ |
757 | - protected function uploadHasError(){ |
|
757 | + protected function uploadHasError() { |
|
758 | 758 | //check if file upload is allowed in the configuration |
759 | - if(! ini_get('file_uploads')){ |
|
759 | + if (!ini_get('file_uploads')) { |
|
760 | 760 | $this->setError($this->error_messages['file_uploads']); |
761 | 761 | return true; |
762 | 762 | } |
763 | 763 | |
764 | 764 | //check for php upload error |
765 | - if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
|
765 | + if (is_numeric($this->file['error']) && $this->file['error'] > 0) { |
|
766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
767 | 767 | return true; |
768 | 768 | } |
769 | 769 | |
770 | 770 | //check for mime type |
771 | - if (! $this->checkMimeType($this->file['mime'])) { |
|
771 | + if (!$this->checkMimeType($this->file['mime'])) { |
|
772 | 772 | $this->setError($this->error_messages['accept_file_types']); |
773 | 773 | return true; |
774 | 774 | } |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | * @param int $code the error code |
793 | 793 | * @return string the error message |
794 | 794 | */ |
795 | - private function getPhpUploadErrorMessageByCode($code){ |
|
795 | + private function getPhpUploadErrorMessageByCode($code) { |
|
796 | 796 | $codeMessageMaps = array( |
797 | 797 | 1 => $this->error_messages['upload_err_ini_size'], |
798 | 798 | 2 => $this->error_messages['upload_err_form_size'], |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class DatabaseQueryResult{ |
|
27 | + class DatabaseQueryResult { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The database query result |
31 | 31 | * @var mixed |
32 | 32 | */ |
33 | - private $result = null; |
|
33 | + private $result = null; |
|
34 | 34 | |
35 | 35 | |
36 | 36 | /** |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param mixed $result the query result |
46 | 46 | * @param int $numRows the number of rows returned by the query |
47 | 47 | */ |
48 | - public function __construct($result = null, $numRows = 0){ |
|
48 | + public function __construct($result = null, $numRows = 0) { |
|
49 | 49 | $this->result = $result; |
50 | 50 | $this->numRows = $numRows; |
51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return mixed |
58 | 58 | */ |
59 | - public function getResult(){ |
|
59 | + public function getResult() { |
|
60 | 60 | return $this->result; |
61 | 61 | } |
62 | 62 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return object DatabaseQueryResult |
68 | 68 | */ |
69 | - public function setResult($result){ |
|
69 | + public function setResult($result) { |
|
70 | 70 | $this->result = $result; |
71 | 71 | return $this; |
72 | 72 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return int |
78 | 78 | */ |
79 | - public function getNumRows(){ |
|
79 | + public function getNumRows() { |
|
80 | 80 | return $this->numRows; |
81 | 81 | } |
82 | 82 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return object DatabaseQueryResult |
88 | 88 | */ |
89 | - public function setNumRows($numRows){ |
|
89 | + public function setNumRows($numRows) { |
|
90 | 90 | $this->numRows = $numRows; |
91 | 91 | return $this; |
92 | 92 | } |